Skip to content

Prevent competing auto turns and false Codex session rebuilds #2241

Description

@ymichael

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:

  1. Start a provider turn and keep the thread in the runtime's pending-turn-start set before its turn/started event is observed.
  2. Submit a turn.submit command with target: { mode: "auto", expectedTurnId: null }, matching the server snapshot in that gap.
  3. Observe that the host daemon calls runTurn and reports appliedAs: "new-turn" instead of waiting for the pending active turn and steering it.
  4. For the Codex-specific rebuild, construct a session with automatic review and permissionEscalation: "ask", then submit a system turn with otherwise identical options and permissionEscalation: "deny".
  5. Observe session/replaced, although both policies map to on-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 ask and deny as different construction signatures under automatic review and replaces the session.

Evidence

Production thread: https://ymichael.getbb.app/projects/proj_qrv2s45kmq/threads/thr_7ccj7nuz57

At the base commit, auto targeting uses only the server's expected id and starts a new turn when it is null:

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:

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

  1. added
    bug
    providers
    threads
    host
    on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughostprovidersthreads

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions