Skip to content

fix(auto-reply): don't block reply completion on transcript mirror - #99549

Merged
steipete merged 3 commits into
openclaw:mainfrom
Shagrat2:fix/mirror-transcript-deadlock
Jul 4, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
Shagrat2:fix/mirror-transcript-deadlock

Conversation

@Shagrat2

@Shagrat2 Shagrat2 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

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 current ReplyOperation to clear, and the current operation waited for dispatcher idle through transcript mirroring.

That forms a cycle:

foreground delivery -> newer same-session turn -> current reply operation -> dispatcher idle
        ^                                                                  |
        +------------------------------------------------------------------+

The user-visible result is a running reply operation plus queued follow-ups and no progress:

stalled session: state=processing queueDepth=3 reason=active_work_without_progress
classification=stalled_agent_run activeWorkKind=embedded_run recovery=none

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:

  • successful final delivery registers a one-shot dispatcher settlement task;
  • dispatcher settlement drains those tasks after delivery becomes idle;
  • final cancellation/failure counters suppress mirroring for undelivered replies;
  • settlement always clears the task registry, including failure paths;
  • the actual post-hook payload remains the mirrored payload.

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:

sendfinal-enter -> sf-tts-exit -> sf-route-exit ok=n -> sf-dispsend queuedFinal=y
  -> mirror-after-enter -> (silence; op never clears)

After

  • Focused regression suite: 4 files, 274 tests passed. It includes the real two-dispatch same-session cycle, settlement ordering, cancellation/failure suppression, and cleanup.
  • Fresh $autoreview: clean; no accepted/actionable findings.
  • Blacksmith Testbox-through-Crabbox tbx_01kwnay65cktjv6sezewjvgx57: built the source and passed the real Gateway + WebSocket/channel 20-turn same-session QA flow with the deterministic OpenAI-compatible provider. Run
  • Blacksmith Testbox-through-Crabbox tbx_01kwnb2209p1meyspqaykh7xz8: exact-tree check:changed passed core/core-test typechecks, lint, import cycles, and runtime/persistence guards. Run
  • Exact PR head: 11c4e2fc322f5340e95183885ca1680d2da7ac15.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 3, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 9:17 PM ET / 01:17 UTC.

Summary
The PR adds dispatcher-settled tasks and moves delivered transcript mirroring out of awaited final reply dispatch, with regression coverage for queued same-session follow-ups.

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.

  • Settlement Ordering Change: 1 transcript mirror moved to dispatcher-settled lifecycle. Maintainers should notice that final reply completion no longer waits for delivered-form transcript reconciliation before queued follow-up admission can proceed.

Stored data model
Persistent data-model change detected: vector/embedding metadata: src/auto-reply/reply/dispatch-from-config.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #99549
Summary: This PR is the canonical current item for the delivered transcript mirror dispatcher-idle deadlock; the related reports are adjacent stalled-session families with different root causes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Maintainers should explicitly accept the delivered-mirror settlement ordering before merge.

Risk before merge

  • [P1] Merging intentionally changes session-state ordering: a queued same-session follow-up may begin after final delivery but before the delivered-form transcript mirror append finishes, so maintainers should accept that mirror as post-delivery reconciliation rather than a next-turn context prerequisite.

Maintainer options:

  1. Accept Settled Mirror Ordering (recommended)
    Merge after maintainers agree that delivered-form transcript reconciliation may run after queued follow-up admission because the primary assistant message is already recorded and the mirror is idempotent reconciliation.
  2. Require Pre-Read Durability Proof
    Ask for proof that a queued follow-up's context read remains correct when it starts before the delivered mirror append, or adjust the design to preserve that ordering.
  3. Pause For A Mirror Queue
    If delivered mirrors must be durable before any next-turn read, pause this branch and design a non-deadlocking post-completion mirror queue with an explicit session ordering contract.

Next step before merge

  • [P2] The remaining action is maintainer acceptance of the session-state ordering plus normal merge gates; there is no narrow automated repair to queue.

Security
Cleared: The diff changes TypeScript auto-reply control flow and tests only; it does not alter dependencies, workflows, permissions, package metadata, credentials, or external code execution.

Review details

Best 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 changes

Label justifications:

  • P1: The PR targets a live auto-reply deadlock that can freeze a session lane and leave user follow-ups queued until stuck-session recovery.
  • merge-risk: 🚨 session-state: The diff intentionally changes when delivered transcript reconciliation happens relative to the next same-session turn.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body provides redacted before/after live gateway logs across multiple backends showing repeated queueDepth>=2 follow-ups with zero stalled_agent_run after the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides redacted before/after live gateway logs across multiple backends showing repeated queueDepth>=2 follow-ups with zero stalled_agent_run after the fix.
Evidence reviewed

PR surface:

Source +33, Tests +91. Total +124 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 47 14 +33
Tests 2 92 1 +91
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 139 15 +124

What I checked:

Likely related people:

  • steipete: Remote history shows work on the dispatcher helper, shared turn kernel, reply follow-up drain lifecycle, and reply idle wait timers; he also force-pushed the final settled-task shape for this PR. (role: dispatcher lifecycle and idle-wait area contributor; confidence: high; commits: 8129fc0f3a6a, 9a9cd0c0abdf, 490a155f1568; files: src/auto-reply/dispatch-dispatcher.ts, src/auto-reply/reply/reply-run-registry.ts, src/auto-reply/reply/dispatch-from-config.ts)
  • sandieman2: Remote history shows c67dc59 reworked same-session final delivery, follow-up barriers, and queued follow-up behavior in the same reply-run boundary. (role: final delivery and follow-up boundary contributor; confidence: high; commits: c67dc59b02b0; files: src/auto-reply/reply/dispatch-from-config.ts, src/auto-reply/reply/reply-run-registry.ts)
  • 100yenadmin: Recent current-main history shows Codex output recovery work touching both dispatch-from-config and reply-run-registry near the active-run completion surface. (role: recent adjacent contributor; confidence: medium; commits: 414ecd2b9689; files: src/auto-reply/reply/dispatch-from-config.ts, src/auto-reply/reply/reply-run-registry.ts)
  • youngting520: Remote history shows recent work ensuring transcript mirrors honor the configured session store, which is the persistence side this PR defers. (role: transcript mirror contributor; confidence: medium; commits: 4c9c6f5116bb; files: src/config/sessions/transcript.ts)
  • obviyus: Recent history shows dispatch-from-config and reply-run-registry changes around session binding, auto-reply suppression, and reply visibility behavior. (role: recent auto-reply/session contributor; confidence: medium; commits: 48e8965b1060, dbccddbf343c, aa935ddeb23f; files: src/auto-reply/reply/dispatch-from-config.ts, src/auto-reply/reply/reply-run-registry.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 3, 2026
@Shagrat2

Shagrat2 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR body with What Problem This Solves and an Evidence section (redacted before/after live logs across three backends: 174 queueDepth>=2 events, 0 stalled_agent_run), and added a focused regression test in dispatch-from-config.reply-dispatch.test.ts (the completion test hangs if the fix is reverted to the awaited mirror). Ready for re-review.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 3, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 3, 2026
@Shagrat2

Shagrat2 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

The one red check — QA Smoke CI — is an unrelated flake in the native-command-session-target scenario, not a regression from this PR:

  • It failed only in the concurrency=8 batch (8 gateways in parallel); the scenario waits on abort/recovery replies with timeoutMs: 15000, so it's timing-sensitive under load. All other 80 smoke scenarios passed.
  • The fix-only revision of this PR (before the test commit) passed QA Smoke, including this scenario. The follow-up commit only adds a *.test.ts file, which is not bundled into the gateway build, so the runtime QA exercises is byte-identical.
  • Local repro on this branch: native-command-session-target passes 5/5 standalone (qa run --scenario native-command-session-target) — abort reply ⚙️ Agent was aborted. and recovery QA-NATIVE-STOP-RECOVERY-OK both land.
  • Direction-wise this fix makes final-reply completion faster (the mirror no longer blocks it), which can only help — not hurt — a 15 s abort-timeout scenario.

Re-triggering CI to clear the flake.

@Shagrat2
Shagrat2 force-pushed the fix/mirror-transcript-deadlock branch from 2cf9406 to 3422ba1 Compare July 3, 2026 14:43
@steipete steipete self-assigned this Jul 3, 2026
Shagrat2 and others added 3 commits July 4, 2026 02:08
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).
@steipete
steipete force-pushed the fix/mirror-transcript-deadlock branch from 3422ba1 to 11c4e2f Compare July 4, 2026 01:10
@steipete

steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Land-ready maintainer proof for exact head 11c4e2fc322f5340e95183885ca1680d2da7ac15:

  • Reworked the initial detached transcript-mirror promise into dispatcher-owned one-shot settlement tasks. Successful final delivery mirrors after dispatcher idle; cancelled/failed finals do not mirror; settlement always clears task ownership.
  • Added the actual same-session cycle regression: first final delivery waits for freshness, the follow-up waits for the current reply operation, the operation clears, both dispatches finish, and the first delivered payload mirrors once.
  • Focused tests: node scripts/run-vitest.mjs src/auto-reply/dispatch.test.ts src/auto-reply/reply/reply-flow.test.ts src/auto-reply/reply/dispatch-from-config.reply-dispatch.test.ts src/auto-reply/reply/dispatch-from-config.test.ts — 4 files, 274 passed.
  • Fresh $autoreview: clean; no accepted/actionable findings.
  • Real Gateway QA: Blacksmith Testbox-through-Crabbox tbx_01kwnay65cktjv6sezewjvgx57 built the source and passed the 20-turn same-session Gateway + WebSocket/channel flow with the deterministic OpenAI-compatible provider. Run
  • Exact-tree changed gate: Blacksmith Testbox-through-Crabbox tbx_01kwnb2209p1meyspqaykh7xz8 passed core/core-test typechecks, lint, import cycles, and runtime/persistence guards. Run
  • Exact-head CI: 44 successful jobs, zero failures. CI · Workflow Sanity
  • Duplicate search: no open same-root issue/PR. Closed Slack thread session stalls after final answer; reply not delivered and follow-up mentions queue #92443 was a similar Slack-visible stall fixed by fix(reply): deliver final reply when queued follow-up claims session; scope dedupe to routed thread #90943, but this is a later distinct transcript-mirror cycle.

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.

@steipete
steipete merged commit b381559 into openclaw:main Jul 4, 2026
102 checks passed
@steipete

steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 4, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants