Skip to content

fix(runtime, service-automation)!: an AI service account starts a flow that runs as the system only through an action its author opted into AI - #32912

Merged
os-zhuang merged 6 commits into
mainfrom
claude/project-thread-mfe3hn
Nov 13, 2026
Merged

os-zhuang merged 6 commits into
mainfrom
claude/project-thread-mfe3hn

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Fixes #31874

Clause-②: no (narrowing) — an AI service account's start of a flow declared runAs: 'system' is refused with 403 PERMISSION_DENIED at POST /api/v1/automation/NAME/trigger (and the legacy POST /api/v1/automation/trigger/NAME), at a declared endpoint of type: 'flow', and at the REST actions route when the action that starts the flow does not declare ai.exposed: true; nothing is widened.
Metadata-protocol: none
Skills-docs: updated here — content/docs/automation/flows.mdx (the start-refusal table under "Run a flow via API" gains the AI service account row, between the elevated self-triggered row and the requiredPermissions row, and the two "checked after" clauses below it count the new row), content/docs/ui/actions.mdx (the flow row under "Call it over REST" and the 'rest' posture row say the REST door reads ai.exposed for an AI service account starting a runAs: 'system' flow), content/docs/ai/agents.mdx (the AI service account paragraph says how an account starts a flow that runs as the system). No skill teaches which principal kinds a flow start admits.

维护者速读

  • 改了什么:AI 服务账号(ADR-0151 的无人值守 AI 账号)启动一个声明为 runAs: 'system'(以系统身份运行)的流程时,默认被拒(403 PERMISSION_DENIED);只有通过作者已声明 ai.exposed: true 的 type: 'flow' 动作来启动才放行。能按名字启动流程的三道门(触发路由、动作门、声明式端点)问的是同一条规则,拒绝文案直接告诉作者该加哪个声明。放行后的系统身份运行,每次数据操作都带 principalKind: 'agent'。ADR-0151 的 Non-goals 加了一句话。
  • 为什么改:裁决 6812617393(C 方案,维护者「同意」):系统身份流程用的是平台权限而不是调用者自己的权限,所以 AI 账号能不能启动它,要有作者明示的 AI 授权;MCP 门已经这样要求,其余的门补上同一条规则。
  • 风险与回滚:收窄(BREAKING)。AI 服务账号经触发路由或声明式端点启动系统身份流程,一律被拒;经 REST 动作路由启动、而动作没有 ai.exposed 的,也被拒。人、代表某个人的 OAuth 代理、系统主体都不受影响;以用户身份运行的流程不受影响。第一方受影响的调用 0:hotcrm 里声明 runAs: 'system' 的流程全是自触发类型,本来就不能按名字启动;本仓示例里只有 showcase 的两个流程(showcase_inquiry_purge、showcase_inbound_task_webhook)会对 AI 账号改口,没有测试或示例用 AI 账号启动它们。回滚即 revert。
  • 先看:packages/runtime/src/flow-start-admission.ts(flowStartRefusal 里规则 2 的那一个 if:排在规则 1 之后、requiredPermissions 之前);packages/runtime/src/action-execution.ts 的 dispatchFlowAction(唯一能把作者授权带给规则的门);packages/services/service-automation/src/run-resume.ts 的 seedRunGrants(系统身份运行保留门传来的 kind)。
  • 两分钟验证:pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/flow-start-required-permissions.test.ts,应见 Tests 81 passed (81)。
  • 需要你做的:批准本 PR(Tier H:docs/adr/0151-… 加了一句话,按方案 A 写)。契约复核 PASS 见评论 6839053991(Head-sha: 183ed607…;文档轮 7de0545a 只动散文面,记录续管)。批准后由席位落地。
  • 席位意见:同意按方案 A 落地。系统身份流程用平台权限写数据,AI 账号要启动它必须经过作者明示授权(ai.exposed: true)的流程动作;三道门同一条规则,已由隔离复核核实没有漏门。方案 A/B 已另呈维护者,ADR 句按 A 写;若改 B,ADR 句与三页文档同改。规格描述文字的过时处转卡 spec: ai.requiresConfirmation's describe says REST /actions reads no ai.exposed opt-in, which PR #32912 makes untrue for an AI service account starting a runAs:system flow action #32924。

席位核对

Tier H 席位记录 · PR #32912 · head 7de0545a6e658b43a49af23c92fe4674a51b0ea7 · Fixes #31874

  1. 形态: draft PR 指向 main,仅 Fixes #31874。路径面(读文件清单):docs/adr/0151-…(一句 Non-goals)、packages/runtime/src/** 五个文件、packages/services/service-automation/src/** 四个文件、一个 changeset、content/docs/{automation/flows,ui/actions,ai/agents}.mdx。docs/adr/** 命中 governed 面 ⇒ Tier H。
  2. 前提实测: 隔离复核在树上核实 flowStartRefusal 恰有三个调用方,且是 packages/runtime 里仅有的三个请求可达的流程启动点;MCP run_action 经动作门;第四道门因参数必填而无法静默漏掉。
  3. 门禁: 代码 head 183ed607 的 check-runs 36 成功、16 跳过、0 失败;文档轮 head 7de0545a 的 check-runs 落地前重读。
  4. 契约复核: CONTRACT_REVIEW_TIER PASS,评论 6839053991,Head-sha: 183ed607592e8bd2fcd31327778c85cc07c30380,无 must-fix;183ed607 → 7de0545a 仅动散文面(三页 content/docs),记录续管,Regen-provenance: 行在 PR 评论。
  5. 接受的偏差与范围外去向: 包级测试在 20959acac0 上测(head 只多一行测试 import,CI 为准);文档轮不重跑包测试(无包内测试读这三页)。复核 S1(tool.zod.ts 描述文字)与 S2(REST 上 AI 账号的确认门,待维护者定)→ 卡 spec: ai.requiresConfirmation's describe says REST /actions reads no ai.exposed opt-in, which PR #32912 makes untrue for an AI service account starting a runAs:system flow action #32924;N1/N2 两条 nit 接受不改。Skills-docs: updated here,三页文档席位逐句对照 diff 核过:账号行排在自触发行之后、requiredPermissions 行之前,与规则顺序一致;人、OAuth 代理、系统主体与以用户身份运行的流程不受此行判定,与代码一致。
  6. 落地条款: Tier H,等 governed 审批人(os-zhuang、hotlong)批准;批准后席位过落地前检、清 pm:awaiting-merge、转 ready、挂 auto-merge。Clause-②: no (narrowing),BREAKING 横幅与 ADR-0087 not-required 处置在 changeset。

What changes

The ruling this executes. Ruling record 6812617393 on #31874 (batch #1 item 4, letter C, maintainer 「同意」 2026-11-12T02:29Z):

Chosen: C, the author's explicit opt-in. When an AI service account starts a flow that runs as system, the start is refused by default. It is admitted only when the flow (or the action that starts it) carries the author's existing ai.exposed: true opt-in. One rule on every door that can start such a flow: the MCP door already applies it, and the REST trigger route, the REST action door and declarative endpoints get the same rule. No new spec key.

Execution: one domain:server PR, Clause-②: no (narrowing). The same rule goes on the doors above, with a refusal by name that tells the author which opt-in to add. Pins and an ablation. ADR-0151's Non-goals gain one sentence. The system-run branch also carries principalKind on its run facts (it does not today).

One rule, in the module every door already asks. packages/runtime/src/flow-start-admission.ts#flowStartRefusal is the one check the trigger routes, the action door and a declared type: 'flow' endpoint ask before a flow starts. It gains rule 2, between the two it had:

  1. an elevated self-triggered flow is refused to any caller but the system principal (unchanged);
  2. new: an AI service account (principalKind: 'agent' with no onBehalfOf, ADR-0151 D3) starting a flow declared runAs: 'system' is refused unless what starts the flow at that door carries the author's ai.exposed: true opt-in;
  3. the flow's own requiredPermissions (unchanged, and still asked of an admitted account).

Each door states one fact about itself, as a required argument (FlowStartDoor.aiExposed), so a door that never considered the rule does not compile:

Door What it states AI service account at a runAs: 'system' flow
POST /api/v1/automation/NAME/trigger and the legacy spelling (domains/automation.ts#respondToFlowTrigger) no action in hand: aiExposed: false refused
declared endpoint of type: 'flow' (endpoint-executor.ts#executeFlow) no action in hand: aiExposed: false refused
action door, REST actions route (action-execution.ts#dispatchFlowAction) the action's own opt-in admitted when the action declares ai.exposed: true, refused otherwise
action door, MCP run_action (same function) the action's own opt-in admitted; the tool's exposure gate has already refused an action without the opt-in, for every caller

The Flow schema and the Endpoint schema declare no AI opt-in, and the ruling adds no key, so the opt-in stands only where an action is in hand. That reading is the narrower of two the ruling's "the flow (or the action that starts it)" allows; the other is in the report's open_questions for the maintainer.

One reading of the opt-in. action-execution.ts#actionIsAiExposed is now the single predicate behind the MCP exposure gate (actionAiExposureError), the system-object exposure gate, the list_actions attestation and the flow start door. No second copy of the check exists.

The refusal. 403 PERMISSION_DENIED (no new code), the same words at every door, naming the opt-in and the doors where it stands:

An AI service account starts a flow that runs as the system only through an action its author opted into AI. Declare ai: { exposed: true, description: … } on an action of type 'flow' that targets the flow, and have the account run that action (the REST actions route or the MCP run_action tool).

It names nothing of the flow, the action or the door. Nothing is dispatched.

The run keeps its kind. service-automation/src/runtime-identity.ts#resolveRunDataContext: the system arm now carries principalKind: 'agent' when the run context does, as the user arm already did. run-resume.ts#seedRunGrants keeps the kind a launch door forwarded onto a runAs: 'system' run (setup resolves no grants for one, so nothing would re-seed it). It is attribution: isSystem answers before any gate reads the kind, so the run's own operations are authorized exactly as before; a hook reads the kind off its session (ADR-0151 D5).

ADR-0151, one sentence in Non-goals:

No elevated run on an account's own say: an account's start of a flow that runs as the system (runAs: 'system') is refused by default at every door that can start one and admitted only where the action that starts it carries its author's existing ai.exposed: true opt-in (packages/runtime/src/flow-start-admission.ts#flowStartRefusal; #31874, ruling record 6812617393), the elevated run keeping principalKind: 'agent' on its run facts.

Unchanged. A person, an agent acting for a person over OAuth, and the system principal start the same flows as before. An account starts a runAs: 'user' flow (the default) at every door as before. The ai.requiresConfirmation gate does not move: it stays on the doors that ask the opt-in of every action. The run log's trigger record is not touched.

Not in this PR. The prose of packages/spec/src/ai/tool.zod.ts, which describes the REST actions route as outside the ai.exposed opt-in and is now imprecise for this one pair: it is with card #32924 (spec lane). No scripts/adr-anchors/ entry (outside the claimed surface; the code carries the ADR id).

Tests

  • packages/runtime/src/flow-start-required-permissions.test.ts: a new top-level describe on the shared four-door harness, 36 tests (the file: 45 before, 81 now). For screen and api flows: the account refused at the trigger route and at the declared endpoint even though an exposed action targets the flow; refused at the REST actions route behind an action without the opt-in; admitted at REST and MCP behind an action with it, the run carrying principalKind: 'agent'. The refusal is asserted by code, status and its words (the message is the contract that names the remedy), and every refusal pin asserts the engine was never called. Order pins: rule 1 answers an account first; holding the flow's capability does not open rule 2; an admitted account is still judged by requiredPermissions. CONTROLS at every door: a person, an OAuth-delegated agent, the system principal, and an account at a runAs: 'user' or undeclared flow, all admitted with no opt-in anywhere.
  • packages/services/service-automation/src/run-agent-account-kind.test.ts: a new describe, 4 tests (the file: 5 before, 9 now). The door-forwarded kind survives run setup on a system run and rides the facts beside isSystem, with no grants resolved; a system run handed only a user carries none; CONTROLS for a person and for non-agent values.

Ablations (fix committed first; each mutation through node scripts/ablation-replace.mjs, which proves the write on disk and the restore against HEAD; these suites resolve the mutated files from src/, so no build sits between mutation and reading):

# Forbidden behaviour put back Suite Result
1 trigger routes state aiExposed: true runtime file 4 failed, 77 passed
2 declared endpoint states aiExposed: true runtime file 4 failed, 77 passed
3 action door states aiExposed: true whatever the action declares runtime file 5 failed, 76 passed
4 rule 2 removed from flowStartRefusal runtime file 11 failed, 70 passed
5 system arm of resolveRunDataContext drops the kind service-automation file 1 failed, 8 passed
6 run setup deletes the kind on a system run service-automation file 1 failed, 8 passed
Ablation failures and restore proofs
#1  FAIL  trigger: an elevated 'screen' flow — the account is refused 403 PERMISSION_DENIED, never dispatched
    FAIL  trigger: an elevated 'api' flow — the account is refused 403 PERMISSION_DENIED, never dispatched
    FAIL  one refusal at every door that can answer it: the same status, code and words
    FAIL  the order of the rules: trigger: holding the flow's capability does not open it
    AssertionError: expected { status: 200, code: undefined, …(1) } to match object { status: 403, …(1) }
    ablation-replace: ok restored: blob == HEAD (f8f81b8738e1) and `git diff HEAD` is empty
#2  FAIL  endpoint: an elevated 'screen' flow — the account is refused 403 PERMISSION_DENIED, never dispatched
    FAIL  endpoint: an elevated 'api' flow — the account is refused 403 PERMISSION_DENIED, never dispatched
    FAIL  one refusal at every door that can answer it: the same status, code and words
    FAIL  the order of the rules: endpoint: holding the flow's capability does not open it
    AssertionError: expected { status: 200, code: undefined, …(1) } to match object { status: 403, …(1) }
    ablation-replace: ok restored: blob == HEAD (90948840ab41) and `git diff HEAD` is empty
#3  FAIL  REST /actions: an elevated 'screen' flow behind an action WITHOUT the opt-in — the account is refused, never dispatched
    FAIL  REST /actions: an elevated 'api' flow behind an action WITHOUT the opt-in — the account is refused, never dispatched
    FAIL  the refusal names the opt-in the author adds, and nothing of the flow
    FAIL  one refusal at every door that can answer it: the same status, code and words
    FAIL  the order of the rules: REST /actions: holding the flow's capability does not open it
    AssertionError: expected { status: 200, code: undefined, …(1) } to match object { status: 403, …(1) }
    ablation-replace: ok restored: blob == HEAD (488d079ef92f) and `git diff HEAD` is empty
#4  the 11 pins of #1, #2 and #3 together (the three share the "one refusal at every door" pin)
    ablation-replace: ok restored: blob == HEAD (fac1b4d2ebc4) and `git diff HEAD` is empty
#5  FAIL  the door-forwarded kind survives run setup and rides every data operation, beside isSystem
    AssertionError: expected { isSystem: true, …(3), …(1) } to match object { isSystem: true, …(2) }
    ablation-replace: ok restored: blob == HEAD (fea0d07a976f) and `git diff HEAD` is empty
#6  FAIL  the door-forwarded kind survives run setup and rides every data operation, beside isSystem
    AssertionError: expected undefined to be 'agent' // Object.is equality
    ablation-replace: ok restored: blob == HEAD (7572dcccbf5a) and `git diff HEAD` is empty

The ablations ran on 60bea520dd; the files they mutate are byte-identical at the PR head (the later commits touch the ADR, the changeset, one test file's cast, and merge main).

Acceptance notes

  • "One rule on every door": the rule is one if in flowStartRefusal; the three call sites differ only in the fact they state. The MCP door's existing check and the new rule read the opt-in through the same predicate.
  • "A refusal by name that tells the author which opt-in to add": the message above; pinned.
  • "Pins and an ablation": 40 tests, six ablations, one per door plus the rule itself and the two halves of the kind.
  • "ADR-0151's Non-goals gain one sentence": exactly one line added to the ADR, nothing else in docs/adr/**.
  • "The system-run branch also carries principalKind on its run facts": resolveRunDataContext's system arm, pinned and ablated.
  • "No new spec key": packages/spec is untouched.
  • Merge: origin/main merged once before opening (5c0f113498, two commits, none touching these packages).

Verification

Head 7de0545a6e658b43a49af23c92fe4674a51b0ea7. Whole-tree build after the merge: turbo run build, 120 of 120 tasks successful.

Check Result Measured on
pnpm --filter @objectstack/runtime typecheck (source and test layer) exit 0 183ed60759
pnpm --filter @objectstack/service-automation typecheck (source and test layer) exit 0 20959acac0
pnpm --filter @objectstack/runtime test Test Files 588 passed (588) · Tests 10287 passed, 19 skipped (10306) 20959acac0
pnpm --filter @objectstack/service-automation test Test Files 278 passed (278) · Tests 3811 passed (3811) 20959acac0
the two pin files 81 passed (81) · 9 passed (9) 183ed60759
pnpm lint exit 0 183ed60759
derived gate families: node scripts/pm/dispatch-gates.mjs --commands, each run, then --ran 109 derived, 109 run, 0 NOT-MEASURED, 0 UNRUN; all 109 exit 0 the head
full dogfood battery, pnpm --filter @objectstack/dogfood test under the verify lock VERDICT command-exit 0 · Test Files 456 passed, 3 skipped (459) · Tests 3831 passed, 42 skipped (3873) · no failure the head

Docs round (183ed60759 to 7de0545a6e): one commit, three content/docs pages, 14 insertions and 4 deletions, no file of any package. No merge of main. The docs paths add 27 derived gate families to the 82; all 109 were run on the head and exit 0 (Run reconciliation — 109 derived, 109 run, 0 NOT-MEASURED, 0 UNRUN.). The package suites, typechecks, pnpm lint and the dogfood battery were not run again: no test in packages/** reads these three pages, and their readings on 183ed60759 stand for the code. The claim was re-posted whole with the three pages in its file surface (comment 6838944179).

20959acac0 is the head's parent. The head adds one module-top import line to the runtime pin file and nothing else: the first pass of the 82 gates, on 20959acac0, had one red, pnpm check:test-source-alias (the edited pin file reaches a dynamic import of @objectstack/metadata in the source under test), and the import is that gate's own prescribed fix. After it, the runtime typecheck, both pin files, lint, the whole gate list and the dogfood battery were run again on the head. No file of service-automation and no non-test file differs between the two commits.

Gate reconciliation and the 82 recorded exit codes
Run reconciliation — 82 derived, 82 run, 0 NOT-MEASURED, 0 UNRUN.
✓ dispatch-gates --ran: 82 derived famil(ies) accounted for — 82 run, 0 NOT-MEASURED (a DERIVED zero — all 82 recorded an exit code and none of them is 3).

pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-adr-links.mjs :: exit 0
node scripts/check-adr-links.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-adoption.mjs :: exit 0
node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-dts-emitted.mjs --self-test :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-issue-citations.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0
node scripts/check-tenant-audit-census.mjs :: exit 0
node scripts/check-tenant-audit-census.mjs --self-test :: exit 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/docs-audit/check-affected-docs.mjs :: exit 0
node scripts/docs-audit/check-drift-comment.mjs :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0
pnpm check:adr-anchors :: exit 0
pnpm check:adr-index :: exit 0
pnpm check:adr-symbol-anchors :: exit 0
pnpm check:authz-resolver :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:doc-authoring :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:dts-closure :: exit 0
pnpm check:dual-build-cjs-loads :: exit 0
pnpm check:durability-log-level :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:error-status-conformance :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:init-service-contract :: exit 0
pnpm check:issue-citations :: exit 0
pnpm check:keyed-text-bounds :: exit 0
pnpm check:lean-entry-closure :: exit 0
pnpm check:logger-receiver-detach :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:object-def-param-keys :: exit 0
pnpm check:objectql-double-limit :: exit 0
pnpm check:optional-error-sink :: exit 0
pnpm check:org-identifier :: exit 0
pnpm check:package-naming :: exit 0
pnpm check:page-declaration-shape :: exit 0
pnpm check:platform-object-tenancy-census :: exit 0
pnpm check:pm-governed-merges :: exit 0
pnpm check:pm-prior-rulings :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:route-envelope :: exit 0
pnpm check:settings-bind-window :: exit 0
pnpm check:slot-lookup :: exit 0
pnpm check:sourcemap-no-sources-content :: exit 0
pnpm check:startup-registry-verdict :: exit 0
pnpm check:swallow-census-controls :: exit 0
pnpm check:system-context-census :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:vouch-for-reference-callers :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
pnpm check:wildcard-fallthrough :: exit 0
Dogfood battery
os-verify-lock: VERDICT command-exit 0 · held the lock 1717s (28m37s) · waited 0s
Test Files  456 passed | 3 skipped (459)
Tests  3831 passed | 42 skipped (3873)
Duration  1715.06s

One run, no shard and no path filter, after the closure build. This PR adds or edits no dogfood file, so the 3 skipped files and 42 skipped tests are the suite's own.

CI on the PR runs the whole farm; none of it was re-run locally beyond the derived list above.


Generated by Claude Code

…w that runs as the system only through an action its author opted into AI

Flow start admission gains one rule, asked by every door that starts a flow
by name (the trigger route, the action door behind REST and MCP, a declared
endpoint): an AI service account starting a `runAs: 'system'` flow is refused
`403 PERMISSION_DENIED` unless the action that starts it carries the author's
`ai.exposed: true` opt-in, the one the MCP `run_action` tool already asks of
every action. A door with no action in hand has nothing to carry the opt-in,
so the account is refused there and the refusal names the action to declare.

The elevated run an admitted account starts keeps `principalKind: 'agent'` on
the facts of every data operation it makes.

Claude-Session: https://claude.ai/code/session_016WV4d1G1mMRC6sZXKcRqqu
Co-Authored-By: Claude <noreply@anthropic.com>
ADR-0151 Non-goals gain one sentence: an account's start of a flow that runs
as the system is refused by default and admitted only by the author's existing
`ai.exposed: true` opt-in on the action that starts it, the run keeping its
kind. The changeset declares the narrowing and its ADR-0087 disposition.

Claude-Session: https://claude.ai/code/session_016WV4d1G1mMRC6sZXKcRqqu
Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/runtime, @objectstack/service-automation, touching 18 documentable anchor(s).

5 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/ai/actions-as-tools.mdx (via aiExposed (symbol, a field of interface FlowStartDoor))
  • content/docs/ai/connect-mcp.mdx (via aiExposed (symbol, a field of interface FlowStartDoor))
  • content/docs/kernel/cluster.mdx (via AutomationEngine (symbol, a top-level class))
  • content/docs/permissions/system-context.mdx (via flowStartRefusal (symbol, a top-level function), resolveRunDataContext (symbol, a top-level function))
  • content/docs/ui/actions.mdx (via dispatchFlowAction (symbol, a top-level function))

⛔ 3 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v16.mdx (via AutomationEngine (symbol, a top-level class))
  • content/docs/releases/v17/17-0.mdx (via AutomationEngine (symbol, a top-level class))
  • content/docs/releases/v17/17-6.mdx (via AutomationEngine (symbol, a top-level class))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: PERMISSION_DENIED (literal, 52 pages)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 35 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 1a6c330945dac00bb42fccd09f42e39ce510d8e1 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from e8b56d4793f74a5317739f57007dcb5af5c71724 — the merge of head 7de0545a6e658b43a49af23c92fe4674a51b0ea7 into base 1a6c330945dac00bb42fccd09f42e39ce510d8e1, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e8b56d4793f74a5317739f57007dcb5af5c71724 && git checkout e8b56d4793f74a5317739f57007dcb5af5c71724
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 1a6c330945dac00bb42fccd09f42e39ce510d8e1 7de0545a6e658b43a49af23c92fe4674a51b0ea7 && git checkout -B drift-repro 1a6c330945dac00bb42fccd09f42e39ce510d8e1 && git merge --no-ff 7de0545a6e658b43a49af23c92fe4674a51b0ea7

node scripts/docs-audit/affected-docs.mjs --json 1a6c330945dac00bb42fccd09f42e39ce510d8e1

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 1a6c330945dac00bb42fccd09f42e39ce510d8e1 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#8 · os-elon-musk · session_016WV4cwqTK71kjQzHae8T5J

Contract-review-claim: session_016WV4cwqTK71kjQzHae8T5J · head 183ed60 · 2026-11-12T23:24Z

…he account page state the AI service account rule

Claude-Session: https://claude.ai/code/session_016WV4d1G1mMRC6sZXKcRqqu
Co-Authored-By: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#8 · os-elon-musk · session_016WV4cwqTK71kjQzHae8T5J

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 183ed607592e8bd2fcd31327778c85cc07c30380
Local-runs: none
Scope: docs/adr/0151-ai-service-account-a-headless-agent-is-a-registered-principal-of-its-own.md, packages/runtime/src/action-execution.ts, packages/runtime/src/domains/automation.ts, packages/runtime/src/endpoint-executor.ts, packages/runtime/src/flow-start-admission.ts, packages/runtime/src/flow-start-required-permissions.test.ts, packages/services/service-automation/src/engine.ts, packages/services/service-automation/src/run-agent-account-kind.test.ts, packages/services/service-automation/src/run-resume.ts, packages/services/service-automation/src/runtime-identity.ts, .changeset/31874-ai-account-elevated-flow-start.md + (read, not reviewed) packages/runtime/src/action-dispatch.ts, packages/runtime/src/flow-slot-view.ts, packages/core/src/security/assemble-execution-context.ts, packages/services/service-print/src/print-service.ts, packages/plugins/plugin-security/src/security-plugin-permission-sets.ts, packages/spec/src/automation/flow.zod.ts, packages/spec/src/ui/action.zod.ts, packages/spec/src/ai/tool.zod.ts, content/docs/automation/flows.mdx, examples/app-showcase/src/automation/flows/index.ts, examples/app-showcase/src/system/apis/index.ts, hotcrm src/**/flows/*.flow.ts (at 8277e61f)

Inputs read: card #31874 body and its five comments (ruling 6812617393, claims 6836684353 and 6836939154, report 6838841457), PR #32912 body, file list (11 files) and net diff, check-runs on the head. Check-runs at 2026-11-12T23:28Z: 50 listed, 25 success, 16 skipped, 0 failed, 9 still in progress (Test Core 1/8 to 8/8, Type Check · consumer gates). Those nine have no verdict yet; this record does not stand in for them, and the seat reads them before landing.

① Derived judgments

  • Accept set, trigger routes (POST /automation/NAME/trigger and the legacy trigger/NAME, both through respondToFlowTrigger): an AI service account at a runAs: 'system' flow of type screen or api moves from admitted to 403 PERMISSION_DENIED. Narrowing. Right, and inside the ruling.
  • Accept set, declared type: 'flow' endpoint (executeFlow): the same move. Right.
  • Accept set, REST actions route (dispatchFlowAction): the account is refused when the type: 'flow' action does not declare ai.exposed: true, admitted when it does. Narrowing. Right.
  • Accept set, MCP run_action: unchanged. The exposure gate upstream already refuses an unexposed action for every caller, so rule 2 can only see aiExposed: true there. Right.
  • Not moved, confirmed in the tree: a person, an OAuth-delegated agent (onBehalfOf set), the system principal (isSystem returns before any rule), an account at a runAs: 'user' or undeclared flow, the resume routes, flows that start on their own trigger. Rule 1 still answers an account first; requiredPermissions still answers an admitted account.
  • Refusal: PERMISSION_DENIED and 403 reach the caller at all three call sites (trigger: deps.error(message, status, { code }); endpoint: apiErrorResponse; action door: thrown with status and code, mapped by isFlowActionRefusal). No new code is minted. Right.
  • Run facts: the system arm of resolveRunDataContext now carries principalKind: 'agent' when the run context does; seedRunGrants keeps the door-forwarded kind on a system run. Additive on an internal envelope. The readers I found either test isSystem first (print service) or are reached only after elevation has answered, so nothing is narrowed or widened for the run's own operations. A runAs: 'user' hook fired by one of the run's writes now de-elevates to an agent context, which is the narrower and correct answer. The decider switch still deletes the kind before a system run's decision segment. Right.
  • Public surface: flowStartRefusal gains a required fourth argument and isAiServiceAccount, actionIsAiExposed, AI_ACCOUNT_ELEVATED_START_REFUSAL, FlowStartDoor are new exports of their modules. None is re-exported from packages/runtime/src/index.ts, so no published signature moves. packages/spec is untouched: no key, no accept set of any schema. Right.
  • isAiServiceAccount matches the assembler: principalKind: 'agent' with onBehalfOf set only for the OAuth agent (assemble-execution-context.ts lines 332 to 366). Right.

② Semver level

patch on @objectstack/runtime and @objectstack/service-automation, Metadata-protocol: none, a BREAKING banner and an ADR-0087 disposition (not-required, no key or stored row moves). That is what AGENTS.md asks of a non-protocol breaking change, and both packages the diff moves are named. Clause-②: no (narrowing) is present and identical in the PR body and the changeset; the diff widens nothing I could find. Check Changeset and PR-body guards concluded success on the head. Matches.

③ Boundary flags

Open questions (report 6838841457):

  1. By-name doors, A or B. Reviewed from the code. A admits a strict subset of what the ruling's words allow, so it cannot breach the ruling; B would let an opt-in written on one action open two doors that ask none of that action's guards, and needs a lookup the ruling does not spell. The "flow carries the opt-in" half of the ruling has nowhere to be written (Flow and Endpoint declare no ai key, and the ruling adds none), so under A only the action half is live. ESCALATED to the maintainer: the ADR sentence in this PR is written for A, so his Tier H approval should be given with that answer; a later B amends that sentence in the same change.
  2. ai.requiresConfirmation on REST for an account. Answered: A for this PR. The ruling's rule is the opt-in, and the confirmation gate is a separate, standing boundary. One thing the answer leaves open, should-fix S2 below.
  3. "What counts as a start door": one item is with the seat.

Dev flags:

  • security_findings: withheld: one item is with the seat. Nothing of it is judged here.
  • Out of scope, packages/spec/src/ai/tool.zod.ts prose: confirmed at line 98, and it is a published .describe() string. See S1.
  • Out of scope, three content/docs pages: confirmed for flows.mdx line 77 (the door sentence has no account row). See S1.
  • Out of scope, a self-triggered system run carries no kind: confirmed unchanged, and outside the ruling (it speaks of the run a door admits).
  • Deviations: pnpm lint run once per head, accepted. Package suites and the service-automation typecheck ran on the head's parent: the head adds one import line to one runtime test file, and Test Core on the head is the verdict (pending, above). test:repo left to CI: accepted. No scripts/adr-anchors entry: the sentence's path#symbol anchor resolves to an exported function, and every Lint check-run on the head concluded success. Claim re-posted with the tier constant in place of a model id: accepted.
  • First-party reach, verified: every hotcrm flow declaring runAs: 'system' (23 files) is schedule, record_change or autolaunched, already closed by rule 1. In this repo two flows change their answer for an account: showcase_inquiry_purge (screen, behind POST /api/v1/apps/showcase/inquiries/purge and the trigger route; no flow action targets it) and showcase_inbound_task_webhook (api, trigger route only). The dev's count holds.

④ Design judgment

ADR file. One line added, in Non-goals, nothing else in docs/adr/**. Against ruling C: "refused by default", "the author's existing ai.exposed: true opt-in" and "principalKind on its run facts" are each in the sentence. It says "the action that starts it" where the ruling says "the flow (or the action that starts it)", which is reading A stated as the rule (③ item 1). Against its first consumer, flowStartRefusal: the sentence describes what the function does at the three call sites, and the anchor resolves. Holds, on reading A.

Implementing files, sentence by sentence against the ruling:

  • "Refused by default": rule 2 is one if in flowStartRefusal, after rule 1 and before requiredPermissions, and it refuses unless door.aiExposed === true (strict). Agrees.
  • "Admitted only with the existing opt-in": the action door hands actionIsAiExposed(action) on the resolved declaration, the literal true and nothing else; the two by-name doors hand false. No door admits more than the ruling. Agrees.
  • "One rule on every door": flowStartRefusal has exactly three callers, and they are the only three request-reached execute calls in packages/runtime (action door, trigger routes, declared endpoint); MCP reaches the first. A repo-wide search for other callers of the automation service's execute found the engine's own nodes, the verify harness and nothing else that a request reaches. The argument is required, so a fourth door does not compile without stating it. No door missed among the doors; one item is with the seat.
  • "No second copy": ai?.exposed === true now appears once in packages/runtime and packages/mcp (the MCP tools read the bridge's attested aiExposed). The account reading is one function, used by the rule and by both context builders. Agrees.
  • "Refusal by name telling the author which opt-in to add": one frozen constant, same words at every door, names ai: { exposed: true, description } on a type: 'flow' action and the two doors where it stands, and nothing of the flow. Pinned by code, status and message, with execute asserted uncalled. Agrees.
  • "No new spec key": packages/spec untouched. Agrees.
  • "principalKind on the system-run branch's run facts": door forward, seedRunGrants keep, system arm carry; pinned and ablated. Agrees.

Findings:

  • S1, should-fix. Two follow-ups have no carrier (carrier: none · noted, not filed). tool.zod.ts line 98 defines the confirmation's enforced set as "the doors that enforce the author's ai.exposed opt-in" and says REST /actions is not ai.exposed-gated; after this PR the REST route does read the opt-in for one pair, so the published reason is wrong for that pair. flows.mdx line 77 lists the start doors and their refusal with no account row, and the PR is BREAKING. The seat files a spec-lane card and a docs card before landing, so neither is lost.
  • S2, should-fix, follow-up decision. The 403 sends the account to "the REST actions route or the MCP run_action tool" as equals, yet an author's ai.requiresConfirmation: true on that same action is asked on only one of them. Not owed by ruling C and not a defect of this diff; it needs its own decision card (the dev's question 2, option B).
  • N1, nit. flow.runAs === 'system' is now spelled three times in flow-start-admission.ts (isElevatedSelfTriggered, flowRunsElevated, rule 2).
  • N2, nit. ADR D3 says an agent principal "never runs isSystem", and an admitted run's facts now carry isSystem: true beside principalKind: 'agent'. The new Non-goals sentence is where a reader reconciles the two; D3 alone does not say so.

No must-fix.

Implemented-by: claude/project-thread-mfe3hn
Reviewed-by: session_016WV4cwqTK71kjQzHae8T5J

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#8 · os-elon-musk · session_016WV4cwqTK71kjQzHae8T5J

Regen-provenance: 6839053991 · 183ed607592e8bd2fcd31327778c85cc07c30380 → 7de0545a6e658b43a49af23c92fe4674a51b0ea7 · git diff --name-only → content/docs/ai/agents.mdx, content/docs/automation/flows.mdx, content/docs/ui/actions.mdx

Prose-only hop (one commit, three content/docs pages, +14/−4, no package file, no merge of main): the contract-review record 6839053991 continues to govern this head. The three pages were checked sentence by sentence against the diff in the seat record (PR body, ## 席位核对 item 5).

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 12, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 13, 2026 00:31
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 64b46fe Nov 13, 2026
62 of 63 checks passed
@os-zhuang
os-zhuang deleted the claude/project-thread-mfe3hn branch November 13, 2026 02:06
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: may an AI service account trigger a flow declared runAs system? (ADR-0151 non-goal, #31739 follow-up)

3 participants