Skip to content

refactor(gateway): one refusal owner with a required next step - #205337

Merged
obviyus merged 2 commits into
mainfrom
refactor/oa2-refusal-owner
Nov 25, 2026
Merged

obviyus merged 2 commits into
mainfrom
refactor/oa2-refusal-owner

Conversation

@obviyus

@obviyus obviyus commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Refused operator work had no single owner for what the person sees. Each throw site wrote its own sentence, so the same cause read differently by entry point, scope ids and internal words leaked ("Gateway access stopped [access-cause=grant-revoked]", "Restart recovery could not admit this input"), the D23 channel text was copied twice, and the model only got a "do not retry" hint for method-scope refusals. Other refusals reached the model as raw errors, which it paraphrased or retried.

Fix

  • New owner src/gateway/operator-refusal.ts: one cause table (same pattern as connect-error-details.ts). Each cause has a required why and nextStep; the compiler rejects a cause without a next step. Text shape: "I did not . . ." Causes: access-ended, sign-in-ended, role-denies, channel-unverified, owner-removed, requester-access-ended, invitation-ended, github-not-linked (only on the path where linking helps: a profile with no linked account and no write access).
  • OperatorRefusalError(cause, { action }) replaces GatewayOperatorRecoveryAuthorizationError and its free-text messages. Admission (operator-admission.ts) and the recovery helpers pick a cause; R5 ("Gateway access is not active for this requester") is now role-denies; R3/R13 (access-cause=grant-revoked) are now access-ended with the cause chain kept.
  • Refusal sites moved onto the table: R9 / requester write (role-denies), R8/D23 channel identity (channel-unverified, was duplicated), GitHub link (github-not-linked), ownerAllowFrom removal (owner-removed), restart completion notice (requester-access-ended).
  • Delivery: chat already shows OperatorRefusalError.message (agent-runner-error-handler.ts). The tool adapter now returns the same sentence plus "Do not retry." for any refusal (and for method-scope refusals, through the same table). sessions.github.* errors keep the typed failure for in-process tool callers (errorShapeFromError), so R9 reaches the model as a refusal.
  • Boundary lint no-operator-refusal-construction (shrink-only, ceiling 9): new OperatorRefusalError or a subclass outside the owner fails unless the file is listed. No wording lint.

R3 retry loop: already settled by #204609 (definite refusals settle once); unchanged here except the class name and the notice text.

Not in this PR (remaining refusal texts, follow-up): operator-role-policy.ts request-time agent refusal, channel run authorization notice in agent-runner-error-handler.ts, github-publication-failure.ts workflow permission, session-access-authority.ts / tool-policy refusals, connect-time access-cause texts (connect owner).

Production src: net positive (recorded): the cause table is the new owner; 9 free-text refusal producers and one duplicate moved onto it.

User impact

