Skip to content

Commit 29625bc

Browse files
authored
feat(audit): record generic tool action decisions (#130358)
* feat(audit): record generic tool action decisions * fix(audit): bind OpenClaw action descriptors * fix(audit): keep decision routing private * fix(audit): avoid duplicate void-hook decisions * fix(audit): scope plugin hook ownership * docs(agents): preserve decision audit FIFO ownership
1 parent 64f30c7 commit 29625bc

14 files changed

Lines changed: 708 additions & 20 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Review invariants; full doctrine: `docs/gateway/audit.md`.
153153
- Frozen ingress identity facts are diagnostic audit input, not session-ownership state. Session provenance uses the current canonical authenticated profile ID, never a profile display label; only explicitly enabled audit storage may retain its bounded, redacted form.
154154
- Invoker evidence is tri-state: tagged principal-bearing input is `present`, tagged principal-less input is `unknown`, and omission alone is `absent`. Validate the closed raw variant before projection or field dropping; reject malformed, mixed, untagged, or extra-field input instead of normalizing it to `unknown` or absence.
155155
- Each outer admitted turn owns one immutable `executionId` and `contextId`; `runId` is non-unique correlation. Retries, fallbacks, and recovery reuse the original admission identity. Only byte-identical canonical replay is idempotent.
156-
- Decision receipts adapt owner-native durable decisions; `execution_decision_facts` is only for boundaries without an owner-native record, never duplicates approvals, and stays dormant until an explicit product-boundary producer with an operator retention opt-in exists — the 30-day retention bound does not authorize default collection. Receipt coverage `enforced` is diagnostic, not authority: emit it only when the owner changed the outcome and the exact context/execution/run tuple validates. For receipts after awaited work, synchronously revalidate the exact live owner immediately before the sink; stale, released, replaced, or throwing authority emits no receipt — not `unknown` — with no intervening await. Same-run wrappers compose owner predicates; distinct admitted runs start a new predicate root. Insufficient decision evidence remains `unknown`.
156+
- Decision receipts adapt owner-native durable decisions; `execution_decision_facts` is only for boundaries without an owner-native record, never duplicates approvals, and stays dormant until an explicit product-boundary producer with an operator retention opt-in exists — the 30-day retention bound does not authorize default collection. Private decision work shares admission's `AuditEventWriter` FIFO so admission is observed first; producers never write the generic store directly, create another writer/key, or pseudonymize locally. Raw refs are HMAC-projected only by the writer before persistence. Receipt coverage `enforced` is diagnostic, not authority: emit it only when the owner changed the outcome and the exact context/execution/run tuple validates. For receipts after awaited work, synchronously revalidate the exact live owner immediately before the sink; stale, released, replaced, or throwing authority emits no receipt — not `unknown` — with no intervening await. Same-run wrappers compose owner predicates; distinct admitted runs start a new predicate root. Insufficient decision evidence remains `unknown`.
157157
- `audit.run.inspect` exposes only the Gateway-owned `decisionDisplays` allowlist; display trust comes from owner-held call-path provenance, never receipt-controlled `source.owner` or prose. Pair every selected owner row or event with a required opaque selector from the same query or page result; never derive or requery selectors from private receipt, resolution, or event identifiers, or drop corrupt, oversized, or unlinked outcomes.
158158
- Admission may only validate, bound, freeze, and enqueue through the shared audit writer. Admission validates only a recursively owned, enumerable, accessor-free data snapshot constructed from descriptors before schema checks or ordinary property reads; inherited properties are absent and accessors never run. No synchronous SQLite, schema, filesystem, HMAC-key, or readiness work. Audit failure never delays or aborts execution.
159159
- Raw identity references are transient worker-message data. Never persist, export, inspect, or log them. Public Plugin SDK ingress must strip private recovery/admission authority, including JavaScript extra and inherited properties.

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ src/agents/agent-tool-definition-adapter.ts 4
16791679
src/agents/agent-tool-metadata.ts 2
16801680
src/agents/agent-tools.abort.ts 1
16811681
src/agents/agent-tools.before-tool-call.diagnostics.ts 1
1682-
src/agents/agent-tools.before-tool-call.wrapper.ts 8
1682+
src/agents/agent-tools.before-tool-call.wrapper.ts 4
16831683
src/agents/agent-tools.execution-preparer.ts 2
16841684
src/agents/agent-tools.params.ts 5
16851685
src/agents/agent-tools.policy.ts 1

‎src/agents/agent-tool-metadata.ts‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1-
import { copyPluginToolMeta } from "../plugins/tools.js";
1+
import { copyPluginToolMeta, getPluginToolMeta } from "../plugins/tools.js";
22
import type { AnyAgentTool } from "./agent-tools.types.js";
33
import { copyBeforeToolCallHookMarker } from "./before-tool-call-metadata.js";
44
import { copyChannelAgentToolMeta } from "./channel-tool-metadata.js";
55
import { copyCodeModeControlToolIdentity } from "./code-mode-control-tools.js";
66
import { copyInternalToolExecutionPreparer } from "./runtime/internal-hooks.js";
77
import { copyToolTerminalPresentation } from "./tool-terminal-presentation.js";
88

9+
export type AgentToolActionDescriptor = Readonly<{
10+
family: "data" | "tool";
11+
operation: "filesystem" | "memory" | "openclaw" | "process";
12+
}>;
13+
14+
const actionDescriptors = new WeakMap<AnyAgentTool, AgentToolActionDescriptor>();
15+
16+
export function bindAgentToolActionDescriptor(
17+
tool: AnyAgentTool,
18+
descriptor: AgentToolActionDescriptor,
19+
): void {
20+
actionDescriptors.set(tool, descriptor);
21+
}
22+
23+
export function getAgentToolActionDescriptor(
24+
tool: AnyAgentTool,
25+
): AgentToolActionDescriptor | undefined {
26+
return actionDescriptors.get(tool);
27+
}
28+
29+
function copyAgentToolActionDescriptor(source: AnyAgentTool, target: AnyAgentTool): void {
30+
const descriptor = actionDescriptors.get(source);
31+
if (descriptor) {
32+
actionDescriptors.set(target, descriptor);
33+
}
34+
}
35+
36+
/** Preserve only the metadata owned by a before-tool-call wrapper rebuild. */
37+
export function copyBeforeToolCallWrapperMetadata(
38+
source: AnyAgentTool,
39+
target: AnyAgentTool,
40+
): void {
41+
copyPluginToolMeta(source, target);
42+
// SAFETY: both metadata owners attach to the same runtime tool object shape.
43+
copyChannelAgentToolMeta(source as never, target as never);
44+
copyToolTerminalPresentation(source, target);
45+
copyAgentToolActionDescriptor(source, target);
46+
}
47+
48+
/** Bind the broad family at final assembly from private, process-stable owner metadata. */
49+
export function bindAssembledAgentToolActionDescriptor(tool: AnyAgentTool): void {
50+
if (actionDescriptors.has(tool)) {
51+
return;
52+
}
53+
const kind = getPluginToolMeta(tool)?.kind;
54+
const memory = kind === "memory" || (Array.isArray(kind) && kind.includes("memory"));
55+
actionDescriptors.set(
56+
tool,
57+
memory ? { family: "data", operation: "memory" } : { family: "tool", operation: "openclaw" },
58+
);
59+
}
60+
961
/**
1062
* Preserve identity-backed tool metadata that object spread cannot carry.
1163
* Losing it detaches policy, hooks, presentation, and control-flow ownership.
@@ -20,5 +72,6 @@ export function copyAgentToolMetadata<T extends AnyAgentTool>(source: AnyAgentTo
2072
copyToolTerminalPresentation(source, target);
2173
copyCodeModeControlToolIdentity(source, target);
2274
copyInternalToolExecutionPreparer(source, target);
75+
copyAgentToolActionDescriptor(source, target);
2376
return target;
2477
}

0 commit comments

Comments
 (0)