[Bug]: App restart during active turns leaves threads stuck on Working forever, with no startup reconciliation of dead provider sessions #4584
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#
- In the desktop app, start threads on worktrees and let a codex provider turn run (long tasks, several minutes in).
- While the turns are running, the desktop app process exits and a new instance starts. Any restart path hits this: manual relaunch, crash, or an updater cycling the app. No Stop is pressed at any point.
- Relaunch completes. Open the sidebar.
- Send a message to one of the affected threads.
Three concurrent codex threads hit this in one event, so it reproduces reliably when the app dies mid-turn.
Expected behavior#
On startup the server reconciles session rows marked running against provider sessions that are actually alive. A thread whose provider process died with the app should surface as interrupted or failed, accept new messages, and either deliver or bounce anything queued.
Actual behavior#
The threads show Working forever. The timer keeps counting (observed past 3h55m), messages sent to the thread queue and never deliver, and there is no stop or steer affordance to break out. Restarting the app again does not clear it.
The persisted state shows the mismatch. Hours after the provider sessions died, state.sqlite still reports for all three threads:
projection_thread_sessions.status = running
active_turn_id IS NOT NULL
while the codex rollout files under ~/.codex/sessions/ for those same sessions had received no writes since the moment the app restarted, and each ends mid-turn (last records are a reasoning item or tool output, no task_complete).
This looks related to #4561 but is a different path: #4561 needs an explicit Stop before quit and describes a durable stopped state that never replays. Here nothing was stopped. The turns were live when the process died, so no terminal state was persisted at all, and nothing at startup notices that the running rows point at provider sessions that no longer exist.
Impact#
Major degradation or frequent failure
Version or commit#
v0.0.29-nightly.20260725.899 (desktop AppImage)
Environment#
Ubuntu 24.04.4, desktop AppImage, codex-cli 0.145.0 app-server provider
Logs or stack traces#
# journal: new app instance starts while three codex turns are mid-flight
Jul 26 10:04:46 systemd[2035]: Started app-t3code-3992110.scope.
# rollout files for the three sessions: mtime frozen at the restart, no task_complete
# (checked ~4h later, threads still shown as Working)
-rw-rw-r-- 656155 Jul 26 10:04 rollout-2026-07-26T09-53-33-<uuid-1>.jsonl
-rw-rw-r-- 501651 Jul 26 10:04 rollout-2026-07-26T09-54-24-<uuid-2>.jsonl
-rw-rw-r-- 496560 Jul 26 10:04 rollout-2026-07-26T09-55-08-<uuid-3>.jsonl
# state.sqlite, ~4h after the restart, same three threads
sqlite> select s.status, s.provider_name, s.active_turn_id is not null
from projection_thread_sessions s join projection_threads t using(thread_id)
where t.thread_id in (...);
running|codex|1
running|codex|1
running|codex|1
Workaround#
Detection: compare the rollout file mtime under ~/.codex/sessions/YYYY/MM/DD/ against the sidebar timer. Hours-stale mtime plus status = running in state.sqlite means the thread is a ghost.
Recovery: the work is salvageable outside the app. codex exec resume <session-uuid> (uuid from the rollout filename) resumes the dead session headless with full context, and the worktree still holds any uncommitted files. The ghost thread itself can only be archived. Nothing clears its Working state.
Recovery follow-up from
0.0.30-nightly.20260729.938:- For a visible ghost (
projection_thread_sessions.status = running, runtime rowstopped, no provider child),thread.session.stopreturned HTTP 200 and was followed bythread.session-set; the projection converged tostoppedimmediately. - For a soft-deleted ghost, the same command returned HTTP 200 and durably appended
thread.session-stop-requested, but nothread.session-setfollowed and the projection remainedrunning. - An archived ghost behaved the same way: accepted stop request, no convergence.
- The archived row was recoverable through the supported reversible sequence
thread.unarchive→thread.session.stop→thread.archive; its final projection wasstopped. - Deleted residue has no equivalent supported recovery path, so two hidden
runningprojection rows were retained rather than editing SQLite.
This appears consistent with the provider command reactor resolving the thread from a current read model that excludes archived/deleted threads before it emits the stopped session. Startup reconciliation should probably repair persisted session projections independently of shell/read-model visibility.
After supported cleanup: visible false-running = 0, archived false-running = 0, runtime running/starting = 0, provider children = 0. The two remaining false-running rows are soft-deleted and hidden.
- For a visible ghost (
Additional reproduction: full host power loss (OpenCode, multi-environment)#
Hit the same class of bug after a machine power outage (not just desktop app restart). Confirms this is not Codex/desktop-specific.
Setup#
- T3 Code desktop on client host (Veelox) connected to remote T3 server on Halla
- OpenCode provider (
opencode serve) - Multiple long-running turns mid-flight when Halla lost power for ~3h
- After power restored and
t3code.servicecame back, sidebar still showed Working for hours - UI Stop did nothing useful; threads could not be restarted productively
Stuck threads (examples)#
Host owning state Title Observed Halla Continue preflight grilling handoff Working ~3h45m Halla Remediation builder handoff implementation Working ~4h29m Veelox Masthead page and MCP implementation Working after reconnect Persisted state (matches #4584)#
-- zombie session SELECT status, active_turn_id FROM projection_thread_sessions WHERE thread_id = '...'; -- status = running, active_turn_id still set SELECT state, completed_at FROM projection_turns WHERE turn_id = '...'; -- often still running, or interrupted with completed_at set while session stays runningNo live OpenCode processes for those threads after reboot. Provider logs end at the outage.
Why UI Stop fails (observed)#
- Stop mainly records
thread.turn-interrupt-requested. - That can mark the turn
interrupted, but session staysrunninguntil the provider command reactor finishesthread.session.stop→ internalthread.session.set { status: "stopped" }. - With a dead provider / post-crash binding, interrupt becomes a no-op loop (same shape as #4713).
- Client-dispatched
thread.session.setis internal-only → HTTP400on/api/orchestration/dispatch. Onlythread.session.stopis client-dispatchable.
Working recovery (no archive required)#
On the host that owns the thread's
state.sqlite:TOKEN=$(t3 auth session issue --base-dir "$HOME/.t3" --ttl 15m --label stuck-fix --token-only) PORT=$(python3 -c 'import json; print(json.load(open("'"$HOME"'/.t3/userdata/server-runtime.json"))["port"])') NOW=$(date -u +%Y-%m-%dT%H:%M:%S.000Z) curl -sS -X POST "http://127.0.0.1:${PORT}/api/orchestration/dispatch" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"type\":\"thread.session.stop\",\"commandId\":\"$(uuidgen)\",\"threadId\":\"THREAD_ID\",\"createdAt\":\"$NOW\"}"Verified result:
projection_thread_sessions.status = stopped,active_turn_id = NULL- active turn →
interrupted provider_session_runtime.status = stopped- Working spinner clears; thread is usable again without archiving
Expected product fix (same as original report)#
On server startup (and optionally on Stop when no live provider session exists):
- Reconcile
projection_thread_sessions.status = runningagainst actually-alive provider sessions. - Force
thread.session.set { status: stopped|interrupted, activeTurnId: null }for orphans. - Prefer settling the session on the interrupt path itself when the provider is already gone (#4713).
Happy to provide more sqlite dumps / event sequences if useful.
Reproducing this regularly on Windows, with a trigger pattern that may help: it starts every time under heavy subagent work across multiple projects.
Setup: Windows 11, desktop 0.0.33, i5-8365U (4C/8T), 24 GB RAM (upgraded from 8 GB - no change, so not memory pressure).
Pattern: 3-4 threads Working at once, subagent-heavy turns. Threads then show Working for 52m / 1h44m with no output. Messages sent to a stuck thread appear but never get a response, and a client reload does not restore anything - the turn never completed server-side, so nothing was produced. Stop on the stuck thread is sometimes a silent no-op (#4713).
From the same window in
server.trace.ndjson:checkClaudeProviderStatusspans of 31,285 ms and 32,593 ms against the 10 s probe budget, andGitVcsDriver.fetchRemoteForStatustimeouts of 6-13 s, so the whole pipeline is starved while the machine is loaded. Happy to pull specific spans or run a nightly with extra tracing if useful.Adding another variant of this from today.
The desktop app froze while a turn was in flight (the Settings > Appearance monospace font catalog scan, fix in #7494), so I had to force close and reopen it. Since the desktop app bundles the server, the force close killed the server mid-turn. After reopening, the thread still showed "Working for 9m 52s" with the timer counting up, but nothing was actually running. Sending a new message discarded the stale state and kicked off a fresh turn, which matches the "only recovers on user action" behavior noted in #6560 and #4561.
Two details from tracing the code that might be useful for whoever lands the fix:
- When the new message clears the stale state, the orphaned turn row is retroactively settled as "completed" (ProjectionPipeline supersedes other running turn rows once the new activeTurnId appears), so the interrupted turn gets recorded as if it finished successfully, with a bogus completedAt. A startup reconciler should probably settle these as interrupted instead.
- #7315 covers the restart case, but a wedged running turn on a live server still can never self-recover: ProviderSessionReaper explicitly skips any thread with a non-null activeTurnId, and there is no elapsed-time bound on a running turn anywhere. The reaper exemption plus some liveness bound on running turns might be worth treating as the second half of this issue.
Before/after screenshots:
(screenshot 1: stale "Working for 9m 52s" after reopen) (screenshot 2: new message resets the timer to "Working for 20s")
cc @juliusmarminge
closing as completed. Startup reconciliation for orphaned provider sessions landed in #7719, clearing the stale state that blocked thread actions after restart.
Sign in to join this conversation.
Additional macOS reproduction: backend OOM respawn leaves every projected running session stale#
Confirmed on T3 Code
0.0.30-nightly.20260729.938, macOS arm64.A backend-child heap OOM occurred while active turns were in progress. The desktop supervisor ended the child at
2026-07-29T03:32:58.427Z, started a replacement at03:32:58.939Z, and the replacement listened on port 3773 at03:32:59.669Z.After restart:
All ten projected
runningsessions were stale across the replacement backend'sstartedAt:stopped, while projections still saidrunning;running, but theirlast_seen_atvalues predated the replacement backend and no provider children existed;The phone and loopback identity endpoints were healthy (roughly 25 ms and 3 ms respectively), which made this visible as threads that kept saying Working while nothing could update.
This is the same lifecycle bug described in the issue, now reproduced through a supervised backend crash rather than manual relaunch. The triggering OOM evidence is posted on #996.
No database rows were edited or deleted for recovery; cleanup is being done through supported orchestration stop/settle commands.