fix(server): fork Codex threads at the native turn boundary #11490
t3code/codex-turn-mapping fromrefs/pull/11490/head·merged by juliusmarminge View on GitHubSummary#
CodexAdapterV2.forkThreadforked the full native Codex thread and then issuedthread/rollbackto reach the selected turn. Newer Codex versions default to paginated durable threads, which rejectthread/rollback, so retry/edit of an earlier turn created the fork but failed the following provider turn.- The adapter now resolves the selected provider turn's
nativeTurnRef.nativeIdand passes it aslastTurnIdon the originalthread/forkrequest. Codex's inclusive boundary semantics exclude later turns atomically, so no rollback is issued on that path. - The historical fork-then-rollback fallback is kept only where it is valid: when no native turn reference is available, and only on forks whose
historyModeislegacy. A paginated fallback fork now fails with an explicitProviderAdapterForkThreadErrorinstead of sending a request Codex rejects. rollbackThreadnow probeshistoryModefirst and returns an honestProviderAdapterRollbackThreadErrorfor paginated threads rather than issuing an unsupportedthread/rollback. Legacy-thread rollback is unchanged.
Focused proof#
- Real replay fixtures updated and driven through the actual orchestration path:
thread_fork_native(latest-turn boundary),thread_fork_native_prior_turn(inclusive earlier boundary, later source turns absent from the emitted fork, no rollback frames),thread_merge_back_continue/thread_merge_back_siblings(boundary on merge-back forks), andthread_rollback(history-mode probe + preserved legacy rollback). - New unit tests cover boundary resolution: latest/prior turn, missing
nativeId, missing provider turn, missing source-turn history, and turn-not-in-source. - New replay-level tests cover paginated fallback fork failure, paginated direct rollback failure, and fork-request error propagation.
vp teston the touched suites: 84 passed / 1 skipped acrossCodexAdapterV2.test.ts(71),ThreadFork(7),ThreadMergeBack(4),CodexReplayFixtures(3); broader replay/contract suites previously green (81). Typecheck exit 0.
Credit#
Adapts the approach first proposed in #9169 by @Yusuf007R, including the lastTurnId boundary and updated fork fixtures, reworked for the current adapter shape with the paginated-history probes added.
Work performed by SWE-2 (Devin) in T3 Code.
Coordination trace: thread 5c350af2-1c4e-4243-9aa9-de40f39b548d, campaign https://github.com/saphid/t3code-personal/issues/298
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
ebe77e1Macroscope's review found this PR approvable — The production change is confined to the Codex adapter and corrects existing fork-boundary behavior using the provider’s native turn ID, with legacy and paginated-history cases explicitly covered by tests. Other modifications are test fixtures or documentation, with no schema, deployment, security, billing, or product-default impact.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).e93075c. Prior analysis still applies.CI note for reviewers: the three failing checks are pre-existing on the base branch, not caused by this diff.
Check: knip flagsapps/server/scripts/verify-background-live.ts(untouched here) as unused.Test:apps/mobile/src/state/thread-order.test.tspending-move tests — this PR touches only server orchestration and docs.Release Smoke:vp install --lockfile-only --ignore-scriptsinfrastructure failure.
CheckandTestfail identically on run 34659363738 for an unrelated PR head (e03e376a3) targeting the same base. All server test shards, Rust, and Macroscope are green on this head.Update: rebased onto
a8cc38b(the upstream fixes for theCheck/Test/Release Smokefailures) and all checks are now green on the new head6a29e65. GitHub merge state: clean. The earlier comment applied to the previous head only.@juliusmarminge ready for maintainer review on head
6a29e65cdfc1a638fc7ae2ac5d5933ad5be1d915(basea8cc38b).Verified state:
- All 20 check runs green or intentionally skipped;
mergeable_state: clean. - Focused suites on the rebased base: 84 passed / 1 skipped, exit 0 (
CodexAdapterV2.test,ThreadFork.integration,CodexReplayFixtures.integration, plus the rollback fixture contract). - Two independent reviews clean on this exact head: Macroscope APPROVED, plus a GPT-6 Astra xhigh post-babysitting review with zero findings.
- Zero review threads; all feedback pages checked.
Summary:
thread/forknow sends the selected turn's native Codex turn ID aslastTurnId, so the fork boundary is inclusive and atomic — no subsequentthread/rollbackon paginated threads (which Codex rejects). Legacy fork-then-rollback is retained only where a native ref is missing on non-paginated history; paginated rollback without a boundary fails explicitly. Builds on the approach from #9169 (credit to @Yusuf007R).- All 20 check runs green or intentionally skipped;
Heads-up for reviewers: upstream rewrote
t3code/codex-turn-mappingand this PR went dirty. Rebased onto the new tipd8c75ec203; head is nowe93075c3bc1f6930101cb13e729af2a6f32f9e44. The transplant was conflict-free and content-identical (only index lines/one hunk offset shifted); focused suites re-passed (84/1) and all CI is green again on the new head. The earlier ready note above named the superseded head6a29e65.juliusmarminge merged thisf8f2ff1
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes