Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a steer that misses its turn moves into the run it starts #36855

Mergedjuliusmarmingemerged 4 commits intomain fromrefs/pull/36855/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

The brief listed no items, so this round was the PR watch. On 08d5ff4a3d, Test Server 2 failed in ProviderSwitch.integration.test.ts, test 'fails an unsupported queued handoff and advances to the next queued provider': the republished user_message payload had ordinal 2000001 instead of 1000002. I reproduced it locally with the same test file. The failure comes from the fix, and the new behaviour is the one the issue asks for. The test reuses a message's user_message item for a queued run, and that run fails to start. failQueuedRunStart republishes the item with status 'failed' before the run's error. Because the item is no longer 'pending', it moves into its own run's position range, ahead of that run's error, instead of keeping the previous run's slot. The test had copied the old ordinal through ...queuedItem. It now expects ordinal 2_000_001 and also asserts that the message sits above the failed run's error item. No production code changed this round. On 923f441ed0 all 8 required checks passed and Macroscope approved. CodeRabbit's review of 08d5ff4 said 'No actionable comments' and merge risk Minimal; its check was still running on 923f441 when I stopped. There are no line comments on the PR. The thread-transfer report is within every ceiling.

Fixes pingdotgg/t3code#36840

Reproduction on main

On origin/main 73fb6cd009, added these assertions to the end of the existing test 'starts a steer that missed the turn on the saved next-turn selection' in apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts: the steer's user_message turn item has runId equal to run 2, and its ordinal is above the highest ordinal among run 1's turn items. The test runs the real orchestrator, effect worker and SQLite with a scripted provider. It sends a steer_active message to run 1, completes run 1's provider turn before the steer is delivered, then resumes queued runs, so the steer starts run 2. Ran vp test run src/orchestration-v2/SteeringCompletion.integration.test.ts -t "starts a steer that missed the turn". The runId check passes; the ordering check fails with 'expected 1000002 to be above 1000003'. The message belongs to run 2 but keeps its run 1 position, ahead of run 1's last item. I did not run the timing-dependent in-app steps with a live provider: making a steer miss its turn there is unreliable, and an earlier in-app attempt on #27982 never managed it in 47 tries.

Evidence

Steps: start run 1, send a message with Steer, have the scripted provider complete run 1 before rejecting the missed delivery, let the real server start run 2, then reopen the thread. Real web app, Chromium 1280×800, light theme, fresh synthetic data on each commit. The same scenario fails on base and passes on head.

BeforeAfter
Commit73fb6cd009923f441ed0
ResultOrdering assertion fails; late steer remains above run 1's final replyOrdering assertion passes; late steer follows run 1's final reply
TimelineBefore: missed steer timelineAfter: missed steer timeline
After reloadBefore: incorrect order persists after reloadAfter: correct order persists after reload
Failure captureBefore: assertion failure capture
Interaction recordingBefore recordingAfter recording

Scenario and embedded protocol replay script. Recordings omit pairing screens. Evidence uploaded with ghdrop; no evidence or scenario files committed.

Not shown:

  • Live-provider race frequency was not measured; a scripted protocol replay deterministically forces the missed-delivery ordering through the real adapter and server.
  • The separate failed queued-handoff path covered by the head commit was not exercised; this proof covers the reported missed-steer timeline behavior.

Tests

vp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts: on 08d5ff4a3d, 1 failed and 58 passed, the same failure as CI. After the test update, 59/59 passed. vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (4 files) all passed. CI on 923f441ed0: all 8 required checks passed.

Not in this change

  • The run_start placement option of TurnItemPositionStore.allocate has no callers in apps/server/src; it may be dead code.
  • Positions already saved in a database are not migrated: a thread that hit this before the fix gets corrected only if that message is updated again.
  • steerFollowUpQueuePosition still orders earlier steers by item ordinal; giving it a different way to find earlier steers would make it independent of positions, but it is not needed for this fix.
  • The run_start placement option of TurnItemPositionStore.allocate has no callers in apps/server/src.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

    1. tanstack-source added labelsbug

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      Approvability

      Verdict: Approved at 923f441

      Macroscope's review found this PR approvable — This corrects ordering when a steer starts a later run while preserving submission order for pending steers. The change is limited to item positions, with regression evidence covering both missed-turn and queued-steer scenarios.

      Notes:

      • No code objects were reviewed. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: bef412c · PR result: 923f441 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The position store can move an existing turn item into the selected run’s ordinal range. Tests cover missed-steer placement, declined-steer queue order, and the order of a rejected message and its failure item.

      Changes: Steer Positioning

      Layer / File(s)Summary
      Run-scoped position allocation
      apps/server/src/orchestration-v2/TurnItemPositionStore.ts, apps/server/src/orchestration-v2/TurnItemPositionStore.test.ts
      allocate adds keepExisting and can assign an existing item a position within the selected run’s range. normalize sets keepExisting for pending items. The test expects position 2_000_001 for the specified allocation.
      Steer ordering integration coverage
      apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts, apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
      Tests check that a missed steer belongs to the new run and follows the prior run’s turn items, and that two declined steers remain queued in order. The provider-switch test checks that the rejected message precedes its failure item.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Low

      Suggested reviewers: alb11747

      Merge Risk: Minimal · up to 923f4

      This change fixes the position of a steer message that misses its turn so it appears in the run it starts, after the previous run's final reply. Declined steers keep their queue order. The tests cover the changed behavior, and no concrete merge-blocking risk was found. Messages already stored with the old position are not corrected until they are updated again.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: a steer that misses its turn is moved into the run it starts. This matches the raw summary, which describes repositioning the restarted message into the new run and or…
      Linked Issues checkPassed[#36840] The allocator now moves an existing item into the selected run range when the item is not pending. normalize sets keepExisting for pending items, so a queued steer keeps submission order.…
      Out of Scope Changes checkPassedThe changed source code is limited to turn-item position allocation and pending-item normalization. The changed tests cover missed-turn placement, declined-steer queue order, reused-position allocatio…
      Description checkPassedThe description has a clear problem statement, a detailed change explanation, a linked issue (Fixes pingdotgg/t3code#36840), and extensive verification with test results and evidence. It follows the t…
      Full details: Title check

      Explanation

      The title names the main change: a steer that misses its turn is moved into the run it starts. This matches the raw summary, which describes repositioning the restarted message into the new run and ordering it after the prior run's turn items. The title uses the conventional commit format and is specific. It does not name the keepExisting allocator change, but it does not need to cover every detail.

      Full details: Linked Issues check

      Explanation

      [#36840] The allocator now moves an existing item into the selected run range when the item is not pending. normalize sets keepExisting for pending items, so a queued steer keeps submission order. The missed-turn integration test checks that the steer has the new run ID and an ordinal above all items from the prior run. The allocator test checks allocation in the new run range, and the provider-switch test checks ordering before the failure item. The added two-steers case checks that declined steers retain queue order. These changes satisfy the issue's coding and automated-test requirements. The timing-dependent app reproduction is manual and is not a coding requirement.

      Full details: Out of Scope Changes check

      Explanation

      The changed source code is limited to turn-item position allocation and pending-item normalization. The changed tests cover missed-turn placement, declined-steer queue order, reused-position allocation, and queued-run failure ordering. Each change supports #36840 or verifies the allocator behavior required by that fix. No unrelated change is demonstrated.

      Full details: Description check

      Explanation

      The description has a clear problem statement, a detailed change explanation, a linked issue (Fixes pingdotgg/t3code#36840), and extensive verification with test results and evidence. It follows the template's Problem, Change, Scope, and Verification sections, though the headings are used as stated in the template and the 'Problem' section is covered via the reproduction section rather than a dedicated Problem heading. Some content is repeated (the run_start note appears twice), and the 'Who did the work' attribution is present as the template requests. The description is mostly complete.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 08d5ff4a3d7f972963a982810c5e8946147a5a7e and 923f441ed0741fed34b7e830c84fe282479b3bd6.

      Files selected for processing: 1

      • apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

    6. juliusmarminge merged this8cbaf75

    7. juliusmarminge closed this

Sign in to join this conversation.