diff --git a/extensions/codex/src/app-server/run-attempt.context-engine.test.ts b/extensions/codex/src/app-server/run-attempt.context-engine.test.ts index 88427a9f1549..ae967787d409 100644 --- a/extensions/codex/src/app-server/run-attempt.context-engine.test.ts +++ b/extensions/codex/src/app-server/run-attempt.context-engine.test.ts @@ -525,6 +525,7 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => { params.contextEngine = contextEngine; params.contextTokenBudget = 300_000; params.prompt = "current prompt survives"; + params.currentInboundContext = { text: "current inbound context survives" }; const run = runCodexAppServerAttempt(params); await harness.waitForMethod("turn/start"); @@ -532,6 +533,7 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => { const inputText = getRequestInputText(harness); expect(inputText.length).toBeLessThanOrEqual(CODEX_TURN_START_TEXT_INPUT_MAX_CHARS); expect(inputText).toContain("recent anchor"); + expect(inputText).toContain("current inbound context survives"); expect(inputText).toContain("current prompt survives"); await harness.completeTurn(); diff --git a/extensions/codex/src/app-server/run-attempt.ts b/extensions/codex/src/app-server/run-attempt.ts index c6ef9bb2824b..dc9b10d136c0 100644 --- a/extensions/codex/src/app-server/run-attempt.ts +++ b/extensions/codex/src/app-server/run-attempt.ts @@ -1033,13 +1033,18 @@ export async function runCodexAppServerAttempt( promptInputRange: { start: number; end: number } | undefined, turnPromptText: string, ): CodexProjectedContextRange | undefined => { + const promptTextInputOffset = promptInputRange + ? promptInputRange.end - promptText.length + : undefined; if ( !promptContextRange || !promptInputRange || + promptTextInputOffset === undefined || promptInputRange.start < 0 || promptInputRange.end < promptInputRange.start || promptInputRange.end > prompt.length || - prompt.slice(promptInputRange.start, promptInputRange.end) !== promptText || + promptTextInputOffset < promptInputRange.start || + prompt.slice(promptTextInputOffset, promptInputRange.end) !== promptText || !turnPromptText.endsWith(prompt) ) { return undefined; @@ -1049,7 +1054,7 @@ export async function runCodexAppServerAttempt( // earlier input span. The exact input range still covers prepend-only hooks. const promptTextOffset = prompt.endsWith(promptText) ? prompt.length - promptText.length - : promptInputRange.end - promptText.length; + : promptTextInputOffset; if (promptTextOffset < 0) { return undefined; }