Skip to content

Commit 4d83fbc

Browse files
committed
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.
1 parent 871b18d commit 4d83fbc

38 files changed

Lines changed: 1169 additions & 86 deletions

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ enum class GatewayMethod(
433433
ExecApprovalRequest("exec.approval.request"),
434434
ExecApprovalWaitDecision("exec.approval.waitDecision"),
435435
ExecApprovalResolve("exec.approval.resolve"),
436+
ExecApprovalGrantsList("exec.approval.grants.list"),
437+
ExecApprovalGrantsRevoke("exec.approval.grants.revoke"),
436438
QuestionRequest("question.request"),
437439
QuestionWaitAnswer("question.waitAnswer"),
438440
QuestionResolve("question.resolve"),

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18160,17 +18160,28 @@ public struct ApprovalResolveParams: Codable, Sendable {
1816018160
public let kind: ApprovalKind
1816118161
public let decision: ApprovalDecision
1816218162
public let reviewer: [String: AnyCodable]?
18163+
public let grantexpiresindays: Int?
1816318164

1816418165
public init(
1816518166
id: String,
1816618167
kind: ApprovalKind,
1816718168
decision: ApprovalDecision,
18168-
reviewer: [String: AnyCodable]? = nil)
18169+
reviewer: [String: AnyCodable]? = nil,
18170+
grantexpiresindays: Int? = nil)
1816918171
{
1817018172
self.id = id
1817118173
self.kind = kind
1817218174
self.decision = decision
1817318175
self.reviewer = reviewer
18176+
self.grantexpiresindays = grantexpiresindays
18177+
}
18178+
18179+
private enum CodingKeys: String, CodingKey {
18180+
case id
18181+
case kind
18182+
case decision
18183+
case reviewer
18184+
case grantexpiresindays = "grantExpiresInDays"
1817418185
}
1817518186
}
1817618187

@@ -18561,15 +18572,25 @@ public struct ExecApprovalResolveParams: Codable, Sendable {
1856118572
public let id: String
1856218573
public let decision: String
1856318574
public let reviewer: [String: AnyCodable]?
18575+
public let grantexpiresindays: Int?
1856418576

1856518577
public init(
1856618578
id: String,
1856718579
decision: String,
18568-
reviewer: [String: AnyCodable]? = nil)
18580+
reviewer: [String: AnyCodable]? = nil,
18581+
grantexpiresindays: Int? = nil)
1856918582
{
1857018583
self.id = id
1857118584
self.decision = decision
1857218585
self.reviewer = reviewer
18586+
self.grantexpiresindays = grantexpiresindays
18587+
}
18588+
18589+
private enum CodingKeys: String, CodingKey {
18590+
case id
18591+
case decision
18592+
case reviewer
18593+
case grantexpiresindays = "grantExpiresInDays"
1857318594
}
1857418595
}
1857518596

@@ -22068,40 +22089,6 @@ public enum ToolsGitHubAuthorizePollResult: Codable, Sendable {
2206822089
}
2206922090
}
2207022091

22071-
public enum ApprovalScope: Codable, Sendable {
22072-
case messageSend(MessageSendApprovalScope)
22073-
case payment(PaymentApprovalScope)
22074-
case externalPost(ExternalPostApprovalScope)
22075-
22076-
private enum CodingKeys: String, CodingKey {
22077-
case discriminator = "kind"
22078-
}
22079-
22080-
public init(from decoder: Decoder) throws {
22081-
let container = try decoder.container(keyedBy: CodingKeys.self)
22082-
let discriminator = try container.decode(String.self, forKey: .discriminator)
22083-
switch discriminator {
22084-
case "message-send": self = try .messageSend(MessageSendApprovalScope(from: decoder))
22085-
case "payment": self = try .payment(PaymentApprovalScope(from: decoder))
22086-
case "external-post": self = try .externalPost(ExternalPostApprovalScope(from: decoder))
22087-
default:
22088-
throw DecodingError.dataCorruptedError(
22089-
forKey: .discriminator,
22090-
in: container,
22091-
debugDescription: "Unknown ApprovalScope discriminator value"
22092-
)
22093-
}
22094-
}
22095-
22096-
public func encode(to encoder: Encoder) throws {
22097-
switch self {
22098-
case .messageSend(let value): try value.encode(to: encoder)
22099-
case .payment(let value): try value.encode(to: encoder)
22100-
case .externalPost(let value): try value.encode(to: encoder)
22101-
}
22102-
}
22103-
}
22104-
2210522092
public enum ApprovalPresentation: Codable, Sendable {
2210622093
case exec(ExecApprovalPresentation)
2210722094
case plugin(PluginApprovalPresentation)

‎docs/automation/cron-jobs.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ Before an isolated run starts, OpenClaw checks reachable local endpoints for con
298298
Command payloads run deterministic scripts inside the Gateway scheduler without starting a model-backed turn. They execute on the Gateway host, capture stdout/stderr, record the run in the job's run history, and reuse the same `announce`, `webhook`, and `none` delivery modes as agent-turn jobs.
299299

300300
<Note>
301+
When an agent-turn automation's exec needs approval, the card is delivered to connected approval surfaces and the run waits for the decision; answering **Always allow** mints a scoped standing grant so later occurrences run without prompting. See [Standing grants for automations](/tools/exec-approvals#standing-grants-for-automations) for lifetime, listing, and revocation.
302+
301303
Command payloads are an operator-admin Gateway automation surface, not an agent `tools.exec` call. Creating, updating, removing, or manually running automation jobs requires `operator.admin`; scheduled command runs later execute inside the Gateway process as that admin-authored automation. Agent exec policy (`tools.exec.mode`, approval prompts, per-agent tool allowlists) governs model-visible exec tools, not command payloads.
302304
</Note>
303305

‎docs/cli/approvals.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ For exec requests, `allow-always` means **always allow here**: the generated
9494
grant is tied to the command's exact arguments and current working directory.
9595
The same command from another directory requires a separate approval.
9696

97+
For approvals raised by an automation (cron) run, `allow-always` mints a
98+
scoped standing grant instead of a JSON allowlist entry (see
99+
[Standing grants for automations](/tools/exec-approvals#standing-grants-for-automations)).
100+
By default the grant lives until revoked; `--expires-in-days <n>` freezes an
101+
explicit lifetime instead of the configured `tools.exec.grantExpiryDays`
102+
default:
103+
104+
```bash
105+
openclaw approvals resolve <id> allow-always --expires-in-days 30
106+
```
107+
108+
## Standing grants
109+
110+
Standing grants minted by allow-always on automation approvals are listed and
111+
revoked from the same command group:
112+
113+
```bash
114+
openclaw approvals grants list
115+
openclaw approvals grants list --json
116+
openclaw approvals grants revoke <grant-id>
117+
```
118+
119+
The list shows the owning automation, the exact command, the use count, and
120+
each grant's state (until revoked, expires in N days, expired, or revoked).
121+
Revocation is idempotent and takes effect at the next occurrence's spawn
122+
boundary — that occurrence prompts again. Editing or deleting the automation
123+
invalidates its grants without needing an explicit revoke.
124+
97125
The CLI reads the unified approval record to select its kind, checks the requested decision against the record's allowed decisions, and then calls the unified resolver. A first successful decision exits `0`. Repeating the recorded decision also exits `0` and reports `already resolved (same decision)`. A conflicting decision, missing approval, expired approval, or decision unavailable for that approval kind prints a clear error and exits non-zero.
98126

99127
`--reason` adds a local note to the CLI confirmation. The current Gateway approval record has no free-text resolution-reason field, so this note is not persisted or sent to other approval surfaces.

‎docs/gateway/config-tools.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ Control UI repository previews and project discovery use the separate optional `
287287

288288
Values shown are defaults except `applyPatch.allowModels` (empty/unset by default, meaning any compatible model may use `apply_patch`). `approvalRunningNoticeMs` emits a running notice when approval-backed exec runs long; `0` disables it.
289289

290+
`tools.exec.grantExpiryDays` (unset by default) sets the default lifetime, in days (1–3650), for standing grants minted by Always allow on automation approvals. Unset keeps grants valid until revoked or the owning automation changes. Terms freeze at mint, so changing the value affects only future grants; see [Standing grants for automations](/tools/exec-approvals#standing-grants-for-automations).
291+
290292
### `tools.loopDetection`
291293

292294
Tool-loop safety checks are **disabled by default**. Set `enabled: true` to activate detection. Settings can be defined globally in `tools.loopDetection` and overridden per-agent at `agents.entries.*.tools.loopDetection`.

‎docs/tools/exec-approvals.md‎

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -427,31 +427,72 @@ Each allowlist entry supports:
427427
| `lastUsedCommand` | Last command that matched; omitted for generated hashed argv entries |
428428
| `lastResolvedPath` | Last resolved binary path |
429429

430-
## Cron standing grants
431-
432-
Approvals raised by gateway-host cron runs are delivered only to connected
433-
approval surfaces (Control UI, TUI, macOS app) — never to chat channels, which
434-
would repeat a card on every occurrence. While a reviewer surface is
435-
connected, the scheduled run waits for the decision like an interactive run;
436-
cron jobs are single-flight, so at most one card per job is pending at a
437-
time. With no approval surface connected, the request is denied immediately
438-
and the run's error explains the policy fix, exactly as before. Node-host
439-
cron execs keep the fully headless policy (no cards) until node execution
440-
gains its own standing-grant path.
441-
442-
When an approval originates from a cron job's isolated run, resolving it with
443-
**allow always** does not write a JSON allowlist entry. Instead the Gateway
444-
mints a scoped standing grant bound to that exact agent, cron job, job
445-
configuration, and operation (command text, working directory, and requested
446-
environment). Later occurrences of the same job execute that exact operation
447-
without prompting while the grant is valid.
448-
449-
A grant expires 30 days after the approval and fails closed back to a normal
450-
prompt whenever anything changed: the job was edited or deleted, the command,
451-
working directory, or environment differs, the grant expired or was revoked,
452-
or the original approval record is gone. Mutable file operands and commands
430+
## Standing grants for automations
431+
432+
Approvals raised by gateway-host automation (cron) runs are delivered only to
433+
connected approval surfaces (Control UI, TUI, macOS app) — never to chat
434+
channels, which would repeat a card on every occurrence. While a reviewer
435+
surface is connected, the scheduled run waits for the decision like an
436+
interactive run; automations are single-flight, so at most one card per job
437+
is pending at a time. With no approval surface connected, the request is
438+
denied immediately and the run's error explains the policy fix. Node-host
439+
automation execs keep the fully headless policy (no cards) until node
440+
execution gains its own standing-grant path.
441+
442+
When an approval originates from an automation's isolated run, resolving it
443+
with **Always allow** does not write a JSON allowlist entry. Instead the
444+
Gateway mints a scoped standing grant bound to that exact agent, automation,
445+
job configuration, and operation (command text, working directory, and
446+
requested environment). Later occurrences of the same job execute that exact
447+
operation without prompting while the grant is valid. The approval card says
448+
so up front: automation approvals carry a scope line describing exactly what
449+
Always allow will mint.
450+
451+
### What a grant covers, and when it stops
452+
453+
A grant fails closed back to a normal prompt whenever anything changed: the
454+
job was edited or deleted (any configuration change invalidates it), the
455+
command, working directory, or environment differs by even one byte, the
456+
grant was revoked or expired, or the original approval record is gone. The
457+
check runs immediately before the process spawns, so a revocation or job
458+
edit that lands mid-flight still wins. Mutable file operands and commands
453459
that require explicit review (heredocs, strict inline eval, audit
454-
suppression) keep prompting per occurrence. Non-cron approvals are unchanged.
460+
suppression) keep prompting per occurrence. Non-automation approvals are
461+
unchanged.
462+
463+
### Grant lifetime
464+
465+
By default a grant lives **until revoked** — the same meaning Always allow
466+
has everywhere else in the product. Terms freeze at mint time and never
467+
change retroactively:
468+
469+
- `tools.exec.grantExpiryDays` (unset by default) sets the default lifetime,
470+
in days, for **future** grants. Existing grants keep the terms they were
471+
minted with; use revocation to retire them early. This is the fleet-policy
472+
knob for managed deployments that require periodic re-approval.
473+
- A resolving surface may override the default per grant with the
474+
`grantExpiresInDays` field on `approval.resolve` /
475+
`exec.approval.resolve`, or `openclaw approvals resolve <id> allow-always
476+
--expires-in-days <n>`. The override wins over the config default.
477+
- Expired grants fall back to prompting and are pruned opportunistically.
478+
479+
### Listing and revoking
480+
481+
Every standing grant is visible and revocable:
482+
483+
- **Control UI**: Settings → Approvals shows the standing-grant ledger —
484+
automation, exact command, use count, and state (until revoked, expires in
485+
N days, expired, revoked) — with a Revoke action per active row.
486+
- **CLI**: `openclaw approvals grants list` renders the same ledger;
487+
`openclaw approvals grants revoke <grant-id>` revokes one grant. Revocation
488+
is idempotent and takes effect at the next occurrence's spawn boundary —
489+
that occurrence prompts again.
490+
- Deleting or editing the automation, or reversing the minting approval,
491+
also invalidates the grant without touching the grants surface.
492+
493+
The minting `operator_approvals` row remains the sole authorization owner: a
494+
grant is derivative correlation, revalidated against the live approval row,
495+
automation row, and revocation state on every use.
455496

456497
## Auto-allow skill CLIs
457498

‎packages/gateway-protocol/src/schema/approvals.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ export const ExternalPostApprovalScopeSchema = closedObject({
9898
visibility: Type.Union([Type.Literal("public"), Type.Literal("restricted")]),
9999
});
100100

101+
/**
102+
* What allow-always mints for an automation approval: a standing grant bound
103+
* to this exact command and automation. Absent expiresInDays means the grant
104+
* lives until revoked or the automation changes.
105+
*/
106+
export const StandingGrantApprovalScopeSchema = closedObject({
107+
kind: Type.Literal("standing-grant"),
108+
automation: Type.String({ minLength: 1, maxLength: 128 }),
109+
command: Type.String({ minLength: 1, maxLength: 256 }),
110+
expiresInDays: Type.Optional(Type.Integer({ minimum: 1, maximum: 3650 })),
111+
});
112+
101113
/**
102114
* Owner-declared blast-radius facts for a pending approval. Variants are
103115
* named schemas so native protocol generators emit the discriminated union.
@@ -106,6 +118,7 @@ export const ApprovalScopeSchema = Type.Union([
106118
MessageSendApprovalScopeSchema,
107119
PaymentApprovalScopeSchema,
108120
ExternalPostApprovalScopeSchema,
121+
StandingGrantApprovalScopeSchema,
109122
]);
110123

111124
const ApprovalAllowedDecisionsSchema = Type.Array(ApprovalDecisionSchema, {
@@ -292,6 +305,10 @@ export const ApprovalResolveParamsSchema = closedObject({
292305
kind: ApprovalKindSchema,
293306
decision: ApprovalDecisionSchema,
294307
reviewer: Type.Optional(ApprovalChannelReviewerSchema),
308+
// Per-grant expiry override for allow-always on automation (exec) approvals:
309+
// days from resolution. Absent defers to tools.exec.grantExpiryDays; unset
310+
// config keeps the grant valid until revoked. Ignored for other kinds.
311+
grantExpiresInDays: Type.Optional(Type.Integer({ minimum: 1, maximum: 3650 })),
295312
});
296313

297314
/** First-answer outcome plus the canonical recorded state returned to all contenders. */

‎packages/gateway-protocol/src/schema/exec-approvals.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,49 @@ export const ExecApprovalResolveParamsSchema = closedObject({
316316
id: NonEmptyString,
317317
decision: NonEmptyString,
318318
reviewer: Type.Optional(ApprovalChannelReviewerSchema),
319+
// Per-grant expiry override for allow-always on automation approvals:
320+
// days from resolution. Absent defers to tools.exec.grantExpiryDays, and
321+
// an unset config keeps the grant valid until revoked. Ignored for other
322+
// decisions and non-grant approvals.
323+
grantExpiresInDays: Type.Optional(Type.Integer({ minimum: 1, maximum: 3650 })),
324+
});
325+
326+
/** Operator listing filter for standing grants; bounded for prompt-safe output. */
327+
export const ExecApprovalGrantsListParamsSchema = closedObject({
328+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500 })),
329+
});
330+
331+
/** One standing grant projected for operator surfaces. */
332+
export const ExecApprovalStandingGrantSchema = closedObject({
333+
grantId: NonEmptyString,
334+
mintedByApprovalId: NonEmptyString,
335+
agentId: NonEmptyString,
336+
cronJobId: NonEmptyString,
337+
cronJobName: Type.Union([Type.String({ minLength: 1, maxLength: 200 }), Type.Null()]),
338+
command: Type.String({ minLength: 1, maxLength: 512 }),
339+
cwd: Type.Union([Type.String({ minLength: 1, maxLength: 512 }), Type.Null()]),
340+
createdAtMs: Type.Integer({ minimum: 0 }),
341+
expiresAtMs: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
342+
revokedAtMs: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
343+
revokedBy: Type.Union([Type.String({ minLength: 1, maxLength: 200 }), Type.Null()]),
344+
lastUsedAtMs: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
345+
useCount: Type.Integer({ minimum: 0 }),
346+
});
347+
348+
export const ExecApprovalGrantsListResultSchema = closedObject({
349+
grants: Type.Array(ExecApprovalStandingGrantSchema, { maxItems: 500 }),
350+
});
351+
352+
export const ExecApprovalGrantsRevokeParamsSchema = closedObject({
353+
grantId: NonEmptyString,
354+
});
355+
356+
export const ExecApprovalGrantsRevokeResultSchema = closedObject({
357+
outcome: Type.Union([
358+
Type.Literal("revoked"),
359+
Type.Literal("already-revoked"),
360+
Type.Literal("not-found"),
361+
]),
319362
});
320363

321364
// Owner-local wire types derived directly from local schema consts so the
@@ -329,3 +372,8 @@ export type ExecApprovalsSnapshot = Static<typeof ExecApprovalsSnapshotSchema>;
329372
export type ExecApprovalGetParams = Static<typeof ExecApprovalGetParamsSchema>;
330373
export type ExecApprovalRequestParams = Static<typeof ExecApprovalRequestParamsSchema>;
331374
export type ExecApprovalResolveParams = Static<typeof ExecApprovalResolveParamsSchema>;
375+
export type ExecApprovalGrantsListParams = Static<typeof ExecApprovalGrantsListParamsSchema>;
376+
export type ExecApprovalStandingGrant = Static<typeof ExecApprovalStandingGrantSchema>;
377+
export type ExecApprovalGrantsListResult = Static<typeof ExecApprovalGrantsListResultSchema>;
378+
export type ExecApprovalGrantsRevokeParams = Static<typeof ExecApprovalGrantsRevokeParamsSchema>;
379+
export type ExecApprovalGrantsRevokeResult = Static<typeof ExecApprovalGrantsRevokeResultSchema>;

‎packages/gateway-protocol/src/validator-registry.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ export const validateExecApprovalsSetParams = compile(S.ExecApprovalsSetParamsSc
435435
export const validateExecApprovalGetParams = compile(S.ExecApprovalGetParamsSchema);
436436
export const validateExecApprovalRequestParams = compile(S.ExecApprovalRequestParamsSchema);
437437
export const validateExecApprovalResolveParams = compile(S.ExecApprovalResolveParamsSchema);
438+
export const validateExecApprovalGrantsListParams = compile(S.ExecApprovalGrantsListParamsSchema);
439+
export const validateExecApprovalGrantsRevokeParams = compile(
440+
S.ExecApprovalGrantsRevokeParamsSchema,
441+
);
438442
export const validateQuestionRequestParams = compile(S.QuestionRequestParamsSchema);
439443
export const validateQuestionWaitAnswerParams = compile(S.QuestionWaitAnswerParamsSchema);
440444
export const validateQuestionResolveParams = compile(S.QuestionResolveParamsSchema);

0 commit comments

Comments
 (0)