fix(codex): bound inbound projected context

This commit is contained in:
Vincent Koc
2026-06-21 00:40:42 +08:00
committed by Vincent Koc
parent 7e80bb8abf
commit 43e8c29fbf
2 changed files with 9 additions and 2 deletions

View File

@@ -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();

View File

@@ -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;
}