Skip to content

refactor(gateway): check exec approval authority once at request start - #201812

Merged
obviyus merged 3 commits into
mainfrom
refactor/check-once-approvals
Nov 19, 2026
Merged

obviyus merged 3 commits into
mainfrom
refactor/check-once-approvals

Conversation

@obviyus

@obviyus obviyus commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

What problem this solves

The exec approval manager re-checked the requesting run's authority at many points while an approval existed: when it registered, when observed, before a non-deny resolution, inside the store's mutation guard, in storage-error recovery, before keeping a standing grant, and at both consumption points. An approval that was granted while the run was live could then be refused, or silently dropped, at consumption, even though the request that asked for it had already started.

The repo rule (AGENTS.md, "Choose good compromises") is to check authority one time, when work starts. Revocation applies to the next request, and a started request may finish.

Change

  • Run authority for an approval is checked once, when the approval request starts. That is the exec.approval.request / plugin.approval.request entry check, and the Gateway's pre-dispatch admission since refactor(gateway): check agent runtime authority once at request start #201697.
  • A pending approval whose run ends is still cancelled (cancelled / run-aborted). That is cleanup of work nobody can resume, and the run-closure observer is its only cause (server-aux-handlers -> approval-run-cancellation). A later "allow" finds a terminal record. The per-call re-validation is deleted.
  • Deleted: the runtime-authority readers of isExecApprovalRuntimeActive in the approval manager (registration, observation, resolve, store mutation guard, error recovery, standing-grant retention, prepared consumption, consumeAllowOnce), the consumption authority callback, and the expiry re-validation. The aborted-run (tombstone) check moves to request start.
  • Kept: the request entry checks, the plugin-owner match, the exact-record and expiry compare, the consumption CAS, the local binding and manager-retirement checks on a prepared consumption, request abort, and manager retirement.
  • isExecApprovalRuntimeActive keeps one reader, forceDenyIfRuntimeAuthorityClosed, which system-agent reconciliation uses. It is deleted with the system-agent chain (a separate PR).

Accepted edges, no code:

  • A run aborted during preparation, after the start check and before creation, leaves its record pending until it expires.
  • When an approval's signal aborts (a tool cancellation or permission change), the listener cancels the record asynchronously. Until that persists, isPending / isPendingDeliveryCurrent can still return true, so a prompt may still be delivered for a moment.

Both are rare, visible and recoverable.

User impact

An approval granted while the run was live is honored by the request that asked for it. A pending approval for a run that has ended is still cancelled.

Evidence

Proof tier: source (ocx test).

  • New regression: an approval granted before its run ended is consumed once by the request that asked for it.
  • Kept as admission: an exec.approval.request for a run whose abort marker is already set is refused at request start ("approval run already aborted"). The check moved from just before record creation to right after the run id is derived, before preparation. That covers clients without an agent runtime identity, which the entry validator skips. Its regression test stays.
  • Kept: a pending approval is cancelled when its run ends, driven through the run-closure observer.
  • All 22 approval-related test files (exec, plugin, system-agent, MCP app, environments, node-invoke, approval-shared, run cancellation): 395 tests. One hit a 120 s timeout under load in the shared run. It passes alone (3.2 s), and its whole file passes (82/82).
  • pnpm tsgo, pnpm check:test-types, oxlint, format, and the lifetime-check, line-cap, session-identity, mock-export and max-lines ratchets: pass. The session-identity baseline is pruned (manager 4→2, consumption 1→0).
  • The system-agent test refuses to apply a delegated change after its run authority closes used a standalone manager without the run-closure observer, so it depended on the deleted per-call check. It now drives the retained forceDenyIfRuntimeAuthorityClosed and still proves the approval is cancelled and the change is not applied. System-agent production code is unchanged. Its other refusal paths (observer, afterDecision, applyDecision, reconciliation) remain.
  • Abort listeners on approvalSignals are kept as closure events, because system-agent, MCP app and environments records are not always lease-backed. Only their re-validation is removed.

Production −75 lines, tests −137 lines.

- Delete the runtime-authority re-checks in the exec approval manager (registration,
  observation, resolve gate, store mutation guard, error recovery, standing-grant
  retention, prepared and allow-once consumption), the consumption authority
  callback, the expiry re-validation and the pre-creation tombstone re-check.
- Keep run-end cancellation of pending approvals as cleanup driven by the run-closure
  observer, signal-closure listeners, request-entry checks, record ownership,
  expiry, consumption CAS, binding and manager-retirement checks.
- forceDenyIfRuntimeAuthorityClosed stays for system-agent reconciliation (its chain).
- Add a regression: an approval granted before its run ended is consumed once.
@clawsweeper

clawsweeper Bot commented Nov 19, 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.

@github-actions

github-actions Bot commented Nov 19, 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: 68e31b85eb2d9835888509c94e353734cd314e87
  • 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-expiry.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/exec-approval-results.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • 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 19, 2026
…start

- Move the abort-marker check to request start, right after the run id is derived.
  It is the only start check for clients without an agent runtime identity.
- Restore its regression test in exec-approval.admission.test.ts (line cap).
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR checks approval-request authority at admission and removes repeated run-authority checks during approval handling and consumption.

Example: An operator grants allow-once for echo hello, then the requesting run ends before consumption.

  • Before: The manager can refuse consumption despite the already-granted decision.
  • After: The started request can consume the decision once, while new requests still pass admission.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation follows the accepted ownership model, but changed-behavior proof is test-only and three attributable consumer suites remain red.
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) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A started request can lose an already-granted approval when its run ends before consumption.
Reason: The maintainer-authored direction follows the repository's explicit admission policy and removes conflicting manager-level decisions.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored PR implements the accepted admission policy, but three approval-consumer suites still expect the removed behavior and fail on the reviewed head.

Priority: P2
Reviewed head: 7debfdf1798cf98c735a4a8e01542a2472f9c0ed

Before merge

  • [P2] Migrate the remaining approval-consumer tests (P2) - Removing manager-level runtime checks leaves three existing consumer suites incompatible with the new contract, and exact-head CI confirms all three failures. gateway.hosted-routing.test.ts:488 still expects direct manager registration to reject an identity after permission changes; cron-stream-approval.integration.test.ts:464 releases the run without installing or driving the cancellation observer, then expects resolution to reject; tool-resolution.effects.test-support.ts:296 expects isPending() to become false synchronously on signal abort, before durable cancellation settles. Update these consumers to exercise admission refusal and the retained cancellation owner, awaiting cancellation where appropriate, while retaining assertions that cancelled work performs no effect. Restoring the removed polling would contradict this PR's accepted direction.

Findings

  • [P2] [P2] Migrate the remaining approval-consumer tests — src/gateway/exec-approval-manager.ts:93-97

Tests

  • Missing end-to-end proof: Provide a redacted real Gateway trace showing an allowed approval consumed exactly once after run closure, alongside pending-approval cancellation and rejection of a subsequent closed-run request; base-red/head-green regression execution is also not documented.
Agent review details

How this fits together

Gateway approval handlers admit requests, the approval manager persists and settles decisions, and effect owners consume those decisions through the existing store.

flowchart TD
  A[Agent request] --> B[Gateway admission]
  B --> C[Approval manager]
  C --> D[Approval store]
  E[Operator decision] --> C
  F[Run closure observer] --> C
  C --> G[Effect owner consumption]
Loading

Technical review

Best possible solution:

Keep request-start admission and event-driven cancellation, and migrate the remaining consumer tests without restoring repeated run-authority checks.

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

Current-main source rejects consumption when the requesting run closes after approval; the added regression exercises that sequence, but no shipped-entry-point reproduction was supplied or run during this read-only review.

Is this the best way to solve the issue?

Removing repeated checks from the existing manager is the smallest coherent implementation of the accepted policy; admission, cancellation events, exact bindings, expiry, and consumption CAS retain their existing owners.

Full review comments:

  • [P2] [P2] Migrate the remaining approval-consumer tests — src/gateway/exec-approval-manager.ts:93-97
    Removing manager-level runtime checks leaves three existing consumer suites incompatible with the new contract, and exact-head CI confirms all three failures. gateway.hosted-routing.test.ts:488 still expects direct manager registration to reject an identity after permission changes; cron-stream-approval.integration.test.ts:464 releases the run without installing or driving the cancellation observer, then expects resolution to reject; tool-resolution.effects.test-support.ts:296 expects isPending() to become false synchronously on signal abort, before durable cancellation settles. Update these consumers to exercise admission refusal and the retained cancellation owner, awaiting cancellation where appropriate, while retaining assertions that cancelled work performs no effect. Restoring the removed polling would contradict this PR's accepted direction.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Manager registration, resolution, recovery, and projection changes intended behavior with a stated reason (d9c0dd6: Retain live authority and storage ownership across asynchronous approval operations, as explained in fix(gateway): retain approval authority across storage waits #150237.)
  • Pending delivery and observation checks changes intended behavior with a stated reason (4128f11: Preserve current approval eligibility after asynchronous preparation; this PR explicitly replaces run polling with admission and closure events.)
  • Prepared consumption and cron handoff changes intended behavior with a stated reason (1c1b6e0: Bind approval consumption to committed effects and lifecycle settlement; the PR preserves consumption CAS and binding checks while deliberately removing run revalidation.)
  • Aborted-run registration refusal keeps the original intent (8853217: Prevent late registrations for already-aborted runs and settle pending approvals on abort; the refusal remains and moves to request admission.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d9c0dd6 adds src/gateway/exec-approval-manager.ts:214 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d9c0dd614512; files: src/gateway/exec-approval-manager.ts)

PR surface

Source -64, Tests -99, Other -1. Total -164 across 13 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 35 99 -64
Tests 7 220 319 -99
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 2 -1
Total 13 256 420 -164

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.

Review metrics

Metric Value Why it matters
Production versus test changes Production +35/-99; tests +220/-319 The reduction removes repeated authority policy and obsolete expectations without introducing another state owner.

Labels

Label changes:

  • add P2: This is a focused approval-lifecycle correction with concrete consumer-test repairs and no demonstrated urgent production outage.
  • 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: This is a focused approval-lifecycle correction with concrete consumer-test repairs and no demonstrated urgent production outage.
  • 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 19, 2026, 8:22 AM ET / 13:22 UTC.

- Permission change: register the run-closure observer and assert the pending
  approval is cancelled; prove a lease claim with the aborted signal is refused.
- Tool cancellation: assert the signal-closed record after it settles.
- Cron stream revoke: wire the run-closure observer and assert the cancelled stream.
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Nov 19, 2026
@obviyus
obviyus merged commit de680e3 into main Nov 19, 2026
124 of 125 checks passed
@obviyus
obviyus deleted the refactor/check-once-approvals branch November 19, 2026 14:04
obviyus added a commit that referenced this pull request Nov 19, 2026
…provals (#201911)

Problem: operator-approval-placement-grants.test.ts "skips the second launch and re-prompts after the placement generation changes" failed on main since #201812. It expected resolve(allow-always) to be refused after the run's placement-grant authority closed mid-request, which came from the resolve-time run re-check #201812 deleted on purpose. CI's changed-file shards did not select it for that PR.

Fix: test only. The resolve now records the decision. The started launch is still refused because grant retention checks the placement owner (node-invoke-placement-grant.ts), so no stale standing grant survives. A later request while authority is closed re-prompts without allow-always or a placement binding. Every other assertion is unchanged.

Proof: the target test plus every approval, standing-grant, placement-grant and consumption test file (86 files, 2,163 tests) pass; tsgo, test types, oxlint, format and the lifetime-check and line-cap ratchets pass.

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

Problem: the exec approval manager re-checked the requesting run's authority at every step an approval went through: registration, observation, resolve, the store's mutation guard, storage-error recovery, standing-grant retention, and both consumption points. An approval granted while the run was live could then be refused, or silently dropped, at consumption, even though the request that asked for it had already started.

Fix: run authority for an approval is checked once, when the approval request starts: the entry checks, the aborted-run check (now right after the run id is derived, so it also covers clients without an agent runtime identity), and the Gateway's pre-dispatch admission. A pending approval whose run ends is still cancelled. That is cleanup driven by the run-closure observer and the signal-closure listeners, without per-call re-validation. The per-step runtime re-checks, the consumption authority callback and the expiry re-validation are deleted. Record ownership, expiry, the consumption CAS, binding and manager-retirement checks are unchanged. forceDenyIfRuntimeAuthorityClosed stays for system-agent reconciliation, which is its own chain.

User impact: an approval granted while the run was live is honored by the request that asked for it. A pending approval for an ended run is still cancelled, and a request for an already-aborted run is refused at start.

Proof: new regressions (an approval granted before its run ended is consumed once; a request for an already-aborted run is refused); all 22 approval-related test files; tsgo and test types; the lifetime-check, line-cap, session-identity, mock-export and max-lines ratchets; ocx build --dts plus a packed install smoke on the head.

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

Problem: operator-approval-placement-grants.test.ts "skips the second launch and re-prompts after the placement generation changes" failed on main since openclaw#201812. It expected resolve(allow-always) to be refused after the run's placement-grant authority closed mid-request, which came from the resolve-time run re-check openclaw#201812 deleted on purpose. CI's changed-file shards did not select it for that PR.

Fix: test only. The resolve now records the decision. The started launch is still refused because grant retention checks the placement owner (node-invoke-placement-grant.ts), so no stale standing grant survives. A later request while authority is closed re-prompts without allow-always or a placement binding. Every other assertion is unchanged.

Proof: the target test plus every approval, standing-grant, placement-grant and consumption test file (86 files, 2,163 tests) pass; tsgo, test types, oxlint, format and the lifetime-check and line-cap ratchets pass.

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

Problem: the exec approval manager re-checked the requesting run's authority at every step an approval went through: registration, observation, resolve, the store's mutation guard, storage-error recovery, standing-grant retention, and both consumption points. An approval granted while the run was live could then be refused, or silently dropped, at consumption, even though the request that asked for it had already started.

Fix: run authority for an approval is checked once, when the approval request starts: the entry checks, the aborted-run check (now right after the run id is derived, so it also covers clients without an agent runtime identity), and the Gateway's pre-dispatch admission. A pending approval whose run ends is still cancelled. That is cleanup driven by the run-closure observer and the signal-closure listeners, without per-call re-validation. The per-step runtime re-checks, the consumption authority callback and the expiry re-validation are deleted. Record ownership, expiry, the consumption CAS, binding and manager-retirement checks are unchanged. forceDenyIfRuntimeAuthorityClosed stays for system-agent reconciliation, which is its own chain.

User impact: an approval granted while the run was live is honored by the request that asked for it. A pending approval for an ended run is still cancelled, and a request for an already-aborted run is refused at start.

Proof: new regressions (an approval granted before its run ended is consumed once; a request for an already-aborted run is refused); all 22 approval-related test files; tsgo and test types; the lifetime-check, line-cap, session-identity, mock-export and max-lines ratchets; ocx build --dts plus a packed install smoke on the head.

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

Companion audit: Full production diff reviewed: request admission checks abort once; pending signals still cancel, binding/persistence/expiry and consumption CAS stay. Later 59ca885/4ea2deb are separate system-agent/node-plugin owners assigned other ledger rows; 2b5f1a8 adds collaborator guardrails, no exec-manager hunk. No schema change; identity allowlist only removes retired checks.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit f0b90bc058d8cd83cb59178d83a344e588fc6778)
(cherry picked from commit 0483b94eeb98cd37476e3e828bca81856d4659bf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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