Skip to content

Codex thread stays running forever when a message is sent before its launch worktree is bound #44106

Done

Description

@Risardo

What happened

An orchestrating agent launches Codex threads over MCP with t3_thread_launch (workspaceStrategy: { type: "worktree", baseRef: "origin/main", startFromOrigin: true }, no initial message), then sends the brief with t3_thread_send. Four such threads stayed running for hours. Every later message queued behind run 1 and never started. Codex had in fact finished each turn within 5 to 10 minutes, but T3 never recorded it.

Diagnosis

A message-less t3_thread_launch returns before worktree preparation finishes, while worktreePath is still null. In ThreadLaunchService.launch, runId is null, so schedulePreparation runs in the background. The t3_thread_send that follows dispatches a normal message. Nothing marks the thread as still preparing, so run 1 starts at once on the shared Codex app-server, with cwd set to the project root.

About 2 s later, preparation dispatches thread.metadata.update with the new worktreePath (${commandId}:workspace). In Orchestrator.ts, a worktreePath change puts every live provider session into detachSessionIds and queues provider-session.detach ("Workspace changed."). That path never checks for an active run. provider.switch and thread.model-selection.set do check, and they reject with OrchestratorProviderSelectionBusyError.

The detach effect runs right after provider-turn.start settles. ProviderSessionManager.detach looks for running provider turns to interrupt and finds none, because the turn has only just started. It then calls CodexAdapterV2.unloadThread, which sends thread/unsubscribe 10 ms after turn/started. After unsubscribe, the connection never receives turn/completed. unloadThread finalizes only turns that are already being interrupted, so the T3 run stays running permanently.

Side effect: the agent ran the whole turn in the main checkout, not in the worktree bound to the thread.

The same code is still on main (Orchestrator.ts, the detachSessionIds branch for thread.metadata.update).

Steps to reproduce

  1. Use any git project with the Codex provider. The shared app-server session is the default.
  2. Over MCP, call t3_thread_launch with a Codex model, workspaceStrategy: { type: "worktree" } and no initialMessage.
  3. As soon as it returns, before t3_thread_read shows a non-null worktreePath, call t3_thread_send with any prompt that takes more than a few seconds.
  4. Expected: the run executes in the worktree, or waits for it, and completes. Actual: the provider event log shows turn/start with the project root as cwd, then thread/unsubscribe right after turn/started. The thread stays running and later messages queue forever.

Threads launched with workspace root (no worktree) on the same server complete normally. Their only thread/unsubscribe is the idle unload about 30 minutes after turn/completed.

Version

0.1.14-nightly.20261127.5319 (desktop app with its bundled local server; commit ee5b846)

Environment

Windows 11 x64 (10.0.26300), Node v24.22.1, codex-cli 0.172.0, desktop app against local server

Evidence

# provider event log of one affected thread (UTC)
04:02:46.823Z  outgoing thread/start   cwd=<home>\projects\xbot-dashboard        # project root, not the worktree
04:02:50.582Z  outgoing turn/start     cwd=<home>\projects\xbot-dashboard
04:02:50.611Z  incoming turn/started   turn 01a21b2b-9458-...
04:02:50.621Z  outgoing thread/unsubscribe {threadId: 01a21b2b-85ae-...}
04:02:50.622Z  incoming {result: {status: "unsubscribed"}}
04:12:26.643Z  incoming thread/readState/changed, thread/status/changed ... thread/closed   # no turn/completed

# orchestration_v2_effect_outbox for the same thread
provider-turn.start      created 04:02:46.786Z  completed 04:02:50.608Z
provider-session.detach  created 04:02:49.040Z  completed 04:02:50.622Z  detail="Workspace changed."

# projection run 1: status=running, startedAt=04:02:50.412Z, completedAt=null, no workspacePreparation
# thread: worktreePath=<home>\projects\worktrees\t3code\xbot-dashboard\t3-cecb386d-..., runs 2..5 queued

The same sequence (provider-turn.start, then provider-session.detach "Workspace changed." about 1.5 s later, then unsubscribe 10 ms after turn/started) appears on all four affected threads, in three different repos.

Related issues

#35274 (Grok run stuck after t3_worktree_handoff) and #36086 (Codex native child stuck after thread/unsubscribe) end the same way: a turn whose completion never arrives after an unload. Neither has this trigger, a launch-time worktree bind racing an already-started run. #21953 is another workspace-change detach that cuts a run off.

Fix applied or workaround

Nothing was changed on the machine. Workaround for MCP callers: pass the brief as initialMessage to t3_thread_launch, so the run is created as preparing and starts only after the worktree is bound. Alternatively, poll t3_thread_read until worktreePath is non-null before calling t3_thread_send. Stuck threads can be archived or have run 1 interrupted.

Possible fixes: reject or defer a t3_thread_send while launch preparation is pending, and/or make the worktreePath-change detach refuse or wait when a run is active, as provider switching does.

Filed by

Claude Code (claude-opus-5-5) via t3 triage

Activity

  1. added
    via-triage
    on Nov 27, 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

    via-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions