Repository navigation
fix(auto-reply): don't block reply completion on transcript mirror - #99549
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 9:17 PM ET / 01:17 UTC. Summary PR surface: Source +33, Tests +91. Total +124 across 4 files. Reproducibility: yes. Current main source shows final reply dispatch awaiting a mirror helper that first waits for dispatcher idle, while reply operation completion uses a dispatcher-idle follow-up barrier; the PR body also includes live before/after stall logs. Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this narrow settlement-owned mirror fix after maintainers accept delivered transcript mirroring as post-delivery reconciliation; if mirror durability must precede next-turn context reads, require a dedicated post-completion mirror queue with an explicit ordering contract. Do we have a high-confidence way to reproduce the issue? Yes. Current main source shows final reply dispatch awaiting a mirror helper that first waits for dispatcher idle, while reply operation completion uses a dispatcher-idle follow-up barrier; the PR body also includes live before/after stall logs. Is this the best way to solve the issue? Yes, with a maintainer ordering decision. Moving only delivered transcript mirroring to the dispatcher-settled lifecycle is the narrowest maintainable fix for the completion-to-idle cycle while preserving delivery cancellation/failure checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ab9e233d02a8. Label changesLabel justifications:
Evidence reviewedPR surface: Source +33, Tests +91. Total +124 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Updated the PR body with What Problem This Solves and an Evidence section (redacted before/after live logs across three backends: 174 |
|
The one red check — QA Smoke CI — is an unrelated flake in the
Re-triggering CI to clear the flake. |
2cf9406 to
3422ba1
Compare
mirrorTranscriptAfterDispatcherDelivery() opens with `await dispatcher.waitForIdle()` and is awaited from sendFinalPayload, i.e. before the reply operation completes. When a follow-up is queued (queueDepth>=2) the dispatcher cannot go idle until this operation clears, and the operation cannot clear until sendFinalPayload returns — a completion<->dispatcher-idle deadlock. The reply operation stays phase=running and surfaces as stalled_agent_run (recovery=none) until the ~15-minute stuck-session abort. Run the transcript mirror as fire-and-forget: it is post-delivery bookkeeping and does not need to gate completion. The operation completes immediately, the queued follow-up proceeds, the dispatcher goes idle, and the detached mirror then records the transcript. Validated live across three backends (LMStudio openai-completions, claude-cli, DeepSeek cloud): queueDepth 2 and 3, zero stalls.
Two focused tests on the queueDepth>=2 completion<->dispatcher-idle deadlock: - final reply completes even when dispatcher.waitForIdle() never resolves (pre-fix this awaited-mirror path deadlocked; the test hangs on the old code). - a rejecting background mirror does not fail the reply (the detached .catch contains it instead of surfacing an unhandled rejection).
Co-authored-by: Zaytsev Ivan <[email protected]>
3422ba1 to
11c4e2f
Compare
|
Land-ready maintainer proof for exact head
No external model key was needed: deterministic delayed-provider behavior is the stronger timing proof here, while the Gateway, WebSocket, channel, session, delivery, and transcript paths are real. Thanks @Shagrat2 for the detailed live trace and initial diagnosis. |
|
Merged via squash.
|
…penclaw#99549) * fix(auto-reply): don't block reply completion on transcript mirror mirrorTranscriptAfterDispatcherDelivery() opens with `await dispatcher.waitForIdle()` and is awaited from sendFinalPayload, i.e. before the reply operation completes. When a follow-up is queued (queueDepth>=2) the dispatcher cannot go idle until this operation clears, and the operation cannot clear until sendFinalPayload returns — a completion<->dispatcher-idle deadlock. The reply operation stays phase=running and surfaces as stalled_agent_run (recovery=none) until the ~15-minute stuck-session abort. Run the transcript mirror as fire-and-forget: it is post-delivery bookkeeping and does not need to gate completion. The operation completes immediately, the queued follow-up proceeds, the dispatcher goes idle, and the detached mirror then records the transcript. Validated live across three backends (LMStudio openai-completions, claude-cli, DeepSeek cloud): queueDepth 2 and 3, zero stalls. * test(auto-reply): regression coverage for detached transcript mirror Two focused tests on the queueDepth>=2 completion<->dispatcher-idle deadlock: - final reply completes even when dispatcher.waitForIdle() never resolves (pre-fix this awaited-mirror path deadlocked; the test hangs on the old code). - a rejecting background mirror does not fail the reply (the detached .catch contains it instead of surfacing an unhandled rejection). * fix(auto-reply): settle transcript mirrors after delivery Co-authored-by: Zaytsev Ivan <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
A user who sends a second message while the agent is still answering the first can freeze that conversation until stuck-session recovery fires. Neither the first reply nor the queued follow-up completes, despite the model turn itself having finished.
Problem
The reply operation used to await
mirrorTranscriptAfterDispatcherDelivery(). That mirror first awaited dispatcher idle. With a same-session follow-up queued, the foreground freshness fence waited for the newer turn, the newer turn waited for the currentReplyOperationto clear, and the current operation waited for dispatcher idle through transcript mirroring.That forms a cycle:
The user-visible result is a running reply operation plus queued follow-ups and no progress:
Why This Change Was Made
The initial PR correctly removed transcript mirroring from the reply operation's awaited completion path, but detached it as an unowned background promise. That promise could remain pending forever if dispatcher idle never arrived.
The maintainer rewrite instead gives post-delivery work one lifecycle owner:
The reply operation can therefore clear before dispatcher settlement, unblocking the queued same-session turn, while transcript mirroring remains owned and bounded rather than fire-and-forget.
User Impact
Rapid same-session follow-ups no longer wedge reply completion. Delivered source replies still reach the transcript exactly once; cancelled or failed final deliveries are not mirrored.
Evidence
Before
The contributor reproduced the bug on a live Gateway across LMStudio OpenAI-compatible completions,
claude-cli, and DeepSeek. An instrumented stalled run reached final delivery and then stopped inside the mirror's dispatcher-idle wait:After
$autoreview: clean; no accepted/actionable findings.tbx_01kwnay65cktjv6sezewjvgx57: built the source and passed the real Gateway + WebSocket/channel 20-turn same-session QA flow with the deterministic OpenAI-compatible provider. Runtbx_01kwnb2209p1meyspqaykh7xz8: exact-treecheck:changedpassed core/core-test typechecks, lint, import cycles, and runtime/persistence guards. Run11c4e2fc322f5340e95183885ca1680d2da7ac15.No external provider key is required for this lifecycle defect: the deterministic provider makes the queue timing reproducible while the Gateway, WebSocket, channel, session, delivery, and transcript paths remain real.
Workaround
Before upgrading to a build containing this fix, serialize inbound messages per conversation so a second message is not admitted until the first reply operation completes.
Related Work