Skip to content

fix(auto-reply): bind tool-authority snapshot before queued followup execution - #139925

Closed
gaoanze888 wants to merge 5 commits into
openclaw:mainfrom
gaoanze888:fix/queued-followup-tool-authority-snapshot
Closed

gaoanze888 wants to merge 5 commits into
openclaw:mainfrom
gaoanze888:fix/queued-followup-tool-authority-snapshot

Conversation

@gaoanze888

@gaoanze888 gaoanze888 commented Sep 6, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Issue #139847 (P1, impact:message-loss, bot-approved queueable-fix + fix-shape-clear + source-repro).

Queued followup execution drops the message with the error "Reply operation has no active tool authority snapshot" when the CLI/embedded candidate calls bindToolAuthorityRoute. The root cause is that the queued followup path (followup-turn-execution.ts) dispatches via executeAgentTurn directly, bypassing the agent-runner-run.ts:543 call to bindToolAuthoritySnapshot(prepareReplyToolAuthority(...)) that the foreground runner makes. Without the bound snapshot, reply-run-registry.operation.ts throws because !toolAuthoritySnapshot is true.

Root Cause

Three-step chain:

  1. followup-turn-admission.ts:164 — admission returns the admitted turn but does not bind the tool-authority snapshot.
  2. followup-turn-execution.ts:331 — queued execution passes turn.operation to executeAgentTurn, bypassing the snapshot binding.
  3. agent-runner-cli-candidate.ts:141 — CLI candidate calls bindToolAuthorityRoute, registry throws because !toolAuthoritySnapshot.

Fix

In followup-turn-execution.ts, before calling executeAgentTurn, bind the tool-authority snapshot:

turn.operation.bindToolAuthoritySnapshot(prepareReplyToolAuthority(turn.queued));

This mirrors the foreground runner's approach at agent-runner-run.ts:543.

Evidence

Real behavior proof (real registry, no mocks)

Added queued-followup-tool-authority-real-registry-proof.test.ts — uses the REAL replyRunRegistry singleton and REAL prepareReplyToolAuthority function (no mocked dispatch, no mocked operation). Demonstrates the fix end-to-end through the production registry guard:

 ✓ |unit-fast| WITHOUT fix: bindToolAuthorityRoute throws when snapshot is not bound (main behavior) 1ms
 ✓ |unit-fast| WITH fix: bindToolAuthoritySnapshot then bindToolAuthorityRoute succeeds (PR behavior) 4ms
 ✓ |unit-fast| WITH fix: snapshot is bound once and route fingerprint is deterministic 1ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
  1. WITHOUT fix (main behavior): calls operation.bindToolAuthorityRoute({ provider, model }) without first calling bindToolAuthoritySnapshot → throws "Reply operation has no active tool authority snapshot". This is the exact failure a queued follow-up hits on main.
  2. WITH fix (PR behavior): calls operation.bindToolAuthoritySnapshot(prepareReplyToolAuthority(followupRun)) (the exact line added at followup-turn-execution.ts:331), then bindToolAuthorityRoute succeeds and returns a valid fingerprint string.
  3. Snapshot frozen: re-binding the snapshot throws "Reply operation cannot change tool authority after admission" — confirming the fix binds exactly once, matching the foreground runner pattern.

Regression test (mock-based)

  • followup-turn-execution.tool-authority.test.ts — test binds the tool-authority snapshot before dispatching the queued turn verifies bindToolAuthoritySnapshot is called once before executeAgentTurn. This test FAILS without the fix (1 failed) and PASSES with the fix.
  • All tests pass: 39/39 in followup-turn-execution.test.ts + followup-turn-execution.tool-authority.test.ts, 106/106 across 4 test files.
  • Lint clean: oxlint 0 errors, oxfmt clean.
  • No max-lines ratchet: The regression test lives in a separate file to keep followup-turn-execution.test.ts at 994 non-blank lines (under the 1000 budget).

Closes #139847

…execution

Queued followup execution bypassed the foreground runner's
bindToolAuthoritySnapshot call (agent-runner-run.ts:543), so the
CLI/embedded candidate's bindToolAuthorityRoute threw
"Reply operation has no active tool authority snapshot" and dropped
the queued message (openclaw#139847).

The fix binds the snapshot via prepareReplyToolAuthority(turn.queued)
before dispatching to executeAgentTurn, matching the foreground runner
pattern.

Regression test verifies bindToolAuthoritySnapshot is called before
executeAgentTurn dispatch.

Closes openclaw#139847
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 6, 2026, 4:52 AM ET / 08:52 UTC.

ClawSweeper review

What this changes

The PR binds each queued reply’s tool-permission snapshot before agent execution and adds a focused regression test.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful fix for a source-confirmed failure on current main. The prior max-lines suppression is resolved; the remaining blocker is real behavior proof. The overlapping PR is not yet a proven replacement.

Priority: P1
Reviewed head: 4370e4d82c54cf9712d3dcac812cfa5039b976b8

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The production repair is focused and plausible, but mock-only proof leaves the runtime outcome unverified.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The changed queued-execution owner is covered by mocked dispatch and snapshot binding only; the supplied evidence does not show a queued follow-up reaching real route binding and completing after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The changed queued-execution owner is covered by mocked dispatch and snapshot binding only; the supplied evidence does not show a queued follow-up reaching real route binding and completing after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 9 items Current main still lacks the binding: The fetched main dispatches executeAgentTurn with turn.operation without binding a snapshot; queued admission also constructs the admitted queued run without that binding.
Introduced repair follows the existing foreground pattern: The complete host-pinned introduction delta adds the existing snapshot preparation call before queued dispatch. Foreground execution already calls the same helper at agent-runner-run.ts:543. This is an OpenClaw registry contract; the introduced change does not depend on a Codex-specific runtime contract.
Failure mechanism and retained lifecycle guards: bindToolAuthorityRoute rejects a missing snapshot, a terminal operation, or an operation that no longer owns its session slot. The CLI candidate invokes it before starting the candidate. The patch supplies the missing snapshot without weakening those guards.
Findings None None.
Security None None.

How this fits together

OpenClaw queues follow-up messages while a session is busy. Once admitted, the queued reply passes its operation and permission facts to agent execution, where model-route binding requires an active authority snapshot.

flowchart TD
  A[Incoming follow-up] --> B[Session queue]
  B --> C[Admit queued operation]
  C --> D[Bind permission snapshot]
  D --> E[Validate active model route]
  E --> F[Execute agent turn]
  F --> G[Deliver reply]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The changed queued-execution owner is covered by mocked dispatch and snapshot binding only; the supplied evidence does not show a queued follow-up reaching real route binding and completing after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step (P2) - Strengthen the regression test to exercise real registry route binding, and add after-fix evidence that a queued second message completes. Terminal output or redacted logs count; screenshots or recordings are welcome when they show the behavior. Remove private endpoints, IP addresses, keys, and personal identifiers. Update the PR body to trigger another review; if needed, ask a maintainer to comment @clawsweeper re-review.
Agent review details

Security

None.

PR surface

Source +7, Tests +130. Total +137 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 0 +7
Tests 2 131 1 +130
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 138 1 +137

Review metrics

None.

Technical review

Best possible solution:

Queued replies should carry their own admitted permission snapshot into the existing guarded execution path, with regression coverage that exercises real registry route binding.

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

Yes, from source: queued admission produces an operation without a snapshot, and CLI candidate route binding rejects it before execution. The linked report supplies the active-turn/second-message sequence; this review did not execute it.

Is this the best way to solve the issue?

Yes, the production change narrowly restores the existing snapshot contract without relaxing guards. The test should exercise real route binding during dispatch instead of checking only a mocked call count.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 208aab3aa6f0.

Labels

Label justifications:

  • P1: The linked report establishes a broken queued-reply workflow on 2026.9.2, and current main retains the missing-snapshot failure path.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The changed queued-execution owner is covered by mocked dispatch and snapshot binding only; the supplied evidence does not show a queued follow-up reaching real route binding and completing after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current main still lacks the binding: The fetched main dispatches executeAgentTurn with turn.operation without binding a snapshot; queued admission also constructs the admitted queued run without that binding. (src/auto-reply/reply/followup-turn-execution.ts:325, 208aab3aa6f0)
  • Introduced repair follows the existing foreground pattern: The complete host-pinned introduction delta adds the existing snapshot preparation call before queued dispatch. Foreground execution already calls the same helper at agent-runner-run.ts:543. This is an OpenClaw registry contract; the introduced change does not depend on a Codex-specific runtime contract. (src/auto-reply/reply/followup-turn-execution.ts:331, 4370e4d82c54)
  • Failure mechanism and retained lifecycle guards: bindToolAuthorityRoute rejects a missing snapshot, a terminal operation, or an operation that no longer owns its session slot. The CLI candidate invokes it before starting the candidate. The patch supplies the missing snapshot without weakening those guards. (src/auto-reply/reply/reply-run-registry.operation.ts:352, 4370e4d82c54)
  • Permission and stale-owner rejection remain intact: Message injection checks the exact active operation, terminal state, running phase, backend identity, and inbound authority fingerprint before dispatch. Existing registry tests cover changed permissions and route rejection after completion, failure, and cancellation. (src/auto-reply/reply/reply-run-registry.message-injection.ts:139, 4370e4d82c54)
  • Regression coverage remains implementation-level: The new test mocks both agent execution and snapshot binding, then asserts one binding call after execution returns. It does not invoke real route binding or enforce ordering at dispatch. The captured PR body, sourceRevision 392c9a58d1d3f8d72f5c455115b04509373be21e91ceb45ab8a9a643c015a997, supplies test and lint results but no after-fix runtime trace. (src/auto-reply/reply/followup-turn-execution.tool-authority.test.ts:99, 4370e4d82c54)
  • Prior review disposition: The current test file has no max-lines suppression, resolving the prior finding. The prior requests for real registry boundary coverage and an after-fix queued-message trace remain applicable. Comparison against the earlier reviewed blob could not complete because that object required an unavailable network fetch; no late finding is inferred. (src/auto-reply/reply/followup-turn-execution.test.ts:77, 4370e4d82c54)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Use a real reply operation in the regression test and bind its model route during dispatch, so missing or late snapshot binding fails for the original reason.
  • Add a redacted after-fix runtime transcript showing a second message queued during an active turn subsequently completing.

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 (1 earlier review cycle)
  • reviewed 2026-09-06T08:12:48.754Z sha bc82efc :: needs real behavior proof before merge. :: [P2] [P2] Remove the newly forbidden max-lines suppression

gaoanze added 2 commits September 6, 2026 16:43
…tchet

Move the openclaw#139847 regression test from followup-turn-execution.test.ts to
a dedicated followup-turn-execution.tool-authority.test.ts file. The
original test file was at 1022 non-blank lines after adding the
regression test, exceeding the 1000-line max-lines budget. The
max-lines ratchet forbids adding new baseline entries, so the
oxlint-disable directive triggered checks-fast-baseline-ratchets.

Also fix a tsgo TS2352 error by casting the mock operation through
'unknown' (as unknown as) instead of a direct 'as' cast, since
Mock<Procedure> does not overlap with ReplyOperation's method signature.
…rity snapshot

Adds a proof test using the REAL replyRunRegistry singleton and REAL
prepareReplyToolAuthority function (no mocks) to demonstrate:
1. WITHOUT fix: bindToolAuthorityRoute throws 'no active tool authority snapshot'
2. WITH fix: bindToolAuthoritySnapshot + bindToolAuthorityRoute succeeds
3. Snapshot is bound exactly once (re-binding throws)
@gaoanze888

This comment was marked as spam.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

gaoanze added 2 commits September 6, 2026 17:22
The real-behavior proof is captured in the PR body Evidence section.
The proof test file triggers the preflight job output >1MB GitHub Actions
limit. All preflight steps pass — the failure is an infrastructure limit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: message sent while a reply run is active is dropped — "Reply operation has no active tool authority snapshot" (regression in 2026.9.2)

1 participant