Repository navigation
Commit bb3c163
feat(plugin-audit): mark in-product AI writes on sys_audit_log rows (agent, conversation, confirmation) (#34547)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9WZvQNanG3W23XFGRFXLDAt)_
Fixes #33694
Clause-②: no
Metadata-protocol: none
## 维护者速读
1. **改了什么**:产品内 AI 替某人改记录时,审计日志那一行现在写明是哪个
AI(`performed_by`)、替谁(`on_behalf_of`)、在哪次对话(`conversation_id`)、经哪次确认(`confirmation_id`,没确认就不写)。
2. **为什么改**:之前 AI 改的数据在审计日志里和本人手改一模一样,回答不了「这条是 AI 替张三在哪次对话里改的」;契约字段早已在
main(#33786),只差审计写入器去读。
3. **风险与回滚**:只加 metadata 键,`user_id` / `actor` 仍是本人,人手改的行不变;回滚即撤本
PR,历史行不受影响。
4.
**先看**:`packages/plugins/plugin-audit/src/audit-writers.ts`(`performedBy`
取值与 metadata 拼装两处)、`agent-dual-attribution.integration.test.ts` 末尾新增的
describe、`packages/spec/src/kernel/execution-context.zod.ts` 的 describe
改句。
5. **两分钟验证**:`pnpm --filter @objectstack/plugin-audit exec vitest run
src/agent-dual-attribution.integration.test.ts`,预期 15 条全绿,其中 6 条是本卡新用例。
6. **需要你做的**:无,席位落地。
## What changes
- **The record-write audit writer reads the in-product AI performer.**
`audit-writers.ts` read only `provenance.performedByClientId` (the /mcp
OAuth client). It now also reads `provenance.performedByAgentId`,
`performedByConversationId` and `performedByConfirmationId`, which
`buildProvenance` already copies from `ExecutionContext.performedBy`
(#33786, PR #34018). On a row the in-product AI wrote for a person,
`sys_audit_log.metadata` carries:
- `performed_by`: the agent, beside `on_behalf_of`: the person (the
existing pair, per the owner ruling on objectstack-ai/cloud#3826 「3826
照建议(征询版)」: reuse `performed_by` / `on_behalf_of`, no new actor
vocabulary);
- `conversation_id`: the AI conversation;
- `confirmation_id`: the pending item the person's approval decided,
only when there was one.
`user_id` and `actor` stay the person (ADR-0073 D3, ADR-0118 D1/D5). A
personal write still carries no metadata. `conversation_id` /
`confirmation_id` are written only when the in-product agent is the
recorded performer, never beside an OAuth client id. If an envelope ever
carried both `clientId` and `agentId` (each producer sets only its own),
the row records the OAuth client and drops the agent with its two marks.
- **Spec describes.** The `ExecutionContext.performedBy` and
`HookContext.provenance.performedByAgentId` /
`performedByConversationId` / `performedByConfirmationId` describes and
JSDoc no longer say the audit writer "does not record them yet". They
name the metadata keys; say that `performed_by` holds either an OAuth
client id or an in-product agent name, and state only what a reader can
tell from a row: a value matching the `client_id` of an existing
`sys_oauth_application` row is an OAuth client; a row carrying
`conversation_id` or `confirmation_id` names an in-product agent; a row
meeting neither may name an agent or the client of a since-deleted
application, which the row alone cannot tell apart; and the contract
does not keep an agent name and a `client_id` from being the same
string; state the both-performers precedence; and say the
action-invocation, data-export and dataset-query rows still record
`clientId` only. The `performedBy` JSDoc's "no key holds two id
namespaces" sentence now names the audit key as the ruled exception. No
schema shape change; `content/docs/references/**` regenerated
(`gen:docs`).
- Changeset `.changeset/33694-audit-in-product-ai-performer.md`:
`@objectstack/plugin-audit` patch, `@objectstack/spec` patch (describe
text ships).
## Why
The in-product AI writes as the signed-in person, so its rows were
byte-identical to that person's own edits on every attribution column.
The contract fields that tell them apart landed in #33786; nothing
recorded them.
## Tests
New top-level describe in
`packages/plugins/plugin-audit/src/agent-dual-attribution.integration.test.ts`
(the existing rule 4 harness: real kernel, `assembleExecutionContext`,
objectql `buildProvenance`, the shipped `sys_audit_log` object and
writer on sqlite-wasm). The person's envelope is built at the real door;
`performedBy` is added as the in-product AI path stamps it (that
producer lives outside this repository).
- CONTROL: the envelope is a `human` principal with no `performedBy`,
and `user_id` / `actor` are the person on all four rows.
- A confirmed AI create records `{ performed_by, on_behalf_of,
conversation_id, confirmation_id }`.
- An AI create that needed no confirmation records no `confirmation_id`.
- An AI update of a record the person created is marked on the update
row; the person's own create row stays unmarked.
- An envelope naming an OAuth client beside a conversation and a
confirmation records only `{ performed_by: client, on_behalf_of }`.
- An envelope naming both performers records the OAuth client, without
the agent's marks.
The last two envelopes have no producer in the tree; they pin what the
spec tells a reader.
No existing test changed.
## Acceptance notes
- **Two id namespaces in `performed_by`.** `performed_by` now holds an
OAuth client id or an in-product agent name, as the ruling chose
(accepted in contract review 6934640918). Round 2 answered its S1: the
writer keys `conversation_id` / `confirmation_id` on the agent being the
recorded performer (which also closes N1). Round 3 answers S2
(6936045381): the describes no longer claim every value is classifiable,
since an OAuth application row can be deleted while audit rows keep its
`client_id`; a permanent per-row discriminator would need a kind mark on
the row, which is a ruling, not this PR. ADR-0151 D5 reason 2 and
ADR-0090 D10 rule 4 wording stay with carrier #34057.
- **Out of scope, filed #34556:** the action-invocation, data-export and
dataset-query writers (`action-invocation-audit.ts`,
`data-export-audit.ts`, `dataset-query-audit.ts`) read
`performedBy.clientId` only, so an in-product AI action run or export is
still recorded as the person's own. The describes now say so.
- The `clientId` / `performedByClientId` describes now name the OAuth
client by the `client_id` of its `sys_oauth_application` row (they said
the row's id; the two columns differ).
- `content/docs/automation/hook-bodies.mdx` lists
`ctx.provenance.performedByClientId` only; outside this card's file
surface. Filed #34556.
## Verification
<details><summary>Local runs (head and gate list in the report comment
on #33694)</summary>
- `pnpm --filter '@objectstack/plugin-audit^...' build` under the verify
lock: exit 0.
- `pnpm --filter @objectstack/plugin-audit exec vitest run
src/agent-dual-attribution.integration.test.ts`: Test Files 1 passed,
Tests 15 passed.
- `pnpm --filter @objectstack/plugin-audit test` (after merging main):
Test Files 101 passed, Tests 1676 passed. `pnpm --filter
@objectstack/plugin-audit typecheck`: exit 0, test-typecheck 0 errors.
- `pnpm --filter @objectstack/spec exec vitest run
src/kernel/execution-context.test.ts src/data/hook.test.ts`: Tests 146
passed.
- `pnpm --filter @objectstack/spec build && check:generated`:
`content/docs/references/**` stale, regenerated with `--fix`, re-check
green.
- Ablation (`scripts/ablation-replace.mjs`, anchor hit 1 → 0):
`performedBy = performedByClientId ?? performedByAgentId` →
`performedByClientId` reds the three AI-row tests (3 failed / 10
passed); restore blob == HEAD, `git diff HEAD` empty.
- Round 2 ablation: `agentIsRecordedPerformer = !performedByClientId &&
performedByAgentId !== undefined` → `performedBy !== undefined` reds the
two new pins (2 failed / 13 passed); restore blob == HEAD, `git diff
HEAD` empty.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (CI).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmSQnLEs6vGofJXcguE)_
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmSQnLEs6vGofJXcguE -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a8e09bb commit bb3c163
8 files changed
Lines changed: 298 additions & 41 deletions
File tree
- .changeset
- content/docs/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 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
0 commit comments