Skip to content

feat(approvals): typed approval scope summaries on channel cards - #130116

Merged
steipete merged 4 commits into
mainfrom
steipete/agitated-ardinghelli-0b8509
Aug 26, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/agitated-ardinghelli-0b8509

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Channel approval cards today show only the command or title text. For consequence-bearing tool calls — message/email sends, payments, external posts — the reviewer cannot see the blast radius: how many recipients, what amount, which target system, internal vs external audience. Approving "Send customer update" without knowing it goes to 3 external addresses is a bad approval experience.

Why This Change Was Made

Adds a small typed "approval scope" contract the approval owner attaches when it knows the consequences, rendered on every channel with native approvals:

  • Closed discriminated union ApprovalScopeSchema in the gateway protocol: message-send (target, recipientCount, bounded recipient previews, internal/external audience), payment (decimal amount string, currency, payee), external-post (target, public/restricted visibility). No freeform arm — extending later is an additive union member.
  • Owner module src/infra/approval-scope.ts: one bounded summary line (Send to 3 recipients via email (external): alice@…, bob@…, +1 more) and sanitize-once at the producer boundary (same bidi/invisible-char escaping as approval titles; post-escape overflow drops the scope, never the approval).
  • Producers: plugin.approval.request / exec.approval.request wire params, requireApproval.scope in the plugin SDK hook result, node-invoke policy, embedded broker path.
  • Rendering stays core-owned so channels remain transport-only: the view model emits a Scope metadata row (Slack/Discord/Google Chat cards pick it up with zero adapter changes) and the shared text builders add a Scope: line (Telegram/WhatsApp/Signal/iMessage/Matrix). Channel adapters only pass the typed fact through — no scope inference from strings anywhere.
  • Durable path: additive optional scope on the protocol approval presentations, so the operator approval store and Control UI clients carry it. Note: a downgraded reader (older closed presentation schema) rejects persisted presentations carrying scope; accepted — approvals are short-lived and beta contracts aren't shipped.

Scope is display-only, never authorization; missing scope renders exactly today's cards.

User Impact

Approval cards on all native-approval channels now state what an action will actually touch before the operator taps Allow. Plugin authors get a documented, typed requireApproval.scope field (docs/plugins/plugin-permission-requests.md, docs/tools/exec-approvals.md).

Evidence

  • 140+ tests across 10 suites: scope formatting/sanitization unit tests, view-model rows, gateway handler acceptance + closed-union rejection, protocol validators, Slack block rendering, Telegram pending text, embedded-approval propagation.
  • pnpm check:changed green; pnpm plugin-sdk:surface:check green (export budget 4340→4341 for the one new public type); pnpm build clean.
  • Codex autoreview (Sol, high): clean, no findings.
  • Live before/after channel proof: real iMessage delivery from an isolated dev gateway (rig details in the live-proof comment: feat(approvals): typed approval scope summaries on channel cards #130116 (comment)).

Before — approval card without scope (current behavior, unchanged):

before: card without scope

After — message-send scope (recipient count, bounded previews, external audience):

after: message-send scope

After — payment scope (amount, currency, payee) with critical severity:

after: payment scope

Production LOC ≈ +156/−3; the rest is tests and docs. Follow-ups: render scope natively in the Control UI approval inbox; wire the first bundled producer (message/email tools) to declare scope.

@clawsweeper

clawsweeper Bot commented Aug 26, 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 docs Improvements or additions to documentation channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: slack Channel integration: slack channel: telegram Channel integration: telegram app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 26, 2026
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 1:52 PM ET / 17:52 UTC.

ClawSweeper review

What this changes

The PR adds typed, display-only approval-scope summaries to exec and plugin requests, carrying them into channel approval cards.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer-authored PR open. The earlier generator and preview-count findings are addressed; the remaining blocker is an explicit compatibility decision for persisted approval records during a Gateway downgrade.

Priority: P2
Reviewed head: dddf559783716cf0a0699e072a49d84421c95ede
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The implementation addresses prior findings and has strong focused coverage; the remaining compatibility choice needs maintainer confirmation.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR is maintainer-authored, so the external-contributor proof gate does not apply; the supplied isolated-gateway iMessage proof remains useful supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is maintainer-authored, so the external-contributor proof gate does not apply; the supplied isolated-gateway iMessage proof remains useful supplemental evidence.
Evidence reviewed 6 items Typed, bounded scope contract: The PR defines three closed scope variants and adds the optional field to exec and plugin approval presentations.
Producer-to-channel projection: The shared approval view adds a Scope metadata row and carries the typed value for channel-specific renderers.
Display safety boundary: Scope values are redacted/escaped and bounded before storage or cross-channel display; recipient previews are clamped to the declared count.
Findings None None.
Security None None.

Live Verification

Command: pnpm test packages/gateway-protocol/src/approvals-validators.test.ts

Result: PASS (completed)

$ node --import tsx scripts/test-projects.mts packages/gateway-protocol/src/approvals-validators.test.ts
[test] starting test/vitest/vitest.gateway-client.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130116-bwg99b/target

 ✓  gateway-client  packages/gateway-protocol/src/approvals-validators.test.ts (8 tests) 140ms

 Test Files  1 passed (1)
      Tests  8 passed (8)
   Start at  17:53:29
   Duration  1.84s (transform 1.29s, setup 918ms, import 654ms, tests 140ms, environment 0ms)

[test] passed 1 Vitest shard in 6.63s
$ node --import tsx scripts/test-projects.mts packages/gateway-protocol/src/approvals-validators.test.ts
[test] starting test/vitest/vitest.gateway-client.config.ts

Assertions:

  • PASS expect_output: approvals-validators.test.ts

How this fits together

Approval owners create pending exec or plugin requests, which the Gateway persists and distributes to channel adapters and operator clients. This change carries a bounded scope summary from the producer through the shared presentation into rendered approval cards.

flowchart LR
  A[Approval owner] --> B[Gateway request validation]
  B --> C[Scope sanitization]
  C --> D[Durable approval presentation]
  D --> E[Shared channel view]
  E --> F[Approval card]
  D --> G[Operator clients]
Loading

Decision needed

Question Recommendation
May a Gateway downgrade intentionally make a still-pending scoped approval unreadable and therefore denied? Preserve older-reader tolerance: Adjust the durable presentation path or add compatibility handling so a rollback can still open pending approvals.

Why: This is a persisted closed protocol shape with an acknowledged compatibility tradeoff; code review cannot decide whether that operator impact is acceptable.

Before merge

  • Resolve merge risk (P1) - A Gateway downgrade while a scoped approval remains pending can treat its persisted presentation as corrupt and deny it; the PR acknowledges that tradeoff but has no downgrade or candidate-reopen proof.
  • Complete next step (P2) - A protocol owner must decide whether to preserve or explicitly accept the documented downgrade behavior before merge.
Agent review details

Security

None.

PR surface

Source +172, Tests +354, Docs +76, Other +120. Total +722 across 44 files.

View PR surface stats
Area Files Added Removed Net
Source 29 388 216 +172
Tests 11 359 5 +354
Docs 2 76 0 +76
Config 0 0 0 0
Generated 0 0 0 0
Other 2 122 2 +120
Total 44 945 223 +722

Review metrics

Metric Value Why it matters
Production versus test delta production +395/-218, tests +359/-5, docs +76/-0, generated Swift +115/-0 The branch adds a public SDK/protocol contract and generated native-client representation while keeping most added coverage in tests.

Stored data model

Persistent data-model change detected: unknown-data-model-change: packages/gateway-protocol/src/schema/approvals.ts, vector/embedding metadata: extensions/telegram/src/approval-handler.runtime.test.ts, vector/embedding metadata: src/infra/approval-view-model.test.ts, vector/embedding metadata: src/infra/approval-view-model.ts. Confirm migration or upgrade compatibility proof before merge.

Mantis proof suggestion

A redacted Telegram Desktop capture would directly show the new Scope line in one changed channel surface. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify a pending approval card renders its owner-declared Scope line and capture redacted evidence.

Merge-risk options

Maintainer options:

  1. Preserve rollback readability (recommended)
    Add downgrade or candidate-reopen proof, or change persistence so an older Gateway can still decode a pending scoped approval.
  2. Accept the bounded upgrade risk
    A protocol owner may explicitly accept the documented beta-only behavior for short-lived pending approvals.

Technical review

Best possible solution:

Keep scope opt-in and display-only, while either preserving older-reader tolerance for pending records or recording explicit protocol-owner acceptance of the short-lived incompatibility.

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

Not applicable: this PR adds a new approval-card capability rather than repairing a reported failure.

Is this the best way to solve the issue?

Unclear: the producer-to-shared-view design is coherent, but its persisted-protocol downgrade behavior needs explicit owner acceptance or compatibility proof.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded operator-safety feature with no demonstrated urgent regression.
  • merge-risk: 🚨 compatibility: The optional scope field is persisted in a previously closed approval-presentation shape and affects downgrade behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is maintainer-authored, so the external-contributor proof gate does not apply; the supplied isolated-gateway iMessage proof remains useful supplemental evidence.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The PR changes visible Telegram pending-approval text and can be demonstrated in a short Telegram Desktop flow.

Evidence

What I checked:

  • Typed, bounded scope contract: The PR defines three closed scope variants and adds the optional field to exec and plugin approval presentations. (packages/gateway-protocol/src/schema/approvals.ts:75, dddf55978371)
  • Producer-to-channel projection: The shared approval view adds a Scope metadata row and carries the typed value for channel-specific renderers. (src/infra/approval-view-model.ts:39, dddf55978371)
  • Display safety boundary: Scope values are redacted/escaped and bounded before storage or cross-channel display; recipient previews are clamped to the declared count. (src/infra/approval-scope.ts:32, dddf55978371)
  • Persisted downgrade risk: Approval presentations are serialized into the operator approval store; the base schema used closed exec/plugin objects without scope, so rolling back while a scoped record is pending can make that record fail decoding and be denied as storage-corrupt. (src/gateway/operator-approval-store.ts:339, dddf55978371)
  • Feature provenance: The current approval presentation and view-model owners were introduced together by the same area contributor, providing a direct routing trail. (src/infra/approval-presentation.ts:47, 007a2b9df51a)
  • Release and main status: The latest release commit predates this August PR; GitHub context reports the PR head as unmerged. Current-main source objects could not be materialized from this promisor checkout because DNS resolution failed, so this review does not claim current main already implements the feature. (0790d9f593ad)

Likely related people:

  • steipete: Commit 007a2b9 introduced the central approval presentation, view-model, and schema modules; the PR commits continue work in that same surface. (role: introduced the current approval-owner surface and recently maintained it; confidence: high; commits: 007a2b9df51a, 8f29cd64d271, 575ca5dd6b7f; files: src/infra/approval-presentation.ts, src/infra/approval-view-model.ts, packages/gateway-protocol/src/schema/approvals.ts)

Rank-up moves

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

  • Record a protocol-owner decision or provide older-reader and candidate-reopen evidence for persisted scoped approvals.

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 (4 earlier review cycles)
  • reviewed 2026-08-26T13:07:26.945Z sha ccd46b7 :: needs changes before merge. :: [P1] Regenerate native models for the new approval schema | [P2] Reject previews that exceed the declared recipient count
  • reviewed 2026-08-26T13:36:07.358Z sha ccd46b7 :: found issues before merge. :: [P1] Regenerate native models for the new approval schema | [P2] Reject previews that exceed the declared recipient count
  • reviewed 2026-08-26T14:00:14.294Z sha 40ea7ea :: needs changes before merge. :: [P1] Commit regenerated Swift approval models | [P2] Reject previews above the declared recipient count
  • reviewed 2026-08-26T17:39:45.374Z sha 5a23c4b :: needs maintainer review before merge. :: none

@openclaw-mantis

openclaw-mantis Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Mantis could not complete this proof. Open the failed run.

@steipete

steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Live channel proof (iMessage, real gateway)

Rig: isolated dev gateway from this branch's dist (OPENCLAW_STATE_DIR scratch dir, port 19791, never the operator gateway), real iMessage channel via local imsg, approval forwarding mode: targets to a self-DM. Approvals fired through the real plugin.approval.request gateway RPC; cards below are unretouched Messages.app captures (cropped to the message pane only).

Before — card without scope (current behavior, unchanged):

before

After — message-send scope (recipient count, bounded previews, external audience):

after message-send

After — payment scope (amount, currency, payee) with critical severity:

after payment

Also observed live: the fail-closed lifecycle messages (✅ denied on timeout + ⏱️ expired) for unresolved cards, and the gateway echo-drop of its own delivered card (reason="from me"). Text readback of every card matched the expected summarizeApprovalScope output byte-for-byte, e.g. Scope: Send to 3 recipients via email (external): [email protected], [email protected], +1 more.

Decision buttons/reactions are untouched by this PR (card content only); decision handling is covered by the existing suites plus the new handler tests.

@steipete
steipete force-pushed the steipete/agitated-ardinghelli-0b8509 branch from ccd46b7 to 40ea7ea Compare August 26, 2026 13:53
@steipete
steipete marked this pull request as ready for review August 26, 2026 13:53
Approval owners can attach a closed ApprovalScope union (message-send,
payment, external-post) describing an action's blast radius. The gateway
sanitizes it once at the producer boundary, the core view model renders a
Scope metadata row so Slack/Discord/Google Chat cards show it unchanged,
shared text builders cover Telegram/WhatsApp/Signal/iMessage/Matrix, and
the durable presentation carries it additively for operator surfaces.
Scope is display-only, never authorization; missing scope keeps today's
cards.
…reviews

Name the three scope variants as registered protocol schemas so the Swift
generator emits the ApprovalScope discriminated union the presentation
structs reference, and commit the regenerated GatewayModels.swift. Clamp
recipient previews to the declared recipientCount at the sanitize boundary
so a count of 1 with 2 previews can no longer render inconsistently.
Addresses both ClawSweeper findings on #130116.
@steipete
steipete force-pushed the steipete/agitated-ardinghelli-0b8509 branch from 40ea7ea to 575ca5d Compare August 26, 2026 17:14
@steipete

Copy link
Copy Markdown
Contributor Author

Both ClawSweeper findings are addressed in 575ca5d:

  • [P1] Regenerated Swift approval models: the three scope variants are now registered named protocol schemas (MessageSendApprovalScope, PaymentApprovalScope, ExternalPostApprovalScope), so the Swift generator emits the ApprovalScope discriminated union the presentation structs reference; regenerated GatewayModels.swift is committed and pnpm protocol:check's generators run clean against it.
  • [P2] Previews above recipientCount: sanitizeApprovalScope now clamps recipient previews to the declared recipientCount at the sanitize-once boundary (count stays authoritative; excess previews are omitted rather than rendered inconsistently), with a regression test asserting the clamped preview and summary.

Third rank-up move (contract confirmation): the public scope contract is intentional and documented in docs/plugins/plugin-permission-requests.md + docs/tools/exec-approvals.md — owner-declared, typed, display-only, never authorization; channels never infer scope; strings sanitized and bounded before any cross-channel disclosure.

…ls import cycle

check:architecture flagged approval-scope joining the exec-approvals SCC
through exec-approval-command-display. Move the self-contained display
sanitizer into a leaf module (exec-approval-text-sanitize) with no
exec-approvals imports and migrate all sanitize importers; command-display
keeps only the payload-typed command/preview resolver.
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XL and removed size: L labels Aug 26, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
…r extraction

The approval display sanitizers left the publicly reachable SDK graph when
they moved to the exec-approval-text-sanitize leaf: exports 4343 -> 4338,
callable exports 2582 -> 2578. Shrink-only budget pin.
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 26, 2026
@steipete
steipete merged commit 99a02bf into main Aug 26, 2026
357 of 359 checks passed
@steipete
steipete deleted the steipete/agitated-ardinghelli-0b8509 branch August 26, 2026 19:13
@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 27, 2026
…nclaw#130116)

* feat(approvals): typed approval scope summaries on channel cards

Approval owners can attach a closed ApprovalScope union (message-send,
payment, external-post) describing an action's blast radius. The gateway
sanitizes it once at the producer boundary, the core view model renders a
Scope metadata row so Slack/Discord/Google Chat cards show it unchanged,
shared text builders cover Telegram/WhatsApp/Signal/iMessage/Matrix, and
the durable presentation carries it additively for operator surfaces.
Scope is display-only, never authorization; missing scope keeps today's
cards.

* fix(approvals): emit native ApprovalScope union and clamp recipient previews

Name the three scope variants as registered protocol schemas so the Swift
generator emits the ApprovalScope discriminated union the presentation
structs reference, and commit the regenerated GatewayModels.swift. Clamp
recipient previews to the declared recipientCount at the sanitize boundary
so a count of 1 with 2 previews can no longer render inconsistently.
Addresses both ClawSweeper findings on openclaw#130116.

* refactor(approvals): extract text sanitizer to break the exec-approvals import cycle

check:architecture flagged approval-scope joining the exec-approvals SCC
through exec-approval-command-display. Move the self-contained display
sanitizer into a leaf module (exec-approval-text-sanitize) with no
exec-approvals imports and migrate all sanitize importers; command-display
keeps only the payload-typed command/preview resolver.

* chore(plugin-sdk): ratchet public surface budgets down after sanitizer extraction

The approval display sanitizers left the publicly reachable SDK graph when
they moved to the exec-approval-text-sanitize leaf: exports 4343 -> 4338,
callable exports 2582 -> 2578. Shrink-only budget pin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: slack Channel integration: slack channel: telegram Channel integration: telegram cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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