fix(server): a steer that misses its turn moves into the run it starts #36855
main fromrefs/pull/36855/head·merged by juliusmarminge View on GitHubThe 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.
| Before | After | |
|---|---|---|
| Commit | 73fb6cd009 | 923f441ed0 |
| Result | Ordering assertion fails; late steer remains above run 1's final reply | Ordering assertion passes; late steer follows run 1's final reply |
| Timeline | ![]() | ![]() |
| After reload | ![]() | ![]() |
| Failure capture | ![]() | |
| Interaction recording | Before recording | After 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_startplacement 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_startplacement 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
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:M
Approvability#
Verdict: Approved at
923f441Macroscope'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.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 1 1 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 1 1 0 (0.0%) 8 ✅ Other scenarios#
All 64 scenario measurements match
main.All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling Codex short turn resumeWebSocket decoded10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅ Codex short turn resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Codex long turn running, cold openHTTP decoded281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅ Codex long turn running, cold openrows75 75 0 (0.0%) 75 ✅ Codex long turn running, history pageHTTP decoded92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅ Codex long turn running, history pagerows75 75 0 (0.0%) 75 ✅ Codex long turn finished, cold openHTTP decoded381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅ Codex long turn finished, cold openrows151 151 0 (0.0%) 151 ✅ Codex long turn finished, socket cold openWebSocket decoded381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅ Codex long turn finished, socket cold openWebSocket messages2 2 0 (0.0%) 2 ✅ Codex long turn finished, socket cold openrows151 151 0 (0.0%) 151 ✅ Codex long turn finished, work pageHTTP decoded186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅ Codex long turn finished, work pagerows150 150 0 (0.0%) 150 ✅ Codex idle thread resumeWebSocket decoded65 B 65 B 0 B (0.0%) 200 B ✅ Codex idle thread resumeWebSocket messages1 1 0 (0.0%) 1 ✅ Codex fleet shell snapshotHTTP decoded42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅ Codex fleet shell snapshotrows27 27 0 (0.0%) 27 ✅ Codex fleet shell subscribeWebSocket decoded65 B 65 B 0 B (0.0%) 200 B ✅ Codex fleet shell subscribeWebSocket messages1 1 0 (0.0%) 1 ✅ Codex fleet shell resume checkHTTP decoded18 B 18 B 0 B (0.0%) 100 B ✅ Codex fleet shell resume checkrows0 0 0 0 ✅ Codex stale shell reloadHTTP decoded42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅ Codex stale shell reloadrows27 27 0 (0.0%) 27 ✅ Codex stale shell resumeWebSocket decoded140 B 140 B 0 B (0.0%) 400 B ✅ Codex stale shell resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Codex stale todo list cold openHTTP decoded72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅ Codex stale todo list cold openrows75 75 0 (0.0%) 75 ✅ Codex stale todo list cold opennodes2 2 0 (0.0%) 4 ✅ Codex stale todo list cold opensubagents2 2 0 (0.0%) 4 ✅ Codex stale todo list cold openplans1 1 0 (0.0%) 2 ✅ Codex stale todo list cold openproviderTurns1 1 0 (0.0%) 2 ✅ Codex stale todo list cold opencheckpoints1 1 0 (0.0%) 2 ✅ Claude short turn resumeWebSocket decoded10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅ Claude short turn resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Claude long turn running, cold openHTTP decoded283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅ Claude long turn running, cold openrows75 75 0 (0.0%) 75 ✅ Claude long turn running, history pageHTTP decoded93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅ Claude long turn running, history pagerows75 75 0 (0.0%) 75 ✅ Claude long turn finished, cold openHTTP decoded384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅ Claude long turn finished, cold openrows151 151 0 (0.0%) 151 ✅ Claude long turn finished, socket cold openWebSocket decoded384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅ Claude long turn finished, socket cold openWebSocket messages2 2 0 (0.0%) 2 ✅ Claude long turn finished, socket cold openrows151 151 0 (0.0%) 151 ✅ Claude long turn finished, work pageHTTP decoded188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅ Claude long turn finished, work pagerows150 150 0 (0.0%) 150 ✅ Claude idle thread resumeWebSocket decoded66 B 66 B 0 B (0.0%) 200 B ✅ Claude idle thread resumeWebSocket messages1 1 0 (0.0%) 1 ✅ Claude fleet shell snapshotHTTP decoded43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅ Claude fleet shell snapshotrows27 27 0 (0.0%) 27 ✅ Claude fleet shell subscribeWebSocket decoded66 B 66 B 0 B (0.0%) 200 B ✅ Claude fleet shell subscribeWebSocket messages1 1 0 (0.0%) 1 ✅ Claude fleet shell resume checkHTTP decoded18 B 18 B 0 B (0.0%) 100 B ✅ Claude fleet shell resume checkrows0 0 0 0 ✅ Claude stale shell reloadHTTP decoded43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅ Claude stale shell reloadrows27 27 0 (0.0%) 27 ✅ Claude stale shell resumeWebSocket decoded140 B 140 B 0 B (0.0%) 400 B ✅ Claude stale shell resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Claude stale todo list cold openHTTP decoded73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅ Claude stale todo list cold openrows75 75 0 (0.0%) 75 ✅ Claude stale todo list cold opennodes2 2 0 (0.0%) 4 ✅ Claude stale todo list cold opensubagents2 2 0 (0.0%) 4 ✅ Claude stale todo list cold openplans1 1 0 (0.0%) 2 ✅ Claude stale todo list cold openproviderTurns1 1 0 (0.0%) 2 ✅ Claude stale todo list cold opencheckpoints1 1 0 (0.0%) 2 ✅ Baseline:
bef412c· PR result:923f441· Source CI: successScenario 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.
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.tsallocateaddskeepExistingand can assign an existing item a position within the selected run’s range.normalizesetskeepExistingfor pending items. The test expects position2_000_001for 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.tsTests 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 to923f4-
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:
4-
Check name Status Explanation Title check 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 or… Linked Issues check [ #36840] The allocator now moves an existing item into the selected run range when the item is not pending.normalizesetskeepExistingfor pending items, so a queued steer keeps submission order.…Out of Scope Changes check 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 allocatio… Description check 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 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.normalizesetskeepExistingfor 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 addedtwo-steerscase 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
#36840or 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: factory/issue-36840
- File: .coderabbit.config.ts
- Commit: 923f441
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
0008f794-0591-4c41-adac-b0244369716f
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.
-
-
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this8cbaf75
juliusmarminge closed this
Sign in to join this conversation.





macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes