Skip to content

Commit b4f6445

Browse files
committed
fix(codex): decode multiline managed-default edits; qualify context-window docs
Review follow-up for #7553. Edit detection now decodes the whole assignment, so a marked value the user rewrote as a multiline string is adopted instead of refusing the sync. The docs note that Codex caps a root model_context_window at each model's maximum window. Refs #7425
1 parent c6862ad commit b4f6445

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎docs-site/src/content/docs/guides/codex-integration.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ copies, and never overwrites a user-owned root `openai_base_url`; if one exists,
409409
catalog but reports that routing was not injected.
410410

411411
Sync and restore also leave a root `model_context_window` in place, since OpenCodex never writes
412-
that key. Codex applies it to every model ahead of the catalog's per-model windows, so delete it
413-
yourself if you want each model to report its own window.
412+
that key. Codex uses it instead of each model's catalog window, capped at that model's maximum
413+
window, so delete it yourself if you want each model to report its own window.
414414
:::
415415

416416
## Shared model catalog

‎src/codex/subagent-defaults.ts‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { splitSourceLines, type SourceLine } from "./toml-source-lines";
1+
import { sourceAssignment, splitSourceLines, type SourceLine } from "./toml-source-lines";
22

33
/**
44
* Pure, ownership-aware edits for Codex's native `[agents]` defaults.
@@ -313,16 +313,6 @@ function invalidInput(content: string, error: string): ManagedSubagentDefaultsTr
313313
return { ok: false, changed: false, content, conflicts: [], error };
314314
}
315315

316-
/** The decoded string value of a single-line `key = "value"` assignment, or null. */
317-
function assignedString(line: SourceLine, key: ManagedSubagentDefaultKey): string | null {
318-
try {
319-
const value = (Bun.TOML.parse(line.text) as Record<string, unknown>)[key];
320-
return typeof value === "string" ? value : null;
321-
} catch { // no-excuse-ok: catch -- an unparsable value is not edit evidence; the replace step rejects it.
322-
return null;
323-
}
324-
}
325-
326316
/**
327317
* Marker lines whose value differs from what OpenCodex recorded writing. The
328318
* marker is dropped so the line reads as what it now is: a user-owned value.
@@ -337,8 +327,10 @@ function userEditedMarkers(
337327
for (const definition of shape.definitions.values()) {
338328
const recorded = written[definition.key];
339329
if (!definition.owned || typeof recorded !== "string") continue;
340-
const current = assignedString(lines[definition.index]!, definition.key);
341-
if (current !== null && current !== recorded) stale.push(definition.index - 1);
330+
// The whole assignment, so a value rewritten as a multiline string still decodes. An
331+
// undecodable value is not edit evidence; the single-line replace step rejects it later.
332+
const current = sourceAssignment(lines, definition.index, shape.agentsEnd ?? lines.length)?.value;
333+
if (typeof current === "string" && current !== recorded) stale.push(definition.index - 1);
342334
}
343335
return stale;
344336
}

‎tests/codex-integration/codex-sync-user-edits.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ describe("managed sub-agent default ownership evidence", () => {
162162
expect(removal.content).toBe('[agents]\ndefault_subagent_model = "user/x"\n');
163163
});
164164

165+
test("an edit rewritten as a multiline string is still recognized as the user's", () => {
166+
const multiline = '[agents]\n' + MANAGED_SUBAGENT_DEFAULT_MARKER + '\ndefault_subagent_model = """\nuser/x"""\n';
167+
const result = transformManagedSubagentDefaults(multiline, { model: "ocx/b" }, { default_subagent_model: "ocx/a" });
168+
expect(result.ok).toBe(true);
169+
expect(result.conflicts.map(conflict => conflict.key)).toEqual(["default_subagent_model"]);
170+
expect(result.content).toBe('[agents]\ndefault_subagent_model = """\nuser/x"""\n');
171+
});
172+
165173
test("without a journaled record the marker alone decides, as before", () => {
166174
const result = transformManagedSubagentDefaults(marked("user/x"), { model: "ocx/b" }, null);
167175
expect(result.content).toContain('default_subagent_model = "ocx/b"');

0 commit comments

Comments
 (0)