Skip to content

Transactional message delivery + turn watchdog against zombie 'Working' states - #446

Merged
currentbits merged 12 commits into
mainfrom
coder/transactional-message-delivery-turn-watc-a3edde
Aug 18, 2026
Merged

currentbits merged 12 commits into
mainfrom
coder/transactional-message-delivery-turn-watc-a3edde

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #314.

Two failure modes this kills: a prompt typed mid-run that silently never gets sent, and a turn that sits on "Working" forever with no output and no timeout.

Delivery moves into the main process

The type-ahead queue was persisted by main (thread.queued) but delivered by the renderer (useCoder.flushQueued, fired on the working→settled transition). Close or reload the app at the wrong moment and the prompt was never sent — that is the silent loss.

  • services.takeQueued — atomic read-and-clear. Take-and-clear is what makes double delivery impossible.
  • runner.drainQueued → startRun, called at every run terminal (notifyRunTerminal for done/failed/stopped, afterSuccessfulTurn/afterFailedTurn for the simulate path that bypasses it, and the sim-stop branch of stopRun).
  • A start that throws puts the prompt back with queued.error set, so nothing is lost and the composer can offer a Retry.
  • No auto-drain at startup: a queue that survived a quit stays visible with its Retry button rather than firing runs on launch.
  • flushQueued is deleted, so there is exactly one owner of delivery.

Turn watchdog

  • runner.checkStalls() on a 15s unref'd interval sets thread.stalledAt when a working thread has emitted nothing for 10 minutes (CODER_STALL_MS overrides) and is not awaitingInput, and appends one event message.
  • It sweeps the store, not the active map — a working row with no live run at all is the actual zombie, and an active-map scan would miss it.
  • Advisory only: the CLI is never killed. A long Bash tool call legitimately emits nothing for minutes, so killing on silence would be worse than the spinner. The next stream event clears the flag.
  • Activity is stamped in pushDetail, the one funnel every provider goes through, throttled to ~5s and written without touch so the sidebar does not re-sort on every stream chunk. The sweep's own push skips the stamp or it would clear the flag it just set.

The pre-existing 60s CLAUDE_ACK_MS timer (reused warm CLI only) stays as is. The command_lifecycle/command_uuid correlation left over from #178 is deliberately not done here: this generic no-output watchdog covers the "stray first line then silence" hole it was for.

UI

Stalled badge in place of the endless Working spinner (sidebar, thread view status strip, agents panel team rows), and the queued strip now carries the failure reason plus Retry alongside Cancel. Dev-mode fixtures seed both states.

Two joins fixed after the halves came together

Both are the same class of bug this issue is about, and both were invisible to each half on its own:

  • Retry cleared the queue optimistically and only raised a toast when runs.start failed — the prompt vanished. It now restores the prompt with the new error, and Retry is offered for any prompt still queued on a settled thread rather than only one whose error survived a reload.
  • The thread:updated merge re-pinned the renderer's own queued copy whenever the incoming row had none. Correct while the renderer owned delivery; with main draining, an explicit null is real news and re-pinning would have stranded the Queued chip forever. Only an omitted field falls back now.

Verification

npm run test:electron 1168 pass / 0 fail, npm run test:renderer 920 pass / 0 fail, npm run typecheck clean. New coverage in electron/test/stall-watchdog.test.js (stall flagged once, awaitingInput exempt, activity clears it, a terminal delivers a queued prompt exactly once, a throwing start leaves it queued with an error), test/deliveryState.test.tsx, and the rewritten test/queuedFollowup.test.tsx.

🤖 Generated with Claude Code

  • PR created by the Claude Code agent

Willem and others added 12 commits August 18, 2026 08:37
… Tool call bodies scroll horizontally instead of wrapping
… Memory: distill procedural strategy entries from successes a
contextTokens is the last turn's FULL prompt (input + cache-read +
cache-creation + output), and contextWindow carries the CLI's own
window when it reports one. Contract only; runner and UI land next.

Refs #317

Co-Authored-By: Claude Opus 5 <[email protected]>
…ued message

Fields only, no behaviour. Main process fills them (watchdog + transactional
queue drain); the renderer surfaces Stalled and a delivery retry.

Co-Authored-By: Claude Opus 5 <[email protected]>
…into coder/fork-transactional-message-delivery-turn-68408d
…into coder/fork-transactional-message-delivery-turn-22ba60
Main now drains thread.queued at the run terminal and sets stalledAt.
Stop the renderer from also flushing (that double-sent), show
queued.error with Retry, and replace the infinite Working spinner
with Stalled.
A failed retry cleared the queue optimistically and only raised a toast, so
the prompt vanished — the exact loss #314 is about. Restore it with the new
error, and offer Retry for any prompt still queued on a settled thread, not
only one whose error survived a reload.

Co-Authored-By: Claude Opus 5 <[email protected]>
Main-process half of transactional delivery. Stamps lastEventAt on
stream events (throttled, no touch), sweeps working threads for stalls
without killing the CLI, and drains thread.queued at every run terminal
via takeQueued so a queued follow-up survives a reload.
…into coder/transactional-message-delivery-turn-watc-a3edde
The thread:updated merge kept a local queued copy whenever the incoming row
had none — written when the RENDERER owned delivery. With main draining at
the terminal, an explicit null is real news and re-pinning our copy stranded
the Queued chip forever. Only an omitted field falls back now.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 3f9a03d into main Aug 18, 2026
1 check passed
@currentbits
currentbits deleted the coder/transactional-message-delivery-turn-watc-a3edde branch October 3, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transactional message delivery + turn watchdog against zombie 'Working' states

1 participant