Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): fork Codex threads at the native turn boundary #11490

Mergedsaphid(GitHub profile, opens in a new tab)merged 1 commit intot3code/codex-turn-mapping fromrefs/pull/11490/headmerged by juliusmarminge View on GitHub

Summary

  • CodexAdapterV2.forkThread forked the full native Codex thread and then issued thread/rollback to reach the selected turn. Newer Codex versions default to paginated durable threads, which reject thread/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.nativeId and passes it as lastTurnId on the original thread/fork request. 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 historyMode is legacy. A paginated fallback fork now fails with an explicit ProviderAdapterForkThreadError instead of sending a request Codex rejects.
  • rollbackThread now probes historyMode first and returns an honest ProviderAdapterRollbackThreadError for paginated threads rather than issuing an unsupported thread/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), and thread_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 test on the touched suites: 84 passed / 1 skipped across CodexAdapterV2.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

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at ebe77e1

      Macroscope'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 e93075c. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. CI note for reviewers: the three failing checks are pre-existing on the base branch, not caused by this diff.

      • Check: knip flags apps/server/scripts/verify-background-live.ts (untouched here) as unused.
      • Test: apps/mobile/src/state/thread-order.test.ts pending-move tests — this PR touches only server orchestration and docs.
      • Release Smoke: vp install --lockfile-only --ignore-scripts infrastructure failure.

      Check and Test fail 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.

    4. Update: rebased onto a8cc38b (the upstream fixes for the Check/Test/Release Smoke failures) and all checks are now green on the new head 6a29e65. GitHub merge state: clean. The earlier comment applied to the previous head only.

    5. @juliusmarminge ready for maintainer review on head 6a29e65cdfc1a638fc7ae2ac5d5933ad5be1d915 (base a8cc38b).

      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/fork now sends the selected turn's native Codex turn ID as lastTurnId, so the fork boundary is inclusive and atomic — no subsequent thread/rollback on 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).

    6. Heads-up for reviewers: upstream rewrote t3code/codex-turn-mapping and this PR went dirty. Rebased onto the new tip d8c75ec203; head is now e93075c3bc1f6930101cb13e729af2a6f32f9e44. 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 head 6a29e65.

    7. juliusmarminge merged thisf8f2ff1

    8. juliusmarminge closed this

Sign in to join this conversation.