Repository navigation
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
Conversation
…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>
…ening cast Claude-Session: https://claude.ai/code/session_016WV4d1G1mMRC6sZXKcRqqu Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4d1G1mMRC6sZXKcRqqu Co-Authored-By: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 5 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 3 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 35 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # 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
|
|
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>
|
domain:server#8 · os-elon-musk · session_016WV4cwqTK71kjQzHae8T5J Contract reviewServed-tier: 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
② Semver level
③ Boundary flagsOpen questions (report 6838841457):
Dev flags:
④ Design judgmentADR file. One line added, in Non-goals, nothing else in Implementing files, sentence by sentence against the ruling:
Findings:
No must-fix. Implemented-by: VERDICT: PASS |
|
domain:server#8 · os-elon-musk · session_016WV4cwqTK71kjQzHae8T5J Regen-provenance: 6839053991 · Prose-only hop (one commit, three |
Requested by Elon · project thread
Fixes #31874
Clause-②: no (narrowing) — an AI service account's start of a flow declared
runAs: 'system'is refused with403 PERMISSION_DENIEDatPOST /api/v1/automation/NAME/trigger(and the legacyPOST /api/v1/automation/trigger/NAME), at a declared endpoint oftype: 'flow', and at the REST actions route when the action that starts the flow does not declareai.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 therequiredPermissionsrow, and the two "checked after" clauses below it count the new row),content/docs/ui/actions.mdx(theflowrow under "Call it over REST" and the'rest'posture row say the REST door readsai.exposedfor an AI service account starting arunAs: '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.维护者速读
runAs: 'system'(以系统身份运行)的流程时,默认被拒(403 PERMISSION_DENIED);只有通过作者已声明ai.exposed: true的type: 'flow'动作来启动才放行。能按名字启动流程的三道门(触发路由、动作门、声明式端点)问的是同一条规则,拒绝文案直接告诉作者该加哪个声明。放行后的系统身份运行,每次数据操作都带principalKind: 'agent'。ADR-0151 的 Non-goals 加了一句话。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)。docs/adr/0151-…加了一句话,按方案 A 写)。契约复核 PASS 见评论 6839053991(Head-sha: 183ed607…;文档轮7de0545a只动散文面,记录续管)。批准后由席位落地。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 #31874main,仅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。flowStartRefusal恰有三个调用方,且是packages/runtime里仅有的三个请求可达的流程启动点;MCPrun_action经动作门;第四道门因参数必填而无法静默漏掉。183ed607的 check-runs 36 成功、16 跳过、0 失败;文档轮 head7de0545a的 check-runs 落地前重读。CONTRACT_REVIEW_TIERPASS,评论 6839053991,Head-sha: 183ed607592e8bd2fcd31327778c85cc07c30380,无 must-fix;183ed607 → 7de0545a仅动散文面(三页content/docs),记录续管,Regen-provenance:行在 PR 评论。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 代理、系统主体与以用户身份运行的流程不受此行判定,与代码一致。pm:awaiting-merge、转 ready、挂 auto-merge。Clause-②: no (narrowing),BREAKING 横幅与 ADR-0087not-required处置在 changeset。What changes
The ruling this executes. Ruling record 6812617393 on #31874 (batch #1 item 4, letter C, maintainer 「同意」 2026-11-12T02:29Z):
One rule, in the module every door already asks.
packages/runtime/src/flow-start-admission.ts#flowStartRefusalis the one check the trigger routes, the action door and a declaredtype: 'flow'endpoint ask before a flow starts. It gains rule 2, between the two it had:principalKind: 'agent'with noonBehalfOf, ADR-0151 D3) starting a flow declaredrunAs: 'system'is refused unless what starts the flow at that door carries the author'sai.exposed: trueopt-in;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:runAs: 'system'flowPOST /api/v1/automation/NAME/triggerand the legacy spelling (domains/automation.ts#respondToFlowTrigger)aiExposed: falsetype: 'flow'(endpoint-executor.ts#executeFlow)aiExposed: falseaction-execution.ts#dispatchFlowAction)ai.exposed: true, refused otherwiserun_action(same function)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_questionsfor the maintainer.One reading of the opt-in.
action-execution.ts#actionIsAiExposedis now the single predicate behind the MCP exposure gate (actionAiExposureError), the system-object exposure gate, thelist_actionsattestation 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: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 carriesprincipalKind: 'agent'when the run context does, as the user arm already did.run-resume.ts#seedRunGrantskeeps the kind a launch door forwarded onto arunAs: 'system'run (setup resolves no grants for one, so nothing would re-seed it). It is attribution:isSystemanswers 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:
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. Theai.requiresConfirmationgate does not move: it stays on the doors that ask the opt-in of every action. The run log'striggerrecord 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 theai.exposedopt-in and is now imprecise for this one pair: it is with card #32924 (spec lane). Noscripts/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-leveldescribeon the shared four-door harness, 36 tests (the file: 45 before, 81 now). Forscreenandapiflows: 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 carryingprincipalKind: 'agent'. The refusal is asserted bycode,statusand 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 byrequiredPermissions. CONTROLS at every door: a person, an OAuth-delegated agent, the system principal, and an account at arunAs: 'user'or undeclared flow, all admitted with no opt-in anywhere.packages/services/service-automation/src/run-agent-account-kind.test.ts: a newdescribe, 4 tests (the file: 5 before, 9 now). The door-forwarded kind survives run setup on a system run and rides the facts besideisSystem, with no grants resolved; a system run handed only a user carries none; CONTROLS for a person and for non-agentvalues.Ablations (fix committed first; each mutation through
node scripts/ablation-replace.mjs, which proves the write on disk and the restore againstHEAD; these suites resolve the mutated files fromsrc/, so no build sits between mutation and reading):aiExposed: trueaiExposed: trueaiExposed: truewhatever the action declaresflowStartRefusalresolveRunDataContextdrops the kindAblation failures and restore proofs
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 mergemain).Acceptance notes
ifinflowStartRefusal; 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.docs/adr/**.principalKindon its run facts":resolveRunDataContext's system arm, pinned and ablated.packages/specis untouched.origin/mainmerged 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.pnpm --filter @objectstack/runtime typecheck(source and test layer)183ed60759pnpm --filter @objectstack/service-automation typecheck(source and test layer)20959acac0pnpm --filter @objectstack/runtime test20959acac0pnpm --filter @objectstack/service-automation test20959acac0183ed60759pnpm lint183ed60759node scripts/pm/dispatch-gates.mjs --commands, each run, then--ranpnpm --filter @objectstack/dogfood testunder the verify lockDocs round (
183ed60759to7de0545a6e): one commit, threecontent/docspages, 14 insertions and 4 deletions, no file of any package. No merge ofmain. 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 lintand the dogfood battery were not run again: no test inpackages/**reads these three pages, and their readings on183ed60759stand for the code. The claim was re-posted whole with the three pages in its file surface (comment 6838944179).20959acac0is 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, on20959acac0, had one red,pnpm check:test-source-alias(the edited pin file reaches a dynamic import of@objectstack/metadatain 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 ofservice-automationand no non-test file differs between the two commits.Gate reconciliation and the 82 recorded exit codes
Dogfood battery
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