Repository navigation
Description
Summary
An auto-targeted message can start a competing provider turn when the server has already marked the thread active but has not yet observed the provider's turn/started id. In Codex, alternating user and system turns can also rebuild the session unnecessarily because bb's differing permissionEscalation intent is included in the construction signature even when both intents map to the same effective Codex permission settings.
The observed result was that an accepted user message disappeared while a child-completion system notification ran and replied instead. The user message should have remained the active turn, with the notification steered into it.
Versions and environment
- From source at
121dad439e38aa74c6c9490a11f287823d981594 - macOS 26.6.2 (25G83), remote bb Connect session
- Node v26.7.0
- Codex CLI 0.148.0
- Provider: Codex
Steps to reproduce
The production race is timing-sensitive. A deterministic reproduction of the same command path is:
- Start a provider turn and keep the thread in the runtime's pending-turn-start set before its
turn/startedevent is observed. - Submit a
turn.submitcommand withtarget: { mode: "auto", expectedTurnId: null }, matching the server snapshot in that gap. - Observe that the host daemon calls
runTurnand reportsappliedAs: "new-turn"instead of waiting for the pending active turn and steering it. - For the Codex-specific rebuild, construct a session with automatic review and
permissionEscalation: "ask", then submit a system turn with otherwise identical options andpermissionEscalation: "deny". - Observe
session/replaced, although both policies map toon-request, automatic approval review, and the workspace-write sandbox.
Expected vs actual
Expected:
- Auto input is resolved against the daemon's live turn state.
- If a turn start is in flight, the input waits for its id and steers that turn.
- Codex reuses a session whenever the effective construction settings are unchanged.
Actual:
- A null server-side turn-id snapshot unconditionally takes the new-turn path.
- Codex treats
askanddenyas different construction signatures under automatic review and replaces the session.
Evidence
Production thread: https://ymichael.getbb.app/projects/proj_qrv2s45kmq/threads/thr_7ccj7nuz57
- The user's PR Cancel an inline sent-message edit with Escape #1940 request was recorded at event sequence 674.
- A child-completion system notification arrived roughly 600 ms later at sequence 676.
- The user turn was accepted at sequence 681, then a second Codex session rebuild at sequence 685 terminated it.
- The system notification ran and replied
Noted; no child was started for PR Cancel an inline sent-message edit with Escape #1940 until the user resent the request.
At the base commit, auto targeting uses only the server's expected id and starts a new turn when it is null:
bb/apps/host-daemon/src/command-handlers/thread.ts
Lines 419 to 433 in 121dad4
| switch (command.target.mode) { | |
| case "start": | |
| return await runSubmittedTurn(stagedCommand, entry); | |
| case "auto": | |
| return command.target.expectedTurnId | |
| ? await steerSubmittedTurn( | |
| stagedCommand, | |
| entry, | |
| command.target.expectedTurnId, | |
| ) | |
| : await runSubmittedTurn(stagedCommand, entry); | |
| case "steer": | |
| if (!command.target.expectedTurnId) { | |
| // The server saw no active turn, but the user's intent is still "send". | |
| return await runSubmittedTurn(stagedCommand, entry); |
The Codex construction signature includes raw permissionEscalation rather than the effective Codex policy:
bb/plugins/provider-codex/src/bridge/bridge.ts
Lines 491 to 504 in 121dad4
| function constructionSignature( | |
| cwd: string, | |
| sessionOptions: CodexSessionOptions, | |
| ): string { | |
| return JSON.stringify({ | |
| cwd, | |
| reasoningLevel: sessionOptions.reasoningLevel ?? null, | |
| memoryEnabled: sessionOptions.memoryEnabled ?? null, | |
| providerSubagentsEnabled: sessionOptions.providerSubagentsEnabled ?? null, | |
| permissionMode: sessionOptions.permissionMode, | |
| permissionScope: sessionOptions.permissionScope, | |
| approvalReviewer: sessionOptions.approvalReviewer, | |
| permissionEscalation: sessionOptions.permissionEscalation, | |
| }); |
What you ruled out
- Not a duplicate of Provider processes need one host-daemon lease owner tied to active turns #1363: that issue covers provider-process lease ownership and leaking processes, not competing turn submission.
- The dispatch race is provider-agnostic because it occurs in the shared host-daemon command handler.
- The false session rebuild is Codex-specific; the other bridges do not use this Codex construction signature.
- The message was persisted and accepted; it was not lost at the UI or server input boundary.
Suggested priority and effort
High priority, small-to-medium effort: the race can silently discard accepted user work, and it has no reliable user workaround beyond resending the message.
AGENT GENERATED: by GPT-5
Activity
Prevent competing turns and false Codex session rebuilds (#2242)
Preserve stale sends by re-steering the live turn (#2379)