[Bug]: Switching Codex provider instances can leave a thread stuck on "already has an active writer" #8259
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Configure two enabled Codex provider instances in T3 Code that can access the same Codex thread/session store. Use different model selections so T3 treats them as different instances, for example
codexandcodex_a2. - Start a thread on instance A and send a message.
- Interrupt the turn, but leave T3 Code running.
- In the same T3 thread, switch the selected model/provider instance to B and send another message.
- Retry the message after the first failure.
The captured repro used T3 thread e76d... and Codex thread 01a03.... Identifiers are abbreviated here.
Expected behavior#
T3 should release the old provider session before starting the replacement, or perform the replacement atomically. The Codex app-server should have at most one writer for the thread, and the new turn should start once without making the thread unusable.
Actual behavior#
The interrupted turn is persisted as interrupted, but the old Codex app-server runtime remains active. When the provider instance is changed, T3 logs that it is restarting the provider session and passes the previous resume cursor to the new instance.
The new Codex app-server then rejects the request because the same Codex thread already has a writer:
ProviderAdapterProcessError: Provider adapter process error (codex) for thread <t3-thread-id>: thread <codex-thread-id> already has an active writer
[cause]: CodexAppServerRequestError: thread <codex-thread-id> already has an active writer
In the captured run:
- the first turn ended at 06:28:52Z with
turn/completed: interrupted; - at 06:29:16Z T3 changed the selection from
codextocodex_a2; - the restart log reported
currentInstanceId=codex,desiredInstanceId=codex_a2, andhasResumeCursor=true; - the provider start failed before a new turn began;
- a retry at 06:29:52Z failed with the same error.
The current implementation appears to start the target adapter before stopping stale sessions:
- ProviderService.startSession calls the adapter's
startSessionbeforestopStaleSessionsForThread. - ProviderCommandReactor.ensureSessionForThread retains the active session's resume cursor during the instance switch.
- CodexAdapter keeps session state per adapter instance, so the target adapter cannot stop a session held by the previous adapter.
Impact#
Blocks work completely
Version or commit#
T3 Code server package 0.0.34
Environment#
- Linux 6.1.0-40-amd64, x86_64
- Node.js v24.11.1
- Codex CLI 0.149.1
- T3 web/server with two Codex provider instances
Logs or stack traces#
2026-08-26T06:29:16Z
provider command reactor restarting provider session
currentInstanceId=codex
desiredInstanceId=codex_a2
hasResumeCursor=true
2026-08-26T06:29:16Z
CodexAppServerRequestError: thread <codex-thread-id> already has an active writer
2026-08-26T06:29:52Z
CodexAppServerRequestError: thread <codex-thread-id> already has an active writer
No raw logs, prompts, paths, or database files are attached because they may contain private source code or other sensitive data.
Workaround#
Avoid switching Codex provider instances inside an existing T3 thread. Start a new thread on the target instance instead. Restarting T3 before retrying may release the stale runtime, but it also interrupts other active provider sessions.
Suggested fix#
- Enforce a single-writer handoff when changing provider instances: stop or detach the old session before starting the new one, or use an atomic replacement protocol.
- If replacement fails, clean up the attempted target session and leave the thread in an actionable recoverable state.
- Ensure stale lifecycle events from the replaced instance cannot overwrite the new binding.
- Add a regression test that interrupts a Codex turn, switches from instance A to instance B, and verifies that the next turn starts exactly once without an active-writer error.
Related issues#
- #7075 covers large Codex resume responses that can exhaust the T3 server heap. This report concerns the provider-session writer conflict that occurs during instance replacement.
- #4944 covers stale provider shutdown during a Claude instance switch. The lifecycle problem is similar, but this report reproduces the Codex active-writer error.
Disclosure#
I used AI assistance to organize and cross-check the local T3 logs and source. I reviewed the final report, and identifiers and log paths were redacted.
Additional reproduction where the competing writer is the ChatGPT Codex desktop app rather than another T3 provider instance.
Environment#
- T3 Code Alpha 0.0.38
- macOS 26.6.2, arm64
- Codex CLI 0.153.0-alpha.5
- Codex authenticated through Amazon Bedrock
- T3 mobile connected to the desktop-hosted environment
Steps#
- Start or resume a Codex-backed thread in T3 and successfully send a message.
- Open the same underlying Codex thread in the ChatGPT Codex desktop app and send another message there.
- Without quitting the ChatGPT Codex desktop app, return to the same thread from T3 mobile and send another message.
- Retry after the first failure.
Actual result#
T3 repeatedly fails with:
ProviderAdapterProcessError: Provider adapter process error (codex) for thread <t3-thread-id>: thread <codex-thread-id> already has an active writer [cause]: CodexAppServerRequestError: thread <codex-thread-id> already has an active writerQuitting the ChatGPT Codex desktop app releases the writer and allows T3 to continue the thread. Retrying from T3 while the other application remains open does not recover.
Expected result#
T3 should either coordinate a safe writer handoff or surface a recoverable, actionable external-writer state without converting it into a raw provider adapter failure. Once the external writer is gone, retry should re-establish the session without requiring additional cleanup.
This suggests the single-writer lifecycle problem also applies across independent Codex clients sharing a thread, not only when switching between T3 provider instances.
Additional confirmed reproduction on Linux with T3 desktop and a separately running headless T3 server sharing the same T3 home (no provider-instance switch or SSH reconnect required).
Environment:
- T3 Code Alpha 0.0.38
- Codex CLI 0.153.4
- Linux / Wayland
- One persistent
t3 serveprocess and the desktop application's own--bootstrap-fdserver, both using the default T3 state directory and Codex thread store.
Observed sequence:
- Continue a Codex-backed conversation through the headless server.
- Open the same persisted conversation in the native desktop application and try to continue it.
- Desktop fails in
startSession/ensureSessionForThreadwith:
ProviderAdapterProcessError: Provider adapter process error (codex) for thread <t3-thread-id>: thread <codex-thread-id> already has an active writer [cause]: CodexAppServerRequestError: thread <codex-thread-id> already has an active writerLocal process and lock inspection confirms that the corresponding Codex
thread-writer-locks/<thread-id>.lockhas a liveFLOCKowner: acodex app-serverchild of the persistent headless server. The desktop has a separate built-in server process. The headless conversation remains operational. This is a live competing owner, not a stale lock file; deleting the lock would be unsafe.Expected: desktop should detect/reuse the existing compatible local environment, or clearly identify the competing environment and offer a safe connection/handoff. It should not present an opaque adapter error or require killing a server that owns other active conversations. A process-level single-instance guard for the shared state directory may also be relevant.
This extends the cross-client report above to two T3 server processes on the same host. Raw logs, session IDs, project paths, credentials and conversation contents are omitted. Report prepared with AI assistance from local process/lock and application trace evidence.
Additional reproduction when switching among account/provider entries within one existing T3 thread.
Environment#
- T3 Code Alpha 0.0.38
- macOS 26.6.2 (25G83), arm64
- Codex CLI 0.153.4
- Provider/account entries involved: OpenAI, ChatGPT, and Codex
Steps / observed behavior#
- Continue using an existing thread in T3 Code.
- Switch the selected account/provider within that same thread among OpenAI, ChatGPT, and Codex.
- Attempt to send the next turn.
The switch fails in
startSession/ensureSessionForThreadbefore the new turn starts:ProviderAdapterProcessError: Provider adapter process error (codex) for thread eb74...: thread 01a07745... already has an active writer [cause]: CodexAppServerRequestError: thread 01a07745... already has an active writerThe stack reaches
processTurnStartRequestedthroughensureSessionForThreadandstartSession. This appears consistent with the provider-session handoff failure described in the original report, and confirms it still occurs on T3 Code 0.0.38 / Codex CLI 0.153.4 when switching between account-backed provider entries in the same thread.Expected: T3 safely releases or transfers the existing Codex writer during the switch and starts the next turn, or presents an actionable recovery state instead of the raw adapter stack trace.
No project paths, prompts, conversation contents, or full T3 thread identifier are included. Report prepared with AI assistance; environment details and error text were verified locally.
Adding the post-restart context-loss detail from my duplicate report.
I'm experiencing this on macOS with T3 Code Alpha 0.0.38 (commit c0995d2eaf8e) and Codex CLI 0.153.4, using multiple Codex subscriptions with shadow homes sharing session storage.
After subscription A reaches its usage limit:
- Switching to B produces the active-writer error.
- I quit T3 completely and reopen it.
- Continuing the same T3 chat under B works, but the assistant has lost the previous context. The old messages remain visible.
A read-only investigation found a September 5 occurrence where the failed switch was followed by a new Codex thread ID with zero previous turns inside the existing T3 conversation.
Source inspection of the installed bundle suggests a second part of the failure: ProviderService.startSession reuses the persisted resume cursor only when the saved providerInstanceId matches the requested instance. After restarting following a failed switch, the saved binding can still reference A while the selected instance is B, leaving no resume cursor.
Could the fix also cover restarting after a failed switch, verifying that the original conversation context is preserved? Restarting currently clears the error for me but doesn't provide a usable recovery.
These findings came from AI-assisted inspection of local processes, persisted events, and the installed bundle. No patch was applied or tested.
Reporting provenance: The human reporter discovered these failures in their own workflow and directed AI agents to investigate them. They then initiated the upstream reporting process and explicitly asked the agents to review the evidence, prepare the reports, and submit them. GPT-6 Astra in Codex performed the technical investigation and validation, and wrote and submitted this post on the human reporter's behalf.
Confirmed on T3 Code Nightly
0.0.41-nightly.20260908.1414, installed commit5d14c0e9686d8bedf47dd93dd3811fd639255c7e, with Codex CLI0.153.4on macOS arm64.This occurrence adds a normally completed turn case. The previous turn did not need to be interrupted. The process holding the conversation lock was a Codex child of the same T3 server handling the instance switch.
The sequence was: complete a turn on Codex instance A, select compatible instance B in the same T3 conversation, then send a follow-up. Both instances could access the same Codex conversation store. The follow-up failed before a new provider turn began.
Observed sequence, UTC on September 9:
Time Observation 00:35:56.697 Instance A completed its turn successfully; T3 marked its session ready, with no active turn.00:44:07.979 The desktop submitted a model selection for instance B. 00:44:08.128 The next turn was requested using B. Startup failed with thread <codex-thread-id> already has an active writer.Read-only process inspection confirmed that A's
codex app-serverstill had the exact conversation's writer-lock file and transcript open. The runtime binding remained A, while the failed session projection identified B. This was a live session retaining writer ownership after successful completion, not an orphaned lock file.The installed source still has the ordering described in this issue:
ProviderService.startSessionstarts the destination adapter before callingstopStaleSessionsForThread.CodexAdapter.startSessionstops an existing session from that adapter's own session map, which does not release A's session when starting B.
Recovery was possible without restarting T3 or abandoning the conversation: dispatch
thread.session.stopfor the affected task, verify the runtime is stopped and the writer lock has no openers, restore the working instance A, then start the next turn. The provider conversation ID remained unchanged, and fresh replies and tool execution continued. This verifies recovery back to A; it does not establish that an A-to-B handoff works.A regression test should cover switching compatible instances after a normally completed turn, as well as the interrupted-turn case. It should verify that the old writer is released before destination resume, the original resume cursor is preserved, and failure leaves a recoverable binding. I have not tested a patch and am not proposing a bare line reorder without failure-path coverage.
Evidence includes local process ownership, persisted events, installed source maps, and successful same-conversation continuation. Private identifiers, paths, prompts, and credentials are omitted.
Source-verification follow-up to the earlier reproduction: I checked the source embedded in macOS arm64 Nightly
0.0.41-nightly.20260909.1426.In the bundled
apps/server/dist/bin.mjs.map,ProviderService.tslines 1426-1453 still execute this sequence:- Await the destination adapter's
startSession. - Call
stopStaleSessionsForThread. - Persist the new session binding.
The destination startup error handler clears MCP session state, but the stale-session cleanup comes after that awaited startup. If the destination rejects resume because the old adapter still owns the writer, execution does not reach that cleanup. This is the same ordering identified in the earlier report, now checked in
.1426.This follow-up is source evidence only. I have not repeated the live instance-switch reproduction on
.1426or tested a fix. The earlier comment contains the normally completed turn reproduction and the verified recovery back to the original instance.Reporting provenance: The human reporter discovered the original failures and directed the investigation and this follow-up. GPT-6 Astra in Codex inspected the installed source and wrote and submitted this comment at their request.
- Await the destination adapter's
Another reproduction on Nightly
0.0.41-nightly.20260909.1461(commite16b8b05), macOS arm64, confirming thestartSession/stopStaleSessionsForThreadordering is still the cause. Two things this occurrence adds: the previous turn had completed normally and the session had been idle for over three minutes, and the persisted binding survived the failure intact.Environment#
- T3 Code Nightly
0.0.41-nightly.20260909.1461, commite16b8b05, desktop app against its local server - macOS arm64 (Darwin 25.6.0), Node v24.14.0
- Two Codex instances sharing one session store:
codex— default home (~/.codex), resolves tomode: "direct"codex_personal—shadowHomePath: ~/.codex-t3/personal, resolves tomode: "authOverlay"
Both therefore share
sessions/sqliteand produce the samecontinuationKey, so the instance switch passes the compatibility check.Steps to reproduce#
- Run several turns in a thread on
codex_personal. Let the last turn finish normally — no interrupt, no usage limit. - Leave the thread idle (3m14s here).
- Switch the model selector to
codexand send a message in the same thread.
Timeline#
21:12:11Z turn 01a08801… completed (state: completed) 21:15:25Z provider command reactor restarting provider session currentInstanceId: codex_personal desiredInstanceId: codex instanceChanged: true, runtimeModeChanged: false, cwdChanged: false hasResumeCursor: true 21:15:25Z CodexSessionRuntime.start failed after 137ms thread <codex-thread-id> already has an active writer 21:15:25Z startSession → ensureSessionForThread failed after 165ms; no turn startedNotes#
Idle-but-alive is enough. Neither an interrupted turn nor a usage-limit switch is required. The writer was held by a session whose last turn had completed cleanly minutes earlier, which suggests the fix needs to release the source session on any instance switch rather than treating this as an interrupted-turn edge case.
The resume fallback deliberately doesn't cover it.
isRecoverableThreadResumeErrorinCodexSessionRuntime.tsmatches"not found","missing thread","no such thread","unknown thread","does not exist","no rollout found"."already has an active writer"is not in that list, sothread/resumenever falls back tothread/start. That looks correct — falling back here would silently start a fresh thread and drop context — but it does make the error terminal, and retries hit the same wall because cleanup sits after the awaited start.The binding survived this occurrence. After the failure,
provider_session_runtimefor the thread still read:provider_instance_id = codex_personal resume_cursor_json = {"threadId":"01a08779-…"} status = stoppedSo the cursor was not lost, and the thread still resumes with full context on the original instance. That may narrow where the context loss reported in #10414 actually comes from. Reading the source (not observed in this run): after a restart there is no live session, so the reactor takes the fresh-start path with
startProviderSession(undefined), andProviderService.startSessiononly reuses a persisted cursor whenpersistedBinding.providerInstanceIdequals the requested instance — which it never does immediately after a switch. If that reading is right, the loss comes from the restart-then-switch recovery path rather than from the failed switch itself, and both routes are unusable: switching live errors out, switching after a restart starts a fresh Codex thread.
Investigated with Claude Code (Claude Opus 5), working from a source clone of the
v0.0.41-nightly.20260909.1461tag against this machine's server traces and state database. Paths and identifiers abbreviated.- T3 Code Nightly
Also reproduced the following error:
ProviderAdapterProcessError: Provider adapter process error (codex) for thread 55dd3095-1c49-4b6e-a13b-c942857a1067: thread 01a0bb59-f862-7e01-b104-cd86fc5ec313 already has an active writer at file:///home/coder/.t3/runtime/versions/0.0.42/t3:230916:69 at file:///home/coder/.t3/runtime/versions/0.0.42/t3:10250:96 at ~effect/Utils/internal (file:///home/coder/.t3/runtime/versions/0.0.42/t3:2605:10) at startSession (file:///home/coder/.t3/runtime/versions/0.0.42/t3:290512:59) at startSession (definition) (file:///home/coder/.t3/runtime/versions/0.0.42/t3:277924:23) at ensureSessionForThread (file:///home/coder/.t3/runtime/versions/0.0.42/t3:290596:10) at ensureSessionForThread (definition) (file:///home/coder/.t3/runtime/versions/0.0.42/t3:290431:33) at processTurnStartRequested (file:///home/coder/.t3/runtime/versions/0.0.42/t3:291157:12) at processTurnStartRequested (definition) (file:///home/coder/.t3/runtime/versions/0.0.42/t3:290810:36) at processDomainEvent (file:///home/coder/.t3/runtime/versions/0.0.42/t3:291185:46) at processDomainEvent (definition) (file:///home/coder/.t3/runtime/versions/0.0.42/t3:291134:29) { [cause]: CodexAppServerRequestError: thread 01a0bb59-f862-7e01-b104-cd86fc5ec313 already has an active writer at CodexAppServerRequestError.fromProtocolError (file:///home/coder/.t3/runtime/versions/0.0.42/t3:209056:10) at file:///home/coder/.t3/runtime/versions/0.0.42/t3:227048:136 at file:///home/coder/.t3/runtime/versions/0.0.42/t3:227041:11 { [cause]: Error: thread 01a0bb59-f862-7e01-b104-cd86fc5ec313 already has an active writer } }It just appears in the middle of a thread, usually when 2 or more threads are running in parallel, and it shows up in all Codex threads simultaneously. I can continue using the same threads simply by sending new messages afterwards.
Environment
- T3 Code Nightly 0.0.42, desktop app against a remote WSL2 backend via VPN
- Also had the same problem when the WSL2 was on the same computer
- Windows 11 Pro
This happens to me without switching anything, most of my codex threads are now failing with this
This happens when I ask codex to import my codex chat into t3code as well
+1 happening to me without switching anything. Many of my threads fail in this way.
juliusmarminge closed this
Sign in to join this conversation.
Reproduced against current main at 45c0dff8ec33a023c79ccb4e06494309253d1c25
Items 3 through 5 are why a line reorder alone is unsafe
Fix and failure-path tests: #8580