Skip to content

feat(approvals): scoped standing grants make recurring cron automations approvable once - #129526

Merged
steipete merged 7 commits into
mainfrom
steipete/cron-standing-grants
Aug 25, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/cron-standing-grants

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Recurring cron jobs whose command needs exec approval are unusable today: every occurrence is auto-denied. #128031 suppressed cron approval delivery entirely (cards spammed chat on every occurrence and could not be usefully answered), so a scheduled command under ask policy dead-ends with "Automation runs cannot wait for interactive exec approval" forever, and the only fix is hand-editing the allowlist. Resolving a cron approval with Allow always also used to write an unbounded generated command digest into the JSON allowlist — a permanent, job-independent grant that survives job edits and deletion.

Why This Change Was Made

This PR makes recurring automation approvable exactly once, with tightly scoped durable authority:

  • Scoped standing grants (new operator_approval_standing_grants first-use lazy STRICT table in the shared state DB, no schema-version bump): when an operator resolves Allow always on an approval raised by a cron job's isolated run, the Gateway mints a grant bound to that exact agent, cron job, job config revision, and operation (command text, cwd, env hash) inside the same SQLite transaction that resolves the approval — instead of writing a JSON allowlist digest. Later occurrences of the same job execute that exact operation without prompting. Every use revalidates against authoritative rows and fails closed: 30-day expiry, revocation, job edited/deleted (config revision recompute against the live cron_jobs row), or the minting approval row no longer allow-always all fall back to a normal prompt. Mutable file operands, heredocs, strict inline eval, and audit-suppression approvals keep prompting per occurrence. An abort tombstone on the run blocks minting. Non-cron approvals are unchanged.
  • Cron approvals reach approval surfaces: cron approval requests now carry deliverToApprovalClientsOnly — the shared delivery owner broadcasts them to connected websocket approval clients (Control UI, TUI) but skips chat approval runtimes, forwarder/iOS delivery, and turn-source routes, so the per-occurrence chat spam fix: stop cron exec approval spam #128031 removed stays removed. With no approval client connected, the request still expires no-route into the existing headless denial with the same remediation text.
  • The scheduled run waits inline for the decision (the same treatment native chat channels got for Native chat /approve should resume the agent turn (emit Exec lifecycle system event back to the session) #93918): without this, the isolated run finalizes on the approval-pending handoff and authority-close cancels the parked approval seconds later, leaving a ~3-second answer window. Cron jobs are single-flight, so at most one card per job is pending at a time, and the card carries the full approval window (default 30 minutes).

The cron fact is recorded where it happens: the cron run owner registers run → {agent, job, config revision} in a process-local registry at run start, and exec.approval.request stamps the cron source and operation binding onto the approval at creation. Nothing is inferred from session keys or run ids, and the parent operator_approvals row remains the sole authorization owner (grants are derivative, revalidated correlation).

User Impact

An operator with the Control UI (or TUI) open sees one inbox card per scheduled job that needs approval — "Automation: $ <command>" with Allow once / Always allow / Deny. Always allow runs the current occurrence and permanently (30 days, revalidated) unblocks that exact job operation; the card never comes back until the job changes. Allow once runs just this occurrence. Editing the job brings the prompt back. Headless gateways behave exactly as before. The JSON allowlist no longer accumulates generated command digests from automation approvals.

Evidence

Live-proven end to end on a hermetic dev gateway (isolated OPENCLAW_STATE_DIR, own port, Anthropic Haiku, cron job running id -un every minute under tools.exec.mode=allowlist, real Control UI attached in a browser):

  1. Card delivered to the Control UI inbox with a ~30-minute countdown; the isolated run waited inline (exec.approval.waitDecision resolved after 72.6 s when the operator clicked).
  2. Always allow → the occurrence executed (steipete, exit 0, in the session transcript), and grant 8953a518… was minted in the resolving transaction, bound to approval 5e24d5a7…, agent main, and the job id.
  3. JSON allowlist stayed clean: exec_approvals_config still has "agents": {} — no generated digest.
  4. Next occurrence executed promptless via the grant: use_count 0→1, zero new approval rows.
  5. openclaw cron edit … --message '… # revised' → next occurrence did not use the grant (use_count still 1) and parked a fresh pending approval — fail-closed on config revision proven live.
  6. Pre-fix control (same rig, previous build): every cron approval row resolved denied/cancelled within 1 ms–3.3 s; no operator could ever answer.

Inbox card (post-edit reprompt, showing the revised command and full window):

Automation approval card in the Control UI inbox

Focused suites green: operator-approval-standing-grants.test.ts (14), bash-tools.exec-host-gateway.test.ts + bash-tools.exec.approval-id.test.ts (141), approval-shared.test.ts (41 incl. 2 new clients-only cases), bash-tools.exec-host-node.test.ts; check:changed clean; full pnpm build clean.

Production LOC: grants feature +495 (new capability: durable scoped-grant store, mint/consume funnels, cron source registry); delivery/inline-wait fix +38/−15. Follow-ups (not in this PR): grants list/revoke RPC + UI surface, node-host exec grant coverage, doctor migration retiring legacy cron-generated allowlist digests, per-use decision-receipt projection.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 25, 2026 18:25
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 25, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 25, 2026, 6:03 PM ET / 22:03 UTC.

ClawSweeper review

What this changes

Adds expiring, job-scoped standing grants for gateway-host cron exec approvals, routes cron cards to approval clients, and waits for the operator decision inline.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 9 items remain

Keep this PR open: its new standing-grant authority can be minted from a caller-supplied cron run ID rather than an exact live cron runtime, and its docs still advertise the TUI as an exec-approval surface when it is plugin-only.

Priority: P1
Reviewed head: 890b431468a2910c02c69797bc776efbc2fe509b

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The final-spawn revalidation is a strong improvement, but the authority producer remains forgeable.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: Authority-chain proof required: the reported live run demonstrates a grant and parent reversal, but not rejection of caller-supplied or replaced cron runtime identity before process I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: the reported live run demonstrates a grant and parent reversal, but not rejection of caller-supplied or replaced cron runtime identity before process I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 7 items Raw request parameters can mint cron provenance: The handler falls back to raw runId and uses it to look up cron source data, then stamps cronExecutionSource into the approval request.
The request method is available to approval-scoped clients: exec.approval.request requires operator.approvals, so it is not restricted to the internal agent-runtime caller that owns cron execution.
Cron provenance lacks an operational-instance binding: The new registry is keyed only by runId, while cron registers its source from a run with a fresh admitted operational instance.
Findings 2 actionable findings [P1] Require a live cron runtime before minting a standing grant
[P1] Do not advertise the TUI as a cron exec approver
Security Needs attention Caller-controlled run IDs can mint durable cron authority: The public approval-request method accepts raw runId and derives cron provenance from the active registry without requiring the producing runtime's exact authority instance.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/operator-approval-standing-grants.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs src/gateway/operator-approval-standing-grants.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs src/gateway/operator-approval-standing-grants.test.ts"

[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129526-wYMD3g/target

 ✓  gateway-core  ../../src/gateway/operator-approval-standing-grants.test.ts (14 tests) 2282ms
     ✓ mints a scoped grant in the allow-always resolution transaction  375ms

 Test Files  1 passed (1)
      Tests  14 passed (14)
   Start at  22:04:30
   Duration  5.08s (transform 2.14s, setup 816ms, import 1.68s, tests 2.28s, environment 0ms)

[test] passed 1 Vitest shard in 9.84s

Assertions:

  • FAIL expect_output: operator-approval-standing-grants.test.ts

How this fits together

Cron runs request command approval through the Gateway; an allow-always decision now creates a durable grant for the same job and operation. The Gateway rechecks that grant immediately before starting the command process.

flowchart LR
  A[Cron run] --> B[Trusted run identity]
  B --> C[Approval request]
  C --> D[Operator decision]
  D --> E[Scoped grant store]
  E --> F[Final grant revalidation]
  F --> G[Command process]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: the reported live run demonstrates a grant and parent reversal, but not rejection of caller-supplied or replaced cron runtime identity before process I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Require a live cron runtime before minting a standing grant (P1) - A non-agent caller may supply runId and agentId; this code then treats a matching registry entry as cron provenance. Because exec.approval.request is available to operator.approvals, that caller can mint durable cron authority without being the active cron runtime. Bind the source to the validated internal runtime's exact operational instance and reject raw provenance.
  • Do not advertise the TUI as a cron exec approver (P1) - This remains from the prior review: the TUI is registered only for plugin approvals, so an operator with only the TUI connected cannot receive or resolve this exec card. State the supported exec approval clients, or implement the missing TUI exec-approval flow.
  • Resolve security concern: Caller-controlled run IDs can mint durable cron authority - The public approval-request method accepts raw runId and derives cron provenance from the active registry without requiring the producing runtime's exact authority instance.
  • Resolve merge risk (P1) - The stated live re-proof does not provide inspectable final-effect evidence that a stale or cross-job runtime cannot reach process execution.
  • Complete next step (P2) - A protected, security-sensitive PR needs its P1 authority-source repair and exact-head proof reviewed before merge.
  • Improve patch quality - Require a validated internal runtime and exact operational-instance match for cron provenance.
  • Improve patch quality - Add final-effect regressions for raw client forgery and a stale or replaced runtime instance.
  • Improve patch quality - Provide a redacted after-fix trace showing both allowed and nearest-forbidden paths before process I/O.

Findings

  • [P1] Require a live cron runtime before minting a standing grant — src/gateway/server-methods/exec-approval.ts:335-343
  • [P1] Do not advertise the TUI as a cron exec approver — docs/tools/exec-approvals.md:426-428
  • [high] Caller-controlled run IDs can mint durable cron authority — src/gateway/server-methods/exec-approval.ts:335
Agent review details

Security

Needs attention: The PR introduces a concrete durable-execution authority forgery path through caller-controlled cron provenance.

PR surface

Source +602, Tests +882, Docs +26, Generated +16, Other +7. Total +1533 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 15 614 12 +602
Tests 9 888 6 +882
Docs 1 26 0 +26
Config 0 0 0 0
Generated 1 16 0 +16
Other 2 7 0 +7
Total 28 1551 18 +1533

Review metrics

Metric Value Why it matters
Production versus test delta production +614/-12; tests +888/-6; docs/generated/tooling +49/-0 The feature adds a durable authority store and cross-boundary execution flow; the test growth is substantial but does not remove the need to repair the authority producer.

Stored data model

Persistent data-model change detected: database schema: src/gateway/operator-approval-standing-grants.ts, database schema: src/state/openclaw-state-schema.sql, serialized state: src/state/openclaw-state-db.generated.d.ts, vector/embedding metadata: src/agents/auth-profiles/order.test.ts, vector/embedding metadata: src/agents/embedded-agent-runner/model-resolution-consistency.test.ts, vector/embedding metadata: src/agents/embedded-agent-runner/model.static-catalog.prepared.test.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #129526
Summary: This PR is the canonical proposed implementation for cron standing grants; its authority-source flaw is internal to that implementation.

Members:

  • partial_overlap: fix: stop cron exec approval spam #128031 - The merged PR intentionally suppressed unattended cron approval delivery; this PR adds a separate interactive gateway-host path while retaining node-host suppression.

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Bind grants to live runtime authority (recommended)
    Require a validated internal agent-runtime identity and exact operational instance for cron provenance, then add forged and replaced-instance final-effect regressions before merge.

Technical review

Best possible solution:

Bind cron provenance, minting, and consumption to the validated exact operational run instance; reject raw caller-provided run IDs, prove allowed and nearest-forbidden final effects, and document only real exec approval surfaces.

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

Yes, from source: an operator.approvals client can submit a matching raw runId and agentId, causing the new handler to derive cron provenance without an internal runtime identity.

Is this the best way to solve the issue?

No: the scoped-grant design is viable, but provenance must come from the exact validated runtime instance rather than a caller-supplied reusable identifier.

Full review comments:

  • [P1] Require a live cron runtime before minting a standing grant — src/gateway/server-methods/exec-approval.ts:335-343
    A non-agent caller may supply runId and agentId; this code then treats a matching registry entry as cron provenance. Because exec.approval.request is available to operator.approvals, that caller can mint durable cron authority without being the active cron runtime. Bind the source to the validated internal runtime's exact operational instance and reject raw provenance.
    Confidence: 0.98
  • [P1] Do not advertise the TUI as a cron exec approver — docs/tools/exec-approvals.md:426-428
    This remains from the prior review: the TUI is registered only for plugin approvals, so an operator with only the TUI connected cannot receive or resolve this exec card. State the supported exec approval clients, or implement the missing TUI exec-approval flow.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Authority-chain proof required: the reported live run demonstrates a grant and parent reversal, but not rejection of caller-supplied or replaced cron runtime identity before process I/O.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: A client with approval scope can currently forge cron provenance for durable command authority.
  • merge-risk: 🚨 compatibility: The PR changes established cron approval and allow-always persistence behavior.
  • merge-risk: 🚨 security-boundary: The patch creates durable process-execution authority from insufficiently trusted provenance.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the reported live run demonstrates a grant and parent reversal, but not rejection of caller-supplied or replaced cron runtime identity before process I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Authority-chain proof required: the reported live run demonstrates a grant and parent reversal, but not rejection of caller-supplied or replaced cron runtime identity before process I/O.

Evidence

Security concerns:

  • [high] Caller-controlled run IDs can mint durable cron authority — src/gateway/server-methods/exec-approval.ts:335
    The public approval-request method accepts raw runId and derives cron provenance from the active registry without requiring the producing runtime's exact authority instance.
    Confidence: 0.98

What I checked:

Likely related people:

  • steipete: The supplied PR commits introduce the standing-grant flow and its follow-up spawn-boundary revision; local blame attributes the current grafted head to the same author. (role: introduced current implementation; confidence: high; commits: 3535fdee6cc2, 2358ec9c36ec, 890b431468a2; files: src/gateway/operator-approval-standing-grants.ts, src/gateway/server-methods/exec-approval.ts, src/agents/bash-tools.exec-host-gateway.ts)

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 (2 earlier review cycles)
  • reviewed 2026-08-25T20:32:25.896Z sha 57b5b8b :: found issues before merge. :: [P1] Revalidate standing grants immediately before process spawn | [P1] Do not expose node cron approvals as standing-grant capable
  • reviewed 2026-08-25T21:41:14.640Z sha 2219142 :: needs real behavior proof before merge. :: [P1] Revalidate the grant at every process-spawn attempt | [P1] Bind cron grant source to the operational run instance | [P1] Do not advertise TUI as a cron exec approver

When an operator resolves allow-always for an approval raised by a cron
job's isolated run, the Gateway now mints a scoped standing grant in the
same SQLite transaction that resolves the approval, instead of writing an
unbounded command digest into the JSON allowlist. Subsequent occurrences
of that job execute the exact approved operation (command text, cwd, env
hash) without prompting while the grant revalidates against authoritative
rows: 30-day expiry, revocation, the cron job still existing with the same
config revision, and the minting approval row still holding allow-always
all fail closed back to the normal prompt. Non-cron allow-always behavior
is unchanged.

- New first-use lazy STRICT table operator_approval_standing_grants in the
  shared state DB (declared canonically, no schema-version bump; older and
  downgraded readers stay valid without it).
- The cron run owner records run -> {agent, job, config revision} in a
  process-local registry at run start; exec.approval.request stamps the
  cron source and exact operation binding onto the approval at creation,
  so nothing is ever inferred from session keys or run ids.
- The gateway exec host consults grants only when policy would prompt;
  ask=always, security=deny, mutable file operands, heredoc, strict
  inline-eval, and audit-suppression approvals keep prompting. Grant use
  updates last_used_at_ms/use_count and emits the exec approval security
  event with the grant and minting approval as lineage.
- Abort-wins guard: a run with an abort tombstone never mints.
…wait inline

The standing-grant mint path was unreachable end-to-end: #128031 made
cron approval requests register with delivery fully suppressed, so the
shared owner expired them as no-approval-route within milliseconds, and
even a delivered card would have died seconds later when the isolated
run finalized on the approval-pending handoff and authority-close
cancelled the parked approval.

Cron approval requests now carry deliverToApprovalClientsOnly: the
shared delivery owner broadcasts them to connected websocket approval
clients (Control UI, TUI) but skips internal chat approval runtimes,
forwarder/iOS delivery, and turn-source routes, so the per-occurrence
chat spam #128031 removed stays removed. With no approval client
connected, the request still expires no-route into the existing
headless denial. The gateway exec host additionally waits inline for
cron-triggered approvals (the same treatment native chat channels got
in #93918), keeping the isolated run and its delegated authority alive
for the full approval window; cron jobs are single-flight, so at most
one card per job is pending at a time and allow-always ends the
recurrence by minting the standing grant.

Live-proven on a hermetic gateway: card delivered with ~30-minute
window, run waited 72s for the operator click, allow-always executed
the occurrence and minted the grant with no JSON allowlist digest,
the next occurrence ran promptless (use_count 1, no new approval row),
and editing the job failed closed back to a fresh prompt.
…ode cron headless

Review findings from ClawSweeper on #129526:

- Grant authority is now recorded only at the final effect. The consult
  path validates without recording a use and returns a
  revalidateBeforeExecution closure (the mutable-file-binding seam) that
  consumes the grant immediately before runExecProcess; any invalidation
  during awaited pre-spawn work (job edit/delete, revocation, parent
  approval reversal) denies with next-step text instead of executing on
  stale authority. Regression proves consult leaves use_count at 0 and a
  reversed minting approval denies at the boundary.
- Cron approval-client delivery is scoped to host=gateway. Node-host cron
  cannot mint or consume grants yet, so it keeps the fully suppressed
  headless policy from #128031 instead of raising cards whose allow-always
  could not stick; node-host grant support stays a named follow-up.
@steipete
steipete force-pushed the steipete/cron-standing-grants branch from 57b5b8b to 2358ec9 Compare August 25, 2026 21:07
@steipete

Copy link
Copy Markdown
Contributor Author

Both P1 findings were real and are addressed on the new head; thank you — the final-effect gap in particular is exactly the closure-bound-authority invariant this repo documents.

P1 — revalidate at the spawn boundary (fixed). Grant authority is now recorded only at the final effect: the consult path calls a new validateCronStandingGrant (no use recorded) to decide whether to skip the prompt, and returns a revalidateBeforeExecution closure — the same seam mutable-file bindings use — that performs the actual consumeCronStandingGrant immediately before runExecProcess. A job edit, deletion, revocation, or parent-approval reversal that lands during awaited pre-spawn work now denies with an explanatory result ("standing grant no longer valid (…); the next occurrence will prompt for approval again") instead of executing. New regression (bash-tools.exec-host-gateway.test.ts — "denies at the spawn boundary when the grant is invalidated after consult"): consult passes, the minting approval row is reversed, the closure denies, use_count stays 0. The happy-path test now also proves consumption happens in the closure, not at consult (use_count 0 → closure → 1). This is your first rank-up move as well.

P1 — node-host cron cards (fixed by scoping). Cron approval requests now set deliverToApprovalClientsOnly only for host === "gateway"; node-host cron requests keep the fully suppressed headless policy from #128031 (suppressDelivery: true), so no card is raised whose Allow always could not stick as a scoped grant. Node-host mint/consume/final-effect support stays a named follow-up, per your recommended option. Docs updated to state the host scoping explicitly. Tests updated: the two node cron cases assert suppression again, the two gateway cron cases assert clients-only delivery.

Decision item (durable grant policy). This feature was explicitly commissioned by the maintainer (recurring automations approvable once), which is the product acceptance this PR records. Operator revocation exists today through three proven paths: editing or deleting the job invalidates the grant (live-proven, revision recompute against the authoritative cron_jobs row), reversing/pruning the minting approval row fails closed (now regression-tested at the spawn boundary), and the 30-day expiry bounds retention. A dedicated grants list/revoke RPC + UI surface is a named follow-up in the PR body — deliberately not dark-shipped as part of this change.

Live re-proof on the fixed build (head 2358ec9c36e, same hermetic rig): card raised, the isolated run waited 75.3 s inline until openclaw approvals resolve <id> allow-always; that occurrence executed and minted a fresh grant; the next two occurrences executed id -un promptless through the validate → spawn-boundary consume path (use_count 0→1→2, zero new approval rows).

@steipete steipete closed this Aug 25, 2026
@steipete steipete reopened this Aug 25, 2026
Five explicit vi.mock factories for current-plugin-metadata-snapshot.js
exported only getCurrentPluginMetadataSnapshot. Under isolate:false shard
composition the incomplete mock can bleed into siblings that import the
real module — model-resolution-consistency.test.ts failed on CI with
'No withPluginMetadataSnapshotScope export is defined on the mock'.
Spread importOriginal so every binding prod touches stays exported, per
the repo mock-factory rule; only the snapshot getter stays overridden.
@steipete
steipete requested a review from a team as a code owner August 25, 2026 21:31
…uild/

scripts/install-swift-tools.sh installs pinned Swift tools into
.build/swift-tools per the lint-swift.sh remediation hint; the 36MB
binary must never ride a commit. Remove it and ignore the directory.
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive changes noted

This PR includes security-sensitive file changes. The guard is informational because the PR author is a repository admin or a member of @openclaw/openclaw-secops.

  • Current SHA: 890b431468a2910c02c69797bc776efbc2fe509b
  • Trusted actor: @steipete
  • Trusted role: pull request author; openclaw-secops

Changed files:

  • .gitignore: Controls ignored secret and local files, including common .env files, before they can be accidentally committed.

Security review is still recommended before merge when the change is intentional.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 25, 2026
@clawsweeper clawsweeper Bot added the status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. label Aug 25, 2026
…t mocks

The agents-embedded shard still failed after completing five factories:
~20 more test files across the repo mock current-plugin-metadata-snapshot
with incomplete explicit factories, and under isolate:false composition
any of them can strip withPluginMetadataSnapshotScope from this file's
imports. Give the victim a file-local identity mock (importOriginal
spread) that always wins, and revert the static-catalog factory edit that
tipped that grandfathered file over the max-lines cap — the repo-wide
factory completion belongs to a dedicated sweep.
@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 25, 2026
@steipete
steipete merged commit 473b4f1 into main Aug 25, 2026
267 of 272 checks passed
@steipete
steipete deleted the steipete/cron-standing-grants branch August 25, 2026 23:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 26, 2026
Explicit vi.mock factories for src/plugins/current-plugin-metadata-snapshot.ts
exported only getCurrentPluginMetadataSnapshot; under isolate:false shard
composition the incomplete mocks leaked into sibling files (CI incident:
model-resolution-consistency.test.ts lost withPluginMetadataSnapshotScope,
stopgapped in #129526). Convert all 27 incomplete factories to the
importOriginal-spread form, overriding only the stubbed binding, and remove
the now-unneeded self-defense identity mock.

model.static-catalog.test.ts sat at the 1000-counted-line max-lines cap, so
its canonicalizeManifestModelCatalogProviderAlias block moved to a new
model.static-catalog.provider-alias.test.ts sibling (picked up by the
agents-embedded lane glob) instead of adding a suppression.
steipete added a commit that referenced this pull request Aug 26, 2026
Explicit vi.mock factories for src/plugins/current-plugin-metadata-snapshot.ts
exported only getCurrentPluginMetadataSnapshot; under isolate:false shard
composition the incomplete mocks leaked into sibling files (CI incident:
model-resolution-consistency.test.ts lost withPluginMetadataSnapshotScope,
stopgapped in #129526). Convert all 27 incomplete factories to the
importOriginal-spread form, overriding only the stubbed binding, and remove
the now-unneeded self-defense identity mock.

model.static-catalog.test.ts sat at the 1000-counted-line max-lines cap, so
its canonicalizeManifestModelCatalogProviderAlias block moved to a new
model.static-catalog.provider-alias.test.ts sibling (picked up by the
agents-embedded lane glob) instead of adding a suppression.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…ns approvable once (openclaw#129526)

* feat(approvals): mint scoped standing grants for cron allow-always

When an operator resolves allow-always for an approval raised by a cron
job's isolated run, the Gateway now mints a scoped standing grant in the
same SQLite transaction that resolves the approval, instead of writing an
unbounded command digest into the JSON allowlist. Subsequent occurrences
of that job execute the exact approved operation (command text, cwd, env
hash) without prompting while the grant revalidates against authoritative
rows: 30-day expiry, revocation, the cron job still existing with the same
config revision, and the minting approval row still holding allow-always
all fail closed back to the normal prompt. Non-cron allow-always behavior
is unchanged.

- New first-use lazy STRICT table operator_approval_standing_grants in the
  shared state DB (declared canonically, no schema-version bump; older and
  downgraded readers stay valid without it).
- The cron run owner records run -> {agent, job, config revision} in a
  process-local registry at run start; exec.approval.request stamps the
  cron source and exact operation binding onto the approval at creation,
  so nothing is ever inferred from session keys or run ids.
- The gateway exec host consults grants only when policy would prompt;
  ask=always, security=deny, mutable file operands, heredoc, strict
  inline-eval, and audit-suppression approvals keep prompting. Grant use
  updates last_used_at_ms/use_count and emits the exec approval security
  event with the grant and minting approval as lineage.
- Abort-wins guard: a run with an abort tombstone never mints.

* feat(approvals): deliver cron exec approvals to approval clients and wait inline

The standing-grant mint path was unreachable end-to-end: openclaw#128031 made
cron approval requests register with delivery fully suppressed, so the
shared owner expired them as no-approval-route within milliseconds, and
even a delivered card would have died seconds later when the isolated
run finalized on the approval-pending handoff and authority-close
cancelled the parked approval.

Cron approval requests now carry deliverToApprovalClientsOnly: the
shared delivery owner broadcasts them to connected websocket approval
clients (Control UI, TUI) but skips internal chat approval runtimes,
forwarder/iOS delivery, and turn-source routes, so the per-occurrence
chat spam openclaw#128031 removed stays removed. With no approval client
connected, the request still expires no-route into the existing
headless denial. The gateway exec host additionally waits inline for
cron-triggered approvals (the same treatment native chat channels got
in openclaw#93918), keeping the isolated run and its delegated authority alive
for the full approval window; cron jobs are single-flight, so at most
one card per job is pending at a time and allow-always ends the
recurrence by minting the standing grant.

Live-proven on a hermetic gateway: card delivered with ~30-minute
window, run waited 72s for the operator click, allow-always executed
the occurrence and minted the grant with no JSON allowlist digest,
the next occurrence ran promptless (use_count 1, no new approval row),
and editing the job failed closed back to a fresh prompt.

* chore(protocol): regenerate Swift models for deliverToApprovalClientsOnly

* fix(approvals): consume standing grants at the spawn boundary; keep node cron headless

Review findings from ClawSweeper on openclaw#129526:

- Grant authority is now recorded only at the final effect. The consult
  path validates without recording a use and returns a
  revalidateBeforeExecution closure (the mutable-file-binding seam) that
  consumes the grant immediately before runExecProcess; any invalidation
  during awaited pre-spawn work (job edit/delete, revocation, parent
  approval reversal) denies with next-step text instead of executing on
  stale authority. Regression proves consult leaves use_count at 0 and a
  reversed minting approval denies at the boundary.
- Cron approval-client delivery is scoped to host=gateway. Node-host cron
  cannot mint or consume grants yet, so it keeps the fully suppressed
  headless policy from openclaw#128031 instead of raising cards whose allow-always
  could not stick; node-host grant support stays a named follow-up.

* test(agents): complete plugin-metadata-snapshot mock factories

Five explicit vi.mock factories for current-plugin-metadata-snapshot.js
exported only getCurrentPluginMetadataSnapshot. Under isolate:false shard
composition the incomplete mock can bleed into siblings that import the
real module — model-resolution-consistency.test.ts failed on CI with
'No withPluginMetadataSnapshotScope export is defined on the mock'.
Spread importOriginal so every binding prod touches stays exported, per
the repo mock-factory rule; only the snapshot getter stays overridden.

* chore: drop accidentally committed pinned swiftlint binary; ignore .build/

scripts/install-swift-tools.sh installs pinned Swift tools into
.build/swift-tools per the lint-swift.sh remediation hint; the 36MB
binary must never ride a commit. Remove it and ignore the directory.

* test(agents): shield model-resolution-consistency from leaked snapshot mocks

The agents-embedded shard still failed after completing five factories:
~20 more test files across the repo mock current-plugin-metadata-snapshot
with incomplete explicit factories, and under isolate:false composition
any of them can strip withPluginMetadataSnapshotScope from this file's
imports. Give the victim a file-local identity mock (importOriginal
spread) that always wins, and revert the static-catalog factory edit that
tipped that grandfathered file over the max-lines cap — the repo-wide
factory completion belongs to a dedicated sweep.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…law#129791)

Explicit vi.mock factories for src/plugins/current-plugin-metadata-snapshot.ts
exported only getCurrentPluginMetadataSnapshot; under isolate:false shard
composition the incomplete mocks leaked into sibling files (CI incident:
model-resolution-consistency.test.ts lost withPluginMetadataSnapshotScope,
stopgapped in openclaw#129526). Convert all 27 incomplete factories to the
importOriginal-spread form, overriding only the stubbed binding, and remove
the now-unneeded self-defense identity mock.

model.static-catalog.test.ts sat at the 1000-counted-line max-lines cap, so
its canonicalizeManifestModelCatalogProviderAlias block moved to a new
model.static-catalog.provider-alias.test.ts sibling (picked up by the
agents-embedded lane glob) instead of adding a suppression.
steipete added a commit that referenced this pull request Aug 28, 2026
…terms

Completes the operator half of cron standing grants (#129526):

- Grants are listable and revocable. New gateway methods
  exec.approval.grants.list/revoke (operator.approvals scope), CLI
  'openclaw approvals grants list|revoke', and a Standing grants section
  on the Control UI approvals page with per-row revoke. Revocation is
  idempotent, records the acting client, and takes effect at the next
  occurrence's spawn boundary.
- Grant terms are frozen at mint and configurable. Default stays
  until-revoked (matching what shipped Always allow has always meant);
  tools.exec.grantExpiryDays sets a day-bounded default for future
  grants (enterprise fleet policy), and resolve surfaces may override
  per grant via grantExpiresInDays / --expires-in-days. Existing grants
  keep their minted terms; config changes are never retroactive.
- expires_at_ms goes nullable (NULL = until revoked). The mandatory-
  expiry shape never reached a release tag, so the lazy ensure rebuilds
  it in place; grants are re-derivable authority, so the fail-closed
  cost is one re-prompt.
- Approval cards say what Always allow does. Automation approvals carry
  a standing-grant ApprovalScope (new union member) built server-side
  from the cron run registry (now carrying the job display name); the
  Control UI inbox card and modal render it via i18n, e.g. 'Always
  allow runs this exact command for "grant-demo" without asking, for
  10 days (revocable)'.
- Aux method registries stay in lockstep: new parity test fails when a
  GATEWAY_AUX_METHODS entry lacks a lazy handler (this gap produced
  live unknown-method errors during bring-up).

Live-proven on a hermetic gateway: until-revoked grant ran 62 promptless
occurrences; UI and CLI revocation each returned the prompt on the next
occurrence; config default stamped exactly 10.0 days via a UI resolve;
--expires-in-days 99 override stamped 99.0 days; ledger and card
screenshots captured from the running Control UI.
steipete added a commit that referenced this pull request Aug 28, 2026
…terms (#131602)

* feat(approvals): standing-grant ledger, revocation, and configurable terms

Completes the operator half of cron standing grants (#129526):

- Grants are listable and revocable. New gateway methods
  exec.approval.grants.list/revoke (operator.approvals scope), CLI
  'openclaw approvals grants list|revoke', and a Standing grants section
  on the Control UI approvals page with per-row revoke. Revocation is
  idempotent, records the acting client, and takes effect at the next
  occurrence's spawn boundary.
- Grant terms are frozen at mint and configurable. Default stays
  until-revoked (matching what shipped Always allow has always meant);
  tools.exec.grantExpiryDays sets a day-bounded default for future
  grants (enterprise fleet policy), and resolve surfaces may override
  per grant via grantExpiresInDays / --expires-in-days. Existing grants
  keep their minted terms; config changes are never retroactive.
- expires_at_ms goes nullable (NULL = until revoked). The mandatory-
  expiry shape never reached a release tag, so the lazy ensure rebuilds
  it in place; grants are re-derivable authority, so the fail-closed
  cost is one re-prompt.
- Approval cards say what Always allow does. Automation approvals carry
  a standing-grant ApprovalScope (new union member) built server-side
  from the cron run registry (now carrying the job display name); the
  Control UI inbox card and modal render it via i18n, e.g. 'Always
  allow runs this exact command for "grant-demo" without asking, for
  10 days (revocable)'.
- Aux method registries stay in lockstep: new parity test fails when a
  GATEWAY_AUX_METHODS entry lacks a lazy handler (this gap produced
  live unknown-method errors during bring-up).

Live-proven on a hermetic gateway: until-revoked grant ran 62 promptless
occurrences; UI and CLI revocation each returned the prompt on the next
occurrence; config default stamped exactly 10.0 days via a UI resolve;
--expires-in-days 99 override stamped 99.0 days; ledger and card
screenshots captured from the running Control UI.

* chore(ui): annotate the scope narrowing assertion for the safety ratchet

* test(gateway): move aux-method parity check to its own suite

* fix(ci): boundary-parse UI approval scope; register grants schemas for native codegen

- The Swift/Kotlin generators discover named schemas through the
  protocol schema fragments; the standing-grant scope member and the
  grants list/revoke shapes were missing there, which made the Swift
  generator silently drop the ApprovalScope union and broke ios-build.
  Registered, regenerated, union and new struct emitted again.
- The chained-assertion lane rejects 'as unknown as' in the UI scope
  parser; replaced with a real per-kind boundary parser, which is what
  the rule asks for.
- The sqlite-allow-raw marker must share the line of a mid-statement
  prepare() call for the Kysely guardrail; split the pragma read so the
  SAFETY comment and the allow marker each sit on their own guarded
  line.

* chore(ui): record startup-budget growth for the approvals scope line

The standing-grant scope renderer and grants-ledger strings ride the
boot path (~700 B gzip). Recorded via the check's --update-baseline flow
with the reason inline; well under the committed 350 KiB hard cap.

* fix(gateway): restore the channel-restart helper export dropped on main

#118157 made startGatewayChannelFromActiveRegistry module-local while
its colocated test still imports it, breaking check-test-types and the
compact shard on every merge ref. Smallest correct main heal per the
broken-CI doctrine; the test passes again.

* fix(gateway): drive channel-restart reload coverage through its exported owner

Replaces the prior export restore: #118157 made the restart helper
module-local (the dead-export scan is right that tests are not
production consumers), but left its colocated test importing it, so
main failed check-test-types either way. The test now exercises the
same preserveManualStop semantics through rollbackStoppedGatewayChannels,
the exported reload owner, and the helper stays private.

* test(ui): answer the grants ledger request in approvals-page history tests

The approvals page now loads the standing-grant ledger next to history;
a method-aware stub answers it out of band so the ordered history mocks
keep their call counts. Adds coverage for the ledger render and the
revoke round-trip.

* chore(ui): record CI-observed startup-JS baseline for the grants surface

The e2e-real-gateway lane builds the same tree ~600 B larger than checks-ui
and local builds, past the 64 B variance allowance; record the CI-observed
value so the enforcement limit stops straddling cross-lane build variance.

* fix(cli): escape standing-grant ledger fields visibly; register grants methods in inventory tests

The grant ledger's revokedBy (client display name), automation label, and
agent-authored command now go through escapeApprovalTextForTerminal like the
pending-approvals table, so hostile control characters render as visible
\u{...} escapes instead of being silently stripped by the table renderer.
Regression test fails pre-fix. Also lists exec.approval.grants.list/revoke
in the 2026.8 release-train roster, classifies the approvals grants command
group for JSON output, and fixes the stubGrants mock typing.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 29, 2026
…terms (openclaw#131602)

* feat(approvals): standing-grant ledger, revocation, and configurable terms

Completes the operator half of cron standing grants (openclaw#129526):

- Grants are listable and revocable. New gateway methods
  exec.approval.grants.list/revoke (operator.approvals scope), CLI
  'openclaw approvals grants list|revoke', and a Standing grants section
  on the Control UI approvals page with per-row revoke. Revocation is
  idempotent, records the acting client, and takes effect at the next
  occurrence's spawn boundary.
- Grant terms are frozen at mint and configurable. Default stays
  until-revoked (matching what shipped Always allow has always meant);
  tools.exec.grantExpiryDays sets a day-bounded default for future
  grants (enterprise fleet policy), and resolve surfaces may override
  per grant via grantExpiresInDays / --expires-in-days. Existing grants
  keep their minted terms; config changes are never retroactive.
- expires_at_ms goes nullable (NULL = until revoked). The mandatory-
  expiry shape never reached a release tag, so the lazy ensure rebuilds
  it in place; grants are re-derivable authority, so the fail-closed
  cost is one re-prompt.
- Approval cards say what Always allow does. Automation approvals carry
  a standing-grant ApprovalScope (new union member) built server-side
  from the cron run registry (now carrying the job display name); the
  Control UI inbox card and modal render it via i18n, e.g. 'Always
  allow runs this exact command for "grant-demo" without asking, for
  10 days (revocable)'.
- Aux method registries stay in lockstep: new parity test fails when a
  GATEWAY_AUX_METHODS entry lacks a lazy handler (this gap produced
  live unknown-method errors during bring-up).

Live-proven on a hermetic gateway: until-revoked grant ran 62 promptless
occurrences; UI and CLI revocation each returned the prompt on the next
occurrence; config default stamped exactly 10.0 days via a UI resolve;
--expires-in-days 99 override stamped 99.0 days; ledger and card
screenshots captured from the running Control UI.

* chore(ui): annotate the scope narrowing assertion for the safety ratchet

* test(gateway): move aux-method parity check to its own suite

* fix(ci): boundary-parse UI approval scope; register grants schemas for native codegen

- The Swift/Kotlin generators discover named schemas through the
  protocol schema fragments; the standing-grant scope member and the
  grants list/revoke shapes were missing there, which made the Swift
  generator silently drop the ApprovalScope union and broke ios-build.
  Registered, regenerated, union and new struct emitted again.
- The chained-assertion lane rejects 'as unknown as' in the UI scope
  parser; replaced with a real per-kind boundary parser, which is what
  the rule asks for.
- The sqlite-allow-raw marker must share the line of a mid-statement
  prepare() call for the Kysely guardrail; split the pragma read so the
  SAFETY comment and the allow marker each sit on their own guarded
  line.

* chore(ui): record startup-budget growth for the approvals scope line

The standing-grant scope renderer and grants-ledger strings ride the
boot path (~700 B gzip). Recorded via the check's --update-baseline flow
with the reason inline; well under the committed 350 KiB hard cap.

* fix(gateway): restore the channel-restart helper export dropped on main

openclaw#118157 made startGatewayChannelFromActiveRegistry module-local while
its colocated test still imports it, breaking check-test-types and the
compact shard on every merge ref. Smallest correct main heal per the
broken-CI doctrine; the test passes again.

* fix(gateway): drive channel-restart reload coverage through its exported owner

Replaces the prior export restore: openclaw#118157 made the restart helper
module-local (the dead-export scan is right that tests are not
production consumers), but left its colocated test importing it, so
main failed check-test-types either way. The test now exercises the
same preserveManualStop semantics through rollbackStoppedGatewayChannels,
the exported reload owner, and the helper stays private.

* test(ui): answer the grants ledger request in approvals-page history tests

The approvals page now loads the standing-grant ledger next to history;
a method-aware stub answers it out of band so the ordered history mocks
keep their call counts. Adds coverage for the ledger render and the
revoke round-trip.

* chore(ui): record CI-observed startup-JS baseline for the grants surface

The e2e-real-gateway lane builds the same tree ~600 B larger than checks-ui
and local builds, past the 64 B variance allowance; record the CI-observed
value so the enforcement limit stops straddling cross-lane build variance.

* fix(cli): escape standing-grant ledger fields visibly; register grants methods in inventory tests

The grant ledger's revokedBy (client display name), automation label, and
agent-authored command now go through escapeApprovalTextForTerminal like the
pending-approvals table, so hostile control characters render as visible
\u{...} escapes instead of being silently stripped by the table renderer.
Regression test fails pre-fix. Also lists exec.approval.grants.list/revoke
in the 2026.8 release-train roster, classifies the approvals grants command
group for JSON output, and fixes the stubGrants mock typing.
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 docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant