Skip to content

fix(gateway): close ask-fallback replay to cancelled approvals - #124381

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-ask-fallback-gate
Aug 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-ask-fallback-gate

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

consumeAskFallback re-admits a timed-out system.run approval exactly once (the documented ask-fallback bridge until the strict exec-timeout cutover). Its gate only checked "resolved and decision-less" — but run-aborted cancellations and worker-dispatch fencing revocations also end decision-less, so a deliberately closed approval could satisfy the timed-out predicate and be replayed as ask-fallback. That violates the closure-bound-authority invariant: terminal state and fencing must fail closed.

A second dishonesty compounded it: worker-dispatch fencing revoked approvals via expire(), which persists a durable timeout terminal — the audit trail claimed the operator never answered when in fact the gateway deliberately fenced the run.

Why This Change Was Made

  • consumeAskFallback now requires the record's terminal to be genuinely unanswered: status === "expired" (timeout) or terminalReason === "no-route". Cancelled/fenced records fail closed.
  • workerDispatchAuthority.revoke routes through forceDenyDetailed(id, "run-aborted", {kind:"system", id:"worker-dispatch"}, "cancelled") so the durable row records what actually happened. Both managers share one loop.
  • Rider cleanup: PendingEntry.reject/rejectPromise were write-only (no caller ever rejects the decision promise) and lookupPendingId was a pure alias of lookupApprovalId with a single test caller — both deleted.

User Impact

An operator who fences a worker dispatch or aborts a run can no longer have that run's exec approval replayed through the ask-fallback path, and approvals list/audit surfaces show cancelled/run-aborted instead of a false timeout for fenced approvals.

Evidence

  • New regression rejects ask-fallback replay of a run-aborted cancellation (exec-approval-manager.expiry.test.ts) fails pre-fix via stash proof, passes post-fix.
  • node scripts/run-vitest.mjs run src/gateway/exec-approval-manager.test.ts src/gateway/exec-approval-manager.expiry.test.ts src/gateway/node-invoke-system-run-approval.test.ts — 110/110.
  • node scripts/run-vitest.mjs run src/gateway/server-methods/server-methods.test.ts — green.
  • tsgo core + test shards clean; oxfmt/oxlint clean.
  • Autoreview (Codex, gpt-5.6-sol high): clean, 0.98.
  • Prod LOC: +16 −18 (net −2); tests +26 −2.

consumeAskFallback gated only on decision-less resolved records, so
run-aborted cancellations and dispatch-fencing revocations — which also
end decision-less — satisfied the timed-out predicate and could be
replayed as ask-fallback. Require the expired/no-route terminal so only
genuinely unanswered approvals re-admit.

Dispatch fencing now records its closure honestly: worker-dispatch
revocation routes through forceDenyDetailed(run-aborted, cancelled)
instead of expire(), which persisted a false 'timeout' terminal.

Rider cleanup: delete the write-only PendingEntry.reject/rejectPromise
plumbing and the lookupPendingId alias (single test caller moved to
lookupApprovalId).
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 03:31
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 15, 2026, 11:37 PM ET / August 16, 2026, 03:37 UTC.

ClawSweeper review

What this changes

This PR limits ask-fallback replay to genuinely unanswered approvals and records worker-dispatch fencing as a run-aborted cancellation instead of a timeout.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The fallback gate correctly rejects cancelled approvals, but the new worker-dispatch cancellation path drops the existing exec/plugin terminal-publication flow. That leaves native approval clients and iOS push paths unaware that their pending prompt was cancelled, so this PR needs a focused repair before merge.

Priority: P1
Reviewed head: bafcee4f8e14d3c9b50775f71a366f91c8bbd6e9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The core authorization repair is well targeted, but a P1 terminal-publication regression blocks merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored gateway repair is assessed through the focused owner-boundary tests and exact-head CI; no external-contributor proof action is required.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored gateway repair is assessed through the focused owner-boundary tests and exact-head CI; no external-contributor proof action is required.
Evidence reviewed 7 items Current-main defect: Current main admits any resolved, decision-less approval to ask-fallback, while worker-dispatch fencing routes matching approvals through expire(), which records a timeout-shaped terminal.
Fallback repair is sound: The branch restricts replay to expired or no-route terminals, so run-aborted cancellations cannot be re-admitted through ask-fallback.
Dropped terminal publication: The new dispatch loop calls forceDenyDetailed for both approval managers but ignores its winning terminal result; cancellation is therefore not sent to the publication path.
Findings 1 actionable finding [P1] Publish dispatch-fenced approval cancellations
Security None None.

How this fits together

Gateway approval managers retain exec and plugin approval requests until a decision or terminal event. Worker-dispatch fencing closes requests for a session, and terminal publication notifies gateway clients, native forwarders, and iOS push delivery.

flowchart LR
  A[Pending exec or plugin approval] --> B[Worker dispatch fence]
  B --> C[Cancel approval authority]
  C --> D[Terminal approval record]
  D --> E[Gateway publication]
  E --> F[Native forwarder and iOS push]
  D --> G[Ask-fallback eligibility check]
Loading

Before merge

  • Publish dispatch-fenced approval cancellations (P1) - The new loop records cancelled terminals but discards the winning result. onExpired is the only manager callback that reaches publishAuthorityClosure, so exec and plugin forwarders/iOS push will not learn that an outstanding prompt was fenced. Route winning cancellations through the existing terminal-publication path, as the worker-claim cancellation helper does.
  • Resolve merge risk (P1) - As written, dispatch-fenced exec and plugin approvals become cancelled without notifying their native forwarder or iOS push route, leaving an operator-facing prompt outstanding despite its durable closure.
  • Complete next step (P2) - A narrow mechanical repair can preserve the intended cancellation state while restoring the existing terminal-publication invariant.

Findings

  • [P1] Publish dispatch-fenced approval cancellations — src/gateway/server-core-runtime.ts:379-384
Agent review details

Security

None.

PR surface

Source -2, Tests +24. Total +22 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 16 18 -2
Tests 2 26 2 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 42 20 +22

Review metrics

Metric Value Why it matters
Production versus test LOC production −2, tests +24 The repair is net-negative in production code, but its changed terminal path needs end-to-end publication coverage before merge.

Merge-risk options

Maintainer options:

  1. Publish dispatch-fence cancellations (recommended)
    Repair the worker-dispatch fence so each winning exec or plugin cancellation reaches the established terminal publication path, then cover both native approval kinds.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Route winning worker-dispatch cancellations through the canonical exec/plugin terminal-publication flow and add focused coverage for both approval kinds.

Technical review

Best possible solution:

Route worker-dispatch fencing through one canonical cancel-and-publish path for both approval kinds, preserving cancelled/run-aborted records while publishing the winning terminal transition.

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

Yes, from source: fence a session with a pending exec or plugin approval; the new loop records cancellation but does not invoke the terminal publisher that reaches native clients and iOS push.

Is this the best way to solve the issue?

No: the ask-fallback gate is the right repair, but worker-dispatch fencing must also preserve the established terminal-publication behavior for both approval kinds.

Full review comments:

  • [P1] Publish dispatch-fenced approval cancellations — src/gateway/server-core-runtime.ts:379-384
    The new loop records cancelled terminals but discards the winning result. onExpired is the only manager callback that reaches publishAuthorityClosure, so exec and plugin forwarders/iOS push will not learn that an outstanding prompt was fenced. Route winning cancellations through the existing terminal-publication path, as the worker-claim cancellation helper does.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a0498f7a9c8a.

Labels

Label changes:

  • add P1: The patch would leave active exec and plugin approval prompts unresolved after a worker-dispatch fence.
  • add merge-risk: 🚨 message-delivery: The changed cancellation path bypasses the existing forwarder and iOS terminal-notification delivery.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored gateway repair is assessed through the focused owner-boundary tests and exact-head CI; no external-contributor proof action is required.

Label justifications:

  • P1: The patch would leave active exec and plugin approval prompts unresolved after a worker-dispatch fence.
  • merge-risk: 🚨 message-delivery: The changed cancellation path bypasses the existing forwarder and iOS terminal-notification delivery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored gateway repair is assessed through the focused owner-boundary tests and exact-head CI; no external-contributor proof action is required.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs run src/gateway/exec-approval-manager.expiry.test.ts src/gateway/server-aux-handlers.test.ts src/gateway/node-invoke-system-run-approval.test.ts.
  • [P1] node scripts/check-changed.mjs --dry-run -- src/gateway/server-core-runtime.ts src/gateway/server-aux-handlers.ts src/gateway/server-aux-handlers.test.ts.

What I checked:

Likely related people:

  • steipete: Authored the durable approval and revocation work, and has the dominant available history on the approval-manager surface. (role: feature owner and recent area contributor; confidence: high; commits: 9b1c36d23c3f, 5b56a1f664e6, bafcee4f8e14; files: src/gateway/exec-approval-manager.ts, src/gateway/server-aux-handlers.ts, src/gateway/server-core-runtime.ts)

Rank-up moves

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

  • Publish each winning worker-dispatch cancellation through the existing exec/plugin terminal-publication path.
  • Add a focused worker-dispatch test proving exec and plugin prompt resolution reaches the native publication sink.

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.

@steipete
steipete merged commit e8e7598 into main Aug 16, 2026
255 checks passed
@steipete
steipete deleted the codex/autoqa-ask-fallback-gate branch August 16, 2026 03:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…law#124381)

consumeAskFallback gated only on decision-less resolved records, so
run-aborted cancellations and dispatch-fencing revocations — which also
end decision-less — satisfied the timed-out predicate and could be
replayed as ask-fallback. Require the expired/no-route terminal so only
genuinely unanswered approvals re-admit.

Dispatch fencing now records its closure honestly: worker-dispatch
revocation routes through forceDenyDetailed(run-aborted, cancelled)
instead of expire(), which persisted a false 'timeout' terminal.

Rider cleanup: delete the write-only PendingEntry.reject/rejectPromise
plumbing and the lookupPendingId alias (single test caller moved to
lookupApprovalId).
raitoxlol pushed a commit to raitoxlol/hermes-agent that referenced this pull request Nov 23, 2026
Port from openclaw/openclaw#124381: stale interactive approval controls must not resolve a later approval in the same session.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant