Skip to content

fix(orchestrator): defer queued provider handoff until delivery - #12226

Merged
juliusmarminge merged 12 commits into
t3code/codex-turn-mappingfrom
t3code/queued-provider-handoff
Sep 17, 2026
Merged

juliusmarminge merged 12 commits into
t3code/codex-turn-mappingfrom
t3code/queued-provider-handoff

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Sep 17, 2026

Copy link
Copy Markdown
Member

Problem

Queuing a message for a different provider changed the thread provider and detached the running session before the queued message reached delivery. Earlier queued turns could be interrupted or lose context.

Fix

Keep each queued message's selected provider on its run. Change the thread provider and prepare its handoff only when that run reaches the front. Build context from the runs that actually completed, including a steered replacement turn. Preserve native continuation for compatible account changes. If the queued provider cannot start, fail that run visibly and advance the queue. Web and mobile sends pass the selected model through dispatch without a premature metadata update; mobile preserves queue mode after outbox reload.

Evidence

The provider-switch integration suite has 12 passing tests. It holds an active Codex turn, queues two Codex turns and one Claude turn, then verifies all three Codex responses reach Claude only at delivery. Another scenario steers the active turn to Grok and verifies the later Codex and Claude handoffs include the turns that finished. Focused cases cover native account resumption, imported v1 history after the first provider fails, queued-start rejection advancing to the next message, and the live session's detach event and outbox request at delivery. The mobile outbox suite has 45 passing tests, including a queue-mode storage round trip. Server, web, and mobile typechecks and changed-file lint passed. Required CI checks, including Check and all server test shards, passed on the latest head.

Relationship to #12255

Both PRs remove premature web/mobile model updates and record model selection at dispatch or queued delivery. This PR owns cross-provider queued handoffs. #12255 has separate imported-thread, handoff display, and automatic-message changes. Its overlapping dispatch and client hunks should be deduplicated when the branches are reconciled; applying both copies would duplicate selection events.

Stacked on #2829.

Model: GPT-6. Harness: Codex API.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Sep 17, 2026
@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for cbbd1ce.

This comment will update automatically after the next completed run.

Comment thread apps/mobile/src/state/use-thread-outbox-drain.ts Outdated
Comment thread apps/server/src/orchestration-v2/ProjectionStore.ts
Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
@macroscopeapp

macroscopeapp Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR substantially changes production queued-run orchestration, including cross-provider context handoff, provider-session detachment, projection semantics, and startup failure recovery. Although the new integration coverage is broad and the data changes are additive, the runtime state transitions and downstream effects warrant human review.

Notes:

  • No code objects were reviewed. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
@juliusmarminge
juliusmarminge force-pushed the t3code/queued-provider-handoff branch from 715f5d1 to ff8e024 Compare September 17, 2026 18:18
Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
Comment thread apps/server/src/orchestration-v2/Orchestrator.ts Outdated
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Sep 17, 2026
},
]
: [];
const sessionsToDetach = projection.providerSessions.filter(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new queued-switch session-detachment path has no focused test that verifies the emitted provider-session.detached event and matching provider-session.detach outbox request. The existing switch tests only assert releaseProviderSessionIds at the planning layer, so a wiring regression here would be undetected. Add a queued provider-switch integration test that asserts live sessions selected by the plan are detached and stopped/error sessions are excluded.

No diff: the fix belongs in a test file.

Posted via Macroscope — Effect Service Conventions

@macroscopeapp

This comment has been minimized.

Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
],
);
});
}).pipe(Effect.catch((cause) => failQueuedRunStart(threadId, cause)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new queued-start recovery behavior has no focused test: existing queue tests cover successful promotion and cancellation, but none force startup failure or verify the attempt, node, error turn item, and run are terminalized (including the context_handoff_unsupported mapping). Add an integration test using a failing test layer that exercises this catch path and asserts those persisted events.

No diff: the fix belongs in a test file.

Posted via Macroscope — Effect Service Conventions

@macroscopeapp

This comment has been minimized.

@macroscopeapp

This comment has been minimized.

@macroscopeapp

macroscopeapp Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Effect Service Conventions found one blocking issue: the new queued-start failure recovery path lacks focused integration coverage for its terminal state updates and failure-code mapping. See the inline review comment for the required test coverage.

Posted via Macroscope — Effect Service Conventions

completedAt: now,
updatedAt: now,
};
const handoffTurnItem: OrchestrationV2TurnItem | null =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This newly added queued-handoff timeline behavior has no focused test. Existing queue-promotion tests do not assert the persisted handoff turn item, its context/summary fields, or its ordinal * 100 - 1 placement. Add a queued provider-switch integration test using the existing test layers that verifies this item is emitted and projected correctly.

No diff: the fix belongs in a test file.

Posted via Macroscope — Effect Service Conventions

@macroscopeapp

macroscopeapp Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Effect Service Conventions found one blocking issue: the new queued-handoff timeline behavior lacks focused integration coverage for the emitted and projected handoff turn item. See the inline review comment for the required test coverage.

Posted via Macroscope — Effect Service Conventions

@macroscopeapp

This comment has been minimized.

@juliusmarminge
juliusmarminge merged commit 67c07d4 into t3code/codex-turn-mapping Sep 17, 2026
24 checks passed
@juliusmarminge
juliusmarminge deleted the t3code/queued-provider-handoff branch September 17, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant