Skip to content

fix(gateway): give refusals an honest cause and a next step - #202402

Merged
obviyus merged 3 commits into
mainfrom
fix/refusal-next-steps
Nov 20, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/refusal-next-steps

Conversation

@obviyus

@obviyus obviyus commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

What problem this solves

Several refusals that users see were honest but gave no next step, or named the wrong cause, or used internal words:

  • "message action authority is no longer active" and "agent runtime authority is no longer active" for a message turn that ended;
  • "approval consumption is no longer available", "approval record is no longer current" and "approval run already aborted";
  • the owner notice for a refused queued request (fix(channels): record a refused queued request for the owner without replying in the channel #202252), which had no next step;
  • when the system-agent session was replaced: "OpenClaw repair stopped after one corrective attempt" (wrong cause) and "OpenClaw session changed during audit persistence" (internal words).

Also, a Stop during approval preparation could miss the cancellation sweep, so the user still got an approval prompt for work they had already stopped (from #201812).

Change

Text, inside the existing owners (no new error types or notice writers):

  • Ended message turn: "The message turn has ended. Start a new turn to retry."
  • Approvals: "This approval was already used." / "This approval was replaced or closed." / "This approval has expired.", each with "Start a new turn to request approval again." where a retry makes sense. Stopped run: "The approval run was stopped. Start a new turn to request approval again."
  • Refused queued request (owner notice): adds "Review the channel access settings; once access is restored, ask the requester to send the request again."
  • System-agent session replaced: "The system-agent session was replaced before the next proposal could be reviewed." and "This OpenClaw chat was replaced while the change was being saved." Both keep "Check the current settings before making a new request."

Behavior: when approval registration finds the run already stopped (the existing abort marker), it settles the record as cancelled through the existing cancellation owner before any prompt is delivered.

Evidence

Proof tier: source (ocx test) plus a real Gateway run (see the PR comment).

  • New regression: Stop during approval preparation delivers no approval prompt, and the record is durably cancelled. Red on the base, green with the fix.
  • A real openclaw.chat session-replaced regression shows the new outer and inner texts.
  • The tests that pinned the old strings are updated. Affected selection: 163 passed. The 6 corrected cases have a final run pending.
  • pnpm tsgo, type-aware oxlint on all 19 touched files, format, and the lifetime-check and line-cap ratchets: pass.

- Preserve structured message-policy refusals and explain how to retry ended turns and approvals.
- Settle approvals cancelled during preparation before delivering a pending prompt.
- Explain replaced OpenClaw chats in the existing proposal and audit owners.
@clawsweeper

clawsweeper Bot commented Nov 20, 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 gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: d878c101be0bbf2994937cbc826c7fd4a0ee4f31
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/exec-approval-consumption.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/exec-approval-manager.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/server-methods/agent-runtime-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/exec-approval.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR makes Gateway refusals actionable, preserves structured policy errors, and cancels approvals stopped during preparation before prompting.

Example: Stop ends run run-stopped-during-preparation while its exec approval is being prepared.

  • Before: The cancellation sweep misses the unregistered approval, which can subsequently display a prompt.
  • After: Registration is followed by cancellation, and the caller receives a stopped-run explanation without an approval prompt.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful, focused production changes remain unready because validation has two attributable failures and the referenced live evidence is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users can receive misleading refusals or an approval prompt for work they already stopped.
Reason: The maintainer-authored direction addresses observable failure paths while retaining existing authorization, delivery, and persistence owners.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this maintainer-authored PR open: it addresses concrete refusal and cancellation problems, but two diff-caused CI failures require repair.

Priority: P2
Reviewed head: 2a6e7c294075e3017a3020a4c932863356f36493

Before merge

  • Update the remaining channel consumers of the ended-turn message (P2) - Changing this shared exception leaves existing Teams and Slack integration assertions expecting /no longer active|authority/i and /no longer active/i. Current-head CI reports those exact failures at test/msteams-read-authority.integration.test.ts:858 and test/slack-download-read-authority.integration.test.ts:868. Update the affected assertions while retaining their no-request, no-success-cache, and artifact-cleanup checks.
  • Resolve the new diagnostic matches in the identity ratchet (P2) - The session-identity scanner counts the literal phrase was replaced. This new consumption message creates a hit in a file with no allowance; the new manager and system-agent messages add further hits against unchanged allowances. CI confirms the session-identity ratchet fails. Adjust the actionable diagnostics or narrowly correct their classification without expanding the identity baseline or weakening the existing guards.

Findings

  • [P2] Update the remaining channel consumers of the ended-turn message — src/gateway/server-methods/agent-runtime-authority.ts:18
  • [P2] Resolve the new diagnostic matches in the identity ratchet — src/gateway/exec-approval-consumption.ts:70

Tests

  • Missing end-to-end proof: Supply redacted real-Gateway output showing Stop during approval preparation produces no prompt and a cancelled record, plus the changed refusal messages; redact IPs, keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

Gateway handlers accept agent message and approval requests, apply existing authority and persistence rules, and return delivery results, approval prompts, or refusal messages.

flowchart TD
  A[Agent or client request] --> B[Gateway admission]
  B --> C[Message routing and delivery]
  B --> D[Approval registration]
  D --> E[Existing cancellation manager]
  D --> F[Approval prompt]
  C --> G[Structured result or refusal]
  E --> G
Loading

Technical review

Best possible solution:

Keep the existing refusal and cancellation owners, complete the consumer-test updates, and resolve diagnostic-text ratchet matches without expanding identity allowances.

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

Source shows preparation yielding before approval registration, allowing Stop's cancellation sweep to miss the record; the added handler regression exercises that ordering, but no target code was run during this review.

Is this the best way to solve the issue?

The production repair is focused and reuses existing state and cancellation operations; the remaining concrete defects are incomplete consumer validation and diagnostic wording that fails the existing ratchet.

Full review comments:

  • [P2] Update the remaining channel consumers of the ended-turn message — src/gateway/server-methods/agent-runtime-authority.ts:18
    Changing this shared exception leaves existing Teams and Slack integration assertions expecting /no longer active|authority/i and /no longer active/i. Current-head CI reports those exact failures at test/msteams-read-authority.integration.test.ts:858 and test/slack-download-read-authority.integration.test.ts:868. Update the affected assertions while retaining their no-request, no-success-cache, and artifact-cleanup checks.
    Confidence: 1
  • [P2] Resolve the new diagnostic matches in the identity ratchet — src/gateway/exec-approval-consumption.ts:70
    The session-identity scanner counts the literal phrase was replaced. This new consumption message creates a hit in a file with no allowance; the new manager and system-agent messages add further hits against unchanged allowances. CI confirms the session-identity ratchet fails. Adjust the actionable diagnostics or narrowly correct their classification without expanding the identity baseline or weakening the existing guards.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Message-turn refusals and structured authorization errors keeps the original intent (26a5f73: Separate request-start runtime admission from retained message-turn checks; the patch preserves those checks while returning their actual refusal cause.)
  • Approval preparation and cancellation changes intended behavior with a stated reason (de680e3: The earlier refactor removed repeated runtime-authority checks and explicitly accepted preparation-time Stop leaving a record pending; this PR explains and repairs the resulting unwanted prompt.)
  • Approval consumption diagnostics keeps the original intent (1c1b6e0: Consumption retains the exact database owner, binding, grace window, and committed outcome; this patch changes refusal explanations without changing those predicates.)
  • Queued channel refusal notice keeps the original intent (3e7c305: Record a fixed, sanitized explanation for the owner while remaining silent in the channel; the added next step preserves that boundary.)
  • System-agent corrective proposal notice keeps the original intent (387da5e: Permit approved configuration changes with one corrective proposal and bounded cleanup; the patch distinguishes session replacement from exhausting that correction.)
  • System-agent audit-persistence refusal keeps the original intent (e456cc4: Await audit persistence and reject stale session publication; the patch preserves the same predicate and changes its user-facing explanation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test test/msteams-read-authority.integration.test.ts test/slack-download-read-authority.integration.test.ts --maxWorkers=1
  • pnpm check:session-identity-ratchet --base 04d1dd1
  • git diff --check

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit de680e3 adds src/gateway/server-methods/exec-approval.ts:168 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: de680e35f98f; files: src/gateway/server-methods/exec-approval.ts)
  • Peter Steinberger: Raw commit e456cc4 adds src/gateway/server-methods/system-agent.ts:329 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e456cc4aac1e; files: src/gateway/server-methods/system-agent.ts)
  • Josh Avant: Raw commit 1c1b6e0 adds src/gateway/exec-approval-consumption.ts:55 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 1c1b6e00fbe6; files: src/gateway/exec-approval-consumption.ts)

PR surface

Source +58, Tests +132. Total +190 across 19 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 10 87 29 +58
Tests 9 157 25 +132
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 244 54 +190

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Actionable refusals and suppression of stopped-work approval prompts improve a limited Gateway failure path.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Actionable refusals and suppression of stopped-work approval prompts improve a limited Gateway failure path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 20, 2026, 5:03 AM ET / 10:03 UTC.

- Remove cause-selection branches from approval refusals while preserving the existing guards.
- Use one corrective-stop notice with a clear recovery step.
- Update Teams and Slack ended-turn expectations without changing effect assertions.
- Restore the existing plugin-review and corrective-attempt notices unchanged.
- Keep actionable chat persistence guidance at the user-visible audit fence.
- Limit the new Teams ended-turn expectation to Gateway reads.
@obviyus
obviyus merged commit 3371825 into main Nov 20, 2026
120 checks passed
@obviyus
obviyus deleted the fix/refusal-next-steps branch November 20, 2026 10:34
obviyus added a commit that referenced this pull request Nov 20, 2026
## Problem

`channel-run-admission.discord-recovery.test.ts` (#202330) pinned the exact refused-followup notice. #202402 then added a next step to that notice in its owner (`agent-runner-error-handler.ts`), so the test fails on `main` whenever it is selected.

## Fix

Stop pinning wording. The test still proves the behavior: one terminal error event with a notice, the same notice shown once in the transcript, the same text delivered for the unavailable case, and no model or channel effects for a revoked sender.

## Evidence

`ocx test src/auto-reply/reply/channel-run-admission.discord-recovery.test.ts`: passed. oxfmt and test types clean.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…#202402)

Problem: several user-facing refusals were honest but had no next step or used internal words: "message action authority is no longer active" for an ended message turn, "approval consumption is no longer available", "approval record is no longer current", "approval run already aborted", the owner notice for a refused queued request (openclaw#202252), and "OpenClaw session changed during audit persistence". A Stop during approval preparation could also miss the cancellation sweep, so the user still got an approval prompt for stopped work.

Fix (text in existing owners, no new error types and no identity comparisons): "The message turn has ended. Start a new turn to retry."; "This approval is no longer available. Start a new turn to request approval again."; "The approval run was stopped. Start a new turn to request approval again."; the owner notice adds "Review the channel access settings; once access is restored, ask the requester to send the request again."; the system-agent audit fence reads "This OpenClaw chat changed while the change was being saved. Check the current settings before making a new request." Main's two specific corrective notices are unchanged. Approval registration that finds the run already stopped settles the record as cancelled before any prompt is delivered.

Proof: Stop-during-preparation regression red on base, green with the fix; affected Slack, Teams, approval and system-agent suites; session-identity ratchet, oxlint, format; clean exact-head local ClawSweeper review; real Gateway run (Stop on a real-model exec: no approval prompt, the run cancelled, the new stopped-run wording returned).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…#202471)

## Problem

`channel-run-admission.discord-recovery.test.ts` (openclaw#202330) pinned the exact refused-followup notice. openclaw#202402 then added a next step to that notice in its owner (`agent-runner-error-handler.ts`), so the test fails on `main` whenever it is selected.

## Fix

Stop pinning wording. The test still proves the behavior: one terminal error event with a notice, the same notice shown once in the transcript, the same text delivered for the unavailable case, and no model or channel effects for a revoked sender.

## Evidence

`ocx test src/auto-reply/reply/channel-run-admission.discord-recovery.test.ts`: passed. oxfmt and test types clean.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
## Problem

`channel-run-admission.discord-recovery.test.ts` (#202330) pinned the exact refused-followup notice. #202402 then added a next step to that notice in its owner (`agent-runner-error-handler.ts`), so the test fails on `main` whenever it is selected.

## Fix

Stop pinning wording. The test still proves the behavior: one terminal error event with a notice, the same notice shown once in the transcript, the same text delivered for the unavailable case, and no model or channel effects for a revoked sender.

## Evidence

`ocx test src/auto-reply/reply/channel-run-admission.discord-recovery.test.ts`: passed. oxfmt and test types clean.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 656de08)

Companion of #202330 (gap-sweep): its regression pinned notice wording that this branch already extended (4eb5484); main fixed the test the same way.

Co-authored-by: RomneyDa <[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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. gateway Gateway runtime security-sensitive-changed size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant