Skip to content

fix: a stalled turn that already answered posts a second answer or a retry notice - #162756

Merged
obviyus merged 2 commits into
mainfrom
fix/stall-after-delivery
Oct 1, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/stall-after-delivery

Conversation

@obviyus

@obviyus obviyus commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: when a chat turn has already answered through the message tool and then stalls on a later model request, stuck-session recovery treats it as unanswered. It starts a recovery turn, which posts a second, redundant answer, or, if that also stalls, the "Please try again" notice.

User Impact

After a turn's final message-tool answer reaches the chat, a later stall stays quiet: no recovery turn, no second message, no retry notice. Progress messages (final: false) don't count as an answer, so a turn that only said "working on it" still recovers as before. In message-tool-only mode (Slack quiet mode), where every visible reply is a message-tool send, this keeps a stall after the answer from posting the last-resort notice, which bypasses quiet-mode suppression.

Why This Change Was Made

#161069 decides between recovery and the notice with isReplyOperationStalledBeforeOutput(operation), which checked only the stall reason. An adversarial review of #161069 found that this ignores source delivery that already happened.

The run result does carry the delivery evidence, but dispatch makes the notice/recovery decision as soon as the watchdog expires the reply operation, before the aborted run returns its result. A live run confirmed that ordering (cause=skipped:reply_operation_aborted before the fallback chain settles).

So the reply operation, which owns the turn's lifecycle, now owns the fact as well. A successful final message-tool send to the turn's exact source (the existing messageDelivery.sourceReplyDelivered condition: settled, not partial, not dry-run, final not false, current source) marks the active operation sourceReplyDelivered. The single predicate reads it, so dispatch, follow-up delivery and any future caller share one rule.

A user message steered into the same operation after that answer reopens it. Steer acceptance has one owner on the operation (markSteeredInputAccepted, which replaces the audio-only markAcceptedSteeredInboundAudio from #95596; its audio flag is unchanged). It clears the fact, so the newer request still recovers if the turn then stalls.

Bounded cost

This only removes work. No new model calls, runs or messages. A stalled turn that already answered starts no recovery turn (one model run fewer). Recovery stays at most once per stalled turn on every surface, unchanged.

Evidence

  • Telegram Test Server, live model. telegram-e2e-userbot skill, Convex-leased credential, real QA user in a DM, openai/gpt-6-astra through a proof-only local proxy in front of the real OpenAI API, QA stuck-session bound 30 s. A live model can't be made to stall, so the proxy holds open the first model request that follows a completed message tool call. Everything else reaches the live API unchanged. The QA user sends: "Use the message tool to send me the answer to 17*23 as just the number. After that message is sent, you are done: send nothing else."
    • Before (origin/main d06974d): the model sends 391 through the message tool. The next request is held, and stuck recovery aborts the turn at age 47 s. A recovery request carrying the stall guidance then goes to the live model, and the chat gets a second message, "Already sent: 391.". SUT messages: 391, Already sent: 391.
    • After (exact head 50a09f1): the model sends 391 through the message tool, the next request is held, and stuck recovery aborts the turn at age 49 s. There's no recovery request, and the chat shows only 391. No second message and no notice. The earlier run on fe6eed9 matched it: same 391 send, held request, and stuck abort (age 48 s). There's no recovery request, and the chat shows only 391. No second message and no notice.
    • Both runs also show the existing "Working" progress row, which is unchanged.
    • Second message during the stall (exact head 50a09f1): the scenario sends the 1723 request, then "Also, what is 1921? Reply with just the number." 30 s later, while the post-answer request is held.
      • Live, the second message was queued as its own turn rather than steered (queueDepth=1), because the active run doesn't take steering after its answer.
      • The first turn's stall (age 75 s) started no recovery. The queued turn then ran and stalled too (age 58 s), and its recovery answered it.
      • Chat: 391, then 399. One guided recovery request, for the unanswered second message only.
      • The steered-into-the-same-operation variant isn't reachable in this flow, so it's covered by the real runReplyAgent steer test.
  • Regression tests:
    • dispatch-from-config.terminal-recovery.test.ts: a new case marks the active operation answered, then lets the watchdog expire it while the run is still pending, which is the real order. It expects no notice and no continuation. It fails on main.
    • message-tool-execution.test.ts: the existing eligibility table now also asserts that only an eligible final source send marks the operation. Failures, partial sends, dry runs, final: false and other targets don't mark it.
    • The same table has a case where an answer is followed by a steered input. It expects one continuation.
    • agent-runner.media-paths.test.ts: the real steer path through runReplyAgent clears an earlier answer.
    • Focused suites pass, including reply-run-registry, dispatch-from-config and message-tool-execution.
  • One-worker wall times (pnpm test <file> --maxWorkers=1, real / Vitest duration): dispatch-from-config.terminal-recovery.test.ts 27 s / 23.8 s (27 tests); message-tool-execution.test.ts 23 s / 20.3 s (76 tests); agent-runner.media-paths.test.ts 27 s / 23.3 s (21 tests). Transform dominates (75–80%); each is under 30 s.
  • node scripts/check-changed.mjs passes.

LOC vs origin/main: production +25/−7, tests +33/−6.

No new user-visible messages. This only removes a redundant answer and an incorrect notice.

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 1, 2026
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 11:14 AM ET / 15:14 UTC (Revision 4).

ClawSweeper review

What this changes

The PR prevents recovery answers and retry notices after a completed message-tool reply, while restoring recovery eligibility when newer steered input is accepted.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still treats an already answered message-tool turn as eligible for stalled-turn recovery. No blocking correctness finding remains, and the recorded Telegram proof covers the unchanged production code.

Priority: P1
Reviewed head: 12a2cf052531e005857b6b221390acaa371f48ca

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair has relevant live before-and-after evidence and useful boundary regressions, with no blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded Telegram Test Server runs exercise completed message-tool delivery followed by an injected live-provider stall: the fixed chat receives one answer and no recovery notice, while a newer queued request still recovers. GitHub blob identities verify that the changed production owners match the live-proven revision. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded Telegram Test Server runs exercise completed message-tool delivery followed by an injected live-provider stall: the fixed chat receives one answer and no recovery notice, while a newer queued request still recovers. GitHub blob identities verify that the changed production owners match the live-proven revision. No stored-data contract changes.
Evidence reviewed 8 items Verified introduced changes: The pinned merge-base-to-head diff changes delivery tracking, operation state, steering acceptance, the shared stall predicate, and focused regression coverage. The verified test merge has the recorded base and head parents; unrelated build-system endpoint drift is not attributed to this PR.
Current main still needs the fix: The current-main stall predicate checks the terminal failure and expiry reason but does not consult source delivery. The latest supplied release predates this recovery module; no merged replacement fixing this specific delivery gap was established.
Canonical delivery eligibility: The operation is marked only inside the existing settled, complete, non-dry-run, final current-source delivery condition. Failed, partial, progress, and other-target results retain their existing eligibility rules.
Findings None None.
Security None None.

How this fits together

Reply operations track the lifecycle of incoming chat turns. Message-tool delivery and accepted steering update that operation, which dispatch and follow-up delivery consult when deciding whether a stalled turn still needs an answer.

flowchart TD
  A[Incoming chat turn] --> B[Reply operation]
  C[Completed source reply] --> B
  D[Accepted newer input] --> B
  B --> E[Stall recovery decision]
  E --> F[Already answered: stay quiet]
  E --> G[Unanswered: recovery or notice]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +18, Tests +29. Total +47 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 25 7 +18
Tests 5 33 4 +29
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 58 11 +47

Review metrics

Metric Value Why it matters
Production and regression growth production +25/−7; tests and test support +33/−4 Production growth is justified by operation-owned delivery tracking and a complete steering-method cutover.

Technical review

Best possible solution:

Keep completed-source delivery on the existing reply-operation owner so recovery answers only outstanding input.

Do we have a high-confidence way to reproduce the issue?

Yes: complete a final source message-tool send, hold the subsequent model request, and let the watchdog expire the turn. Current-main source establishes the missing delivery check, and the contributor records this failing live sequence.

Is this the best way to solve the issue?

Yes: extending the existing operation and shared recovery predicate is a narrow repair, and accepted steering correctly invalidates an earlier answer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 43873ce187b1.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The recorded live failure duplicates an already delivered chat answer or emits an incorrect retry notice.
  • 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 (live_output): Recorded Telegram Test Server runs exercise completed message-tool delivery followed by an injected live-provider stall: the fixed chat receives one answer and no recovery notice, while a newer queued request still recovers. GitHub blob identities verify that the changed production owners match the live-proven revision. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Telegram Test Server runs exercise completed message-tool delivery followed by an injected live-provider stall: the fixed chat receives one answer and no recovery notice, while a newer queued request still recovers. GitHub blob identities verify that the changed production owners match the live-proven revision. No stored-data contract changes.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Suppressing duplicate answers and retry notices is visible Telegram chat behavior, and the recorded Test Server proof covers it.

Evidence

What I checked:

  • Verified introduced changes: The pinned merge-base-to-head diff changes delivery tracking, operation state, steering acceptance, the shared stall predicate, and focused regression coverage. The verified test merge has the recorded base and head parents; unrelated build-system endpoint drift is not attributed to this PR. (12a2cf052531)
  • Current main still needs the fix: The current-main stall predicate checks the terminal failure and expiry reason but does not consult source delivery. The latest supplied release predates this recovery module; no merged replacement fixing this specific delivery gap was established. (src/auto-reply/reply/stalled-turn-recovery.ts:17, 43873ce187b1)
  • Canonical delivery eligibility: The operation is marked only inside the existing settled, complete, non-dry-run, final current-source delivery condition. Failed, partial, progress, and other-target results retain their existing eligibility rules. (src/agents/tools/message-tool-execution.ts:684, 12a2cf052531)
  • Shared recovery and steering ownership: Dispatch and stalled follow-up delivery both consume the shared predicate. Accepted steering clears the earlier answer through the captured operation owner and preserves the existing inbound-audio latch; the retired audio-only method has no remaining callers. (src/auto-reply/reply/reply-run-registry.registry.ts:202, 12a2cf052531)
  • Real Telegram before-and-after proof: The captured PR body records Telegram Test Server runs with a real user, live model, and a proxy holding the model request after a completed message-tool send. Before the fix, the chat received 391 and a redundant answer; after the fix, it received only 391 with no recovery request or notice. A second queued request separately recovered and answered 399. This exercises the message-tool completion and watchdog recovery boundary. (50a09f1e5747)
  • Proof continuity across the head change: GitHub's tree for the previously reviewed and live-proven revision has identical blob IDs to the current checkout for all five changed production files. The relevant regression-test blobs also match. Local inspection of the older commit was unavailable, so GitHub tree identities supplied the comparison without treating the unavailable local history as a contributor defect. (src/agents/tools/message-tool-execution.ts:694, 50a09f1e5747)

Likely related people:

  • Ayaan Zaidi: Raw commit 872c9ba adds src/auto-reply/reply/stalled-turn-recovery.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 872c9ba2bbd5; files: src/auto-reply/reply/stalled-turn-recovery.ts)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-01T14:22:02.479Z sha 50a09f1 :: needs changes before merge. :: none
  • reviewed 2026-10-01T14:30:51.576Z sha 50a09f1 :: needs changes before merge. :: none
  • reviewed 2026-10-01T15:03:00.977Z sha 50a09f1 :: needs maintainer review before merge. :: none

@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. 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. labels Oct 1, 2026
@obviyus
obviyus marked this pull request as ready for review October 1, 2026 14:55
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus force-pushed the fix/stall-after-delivery branch from 50a09f1 to 12a2cf0 Compare October 1, 2026 15:10
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit eaae5f6 into main Oct 1, 2026
123 checks passed
@obviyus
obviyus deleted the fix/stall-after-delivery branch October 1, 2026 15:27
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Landed after the full landing checklist on the exact head: adversarial review LAND, ClawSweeper ready, live before/after proof in the PR body, full CI green, bounded cost, and no new user-visible messages.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…retry notice (openclaw#162756)

## What Problem This Solves

Fixes: when a chat turn has already answered through the message tool and then stalls on a later model request, stuck-session recovery treats it as unanswered. It starts a recovery turn, which posts a second, redundant answer, or, if that also stalls, the "Please try again" notice.

## User Impact

After a turn's final message-tool answer reaches the chat, a later stall stays quiet: no recovery turn, no second message, no retry notice. Progress messages (`final: false`) don't count as an answer, so a turn that only said "working on it" still recovers as before. In message-tool-only mode (Slack quiet mode), where every visible reply is a message-tool send, this keeps a stall after the answer from posting the last-resort notice, which bypasses quiet-mode suppression.

## Why This Change Was Made

openclaw#161069 decides between recovery and the notice with `isReplyOperationStalledBeforeOutput(operation)`, which checked only the stall reason. An adversarial review of openclaw#161069 found that this ignores source delivery that already happened.

The run result does carry the delivery evidence, but dispatch makes the notice/recovery decision as soon as the watchdog expires the reply operation, before the aborted run returns its result. A live run confirmed that ordering (`cause=skipped:reply_operation_aborted` before the fallback chain settles).

So the reply operation, which owns the turn's lifecycle, now owns the fact as well. A successful final message-tool send to the turn's exact source (the existing `messageDelivery.sourceReplyDelivered` condition: settled, not partial, not dry-run, `final` not `false`, current source) marks the active operation `sourceReplyDelivered`. The single predicate reads it, so dispatch, follow-up delivery and any future caller share one rule.

A user message steered into the same operation after that answer reopens it. Steer acceptance has one owner on the operation (`markSteeredInputAccepted`, which replaces the audio-only `markAcceptedSteeredInboundAudio` from openclaw#95596; its audio flag is unchanged). It clears the fact, so the newer request still recovers if the turn then stalls.

Hermes (sibling framework) keeps one per-turn reply owner and never re-answers after a delivered reply. Its inactivity timeout only reports through that owner.

## Bounded cost

This only removes work. No new model calls, runs or messages. A stalled turn that already answered starts no recovery turn (one model run fewer). Recovery stays at most once per stalled turn on every surface, unchanged.

## Evidence

- **Telegram Test Server, live model.** `telegram-e2e-userbot` skill, Convex-leased credential, real QA user in a DM, `openai/gpt-6-astra` through a proof-only local proxy in front of the real OpenAI API, QA stuck-session bound 30 s. A live model can't be made to stall, so the proxy holds open the first model request that follows a completed `message` tool call. Everything else reaches the live API unchanged. The QA user sends: "Use the message tool to send me the answer to 17*23 as just the number. After that message is sent, you are done: send nothing else."
  - **Before (`origin/main` 02f46a6):** the model sends `391` through the message tool. The next request is held, and stuck recovery aborts the turn at age 47 s. A recovery request carrying the stall guidance then goes to the live model, and the chat gets a second message, "Already sent: 391.". SUT messages: `391`, `Already sent: 391.`
  - **After (exact head `50a09f1`):** the model sends `391` through the message tool, the next request is held, and stuck recovery aborts the turn at age 49 s. There's no recovery request, and the chat shows only `391`. No second message and no notice. The earlier run on `fe6eed9` matched it: same `391` send, held request, and stuck abort (age 48 s). There's no recovery request, and the chat shows only `391`. No second message and no notice.
  - Both runs also show the existing "Working" progress row, which is unchanged.
  - **Second message during the stall (exact head `50a09f1`):** the scenario sends the 17*23 request, then "Also, what is 19*21? Reply with just the number." 30 s later, while the post-answer request is held.
    - Live, the second message was queued as its own turn rather than steered (`queueDepth=1`), because the active run doesn't take steering after its answer.
    - The first turn's stall (age 75 s) started no recovery. The queued turn then ran and stalled too (age 58 s), and its recovery answered it.
    - Chat: `391`, then `399`. One guided recovery request, for the unanswered second message only.
    - The steered-into-the-same-operation variant isn't reachable in this flow, so it's covered by the real `runReplyAgent` steer test.
- **Regression tests:**
  - `dispatch-from-config.terminal-recovery.test.ts`: a new case marks the active operation answered, then lets the watchdog expire it while the run is still pending, which is the real order. It expects no notice and no continuation. It fails on `main`.
  - `message-tool-execution.test.ts`: the existing eligibility table now also asserts that only an eligible final source send marks the operation. Failures, partial sends, dry runs, `final: false` and other targets don't mark it.
  - The same table has a case where an answer is followed by a steered input. It expects one continuation.
  - `agent-runner.media-paths.test.ts`: the real steer path through `runReplyAgent` clears an earlier answer.
  - Focused suites pass, including `reply-run-registry`, `dispatch-from-config` and `message-tool-execution`.
- One-worker wall times (`pnpm test <file> --maxWorkers=1`, real / Vitest duration): `dispatch-from-config.terminal-recovery.test.ts` 27 s / 23.8 s (27 tests); `message-tool-execution.test.ts` 23 s / 20.3 s (76 tests); `agent-runner.media-paths.test.ts` 27 s / 23.3 s (21 tests). Transform dominates (75–80%); each is under 30 s.
- `node scripts/check-changed.mjs` passes.

LOC vs `origin/main`: production +25/−7, tests +33/−6.

No new user-visible messages. This only removes a redundant answer and an incorrect notice.

No overlap with Pash/Sarah changes on the touched files.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. 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.

1 participant