Repository navigation
Commit a1082f3
fix(plugin-audit): mark in-product AI calls on the action-invocation, data-export and dataset-query audit rows (#34679)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi99ewj5JRWXTB3u38E9HLhnj)_
Fixes #34556
Clause-②: no
Metadata-protocol: none
Spec surface: since round r2 this PR touches `packages/spec/src`
(describe and JSDoc prose only, no key, type or refine), so it owes an
L2 contract review and the seat's Tier H step before it lands.
## 维护者速读
1. **改了什么**:产品内 AI 替某人执行动作、导出数据、查询数据集时,这三类审计行现在和记录写入行一样,写明是哪个
AI(`performed_by`)、替谁(`on_behalf_of`)、在哪次对话(`conversation_id`)、经哪次确认(`confirmation_id`,没确认就不写)。spec
里描述这件事的说明文字同步改正(只改文字,不改字段)。
2. **为什么改**:之前这三类行只认 OAuth 客户端,产品内 AI 做的动作、导出、查询在审计日志里和本人亲手操作一模一样,查不到是哪次
AI 对话、哪次确认触发的。
3. **风险与回滚**:只在 metadata 里加键,`user_id` / `actor` 仍是本人;OAuth
客户端的行和本人亲手操作的行不变。四类行现在共用一个规则函数,记录写入行的行为不变(原有 15 条钉子测试全绿)。回滚即撤本
PR,历史行不受影响。
4. **先看**:`packages/plugins/plugin-audit/src/audit-writers.ts`(新的
`auditPerformerMetadata`
与记录写入处的调用)、`packages/spec/src/kernel/execution-context.zod.ts`(`performedBy`
的 describe 与 JSDoc 改句)、三个写入器各自的一行接线与三个测试文件末尾新增的 describe。
5. **两分钟验证**:`pnpm --filter @objectstack/plugin-audit exec vitest run
src/action-invocation-audit.test.ts src/data-export-audit.test.ts
src/dataset-query-audit.test.ts
src/agent-dual-attribution.integration.test.ts`,预期 4 个文件 62 条全绿,其中 9
条是本卡新用例。
6. **需要你做的**:本 PR 改了 `packages/spec/src` 的说明文字,契约复审(L2)通过后按席位的 Tier H
流程由你确认落地。
## What changes
- **One performer rule for every `sys_audit_log` writer.** PR #34547
wrote the in-product AI rule inline in the record-write writer
(`installAuditWriters`), reading `HookContext.provenance` through a
private reader. This PR moves that rule, unchanged, into one exported
function in `audit-writers.ts`, `auditPerformerMetadata(performer,
onBehalfOf)`, which takes the `ExecutionContext.performedBy` shape
(`clientId`, `agentId`, `conversationId`, `confirmationId`) and returns
the metadata keys or nothing. The record-write writer now calls it with
its four `provenance` marks. The rule is the one #34547 settled:
- `performed_by` is the OAuth client, else the in-product agent;
`on_behalf_of` is the row's own `user_id` value;
- `conversation_id` / `confirmation_id` are written only when the
in-product agent is the recorded performer, each only when stamped;
- an envelope naming both performers records the OAuth client and drops
the agent with its two marks;
- no performer ⇒ none of these keys.
- **The three writers apply it.** `action-invocation-audit.ts`,
`data-export-audit.ts` and `dataset-query-audit.ts` read
`performedBy.clientId` only. Each now calls
`auditPerformerMetadata(ctx.performedBy, userId)` in place of its own
two-key block. All three write `sys_audit_log` and keep `metadata` as
one JSON text column, so no column or key is added. Their header
comments now name the two marks.
- **`hook-bodies.mdx`.** The `ctx.provenance` table listed
`performedByClientId` only. It now lists `performedByAgentId`,
`performedByConversationId`, `performedByConfirmationId` and
`impersonatedBy`, which the hook-body sandbox already copies
(`packages/runtime/src/sandbox/body-runner.ts`). `performedByAgentId` is
included because the other two are defined as set beside it.
- **Spec describes (round r2).**
`packages/spec/src/kernel/execution-context.zod.ts`: the `performedBy`
describe and JSDoc said "The action-invocation, data-export and
dataset-query rows record clientId only", which this PR makes false.
They now say those rows "record the performer and the two marks by the
same rule". The reader rule there, and in
`packages/spec/src/data/hook.zod.ts`'s `performedByAgentId` describe,
also takes the L2 nit N3 from record 6937613475: "where both tells apply
the mark decides, and a matching value with no mark is the client unless
an agent shares that string". No key, type, refine or optionality moves.
`content/docs/references/**` regenerated (`gen:docs`):
`kernel/execution-context.mdx`, `data/data-engine.mdx` (12 `performedBy`
rows), `data/hook.mdx`.
- Changeset `.changeset/34556-audit-ai-marks-three-rows.md`:
`@objectstack/plugin-audit` patch, `@objectstack/spec` patch (describe
text ships).
`auditPerformerMetadata` is exported from the module, not from the
package entry (`src/index.ts` is unchanged), so the published API
surface does not change.
## Enumeration (from the card)
- [x] action-invocation audit row: pinned by
`action-invocation-audit.test.ts` › "[#33694] an in-product AI call is
marked on the action_invocation row by the CRUD mirror's rule" (the AI
row is written and read back through a real ObjectQL engine).
- [x] data-export audit row: pinned by `data-export-audit.test.ts` ›
"[#33694] an in-product AI export is marked on the export row by the
CRUD mirror's rule".
- [x] dataset-query audit row: pinned by `dataset-query-audit.test.ts` ›
"[#33694] an in-product AI query is marked on the dataset_query row by
the CRUD mirror's rule".
- [x] `hook-bodies.mdx`: the `ctx.provenance` table lists
`performedByConversationId` and `performedByConfirmationId` (and
`performedByAgentId`, and since L1 R1 `impersonatedBy`) beside
`performedByClientId`. Docs only, no test.
## Tests
Each of the three describes has three cases:
- An AI-performed call (`performedBy: { agentId, conversationId,
confirmationId }`) records `performed_by` = agent, `on_behalf_of` =
person, `conversation_id`, `confirmation_id`; `user_id` stays the
person.
- CONTROL: an OAuth client with a conversation and a confirmation, and
an envelope naming both a client and an agent, each record only `{
performed_by: client, on_behalf_of }` and no marks.
- CONTROL: a person's own call carries none of the four keys.
No existing test changed. `agent-dual-attribution.integration.test.ts`
(the record-write pins #34547 added) passes unchanged against the
extracted function.
## Acceptance notes
- **Round r2 (seat chose option A).** The spec sentence this PR made
false is corrected in this PR, as described above, instead of in a
follow-up card. `hook.zod.ts` carried no "clientId only" claim; it is
touched only to carry N3 in the third place the reader rule is stated.
- **L1 R1 (record 6941727354).** The `ctx.provenance` table in
`hook-bodies.mdx` now also lists `impersonatedBy`, which the sandbox
copies (`packages/runtime/src/sandbox/body-runner.ts`), so every member
it carries has a row. Commit `f62fa7ad00`, one docs line.
- Merge probe against PR #34545 (`claude/project-thread-l1nf08`, which
also edits `hook-bodies.mdx`): `git merge-tree --write-tree --name-only
HEAD origin/claude/project-thread-l1nf08` reports `Auto-merging
content/docs/automation/hook-bodies.mdx` with no conflict in that file.
The one textual conflict it reports,
`packages/spec/dropped-refinements.baseline.json`, is between #34545 and
`main` and is not in this diff. The three-ref form in the dispatch (`git
merge-tree --write-tree origin/main HEAD BRANCH`) is not valid syntax
and exits 129, so the two-ref form was used. This is a local probe with
the repo's merge driver registered, not GitHub's mergeability.
## Verification
<details><summary>Round r2, at head 5f005fb (after merging
origin/main twice)</summary>
- Commits: `49dc838adb` (spec prose: the two spec files), `c5eafdb182`
(regenerated references), `19d92fd27e` (changeset), then the merge of
`origin/main` at `5f005fb26a`.
- `pnpm --filter @objectstack/spec build` under the lock: exit 0. `pnpm
--filter @objectstack/spec gen:docs`: exit 0, three reference pages
changed (14 lines). `pnpm --filter @objectstack/spec check:generated`:
"All 14 generated artifacts are up to date", exit 0. The first attempt
reported `test-typecheck-debt.json` with "tsc -p tsconfig.test.json
failed without diagnostics": a JavaScript heap OOM under the 4096 MB
default on this shared box, not staleness. It was re-run with
`--max-old-space-size=6144`, and the later gate sweep at 4096 was green
too.
- No remaining copy of "record clientId only" in `packages/spec/src` or
`content/docs/references`.
- `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2
src/kernel/execution-context.test.ts src/data/hook.test.ts`: Test Files
2 passed (2), Tests 146 passed (146).
- plugin-audit after the final merge: closure build exit 0; `vitest run
--maxWorkers=2` gives Test Files 101 passed (101), Tests 1696 passed
(1696); typecheck exit 0.
- Full workspace build (`turbo run build --concurrency=2
--filter=!@objectstack/docs`): 119 of 119 tasks successful.
- `dispatch-gates --commands` derived 119 commands at this head. All ran
with stdin closed and the exit taken before any pipe; all exited 0.
`--ran`: "119 derived famil(ies) accounted for — 119 run, 0
NOT-MEASURED".
</details>
Round 1 readings below were taken at head `41a26f1134` (after merging
`origin/main` `e5336512f`). The plugin-audit code has not changed since.
<details><summary>Build, tests, typecheck</summary>
- `pnpm --filter '@objectstack/plugin-audit^...' build` under the verify
lock: exit 0.
- `pnpm --filter @objectstack/plugin-audit exec vitest run
--maxWorkers=2 src/action-invocation-audit.test.ts
src/data-export-audit.test.ts src/dataset-query-audit.test.ts
src/agent-dual-attribution.integration.test.ts`: Test Files 4 passed
(4), Tests 62 passed (62).
- `pnpm --filter @objectstack/plugin-audit exec vitest run
--maxWorkers=2` (whole package): Test Files 101 passed (101), Tests 1696
passed (1696).
- `pnpm --filter @objectstack/plugin-audit typecheck`: exit 0;
`check:test-typecheck: OK`, 0 errors.
</details>
<details><summary>Ablations (scripts/ablation-replace.mjs; tests import
the writers from src)</summary>
Each writer's wiring `Object.assign(metadata,
auditPerformerMetadata(ctx.performedBy, userId));` replaced by the old
client-only reading `auditPerformerMetadata({ clientId:
ctx.performedBy?.clientId }, userId)`. Anchor 1 → 0 each time; restored
blob == HEAD and `git diff HEAD` empty each time.
- `action-invocation-audit.ts` → its pin "an AI-performed call records
the agent, the person, the conversation and the confirmation" FAILS:
Tests 1 failed / 13 passed (14).
- `data-export-audit.ts` → "an AI-performed export records …" FAILS:
Tests 1 failed / 18 passed (19).
- `dataset-query-audit.ts` → "an AI-performed query records …" FAILS:
Tests 1 failed / 13 passed (14).
The shared rule in `audit-writers.ts`: `agentIsRecordedPerformer =
!performedByClientId && performedByAgentId !== undefined` replaced by
`performedBy !== undefined`, run over the four files: Tests 5 failed /
57 passed (62). The three new CONTROL pins (client alone or beside an
agent) fail, and so do #34547's two record-write pins ("never ride
beside an OAuth client id", "an envelope naming both performers").
Restored blob == HEAD.
</details>
<details><summary>Gates</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 102 commands for this diff. Each was
run with stdin closed and its exit taken before any pipe.
- Three first exited 3 (prerequisite not met: no built output):
`check:skill-examples`, `check:dual-build-cjs-loads`, `check:i18n`.
After `turbo run build --concurrency=2 --filter=!@objectstack/docs`
under the lock (exit 0), each re-ran with exit 0.
- `dispatch-gates --ran`: "102 derived famil(ies) accounted for — 102
run, 0 NOT-MEASURED". Exit 0.
- Not run locally, left to CI: the repo-wide scans, `test:repo`, and the
dogfood battery. The title has no `!` and the claim has no `(narrowing)`
arm.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmSYVw1sqCsaHSJS9JC
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmSYVw1sqCsaHSJS9JC -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f02f4f6 commit a1082f3
14 files changed
Lines changed: 281 additions & 77 deletions
File tree
- .changeset
- content/docs
- automation
- references
- data
- kernel
- packages
- plugins/plugin-audit/src
- spec/src
- data
- kernel
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
0 commit comments