Skip to content

Commit 97c95dd

Browse files
committed
docs(spec): state only what a performed_by reader can tell, name client_id for the OAuth client
Claude-Session: https://claude.ai/code/session_01ADHkmSQnLEs6vGofJXcguE Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8cc2192 commit 97c95dd

3 files changed

Lines changed: 31 additions & 29 deletions

File tree

‎packages/plugins/plugin-audit/src/audit-writers.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,6 @@ const NOISE_FIELDS = new Set<string>([
469469
*/
470470
export { createFieldPresenceProbe, resolveRecordOrganizationField } from '@objectstack/metadata-core';
471471

472-
/**
473-
* Action name produced from a HookContext.event string.
474-
*
475-
* [#21155] Typed by the ledger's record-write vocabulary: these are the rows
476-
* whose snapshots are a parent record's field map, and the read side
477-
* (`audit-log-field-redaction.ts`) narrows exactly those. A new record-write
478-
* action does not compile until that list names it.
479-
*/
480472
/**
481473
* [#33694] The `sys_audit_log.metadata` keys that ride beside `performed_by` /
482474
* `on_behalf_of` when the in-product AI performed a record write for a person:
@@ -499,6 +491,14 @@ function provenanceMark(
499491
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
500492
}
501493

494+
/**
495+
* Action name produced from a HookContext.event string.
496+
*
497+
* [#21155] Typed by the ledger's record-write vocabulary: these are the rows
498+
* whose snapshots are a parent record's field map, and the read side
499+
* (`audit-log-field-redaction.ts`) narrows exactly those. A new record-write
500+
* action does not compile until that list names it.
501+
*/
502502
function actionFor(event: string): LedgerRecordWriteAction | null {
503503
if (event === 'afterInsert') return 'create';
504504
if (event === 'afterUpdate') return 'update';

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,11 +1683,10 @@ export const HookContextSchema = lazySchema(() => z.object({
16831683
* `ExecutionContext.performedBy` sibling, as `performedByClientId` is from
16841684
* `clientId`. The record-write audit writer records the agent as
16851685
* `performed_by` beside `on_behalf_of`, the same key it records
1686-
* `performedByClientId` in, so a reader tells the two by resolving the
1687-
* value (a registered `sys_oauth_application` `client_id` is the OAuth
1688-
* client, any other value the in-product agent); only beside the agent
1689-
* does it also record the conversation as `conversation_id` and the
1690-
* confirmation as `confirmation_id` (#33694);
1686+
* `performedByClientId` in; only beside the agent does it also record
1687+
* the conversation as `conversation_id` and the confirmation as
1688+
* `confirmation_id` (#33694). What a reader can and cannot tell from
1689+
* such a row is stated on `ExecutionContext.performedBy`;
16911690
* - `impersonatedBy` — WHICH ADMINISTRATOR made a write from an
16921691
* impersonation session, authorized as the impersonated user in
16931692
* `session.userId`.
@@ -1704,8 +1703,8 @@ export const HookContextSchema = lazySchema(() => z.object({
17041703
provenance: z.object({
17051704
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.'),
17061705
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.'),
1707-
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.'),
1708-
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`: the record-write audit writer records it in `sys_audit_log.metadata` as `performed_by` beside `on_behalf_of`, the key an OAuth client id is also recorded in: a value matching the `client_id` of a registered `sys_oauth_application` row is the OAuth client, any other value is an in-product agent name (when `performedByClientId` is also present the row records the client instead); no security middleware reads it and it never becomes the subject the write is authorized as. Absent on every write the person made themselves.'),
1706+
performedByClientId: z.string().optional().describe('[ADR-0090 D10 rule 4] The AGENT that performed this write — the OAuth client (`azp`, the `client_id` of a registered sys_oauth_application) 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.'),
1707+
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`: the record-write audit writer records it in `sys_audit_log.metadata` as `performed_by` beside `on_behalf_of`, the key an OAuth client id is also recorded in (when `performedByClientId` is also present the row records the client instead). A value matching the `client_id` of an existing `sys_oauth_application` row is an OAuth client, and 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; no security middleware reads it and it never becomes the subject the write is authorized as. Absent on every write the person made themselves.'),
17091708
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: the record-write audit writer records it as `sys_audit_log.metadata.conversation_id`, only when `performed_by` names the in-product agent; no security middleware reads it.'),
17101709
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: the record-write audit writer records it as `sys_audit_log.metadata.confirmation_id`, only when `performed_by` names the in-product agent; no security middleware reads it, and it is never the authorization for the write, which runs as the person with every gate re-checked.'),
17111710
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: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,18 @@ export const ExecutionContextSchema = lazySchema(() => z.object({
367367
* performer in `sys_audit_log.metadata` as `performed_by` beside
368368
* `on_behalf_of` — {@link clientId}, or {@link agentId} for the in-product AI
369369
* (owner ruling on objectstack-ai/cloud#3826: the existing pair, no new actor
370-
* vocabulary). So that one key holds two id kinds, and its reader tells them
371-
* apart by resolving the value: one that matches the `client_id` of a
372-
* registered `sys_oauth_application` row is the OAuth client; any other
373-
* value is an in-product agent name. Only when the in-product agent is the
374-
* recorded performer does the row also carry {@link conversationId} as
375-
* `conversation_id` and {@link confirmationId} as `confirmation_id` (each
376-
* when set); a row naming an OAuth client never carries either, but their
377-
* absence alone does not mark a row as the client's, since both are
378-
* optional. If one envelope ever carried both performers, the row records
370+
* vocabulary). So that one key holds two id kinds. Only when the
371+
* in-product agent is the recorded performer does the row also carry
372+
* {@link conversationId} as `conversation_id` and {@link confirmationId} as
373+
* `confirmation_id` (each when set); a row naming an OAuth client never
374+
* carries either. What a reader can tell from a row: a value that matches
375+
* the `client_id` of an existing `sys_oauth_application` row is an OAuth
376+
* client; a row carrying `conversation_id` or `confirmation_id` names an
377+
* in-product agent. A row meeting neither may name an in-product agent or
378+
* an OAuth client whose application has since been deleted (its rows keep
379+
* the `client_id`), and the row alone cannot tell which. Nor does the
380+
* contract keep an agent name and a `client_id` from being the same string.
381+
* If one envelope ever carried both performers, the row records
379382
* {@link clientId} and drops the agent with its two marks. The
380383
* action-invocation, data-export and dataset-query rows record
381384
* {@link clientId} only. ⛔ It
@@ -391,11 +394,11 @@ export const ExecutionContextSchema = lazySchema(() => z.object({
391394
*/
392395
performedBy: z.object({
393396
/**
394-
* The OAuth client (`azp`) that performed the operation — the id of the
395-
* registered `sys_oauth_application` the access token was issued to. Set
396-
* by the `/mcp` OAuth door only.
397+
* The OAuth client (`azp`) that performed the operation — the
398+
* `client_id` of the registered `sys_oauth_application` the access token
399+
* was issued to (not that row's `id`). Set by the `/mcp` OAuth door only.
397400
*/
398-
clientId: z.string().optional().describe('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.'),
401+
clientId: z.string().optional().describe('The OAuth client (`azp`, the client_id of a registered sys_oauth_application) that performed the operation. Set by the /mcp OAuth door only; absent when the in-product AI performed it.'),
399402
/**
400403
* The in-product AI agent that performed the operation for the signed-in
401404
* person — the agent the chat runs as, the same value as
@@ -423,7 +426,7 @@ export const ExecutionContextSchema = lazySchema(() => z.object({
423426
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.'),
424427
}).refine(requiredOneOf(['clientId', 'agentId']), {
425428
message: 'performedBy names its performer: clientId (the /mcp OAuth door) or agentId (the in-product AI path)',
426-
}).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 record-write audit writer records the performer (clientId, or agentId for the in-product AI) as sys_audit_log.metadata.performed_by beside on_behalf_of, so that key holds two id kinds: a value matching the client_id of a registered sys_oauth_application row is the OAuth client, any other value is an in-product agent name. Only when the agent is the recorded performer does the row also carry conversationId as metadata.conversation_id and confirmationId as metadata.confirmation_id (each when set); a client row never carries them, but both are optional, so their absence does not mark a client row. An envelope carrying both performers is recorded as the client. The action-invocation, data-export and dataset-query rows record clientId only. It does not move `actor`, which ADR-0118 D1/D5 keeps two-valued.'),
429+
}).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 record-write audit writer records the performer (clientId, or agentId for the in-product AI) as sys_audit_log.metadata.performed_by beside on_behalf_of, so that key holds two id kinds. Only when the agent is the recorded performer does the row also carry conversationId as metadata.conversation_id and confirmationId as metadata.confirmation_id (each when set); a client row never carries them. A reader can tell: 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, and the row alone cannot tell which; nor does the contract keep an agent name and a client_id from being the same string. An envelope carrying both performers is recorded as the client. The action-invocation, data-export and dataset-query rows record clientId only. It does not move `actor`, which ADR-0118 D1/D5 keeps two-valued.'),
427430

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

0 commit comments

Comments
 (0)