diff --git a/src/agents/command/cli-compaction.test.ts b/src/agents/command/cli-compaction.test.ts index f070bd7c2534..fee90b291b2f 100644 --- a/src/agents/command/cli-compaction.test.ts +++ b/src/agents/command/cli-compaction.test.ts @@ -882,7 +882,7 @@ describe("runCliTurnCompactionLifecycle", () => { expect(recordCliCompactionInStore).not.toHaveBeenCalled(); }); - it("falls back to context-engine compaction when Codex owns automatic compaction", async () => { + it("skips context-engine fallback when Codex owns automatic compaction", async () => { const sessionKey = "agent:main:codex-native-auto-compaction"; const sessionId = "session-codex-native-auto-compaction"; const sessionFile = path.join(tmpDir, "session-codex-native-auto-compaction.jsonl"); @@ -954,20 +954,12 @@ describe("runCliTurnCompactionLifecycle", () => { model: "gpt-5.5", }); + // Codex owns automatic compaction; the ownership skip must not fall back to + // context-engine compaction (OAuth-only sessions have no direct API key). expect(compactAgentHarnessSession).toHaveBeenCalledTimes(1); - expect(compactCalls).toHaveLength(1); - expect(compactCalls[0]?.sessionId).toBe(sessionId); - expect(compactCalls[0]?.sessionKey).toBe(sessionKey); - expect(compactCalls[0]?.currentTokenCount).toBe(950); - expect(maintenance).toHaveBeenCalledTimes(1); - expect(recordCliCompactionInStore).toHaveBeenCalledWith( - expect.objectContaining({ - provider: "codex", - sessionKey, - tokensAfter: 100, - }), - ); - expect(result?.compactionCount).toBe(1); + expect(compactCalls).toHaveLength(0); + expect(recordCliCompactionInStore).not.toHaveBeenCalled(); + expect(result).toBe(sessionEntry); const lockedEntry: SessionEntry = { ...sessionEntry, modelSelectionLocked: true }; sessionStore[sessionKey] = lockedEntry; @@ -986,9 +978,8 @@ describe("runCliTurnCompactionLifecycle", () => { }); expect(compactAgentHarnessSession).toHaveBeenCalledTimes(2); - expect(compactCalls).toHaveLength(1); - expect(maintenance).toHaveBeenCalledTimes(1); - expect(recordCliCompactionInStore).toHaveBeenCalledTimes(1); + expect(compactCalls).toHaveLength(0); + expect(recordCliCompactionInStore).not.toHaveBeenCalled(); const lockedNativeCall = compactAgentHarnessSession.mock.calls[1]?.[0]; expect(lockedNativeCall).toMatchObject({ agentHarnessId: "codex", diff --git a/src/agents/command/cli-compaction.ts b/src/agents/command/cli-compaction.ts index aa3e0e86e843..78764150e424 100644 --- a/src/agents/command/cli-compaction.ts +++ b/src/agents/command/cli-compaction.ts @@ -569,14 +569,13 @@ async function compactNativeHarnessCliTranscript(params: { return { compacted: false }; } if (isIntentionalNativeAutoCompactionSkip(result)) { - if (params.sessionEntry.modelSelectionLocked === true) { - return { compacted: false }; - } - return { - compacted: false, - fallbackToContextEngine: true, - failureReason: CODEX_APP_SERVER_OWNS_AUTO_COMPACTION_REASON, - }; + // Codex owns automatic thread compaction (codex-rs runs it inline during + // turns); falling back to context-engine compaction here fought that + // ownership and failed OAuth-only sessions with "No API key found". + log.info( + `CLI native harness compaction skipped for ${params.provider}/${params.model}: ${CODEX_APP_SERVER_OWNS_AUTO_COMPACTION_REASON}`, + ); + return { compacted: false }; } const recoverableBindingFailure = isRecoverableNativeHarnessBindingFailure(result); const fallbackToContextEngine =