You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2539ad9
Browse filesBrowse the repository at this point in the historyBrowse files
feat(spec, objectql, runtime): the in-product AI path can name itself on ExecutionContext.performedBy, and hooks see it on HookContext.provenance (#34018)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi93QWxWQ7bNzeUg7g48SSecH)_Fixes#33786
Clause-②: yes
Metadata-protocol: none
Claim by `domain:spec#2` (6896038213). The spec half of #33694
(cloud#3826 phase 2). Ruling-ref: the account owner on
objectstack-ai/cloud#3826, 「3826 照建议(征询版)」 (decision request
6890278459), as carried in the #33694 body: "Accept AI-on-behalf,
conversation id and confirmation id on the write context, using the
existing `performed_by` / `on_behalf_of` columns plus contract fields.
Do not add a new actor vocabulary."
## 维护者速读
- 改了什么:写入上下文 `ExecutionContext.performedBy` 在 `clientId` 旁新增
`agentId`、`conversationId`、`confirmationId` 三个可选键;hook 上下文 `provenance`
同步新增三个对应标记,引擎和沙箱都会带过去。
- 为什么改:产品内 AI 以本人身份写数据,之前写入上下文没有位置标明「是 AI
替本人做的、哪次对话、哪次确认」,而且引擎解析时会把多出来的键丢掉,审计日志无从记录。
- 风险与回滚:只放宽,原来只带 `clientId` 的上下文解析结果不变;`clientId` 在类型上变为可选,读它的
TypeScript 代码需判空(第一方读者都已判空)。回滚即 revert。
- 先看:`packages/spec/src/kernel/execution-context.zod.ts` 的 `performedBy`
块,`packages/objectql/src/engine-execution-plumbing.ts` 的
`buildProvenance`,`packages/spec/src/data/hook.zod.ts` 的 `provenance`。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run
--maxWorkers=2 src/engine.test.ts -t "in-product AI performer"`,预期 2
条全过。
- 需要你做的:无,席位落地。审计日志写入那一半在 #33694,ADR-0090 D10 第 4 条的补注由 skills 车道另行提交。
## What changes
- **`packages/spec/src/kernel/execution-context.zod.ts`**
(`performedBy`): three optional sibling keys beside `clientId`.
- `agentId`: the in-product AI agent that performed the write for the
signed-in person. Same value as `ToolExecutionContext.agentId` (the
agent the chat runs as). Never a `sys_user` id or an OAuth client id, so
one key never holds two id namespaces.
- `conversationId`: same id as `ToolExecutionContext.conversationId`.
- `confirmationId`: the id of the pending item the person's approval
decided, i.e. the in-app pending action id
(`IAIService.proposePendingAction`'s `id`, the seam #33808 aligns) or
the pending-confirmation service's
`ActionConfirmationPending.pendingId`. Absent when no confirmation was
needed.
- `clientId` is now optional, because the shape forces it: the
in-product AI has no OAuth client. The object takes
`.refine(requiredOneOf(['clientId', 'agentId']))`, so a `performedBy`
naming no performer is still refused at parse, as it was when `clientId`
was required. The rule is on the projectable closed list, so the
published JSON Schema states it (`allOf: [{ anyOf: [{ required:
[clientId] }, { required: [agentId] }] }]`) and
`dropped-refinements.baseline.json` does not grow.
- The docblock and `.describe` stop saying "Set only at the /mcp OAuth
door". They name both producers: the `/mcp` OAuth door (`clientId`) and
the server-constructed in-product AI path acting for and running as the
signed-in person (`agentId` + `conversationId` + `confirmationId`). The
ruling chain is cited in the jsdoc only. Kept as is: server-constructed
only, never client-supplied; attribution only; never the authorization
subject; `userId` stays the person; no `onBehalfOf` on the in-product
path, since the write runs on the person's own grants. The ADR-0090
2026-09-20 room for an agent-run id stays reserved; `conversationId` is
not that id.
- The in-product producer's duty (review S1): its ids can start as
values a request named (the chat route's `:agentName`, a continued
conversation, the pending item an approval names). It stamps one only
after the server resolved it in its own store for the person in
`userId`: `agentId` the agent it actually ran, `conversationId` a
conversation that person owns, `confirmationId` a pending item that
person's approval decided for this operation. An unresolved id is not
stamped.
- The audit writer (review S2): the descriptions say the audit writer
records `clientId` as `performed_by` beside `on_behalf_of`, which is
true today, and that the in-product keys are carried for it and not
recorded yet. How they are recorded is #33694's.
- **`packages/spec/src/data/hook.zod.ts`** (`HookContext.provenance`):
`performedByAgentId`, `performedByConversationId`,
`performedByConfirmationId`, flattened the way `performedByClientId`
copies `clientId`. The provenance docblock goes from four marks to five.
- **`packages/objectql/src/engine-execution-plumbing.ts`**
(`buildProvenance`): copies the three keys. Its own docblock says a key
declared on `hook.zod.ts` and missing there is declared and never
populated (ADR-0049), so the spec keys need this copy to be live.
- **`packages/runtime/src/sandbox/body-runner.ts`** and
**`script-runner.ts`**: the sandboxed body face carries the three marks
member by member, like the other four, so a lowered hook body reads them
on `ctx.provenance` too.
- Not touched: `packages/plugins/plugin-audit/**` (the writer half stays
on #33694), `docs/adr/**`, the MCP door
(`packages/core/src/security/assemble-execution-context.ts` still sets
`{ clientId }` alone).
- Why the widening is needed, not only declared:
`ObjectQL#createContext` runs `ExecutionContextSchema.parse(ctx)`, which
keeps declared keys only. On main an `agentId` a host put on
`performedBy` was dropped there.
## Tests
- `packages/spec/src/kernel/execution-context.test.ts`, a new top-level
describe. CONTROL: `{ clientId }` alone parses unchanged. The three new
keys survive a parse. A write with no confirmation parses. `{}`, `{
conversationId }` and `{ confirmationId }` are refused at path
`performedBy`. A non-string `agentId` is refused. The description names
both producers and no longer says "Set only at the /mcp OAuth door".
- `packages/spec/src/data/hook.test.ts`, a new top-level describe.
CONTROL: `performedByClientId` alone parses unchanged. The three marks
survive a parse. A non-string mark is refused.
- `packages/objectql/src/engine.test.ts`, a new describe at the engine
seam. A write whose context carries `performedBy: { agentId,
conversationId, confirmationId }` reaches a `beforeInsert` hook with the
three `provenance` marks, and `session` stays the person with no
`performedBy`. CONTROL: `{ clientId }` alone still gives `provenance: {
performedByClientId }`.
- **Forced test edit**:
`packages/cli/test/lowered-body-face-enumeration.test.ts` pins the
in-process and body `provenance` member sets. Both now list seven
members instead of four.
## Acceptance notes
- Key names are the seat's call. `agentId` and `conversationId` reuse
`ToolExecutionContext` vocabulary. `confirmationId` follows the card and
ruling wording; `pendingId` (the `ActionConfirmationPending` key) is the
alternative. The hook-side names follow the `performedBy` + key prefix
of `performedByClientId`.
- The type reader face: `ExecutionContext['performedBy']['clientId']` is
`string | undefined` now. Every first-party reader already checks it
(`apiForwardAgentOf`, the MCP interceptor, the three plugin-audit
writers, objectql). The changeset says so for outside readers.
- `Metadata-protocol: none`: `ExecutionContext` is server-constructed
and `HookContext.provenance` is server-stamped, so a metadata author
writes neither. No `authorable-surface/` shard moved. The #31740
precedent took `added` for `HookContext.session.principalKind`; the seat
may read this the same way, which would raise spec to `minor`.
- The ADR-0090 D10 rule 4 text names the agent principal only. The
ADR-0090/0151 note recording the in-product AI case is carried by #34057
(ADR-0090 D10 rule 4, ADR-0151 "Leaves unchanged", and the 2026-09-20
one-key note).
- The audit writer mapping (what `performed_by` holds for an in-product
AI row) is #33694's. ADR-0151 D5 refused putting a second id namespace
into one `performed_by` key, so the writer should keep the agent id
apart from OAuth client ids in the row.
- Note for #33694 (review N2): `confirmationId` is one key over two
stores, the in-app pending action id and the pending-confirmation
service item id. Which store an id names follows from the performer key
beside it, and #33694 should say so when it records the id.
- Accepted deviations from the contract review (record 6897691839): N1,
the schema admits `{ clientId, agentId }` although no producer builds
it; N3, a performer-less `performedBy` is now refused at path
`performedBy` with a custom code instead of `invalid_type` at
`performedBy.clientId`.
## Verification
Head and readings are listed in the os-dev-report on #33786. Every heavy
run went under `os-verify-lock`.
Round 2 (review S1, S2), at `bfaef935`, changes prose only: the two
`.zod.ts` docblocks and descriptions, and the three regenerated
reference pages. Spec pins 146/146 and `check:generated` are green
there. `ceeec029` merges main `b4ce310b`, and the round 2 contract
review (6898426121) is on that head.
Current head `75dcf734` is a merge-only commit made under the seat's K ≥
15 landing rule. It merges main `529ed7d9` into `ceeec029` with no hand
resolution, and all 13 PR files are byte-identical to `ceeec029`
(+311/-49). On it, the spec build, `check:generated` (14/14 up to date)
and the spec pins (146/146) are green.
<details><summary>Consumer test runs (branch at ca6e40c, before the
main merge)</summary>
- spec 842 files / 26965 passed (1 todo). objectql 596 / 13174. core 147
/ 3402. mcp 65 / 1185. rest 412 / 8442 (332 skipped). plugin-audit 94 /
1541. runtime 605 / 10958 (19 skipped). plugin-auth 277 / 5485 (10
skipped). cli: `test/lowered-body-face-enumeration.test.ts` (unit) 4 /
4; the rest of the cli unit layer is left to CI.
- Typecheck of spec, objectql, runtime, core, mcp, rest, plugin-audit,
plugin-auth and cli: all exit 0.
</details>
<details><summary>After merging main 0ac112f (head 93b0b11), and again
b4ce310 (head ceeec02)</summary>
- `check:generated`: all 14 artifacts up to date. Closure build 113/113.
- Rerun: spec pins 146/146, objectql `engine.test.ts` 138/138, cli face
test 4/4, runtime `hook-provenance-signal.integration.test.ts` 1/1,
objectql and runtime typecheck exit 0.
- The same reruns on `ceeec029` were all green, and `dispatch-gates`
there gave 118 derived, 118 run, 0 NOT-MEASURED.
</details>
<details><summary>Ablations (each through scripts/ablation-replace.mjs,
restored with blob == HEAD and git diff HEAD empty)</summary>
1. objectql `buildProvenance` stops copying `agentId`: `engine.test.ts`
"copies agentId, conversationId and confirmationId onto provenance" red.
2. spec `.refine(requiredOneOf(...))` becomes `.refine(() => true)`:
"REJECTS a performedBy naming no performer" red (1 failed / 45).
3. body-runner drops the `performedByAgentId` projection: cli face test
3 failed / 4.
4. Type reverse check against the rebuilt spec dist, in objectql: a
typed `performedBy: { agentId, probeBogusKey }` gives TS2353 on
`probeBogusKey` only, while `{ agentId, conversationId, confirmationId
}` and a reader of `performedBy?.agentId` compile. The probe file was
deleted.
</details>
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmRAvNc1qLS722dnoqn
<!-- signed: domain:spec#2 · os-steve · session_01ADHkmRAvNc1qLS722dnoqn
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>
feat(spec): the server-constructed in-product AI path can name itself on `ExecutionContext.performedBy`, and hooks see it on `HookContext.provenance`
8
+
9
+
Clause-②: yes — widened: `ExecutionContext.performedBy` accepts three new optional keys beside `clientId`: `agentId` (the in-product AI agent that performed the write for the signed-in person), `conversationId` (the AI conversation) and `confirmationId` (the id of the pending item the person approved). `clientId` is now optional, and a `performedBy` must name at least one of `clientId` and `agentId`, so `{ agentId }` parses where only `{ clientId }` did; a `performedBy` naming neither is refused at parse exactly as before, and the published JSON Schema states that rule as an `anyOf`. `HookContext.provenance` accepts `performedByAgentId`, `performedByConversationId` and `performedByConfirmationId`, each copied from its `performedBy` sibling by the engine the way `performedByClientId` is copied from `clientId`, and a sandboxed hook body reads them on `ctx.provenance` too.
10
+
Metadata-protocol: none
11
+
12
+
Before this, the in-product AI had no place on the write context: it writes as the person, and `ObjectQL#createContext` parses the envelope, so an `agentId` a host put on `performedBy` was dropped there and the write looked like the person's own. The attribution stays server-constructed and never client-supplied, no security middleware reads it, and it never becomes the subject a write is authorized as; the write still runs as the person, with `userId` theirs and no `onBehalfOf`. The OAuth `/mcp` door is unchanged: it still sets `performedBy.clientId` alone, and hooks still see `provenance.performedByClientId`.
13
+
14
+
What to do: nothing, unless your TypeScript reads `ExecutionContext['performedBy']` and assumes `clientId` is there. It is now `string | undefined`, because the in-product AI path names `agentId` instead; check it before use, as `performedBy?.clientId` readers already do. Recording these keys in `sys_audit_log` is a separate change to the audit writer.
|**referentialFieldClear**|`boolean`| optional | Engine-produced marker: true exactly when this write is the engine's own referential cleanup (the set_null cascade UPDATE clearing — or, for multiple: true, removing the deleted member from — a lookup, tree or user field that references a record being deleted, where a user field takes part only when it declares its deleteBehavior). Absent on every other write, including a user hand-clearing the same field; read as `ctx.referentialFieldClear === true`. The declared projection of the operation-private `__referentialFieldClear`, carried across the sandbox boundary by contract; server-derived and never client-supplied. |
112
112
|**referentialCascadeDelete**|`boolean`| optional | Engine-produced marker: true exactly when this delete is one the engine's cascade issued (the child delete removing a row that references a record being deleted through a relation whose deleteBehavior resolves to cascade, at any depth), in both phases of that delete. Absent on every other delete, including a user hand-deleting the same child and a delete a hook issues through ctx.api; read as `ctx.referentialCascadeDelete === true`. The delete twin of referentialFieldClear, carried across the sandbox boundary by contract; server-derived, never client-supplied, and with no operation-private spelling to read instead. |
@@ -148,6 +148,9 @@ L2 sandboxed JS body — runs inside an isolated VM with declared capabilities
148
148
|**flowRunId**|`string`| optional | Id of the automation flow run performing this write, when it originates from a flow data node. Lets a hook recognize the run that OWNS state that run itself opened — the approvals record lock exempts the run holding the pending request. |
149
149
|**attributedUserId**|`string`| optional | The real human credited for a write whose authorization subject was the SYSTEM — e.g. the admin whose better-auth `update-member-role` call the identity adapter executes as `isSystem`. ATTRIBUTION ONLY: the audit writer records it as `sys_audit_log.user_id`; no security middleware reads it, and it never becomes the subject the write is authorized as. |
150
150
|**performedByClientId**|`string`| optional |[ADR-0090 D10 rule 4] The AGENT that performed this write — the OAuth client (`azp`, a registered sys_oauth_application id) the access token was issued to, when an AI client acted on behalf of the human in `session.userId`. Copied from `ExecutionContext.performedBy.clientId`, which only the /mcp OAuth door sets. ATTRIBUTION ONLY, exactly like `attributedUserId`: the audit writer records it in `sys_audit_log.metadata` as `performed_by` beside `on_behalf_of`; no security middleware reads it and it never becomes the subject the write is authorized as. Absent on every non-delegated write, so a hook tells the two apart by the key being there rather than by guesswork. |
151
+
|**performedByAgentId**|`string`| optional | The in-product AI agent that performed this write for the signed-in person in `session.userId`, whose write it runs as: the agent the chat runs as. Copied from `ExecutionContext.performedBy.agentId`, which only the server-constructed in-product AI path sets, after resolving it as the agent it actually ran. ATTRIBUTION ONLY, exactly like `performedByClientId`: carried for the audit writer, which does not record it yet; no security middleware reads it and it never becomes the subject the write is authorized as. Absent on every write the person made themselves. |
152
+
|**performedByConversationId**|`string`| optional | The AI conversation an in-product AI write was performed in. Copied from `ExecutionContext.performedBy.conversationId`, set beside `performedByAgentId`. ATTRIBUTION ONLY: no security middleware reads it. |
153
+
|**performedByConfirmationId**|`string`| optional | The confirmation the person gave before an AI-performed write ran: the id of the pending item their approval decided. Copied from `ExecutionContext.performedBy.confirmationId`; absent when the write needed no confirmation. ATTRIBUTION ONLY: no security middleware reads it, and it is never the authorization for the write, which runs as the person with every gate re-checked. |
151
154
|**impersonatedBy**|`string`| optional | The ADMINISTRATOR (a sys_user id) who made this write from an impersonation session, while `session.userId` is the impersonated user the write is authorized as. Copied from `ExecutionContext.impersonatedBy`, which the shared request-identity resolution sets from the session read. ATTRIBUTION ONLY, exactly like `performedByClientId`: the audit writer records it as `sys_audit_log.metadata.impersonated_by` and on the sys_activity row; no security middleware reads it and it never becomes the subject the write is authorized as. Absent on every write the user made themselves. |
Copy file name to clipboardExpand all lines: content/docs/references/kernel/execution-context.mdx
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ const result = AuthGateCodeSchema.parse(data);
64
64
|**posture**|`Enum<'PLATFORM_ADMIN' \| 'TENANT_ADMIN' \| 'MEMBER' \| 'EXTERNAL'>`| optional | ADR-0095 D2 posture rung — PLATFORM_ADMIN crosses the tenant wall where object posture permits; TENANT_ADMIN sees all rows in the org; MEMBER gets business RLS; EXTERNAL (an external organization member) reaches explicit grants only — shares, sharing rules, and grant RLS — never the OWD baseline. |
65
65
| **authGate** | `{ code: Enum<'PASSWORD_EXPIRED' \| 'PASSWORD_RESET_REQUIRED' \| 'MFA_REQUIRED'>; message: string }` | optional | ADR-0069 authentication-policy gate: present only while the principal is blocked from protected resources until they remediate (expired password, enforced MFA), absent for every healthy session. `code` is the stable machine code the client branches on, from the closed vocabulary PASSWORD_EXPIRED / PASSWORD_RESET_REQUIRED (an administrator forced a password change) / MFA_REQUIRED, and `message` is what the blocked user reads; both are required because the transport seam renders them as the 403 body. Each code declares a scope: MFA_REQUIRED holds the account, so an API key whose owner holds it is refused with the same 403; PASSWORD_EXPIRED and PASSWORD_RESET_REQUIRED hold password sign-in alone, and API keys of that owner keep working. AUTHENTICATION, not authorization — it suspends access entirely rather than narrowing it, and nothing in the permission/RLS path reads it, while the allow-listed remediation endpoints stay reachable. Server-constructed only, never client-supplied; a guest/anonymous principal never carries one. |
|**performedBy**|`{ clientId: string }`| optional | ADR-0090 D10 rule 4 dual attribution: the agent that PERFORMED this operation, when the performer is not the principal the write is authorized as. Set only at the /mcp OAuth door, on the same branch that decides principalKind: agent and onBehalfOf; absent everywhere else, and the absence is the record that the principal acted for itself. ATTRIBUTION ONLY — no security middleware reads it, it never becomes the authorization subject, and userId stays the human so owner-stamping and current_user.* RLS still resolve to them. Server-constructed only, never client-supplied. Surfaced to hooks as HookContext.provenance.performedByClientId and recorded by the audit writer as sys_audit_log.metadata.performed_by beside on_behalf_of; it does not move `actor`, which ADR-0118 D1/D5 keeps two-valued. |
67
+
| **performedBy** | `{ clientId?: string; agentId?: string; conversationId?: string; confirmationId?: string }` | optional | ADR-0090 D10 rule 4 dual attribution: what PERFORMED this operation, when the performer is not the principal the write is authorized as. Two server-side producers set it: the /mcp OAuth door names the agent client in clientId, on the same branch that decides principalKind: agent and onBehalfOf; the server-constructed in-product AI path, acting for the signed-in person and running as them, names its agent in agentId with conversationId and, when the person confirmed the call, confirmationId. Absent everywhere else, and the absence is the record that the principal acted for itself; when present it names its performer, at least one of clientId and agentId, each set only by its own producer. ATTRIBUTION ONLY — no security middleware reads it, it never becomes the authorization subject, and userId stays the human so owner-stamping and current_user.* RLS still resolve to them. Server-constructed only, never client-supplied: an id a request named (an agent name, a conversation, a pending item) is stamped only after the server resolved it in its own store for the person in userId, and an unresolved id is not stamped. Surfaced to hooks as HookContext.provenance.performedByClientId / performedByAgentId / performedByConversationId / performedByConfirmationId. The audit writer records clientId as sys_audit_log.metadata.performed_by beside on_behalf_of; the in-product AI keys are carried for the audit writer, which does not record them yet. It does not move `actor`, which ADR-0118 D1/D5 keeps two-valued. |
68
68
|**surface**|`Enum<'rest' \| 'mcp'>`| optional | The door an action invocation came through: `rest` (the REST POST /actions/:object/:action door — console buttons, the SDK) or `mcp` (the /mcp bridge's run_action and resume_run tools — an AI client). Set only by those two doors, on the envelope of the invocation they hand the audit writer, from the door's own identity (an upstream value, header or body member never moves it); absent on every other operation. ATTRIBUTION ONLY — no security middleware reads it and it is never an authorization subject, scope or gate. Server-constructed only, never client-supplied. Recorded by the audit writer as sys_audit_log.metadata.surface on the action_invocation row. |
69
69
|**impersonatedBy**|`string`| optional | The administrator (a sys_user id) who started the impersonation session this request runs in — better-auth admin plugin session.impersonatedBy, stored as sys_session.impersonated_by. Absent on every other request; absence is the record that the user in userId acted themselves. userId stays the impersonated user, so ownership, current_user.* RLS and permissions still resolve to them. ATTRIBUTION ONLY — no security middleware reads it and it never becomes the authorization subject. Server-constructed only from the session read that admitted the caller, never client-supplied. Surfaced to hooks as HookContext.provenance.impersonatedBy and recorded by the audit writer as sys_audit_log.metadata.impersonated_by and on the sys_activity row metadata; it does not move actor or user_id. |
@@ -87,6 +87,15 @@ const result = AuthGateCodeSchema.parse(data);
87
87
|**transaction**|`any`| optional ||
88
88
|**traceId**|`string`| optional ||
89
89
90
+
### Nested Shape: `ExecutionContext.performedBy`
91
+
92
+
| Property | Type | Required | Description |
93
+
| :--- | :--- | :--- | :--- |
94
+
|**clientId**|`string`| optional | The OAuth client (`azp`, a registered sys_oauth_application id) that performed the operation. Set by the /mcp OAuth door only; absent when the in-product AI performed it. |
95
+
|**agentId**|`string`| optional | The in-product AI agent that performed the operation for the signed-in person in userId: the agent the chat runs as (the same value as ToolExecutionContext.agentId). Set by the server-constructed in-product AI path only, and only after the server resolved it as the agent it actually ran; never a sys_user id or an OAuth client id. |
96
+
|**conversationId**|`string`| optional | The AI conversation the operation was performed in (the same id as ToolExecutionContext.conversationId). Set beside agentId by the in-product AI path, and only after the server resolved it as a conversation the person in userId owns. |
97
+
|**confirmationId**|`string`| optional | The confirmation the person gave before the operation ran: the id of the pending item their approval decided (the in-app pending action id, or the pending-confirmation service item id). Stamped only after the server resolved it as a pending item the person in userId decided for this operation; absent when the operation needed no confirmation. |
0 commit comments