Skip to content

Commit e1b47ee

Browse files
committed
docs(spec): state the in-product producer's resolve-before-stamp duty; stop claiming the audit writer records the new keys
Claude-Session: https://claude.ai/code/session_01ADHkmRAvNc1qLS722dnoqn Co-authored-by: Claude <noreply@anthropic.com>
1 parent 93b0b11 commit e1b47ee

2 files changed

Lines changed: 32 additions & 15 deletions

File tree

‎packages/spec/src/data/hook.zod.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,12 +1646,13 @@ export const HookContextSchema = lazySchema(() => z.object({
16461646
* - `performedByAgentId`, with `performedByConversationId` and
16471647
* `performedByConfirmationId` — WHICH IN-PRODUCT AI performed a write for
16481648
* the signed-in person in `session.userId`, in which conversation, and
1649-
* under which confirmation. The same `performed_by` mark from its second
1649+
* under which confirmation. Rule 4's attribution from its second
16501650
* producer, the server-constructed in-product AI path, whose write runs as
16511651
* that person (owner ruling on objectstack-ai/cloud#3826, 「3826 照建议
16521652
* (征询版)」, carried by #33694 and #33786); each key is copied from its
16531653
* `ExecutionContext.performedBy` sibling, as `performedByClientId` is from
1654-
* `clientId`;
1654+
* `clientId`, and carried for the audit writer, which records them under
1655+
* #33694 (at this revision it reads `performedByClientId` only);
16551656
* - `impersonatedBy` — WHICH ADMINISTRATOR made a write from an
16561657
* impersonation session, authorized as the impersonated user in
16571658
* `session.userId`.
@@ -1669,7 +1670,7 @@ export const HookContextSchema = lazySchema(() => z.object({
16691670
flowRunId: z.string().optional().describe('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.'),
16701671
attributedUserId: z.string().optional().describe('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.'),
16711672
performedByClientId: z.string().optional().describe('[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.'),
1672-
performedByAgentId: z.string().optional().describe('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. ATTRIBUTION ONLY, exactly like `performedByClientId`: 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 write the person made themselves.'),
1673+
performedByAgentId: z.string().optional().describe('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.'),
16731674
performedByConversationId: z.string().optional().describe('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.'),
16741675
performedByConfirmationId: z.string().optional().describe('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.'),
16751676
impersonatedBy: z.string().optional().describe('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.'),

‎packages/spec/src/kernel/execution-context.zod.ts‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,24 @@ export const ExecutionContextSchema = lazySchema(() => z.object({
347347
* replaces; the in-product AI's write carries the person's own.
348348
*
349349
* Server-constructed only, never client-supplied — exactly like
350-
* {@link isSystem}. No request header, body member or model output may set
351-
* any key of it.
350+
* {@link isSystem}. A request header, body member or model output never
351+
* sets a key of it. The in-product AI path's ids can START as values a
352+
* request named (the `:agentName` of the chat route, the conversation a
353+
* caller continues, the pending item an approval names), so that producer
354+
* owes one thing more: it stamps such an id only after the server resolved
355+
* it in its own store for the person in {@link userId} — {@link agentId}
356+
* the agent it actually ran, {@link conversationId} a conversation that
357+
* person owns, {@link confirmationId} a pending item that person's approval
358+
* decided for this operation. An id the server did not resolve is not
359+
* stamped. That keeps the envelope's refusal of caller-controlled ids
360+
* (ADR-0090 D10's 2026-09-20 note: `traceId`, `requestId`) whole.
352361
*
353362
* Surfaced to hooks as `HookContext.provenance.performedByClientId`,
354363
* `performedByAgentId`, `performedByConversationId` and
355-
* `performedByConfirmationId`, and recorded by the audit writer in
356-
* `sys_audit_log.metadata` as `performed_by` beside `on_behalf_of`. ⛔ It
364+
* `performedByConfirmationId`. The audit writer records {@link clientId} in
365+
* `sys_audit_log.metadata` as `performed_by` beside `on_behalf_of`; the
366+
* in-product AI keys are carried for the audit writer, which records them
367+
* under #33694 (at this revision it reads `performedByClientId` only). ⛔ It
357368
* does NOT move `actor`: ADR-0118 D1/D5 keeps that column two-valued (a user
358369
* id, or `null` for the system) and answers "which non-user acted" with an
359370
* ADDED attribution field — this one — never with a second actor
@@ -375,25 +386,30 @@ export const ExecutionContextSchema = lazySchema(() => z.object({
375386
* The in-product AI agent that performed the operation for the signed-in
376387
* person — the agent the chat runs as, the same value as
377388
* `ToolExecutionContext.agentId`. Set by the server-constructed in-product
378-
* AI path only; never a `sys_user` id and never an OAuth client id.
389+
* AI path only, and only once the server resolved it as the agent it
390+
* actually ran; never a `sys_user` id and never an OAuth client id.
379391
*/
380-
agentId: z.string().optional().describe('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; never a sys_user id or an OAuth client id.'),
392+
agentId: z.string().optional().describe('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.'),
381393
/**
382394
* The AI conversation the operation was performed in — the same id as
383-
* `ToolExecutionContext.conversationId`. Set beside {@link agentId}.
395+
* `ToolExecutionContext.conversationId`. Set beside {@link agentId}, and
396+
* only once the server resolved it as a conversation the person in
397+
* {@link userId} owns.
384398
*/
385-
conversationId: z.string().optional().describe('The AI conversation the operation was performed in (the same id as ToolExecutionContext.conversationId). Set beside agentId by the in-product AI path.'),
399+
conversationId: z.string().optional().describe('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.'),
386400
/**
387401
* The confirmation the person gave before the operation ran — the id of
388402
* the pending item their approval decided: the in-app pending action
389403
* (`IAIService.proposePendingAction`'s `id`) or the pending-confirmation
390-
* service's item (`ActionConfirmationPending.pendingId`). Absent when the
391-
* operation needed no confirmation.
404+
* service's item (`ActionConfirmationPending.pendingId`). Stamped only once
405+
* the server resolved it as a pending item that person's approval decided
406+
* for this operation; absent when the operation needed no confirmation.
407+
* Which store it names follows from the performer key beside it.
392408
*/
393-
confirmationId: z.string().optional().describe('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). Absent when the operation needed no confirmation.'),
409+
confirmationId: z.string().optional().describe('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.'),
394410
}).refine(requiredOneOf(['clientId', 'agentId']), {
395411
message: 'performedBy names its performer: clientId (the /mcp OAuth door) or agentId (the in-product AI path)',
396-
}).optional().describe('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. Surfaced to hooks as HookContext.provenance.performedByClientId / performedByAgentId / performedByConversationId / performedByConfirmationId 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.'),
412+
}).optional().describe('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.'),
397413

398414
/**
399415
* [#27908 — ruling 6513869839 on #27681, parameter 3] WHICH DOOR an action

0 commit comments

Comments
 (0)