Example (revoked member's queued message): "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to do it, or to add the permission to your role." The model gets the same sentence plus "Do not retry."

Evidence

  • src/gateway/operator-refusal.test.ts: one case per cause through the real tool adapter (sentence + "Do not retry."), plus the in-process Gateway method path. Red on base (no owner).
  • Updated contract tests: restart completion notice, tool-bridge member refusal, GitHub inspection, recovery.
  • E2E (isolated Gateway, real model) on 2926527b454e: R/Q/S pass; refactor(gateway): one refusal owner with a required next step #205337 (comment)
  • Known gap: a queued /followup refusal shows the existing pending-input status in chat, not the cause sentence (needs a queue-lifecycle notice or a pending-input field; follow-up).

@clawsweeper

clawsweeper Bot commented Nov 25, 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 docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Nov 25, 2026
Operator refusals now name a typed cause from one table in
src/gateway/operator-refusal.ts. Each cause carries a required next step;
the person sees what was not done, whose access and why, and that step.
The tool result gives the model the same sentence plus "Do not retry."
A shrink-only boundary rule keeps refusal construction in listed files.

Co-authored-by: obviyus <[email protected]>
@github-actions

github-actions Bot commented Nov 25, 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: 8c4eed0a4f9a148bf06d3484e3b4d2bb1fd4b071
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/worker-environments/provision-source-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 25, 2026
@obviyus
obviyus force-pushed the refactor/oa2-refusal-owner branch from 9962519 to 2926527 Compare November 25, 2026 12:29
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on exact head 2926527b454e (isolated Gateway, real model through a byte-forwarding relay, one-admission journey):

  • R.running-turn-finishes: pass (revoked mid-run, the running turn finished; 3 tool ends after revoke)
  • Q.queued-input-refused-visibly: pass (worker demoted to readonly while a /followup was queued; 0 provider requests for it; pending input ends cancelled / policy-refused)
  • S.stop-cancels: pass

verdict.json:

{"pass":true,"checks":["R.running-turn-finishes","Q.queued-input-refused-visibly","S.stop-cancels"],"elapsedMs":58674}

Refusal produced by admission for the revoked member's queued input (Gateway log):

OperatorRefusalError: I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to do it, or to add the permission to your role.

Known gap, recorded (not fixed here): for this queued /followup path the chat shows the existing pending-input status ("This message was blocked by a policy and did not run."), not the cause sentence. Carrying the sentence there needs either a new transcript notice from the queue lifecycle or a new pending-input field (stored row). Live-turn refusals (agent-runner-error-handler.ts settles with the sentence), the restart completion notice, and tool results already show it.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR centralizes operator refusal messages and gives tool callers the same explanation followed by “Do not retry.”.

Example: A member without operator write permission asks github_publish to act on another person's PR.

  • Before: The refusal uses a site-specific permission message without the shared retry guidance.
  • After: The tool receives an explanation of the refused action, whom to ask, and “Do not retry.”

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful consolidation with partial live evidence, one source-verifiable response-contract regression, and unresolved CI attribution.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: People receive inconsistent or internal permission errors, and models may retry refused operations without useful recovery guidance.
Reason: The maintainer-authored direction addresses a concrete presentation problem without adding settings or changing admission policy.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this maintainer-authored PR open: the shared refusal owner is useful, but the GitHub error conversion introduces a structured-error regression.

Reviewed head: 8c4eed0a4f9a148bf06d3484e3b4d2bb1fd4b071

Before merge

  • Preserve lease-acquisition details when retaining typed failures (P2) - When a publication or confirmation lease acquisition fails with an underlying unavailable storage worker or SQLITE_FULL error, acquireOpenClawStateLease throws OpenClawStateLeaseAcquisitionError with outcome.kind = store-unavailable and retains that storage error as its cause. The new errorShapeFromError call traverses the cause, selects its storage branch, and replaces the supplied details with { code: storageFailure }. The response therefore loses details.leaseAcquisition, breaking the existing structured acquisition contract. Preserve the original response metadata while attaching the typed cause, or limit the new conversion to operator refusals.
  • Explain or restore the original intent of Publication lease-acquisition error responses - 44b0127: Distinguish held leases, unavailable storage, and caller cancellation using structured outcomes.

Findings

  • [P2] Preserve lease-acquisition details when retaining typed failures — src/gateway/server-methods/sessions-github.ts:143-148

Provenance

  • Publication lease-acquisition error responses changes intended behavior without addressing why it exists (44b0127: Distinguish held leases, unavailable storage, and caller cancellation using structured outcomes.)

Tests

  • Missing end-to-end proof: Show a refused operation through the real tool or live-turn delivery path with the new sentence reaching its recipient and retry guidance reaching the model; redact credentials and private endpoints.
Agent review details

How this fits together

Gateway admission and publication operations produce refusals; chat error handling and the agent tool adapter present them to people and models.

flowchart LR
  A[Operator request] --> B[Admission or publication]
  B --> C[Typed refusal cause]
  C --> D[Shared refusal text]
  D --> E[Chat reply]
  D --> F[Tool result]
  F --> G[Agent model]
Loading

Technical review

Best possible solution:

Keep the shared refusal owner while preserving existing publication error envelopes when retaining typed causes.

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

Source confirms inconsistent refusal presentation and the introduced publication-envelope failure; no target code was executed during this read-only review.

Is this the best way to solve the issue?

A shared typed cause table is a focused solution, but retaining an error cause should not also replace unrelated publication failure metadata.

Full review comments:

  • [P2] Preserve lease-acquisition details when retaining typed failures — src/gateway/server-methods/sessions-github.ts:143-148
    When a publication or confirmation lease acquisition fails with an underlying unavailable storage worker or SQLITE_FULL error, acquireOpenClawStateLease throws OpenClawStateLeaseAcquisitionError with outcome.kind = store-unavailable and retains that storage error as its cause. The new errorShapeFromError call traverses the cause, selects its storage branch, and replaces the supplied details with { code: storageFailure }. The response therefore loses details.leaseAcquisition, breaking the existing structured acquisition contract. Preserve the original response metadata while attaching the typed cause, or limit the new conversion to operator refusals.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Admission and saved-requester refusals keeps the original intent (3ad2cce: Unify admission when saved work starts while allowing admitted work to finish.)
  • Missing-scope tool presentation keeps the original intent (1ea3d5f: Give models action-specific permission guidance instead of raw scope identifiers.)
  • Restart completion settlement keeps the original intent (b3dfd35: Settle definitively refused completions once while preserving uncertain failures for retry.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +37, Tests +91, Docs +1, Other +73. Total +202 across 53 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 19 156 119 +37
Tests 29 146 55 +91
Docs 1 3 2 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 4 73 0 +73
Total 53 378 176 +202

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 merge-risk: 🚨 compatibility: Storage failures during publication lease acquisition can lose the existing details.leaseAcquisition response field.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • merge-risk: 🚨 compatibility: Storage failures during publication lease acquisition can lose the existing details.leaseAcquisition response field.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • 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 25, 2026, 8:08 AM ET / 13:08 UTC.

@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: every red on head 8c4eed0a4f9a is not ours.

ci-triage:

# PR #205337 head 8c4eed0a4f9a; main run 45604380188
checks-node-changed-compact-large-20-1	src/auto-reply/reply/commands-plugin.scheduled-turns-restart.test.ts	OURS
checks-node-changed-compact-large-27	src/gateway/server.auth.openclaw-id-tunnel.test.ts	MAIN-ALSO
checks-node-changed-compact-large-41-1	src/auto-reply/reply/commands-plugin.scheduled-turns.test.ts	OURS
checks-node-changed-compact-large-41-1	src/cron/service.restart-session-event.test.ts	OURS
checks-node-changed-compact-large-8	src/gateway/server.plugin-reload-send-revocation.product.test.ts	MAIN-ALSO

Proof per file (local runs on the merge base 52715199483c, ocx base merge-base --src, without this PR):

  • src/auto-reply/reply/commands-plugin.scheduled-turns-restart.test.ts: red on base, same 2 cases ("re-arms the same code and exhausts its budget", handler called 0 times).
  • src/auto-reply/reply/commands-plugin.scheduled-turns.test.ts: red on base (16 failed / 12 passed).
  • src/cron/service.restart-session-event.test.ts: red on base ("finishes a queued Cron event only after its adopted turn and transport settle").
  • src/gateway/server.plugin-reload-send-revocation.product.test.ts: red on base, same inner result (1 passed, 1 failed).
  • src/gateway/server.auth.openclaw-id-tunnel.test.ts: MAIN-ALSO per ci-triage.
  • build-artifacts: total CSS gzip 49 B over its ceiling; this PR changes no ui/ or CSS file.

The only OURS red on the first head (test/scripts/eager-import-closure.test.ts, PR wrapper inventory) is fixed in 8c4eed0a4f9a.

@obviyus
obviyus merged commit 2a14180 into main Nov 25, 2026
162 of 169 checks passed
@obviyus
obviyus deleted the refactor/oa2-refusal-owner branch November 25, 2026 13:36
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 2a14180. Refusals now come from one cause table (src/gateway/operator-refusal.ts) with a required next step; the model gets the same sentence plus "Do not retry." Proof: per-cause tests through the real tool adapter, E2E R/Q/S pass (#205337 (comment)), clean local review. Follow-up: show the cause sentence for queued /followup refusals in chat (today the pending-input status).

vincentkoc added a commit that referenced this pull request Nov 25, 2026
* commit '92569e37ab84a8cb1e4a12c3dcbb45acb97977c9':
  fix: distinguish Desktop sources without wrapping their names or IDs (#203747)
  fix(ui): Greek sigma searches miss matches outside Sessions and Files (#189518)
  fix: keep agent skill names on one line beside their switches (#203734)
  test(cron): admit scheduled occurrences in cron fixtures and fix Node 24 toHex in Vitest (#205383)
  fix: keep the Agents menu usable after copying an ID (#203739)
  fix(whatsapp): preserve code table spaces across message chunks (#205327)
  refactor(cron): admit legacy scheduled requesters through operator admission (#205346)
  fix: keep silent Codex turns healthy with running commands (#196062)
  test(update): verify the recorded preparation failure (#205363)
  fix(test): prove sibling imports on the active update path
  fix(chat): complete mentions without leaving part of the name behind (#205326)
  fix(test): restore Side chat hydration and retry checks (#205376)
  refactor: plugin-run turns get owner status from commands.ownerAllowFrom, like text messages (#205373)
  chore(ui): refresh control ui locales (#205378)
  fix: keep Telegram rich <details> and list blocks in one message when replies stream in chunks (#205318)
  refactor(gateway): one refusal owner with a required next step (#205337)
  fix(discord): keep long table labels bold across messages (#205328)
  feat: invitation, sharing and participant controls in the Control UI (#204920)
  fix(test): distinguish stamped Skill Library upgrade policies
  fix(markdown): preserve trailing inline-code spaces in plain-text tables (#205317)
obviyus added a commit that referenced this pull request Nov 25, 2026
## Problem

A queued input (including `/followup`) that admission refused at start was visible only in the Gateway log. In chat the person saw only the generic pending-input line "This message was blocked by a policy and did not run." The cause sentence from #205337 (`OperatorRefusalError`, e.g. "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to …") did not reach them. Cause: `followup-runner.ts` treats a start refusal as a plain retry→consumed failure, so the existing "withheld" outcome (visible transcript notice plus source delivery) never runs for it.

Some refusal texts also still sat outside the cause table (follow-ups listed in #205337).

## Fix

- `src/auto-reply/reply/followup-runner.ts`: an `OperatorRefusalError` thrown before the turn is admitted (`!admittedTurn`) now takes the existing withheld branch, like a retired cron delivery. The notice is the refusal's own sentence (no `withheld:` prefix). That branch already records a visible `run-failed-before-reply` transcript notice and hands the failed completion to the source owner (Gateway chat records it in the run's chat). A refusal after the turn starts does not match, so a running turn never gets a false "I did not run".
- Cause table (`src/gateway/operator-refusal.ts`) gets three rows. These sites now use it:
  - role agent refusal (`operator-role-policy.ts`, `agent-not-in-role`)
  - channel access notice (`agent-runner-error-handler.ts`, `channel-access-ended`)
  - workflow-permission failure (`github-publication-failure.ts`, `role-denies`; the nextAction keeps "not a token scope failure, saved changes intact")
  - session tool-policy refusals (`session-resource-tool-policy.ts`, `session-access-authority.ts`, `tool-policy-denies`)

### Decision: no new pending-input column

The brief allowed one new nullable field on `session_pending_inputs` to carry the cause id. I did not add it. The existing withheld path already puts the sentence in the chat, so the schema change is avoidable (schema changes only when unavoidable; no new state). A column would have needed a PostgreSQL schema bump, a protocol field and about 20 files of threading. Consulted Fable 5.2; same pick. Trade-off: the pending-input line stays generic ("blocked by a policy"). The sentence shows as its own notice right after it. Old rows: unchanged, because nothing is stored.

### Known gap: channel messages

Channel-originated queued inputs get the transcript notice (seen in the session in Control UI). They do not get a channel message. Channel inbound followups register no `onQueuedFollowupReplyBatch` source delivery, and a refused input has no admitted turn to deliver through. Sending one needs a new delivery path for unadmitted input, which this PR does not add. Tracked in #205417.

Production `src`: net +25 lines (three cause rows, the refusal condition and notice selection; long free-text strings removed).

## User impact

A member whose role was lowered while their `/followup` waited sees in the chat: "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to do it, or to add the permission to your role." Before, they saw only "This message was blocked by a policy and did not run."

## Evidence

- `src/gateway/server-methods/chat-send-direct-followup.test.ts` "refuses a queued /followup … and says why in chat": real chat dispatch, queued `/followup`, requester demoted before start. It asserts the sentence in the transcript notice. It fails on base (followup-runner reverted) and passes on head.
- Updated wording tests for the moved texts; `operator-refusal.test.ts` covers the new causes through the tool adapter.
- E2E (isolated Gateway, real model) on `17bb2763cffa`: R, Q (with the new sentence assertion) and S pass; #205408 (comment)

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

## Problem

Refused operator work had no single owner for what the person sees. Each throw site wrote its own sentence, so the same cause read differently by entry point, scope ids and internal words leaked ("Gateway access stopped [access-cause=grant-revoked]", "Restart recovery could not admit this input"), the D23 channel text was copied twice, and the model only got a "do not retry" hint for method-scope refusals. Other refusals reached the model as raw errors, which it paraphrased or retried.

## Fix

- New owner `src/gateway/operator-refusal.ts`: one cause table (same pattern as `connect-error-details.ts`). Each cause has a required `why` and `nextStep`; the compiler rejects a cause without a next step. Text shape: "I did not <action>. <whose access and why>. <one next step>." Causes: `access-ended`, `sign-in-ended`, `role-denies`, `channel-unverified`, `owner-removed`, `requester-access-ended`, `invitation-ended`, `github-not-linked` (only on the path where linking helps: a profile with no linked account and no write access).
- `OperatorRefusalError(cause, { action })` replaces `GatewayOperatorRecoveryAuthorizationError` and its free-text messages. Admission (`operator-admission.ts`) and the recovery helpers pick a cause; R5 ("Gateway access is not active for this requester") is now `role-denies`; R3/R13 (`access-cause=grant-revoked`) are now `access-ended` with the cause chain kept.
- Refusal sites moved onto the table: R9 / requester write (`role-denies`), R8/D23 channel identity (`channel-unverified`, was duplicated), GitHub link (`github-not-linked`), ownerAllowFrom removal (`owner-removed`), restart completion notice (`requester-access-ended`).
- Delivery: chat already shows `OperatorRefusalError.message` (`agent-runner-error-handler.ts`). The tool adapter now returns the same sentence plus "Do not retry." for any refusal (and for method-scope refusals, through the same table). `sessions.github.*` errors keep the typed failure for in-process tool callers (`errorShapeFromError`), so R9 reaches the model as a refusal.
- Boundary lint `no-operator-refusal-construction` (shrink-only, ceiling 9): `new OperatorRefusalError` or a subclass outside the owner fails unless the file is listed. No wording lint.

R3 retry loop: already settled by openclaw#204609 (definite refusals settle once); unchanged here except the class name and the notice text.

Not in this PR (remaining refusal texts, follow-up): `operator-role-policy.ts` request-time agent refusal, channel run authorization notice in `agent-runner-error-handler.ts`, `github-publication-failure.ts` workflow permission, `session-access-authority.ts` / tool-policy refusals, connect-time `access-cause` texts (connect owner).

Production `src`: net positive (recorded): the cause table is the new owner; 9 free-text refusal producers and one duplicate moved onto it.

## User impact

Example (revoked member's queued message): "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to do it, or to add the permission to your role." The model gets the same sentence plus "Do not retry."

## Evidence

- `src/gateway/operator-refusal.test.ts`: one case per cause through the real tool adapter (sentence + "Do not retry."), plus the in-process Gateway method path. Red on base (no owner).
- Updated contract tests: restart completion notice, tool-bridge member refusal, GitHub inspection, recovery.
- E2E (isolated Gateway, real model) on `2926527b454e`: R/Q/S pass; openclaw#205337 (comment)
- Known gap: a queued `/followup` refusal shows the existing pending-input status in chat, not the cause sentence (needs a queue-lifecycle notice or a pending-input field; follow-up).

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

## Problem

A queued input (including `/followup`) that admission refused at start was visible only in the Gateway log. In chat the person saw only the generic pending-input line "This message was blocked by a policy and did not run." The cause sentence from openclaw#205337 (`OperatorRefusalError`, e.g. "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to …") did not reach them. Cause: `followup-runner.ts` treats a start refusal as a plain retry→consumed failure, so the existing "withheld" outcome (visible transcript notice plus source delivery) never runs for it.

Some refusal texts also still sat outside the cause table (follow-ups listed in openclaw#205337).

## Fix

- `src/auto-reply/reply/followup-runner.ts`: an `OperatorRefusalError` thrown before the turn is admitted (`!admittedTurn`) now takes the existing withheld branch, like a retired cron delivery. The notice is the refusal's own sentence (no `withheld:` prefix). That branch already records a visible `run-failed-before-reply` transcript notice and hands the failed completion to the source owner (Gateway chat records it in the run's chat). A refusal after the turn starts does not match, so a running turn never gets a false "I did not run".
- Cause table (`src/gateway/operator-refusal.ts`) gets three rows. These sites now use it:
  - role agent refusal (`operator-role-policy.ts`, `agent-not-in-role`)
  - channel access notice (`agent-runner-error-handler.ts`, `channel-access-ended`)
  - workflow-permission failure (`github-publication-failure.ts`, `role-denies`; the nextAction keeps "not a token scope failure, saved changes intact")
  - session tool-policy refusals (`session-resource-tool-policy.ts`, `session-access-authority.ts`, `tool-policy-denies`)

### Decision: no new pending-input column

The brief allowed one new nullable field on `session_pending_inputs` to carry the cause id. I did not add it. The existing withheld path already puts the sentence in the chat, so the schema change is avoidable (schema changes only when unavoidable; no new state). A column would have needed a PostgreSQL schema bump, a protocol field and about 20 files of threading. Consulted Fable 5.2; same pick. Trade-off: the pending-input line stays generic ("blocked by a policy"). The sentence shows as its own notice right after it. Old rows: unchanged, because nothing is stored.

### Known gap: channel messages

Channel-originated queued inputs get the transcript notice (seen in the session in Control UI). They do not get a channel message. Channel inbound followups register no `onQueuedFollowupReplyBatch` source delivery, and a refused input has no admitted turn to deliver through. Sending one needs a new delivery path for unadmitted input, which this PR does not add. Tracked in openclaw#205417.

Production `src`: net +25 lines (three cause rows, the refusal condition and notice selection; long free-text strings removed).

## User impact

A member whose role was lowered while their `/followup` waited sees in the chat: "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to do it, or to add the permission to your role." Before, they saw only "This message was blocked by a policy and did not run."

## Evidence

- `src/gateway/server-methods/chat-send-direct-followup.test.ts` "refuses a queued /followup … and says why in chat": real chat dispatch, queued `/followup`, requester demoted before start. It asserts the sentence in the transcript notice. It fails on base (followup-runner reverted) and passes on head.
- Updated wording tests for the moved texts; `operator-refusal.test.ts` covers the new causes through the tool adapter.
- E2E (isolated Gateway, real model) on `17bb2763cffa`: R, Q (with the new sentence assertion) and S pass; openclaw#205408 (comment)

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 docs Improvements or additions to documentation gateway Gateway runtime impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts security-sensitive-changed size: L 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