fix(server): held assistant drafts keep their position when flushed at turn end #19023
main fromrefs/pull/19023/head·merged by juliusmarminge View on GitHubProblem#
Fixes #18652
When a Codex steer cuts off a streaming commentary draft, that held draft is only written at turn end. Its turn item gets a position at that moment, behind every item that started after it, so the old draft shows up as the turn's answer and the real answer folds under "Worked for …".
Change#
In RunExecutionService, the first streaming turn_item.updated for a held assistant message or reasoning item now reserves its position through TurnItemPositionStore. When the draft is flushed at turn end it keeps the slot it started in. TurnItemPositionStore.layer is provided to the run execution layer in runtimeLayer.ts and the replay test harness, and one replay fixture's expected output is updated for the corrected order.
Happy to drop or rework this if it conflicts with the orchestration V2 rewrite.
Scope and approval#
Triaged bug: #18652, confirmed on main by Julius in https://github.com/pingdotgg/t3code/issues/18652#issuecomment-6124691299.
Verification#
- Added a unit case in
RunExecutionService.test.tsand aSteeringCompletion.integration.test.tscase that steers mid-draft and checks the final item order. cd apps/server && bun run test src/orchestration-v2/RunExecutionService.test.ts src/orchestration-v2/SteeringCompletion.integration.test.ts src/orchestration-v2/testkit: 11 files, 294/294 pass.- Lint, format and server typecheck are clean.
- Not checked against a live Codex session.
Written with Claude Sonnet 5.5 in t3code; I reviewed the diff and ran the checks.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
8959c97Macroscope's review found this PR approvable — This is a focused orchestration bug fix that preserves the position of held assistant drafts when they are later flushed, with a targeted integration regression test. Production wiring is limited to the existing position store, and no defaults, schemas, infrastructure, security-sensitive code, or static-analysis overrides are changed.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
00f8f580-4975-40f1-9121-04f9501a6cb0
📥 Commits
-
Reviewing files that changed from the base of the PR and between 6524a8d43795dc543f7cfb572388cdea3662ad48 and 8959c97e72fe76dd3d20d8218dff7c94e05bcbe5.
📒 Files selected for processing (6)
-
apps/server/src/orchestration-v2/RunExecutionService.test.tsapps/server/src/orchestration-v2/RunExecutionService.tsapps/server/src/orchestration-v2/SteeringCompletion.integration.test.tsapps/server/src/orchestration-v2/runtimeLayer.tsapps/server/src/orchestration-v2/testkit/ProviderReplayHarness.tsapps/server/src/orchestration-v2/testkit/fixtures/opencode2_tool_call/output.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The execution service now reserves positions for held streaming assistant messages and reasoning items. Runtime layers provide the position store. Tests cover item ordering during steering and tool-call streaming.
Changes: Held assistant item positions
Layer / File(s) Summary Reserve positions for held items
apps/server/src/orchestration-v2/RunExecutionService.ts,apps/server/src/orchestration-v2/runtimeLayer.ts,apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts,apps/server/src/orchestration-v2/RunExecutionService.test.ts,apps/server/src/orchestration-v2/testkit/fixtures/opencode2_tool_call/output.tsThe execution service allocates a position once when it holds a streaming assistant message or reasoning item. Runtime and test layers provide the position store. The tool-call fixture expects the assistant message before the tool calls. Verify steering item order
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.tsThe integration test verifies that an incomplete assistant draft remains before commentary and the steer, and that the final answer follows the steer. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeFixed issue severity: Medium
Merge Risk: ⚪ Minimal · up to
8959c-
The held-draft ordering fix has no demonstrated merge-blocking issue.
Security architecture risk: 🔵 Low · up to
8959c-
The change is limited to conversation ordering and reuses existing storage and provider-event routing. No new access or privilege path was identified, but interruption and restart behavior is not fully established.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The added write affects ordering metadata in the existing server database. It does not itself persist held text, execute tools, issue credentials or modify deployment authority. Delivered turn items already reached this allocator using their provider-supplied identity before the change.
Trust Boundaries and Controls
- observed — Provider-event routing precedes the new allocation branch. Turn-item routing accepts the current run or an owned child thread; its separate inherited-background route requires an exact carried-over identity and a background-capable item type. These are existing ingestion controls, not a newly demonstrated tenant-authentication boundary.
Resilience and Maintainability Implications
- inferred — If execution stops before a final item update, a reserved ordinal can remain without projected content. The store has no per-item release; full projection rebuild instead clears reservations and reconstructs them from committed events. This establishes a metadata-lifecycle limitation, not a verified security failure or guaranteed recovery of held text.
- observed — Allocation errors enter the existing ingestion-failure handler, which attempts guarded run finalization and closes the subscription. The position table enforces unique thread/item and thread/ordinal keys, while SQLite is configured to wait for competing writers. These controls limit failure effects but do not prove every concurrent or interrupted execution outcome.
-
Pre-merge checks:
4-
Passed checks (4 passed)-
Check name Status Explanation Title check The title is concise, specific, and accurately describes the main fix for held assistant drafts. Description check The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, linked issue, focused tests, observed results, and the live-s… Linked Issues check Issue #18652requires a cut-off commentary item to remain before the steer and the final answer to remain after it.RunExecutionServicenow allocates a position for the first streaming `assistant_me…Out of Scope Changes check The changes stay within issue #18652. Production changes reserve positions for held streaming assistant items and provide the required store layer. Test changes cover the regression, update test depen…
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge merged thisa917d84
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes