Skip to content

Commit 99bd220

Browse files
feat(spec, service-automation): a packaged flow can ship switched off for an administrator to turn on (defaultActive) (#34793)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBFyg5B2muWbKZjA9phXVWse)_ Fixes #34655 Clause-②: yes (widening) — `FlowSchema` gains the optional `defaultActive` boolean. Before, any flow declaring it was refused as an unknown key (`strictObject`); now a packaged flow that declares it registers. A flow authored in the environment that declares it is still refused, now by the engine with a sentence naming its `status` as its switch. Nothing that registered before is refused. Metadata-protocol: added Skills-docs: updated here — skills/objectstack-automation/SKILL.md (one paragraph under "A flow an installed package ships"), evals/flows-triggers-approvals.json (eval id 24) ## 维护者速读 - 改了什么:flow 新增作者可写的 `defaultActive`(紧挨 `status`,可选,缺省为开)。打包 flow 写 `defaultActive: false` 后,新装时不挂触发器、不运行,`/automation/_status` 报 `enabled:false`;管理员用现有开关(toggle / Studio 的 Enabled)打开即写一行账本,这行优先于包默认,重启、升级、重装都保持。环境自写 flow 写这个键在注册时被拒(它的开关是 status);克隆去掉这个键;unmanaged 安装把 `false` 抄成 `status:'obsolete'`。ADR-0126 §4 加修订注;automation skill 加一段说明和 eval 24。 - 为什么改:hotcrm#2558「接受报价起草合同」要作为默认关闭、管理员可开的打包 flow 发出,今天做不到:没有账本行就是开,`status:'obsolete'` 又会永久关死。 - 风险与回滚:加法,没写这个键的 flow 行为不变(空账本仍然什么都不改)。默认是读时取的,安装时不写行,所以「有行=管理员选过」不变;包升级改默认只影响没人动过开关的安装;本轮(L2 S4)补上 override 被元数据保存激活后、基础包热升级翻转默认时的漏读,每次 `metadata:reloaded` 重新读一次包默认。回滚即 revert 本 PR(已写 `defaultActive` 的包会回到「未知键被拒」)。 - 先看:`packages/services/service-automation/src/engine.ts`(`shipsOff` 接线、`refuseUnpackagedDefaultActive`、`refreshPackagedFlowDefaults`)、`packages/services/service-automation/src/flow-activation-projection.ts`(无行时读包默认)、`packages/services/service-automation/src/plugin.ts`(`resyncFlowsFromProtocol` 每次重同步调用刷新)。 - 两分钟验证:`pnpm --filter @objectstack/service-automation exec vitest run src/flow-default-active-34655.test.ts`,预期 34 条全过。 - 需要你做的:批准本 PR(碰 packages/spec/src、docs/adr 与 skills/,契约复审记录由席位路由)。 ## What changes A packaged flow can ship switched off, for an administrator to turn on. - **`packages/spec/src/automation/flow.zod.ts`**: `FlowSchema.defaultActive`, `z.boolean().optional()`, next to `status`, with no materialized default, so a flow that does not declare it parses exactly as before. The JSDoc and `describe` say what it is (the default of the packaged-flow switch), that a ledger row wins over it, that `status` stays the author's, and that only a packaged flow may carry it. - **`packages/services/service-automation/src/flow-activation-projection.ts`**: `has(key)` is now the row that decides for the flow (`rowVerdict`, the old body, answering `undefined` where it used to answer `false` for "no row decides") or else the new `shipsOff` reader. `offByDefault(key)` names the "no row, shipped off" case for the refusal log. `hasShared` became `sharedRowVerdict` the same way. - **`packages/services/service-automation/src/engine.ts`**: the projection's `shipsOff` reader is `packagedFlowDefault(key) === false`, the declaration of the PACKAGE's own body for the version installed now: the armed body when the loader's body is armed, else the loader's body for the slot's package (new `setPackagedFlowDefaultSource`; seat ruling on L2 S2, option (a)), asked once per armed body and cached against it, so `isFlowEnabled` never reads the loader's set; the cache is replaced at every `metadata:reloaded` re-sync by `refreshPackagedFlowDefaults()` (new public method, L2 S4), which re-arms or disarms each held flow whose armed body is not the loader's own when its answer moved, because the re-sync does not re-register every body. So an upgrade that changes the declaration moves only an installation nobody switched, and a declared `.custom` override does not move the default in either direction. `refuseUnpackagedDefaultActive` is a member of the one registration check list (#23317), judged by name: does ANY package's loader set hold it (`isShippedFlowName`, the loader's own per-package answer, so a name two packages ship keeps the key): `registerFlow` throws it (the automation write doors answer `VALIDATION_FAILED` / 400, `registerAndSaveFlow`), `dryRun` refuses the draft, and the stored pass (`canonicalizeStoredFlow().todos`) lists a stored row at `flows[0].defaultActive`. The metadata door (`PUT /api/v1/meta/flow/:name`) parses without registering, so it stores such a row; the engine refuses to arm it. `describeDisabledFlow`'s log line names the shipped default when no row decides; the `isFlowEnabled` and `hydrateFlowActivations` docblocks say what the default and an active row now do. - **`packages/services/service-automation/src/plugin.ts`**, **`flow-registration-checks.ts`**, **`index.ts`**: `packagedFlowDefaultReader`, over the protocol's `shippedArtifactsOf` at question time (the read `packagedFlowReader` already makes for a package's own question), attached at init beside `setPackagedFlowSource`; `resyncFlowsFromProtocol` calls `refreshPackagedFlowDefaults()` after its loop (L2 S4); the check list gains the member; `PackagedFlowDefaultSource` is exported beside `PackagedFlowSource`. - **`packages/services/service-automation/src/flow-definitions.ts`** (`hydrateFlowActivations` only): a row switching a flow ON is now applied through `activateFlowTrigger` (idempotent, the same gate) and its callers re-judged. Without it, a host whose trigger was registered before the pull would keep a shipped-off flow unarmed after a restart even though an administrator switched it on. The stock boot order (trigger plugins at `kernel:ready`) armed it anyway. - **`packages/runtime/src/flow-clone.ts`**: `FLOW_CLONE_DROPPED_KEYS` names `defaultActive`. The copy is a writable package's flow, switched by its `status`, which the clone already writes `obsolete`. - **`packages/metadata-protocol/src/package-unmanaged-install.ts`**: `copyUnmanagedFlowSwitch`: an unmanaged install copies `defaultActive: false` as `status: 'obsolete'` (a status that already disarms is kept) and drops the key; `true` is dropped. A non-boolean is handed on for the save door to refuse. - **`packages/spec/src/contracts/automation-service.ts`** (`toggleFlow` JSDoc) and **`packages/spec/src/api/automation-api.zod.ts`** (module JSDoc; regenerated `content/docs/references/api/automation-api.mdx`): N1 of the contract review on #34810 (record 6952048597), carried here at the seat's request because half A edits `packages/spec`. The toggle contract prose now names the 409 for switching ON a packaged flow whose own `status` disables it (landed with #34810, merged into this branch), and that switching such a flow off is accepted. Prose only: no schema, `describe`, export or error code moves. - **`docs/adr/0126-packaged-metadata-customization-model.md`**: an amendment note under §4 and a Status-line entry. The amended sentence is not rewritten. - **`skills/objectstack-automation/SKILL.md`** (the card's "Document it in the automation skill"): one paragraph under "A flow an installed package ships": `defaultActive: false` ships the flow unarmed (`_status` `enabled: false`) until an administrator turns the switch on, that choice outlives restart / upgrade / reinstall, `status: 'obsolete'` disarms past the switch, and a flow authored in the deployment is refused the key. `evals/flows-triggers-approvals.json` gains eval 24. `scripts/check-skills-token-ratchet.mjs`: the file's ceiling 6903 → 6992, the measured addition (+357 priced bytes, nothing removed), under the standing ruling 「A:先削重复,余额按实测提高」 (record 6513306068); no restatement of the switch, its default or `status` as a switch was found to pay down, as the ceiling's note says. - `packages/spec/liveness/flow.json` (`defaultActive`: live), regenerated `authorable-surface`, `content/docs/references/**`, `liveness/state-counts/flow.md`; `.changeset/34655-flow-default-active.md` (`minor` spec and service-automation, `patch` runtime and metadata-protocol). ## Tests - `packages/services/service-automation/src/flow-default-active-34655.test.ts` (34): fresh install neither arms nor runs it (`FLOW_DISABLED`, the switched-off sentence, `_status` `enabled:false`); the log line names the shipped default; toggle on writes `{ active: true }`, arms and runs; survives a restart in the stock boot order and on a host whose trigger was registered first; survives an uninstall (a boot without the package leaves the row) and a reinstall; survives an upgrade that changes the body; a flow switched back off stays off when the next version ships it on; with no row, an upgrade that changes the declaration moves the installation both ways; CONTROL `true` and absent ship on; an `obsolete` flow a row switches on still does not arm; a packaged caller of a shipped-off subflow is held unarmed until the subflow is switched on; `defaultActive: false` and `true` on an environment flow are refused with the exact sentence and nothing is filed (the code and status are the write door's, as for every `registerFlow` refusal); CONTROL: the same environment flow without the key runs; the key is judged by name, so a package arm for a name the loader's set does not hold is refused and a name it holds keeps the key under any arm; a dry run of an environment draft with the key throws what registration throws; the stored pass lists such a row at `flows[0].defaultActive` and none without it; a package that ships the flow off is not armed by an override that omits the key, and one that ships it on is not switched off by an override writing `false` (the administrator's switch works in both); `packagedFlowDefaultReader` answers the named package's own body and none for a missing body, a non-boolean, or no protocol. L2 S4 / N13 (six cases): on the engine, `refreshPackagedFlowDefaults()` moves a held override with no row both ways after the loader's answer flips, a CONTROL where a ledger row and a loader-armed body are not moved, and a body `rollbackFlow` puts back reads the set installed now; on the automation plugin (LiteKernel, a protocol stand-in serving the declared override in the base's slot, no ledger), an override armed by the metadata-mutation sync (no reload) is not re-registered by the next `metadata:reloaded`, and a hot upgrade flipping the base's `defaultActive` still moves it: on to off stops it (unbound, `FLOW_DISABLED`), off to on starts it (bound, runs), with a CONTROL reload that leaves the declaration as it was and moves nothing. - `packages/spec/src/automation/flow-default-active-34655.test.ts` (3): accepts both booleans, absent stays absent, a non-boolean is refused at the key. - `packages/runtime/src/flow-clone-default-active-34655.test.ts` (2) and `packages/metadata-protocol/src/package-unmanaged-flow-switch-34655.test.ts` (5). - Two existing tests account for the new key: `packages/spec/src/system/metadata-form-zod-reconciliation.test.ts` gains a root ledger row for `flow.defaultActive` (the flow form saves only environment-authored flows, where the engine refuses the key, and its meaning lives in its absence, like `skill.mcpPrompt`), and `packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts` moves `flow`'s served top-level count 23 → 24. No other existing test changed. ## Acceptance notes - **Read-time default, not an install-time row** (seat ruling on the area thread). A row written at install could not be told from an administrator's choice, so an upgrade that turns the default on would either override an administrator's off or never reach an installation nobody touched. - **Only packaged flows** (area agreed, for the L2 and the seat to read): the predicate is by name, with no arm exception since the L2 round: does any package's loader set hold the name (`isShippedFlowName`). It asks the one owner first (the toggle door's `isPackagedFlow`), then each package that may hold the name, per package (`packagedFlowSlotOwner`): the packages whose slots hold it now and the package the body names itself as. The stamp only picks which package to ask; a stamp naming a package that ships no such flow is still refused (pinned). A `.custom` override is served at the base's name, which the loader's set holds (ADR-0146 D9.3), so it is not refused; the default it carries is not read (seat ruling, S2 option (a)). - **Reinstall**: the activation store has no delete (`packages/core/src/utils/metadata-activation-store.ts`, "deliberately has no `delete`"), and nothing on the uninstall path writes the ledger (read). The engine half is now pinned: a boot without the package leaves the row and the reinstall arms the flow. - **"On" rows that do not count**: a row naming no package that switches a flow ON is not recorded by the projection, and an ON row of a package that no longer holds the name is skipped, so neither overrides a ship-off default (the matching OFF rows still switch the flow off). Both fail closed; the JSDoc and the ADR note now say so. Not changed here. - **Release floor**: a package declaring the key needs a platform at or above this release; an older runtime refuses the flow as an unknown key. Said in the changeset. - **Unmanaged import answer** (L2 N7): the answer does not list a flow whose `defaultActive: false` was copied as `status: 'obsolete'`. Accepted as is: the copy's `status` says it, and listing it is new answer surface outside the card. - **No reader attached** (L2 N8): a host that composes the engine without `setPackagedFlowDefaultSource` reads the default only off an armed package body, so while a `.custom` override is armed a flow its package ships off runs (fail-open). Such an engine cannot see the package's body, and an unknown default treated as on is how every packaged flow behaved before this key. The automation plugin always attaches the reader; the changeset says so. - **The reader's protocol read** (L2 N8): `packagedFlowDefaultReader` reaches the protocol's `shippedArtifactsOf` by duck type, as `packagedFlowReader` already does. It is now pinned through the real protocol: the first-boot-pull integration harness (ObjectKernel + ObjectQLPlugin + SqlDriver + AutomationServicePlugin) boots a base shipping `defaultActive: false` with a stored override that omits the key; the reader answers `false` for the base and nothing for the pair, the override is armed and reported `enabled: false`, and a record change fires nothing. - **Half B** (the toggle door for a status-disarmed flow) landed as #34810 and is merged into this branch from `main`, as is #34654; this PR does not touch `toggleFlow` or `packages/runtime/src/domains/automation.ts`. - **L2 S4 fix direction** (delta record 6949383615 offered two): the cache is dropped at every re-sync and the held non-loader flows go back through the arming gate, rather than skipping the mutation-mark skip for a non-loader winner. The review notes N13 rides with the cache drop, and the drop also covers the second stock path the review names (a re-registration that throws keeps the old body), which the skip change would not. Cost per reload: one reader call per held flow whose armed body is not the loader's own. N14 (an unstamped first or third holder registered through the engine API) is left as the review allowed: registry-fed bodies are stamped. - **Changed lines after this round's merges**: the PR's net diff against `main` stays inside the claimed surface plus claim amendment 6953980143 (the two spec JSDoc paths for #34810's N1). - **CI at `1074c040`, seat 3 fix round** (no code change): `Test Core (2/10)` failed one case, `packages/spec/scripts/build-schemas-check-mode.anchor.test.ts` "still fails offline on a deletion the anchor records and this build cannot account for", with `Hook timed out in 10000ms` in its `beforeEach` (line 69: fixture file writes plus `git add`/`commit`/`rev-parse`/`update-ref` in the sandbox). Judged a flake: the same hook passed for the file's other 14 cases in that run; the file's inputs (`packages/spec/authorable-surface/**`, `authorable-surface.base.json`, `packages/spec/scripts/**`, root `scripts/**`) are byte-identical to `5fe7b810`, whose Test Core shards were all green, and `1074c040` touched only a JSDoc comment in `packages/spec`. The failed jobs of run 44082971653 are re-run once; a second failure is real. ## Verification Head `34181ed124`: this round (below) on top of `208c272ef1` (a merge of `origin/main` c4c0794, then the regenerated automation API reference), the automation-skill commit and the two existing-test updates (`bef53a4790`, CI all green), then the contract-review rework (`5fe7b810c4`) and its delta (`1074c040a7`). <details><summary>L2 delta 6949383615 fix round (S4, N12, N13) and #34810's N1, on 34181ed</summary> - Commits: `96a99d06d8` merge of `origin/main` (#34654); `05656d74f1` the S4 fix and its pins; `536d5a1c12` the spec prose (#34810 N1) and the changeset sentence; `198cdf7bf6` merge of `origin/main` (#34810 landed); `34181ed124` the regenerated automation API reference, and `authorable-surface/api.json` regenerated after the merge (the driver had deferred it; it differs from `main`'s only by this PR's own `api/CreateFlowRequest:defaultActive` row). - **S4**: `AutomationEngine.refreshPackagedFlowDefaults()`; the plugin's `resyncFlowsFromProtocol` calls it after its loop on every `metadata:reloaded`. The `packagedFlowDefaults` and `packagedFlowDefault` docblocks say when the default is read again. The changeset names the method as public API, since a host composing the engine itself must call it after the installed packages change. - **N13**: covered by the same drop (the map a rolled-back body was cached in is replaced), pinned. **N12**: this body counts 34 for the card's test file (28 before this round plus six). - Ablation (`scripts/ablation-replace.mjs`, anchor `this.engine.refreshPackagedFlowDefaults();` in `plugin.ts` deleted, x1 to x0, blob `02ab3709` to `1e49c39b`): 2 failed / 32 passed. The two flip pins fail (`expected true to be false` on to off, `expected false to be true` off to on); the CONTROL reload stays green. Restored: blob equals HEAD (`02ab3709`), `git diff HEAD` empty. The test imports `./plugin.js` from source, so no build is involved. - `service-automation`: `tsc --noEmit` and `check:test-typecheck` exit 0; full suite `Test Files 288 passed (288)`, `Tests 4174 passed (4174)` at `198cdf7bf6` (4167 at `536d5a1c12`, before #34810 merged). `flow-default-active-34655.test.ts` 34/34. - runtime targeted (`flow-clone-default-active-34655`, `automation-flow-clone`, `automation-toggle-caller`, `automation-addressed-route`, `automation-toggle-deny-message`, `automation-toggle-unknown-flow`): 6 files, 111/111. Spec `typecheck` exit 0; spec `check:generated` 14/14 and `check:docs` exit 0 at `34181ed124` (the spec `dist` was built after the merge; `gen:docs` regenerated `automation-api.mdx`). - `dispatch-gates --commands` at `198cdf7bf6`: 149 families, each run with its exit code captured before any pipe; `--ran`: 149 accounted for, 146 run, 3 NOT-MEASURED. **NOT MEASURED** (declared narrowing, CI runs them): `check:skill-examples` and `check:dual-build-cjs-loads` (exit 3, they need built packages outside the closure: client, client-react and 30 more), `check:type-check-debt` (exit 3, its closure build never got the shared verify lock behind a long dogfood run). This round changed no skill file and no package's typecheck wiring. `check:docs` and `check:generated` first exited 1 (the reference page above), and both exit 0 after the regeneration. `check-nul-bytes` exit 0. `overlap-check` at `34181ed124`: clean against `origin/main` 46991d0 and the two open PRs that share files. - CI on `34181ed124`: in progress when this was written. </details> <details><summary>Contract review delta (record 6947617913 on 5fe7b81)</summary> - **S3** (a name two packages ship refused the key): the check asks whether any package's loader set holds the name (`isShippedFlowName`), not whether it has one owner. Pinned: both holders, a re-sync / hot upgrade re-registration and a third holder register with the key, `true` and `false`; a dry run and the stored pass agree; CONTROL: a name no package ships is still refused, whatever package the body names itself as. - **N8**: the changeset names `AutomationEngine.setPackagedFlowDefaultSource` and `PackagedFlowDefaultSource` as public additions and states the fail-open behaviour without a reader, with the reason; the duck-typed protocol read is pinned through the real protocol (Acceptance notes). - **N9**: the reader is asked once per armed body (`packagedFlowDefaults`, a `WeakMap` keyed by the body `registerFlow` armed); a re-registration (the `metadata:reloaded` re-sync after an upgrade re-registers the winner) asks again. Pinned: one call across repeated state reads and runs, one more after a re-registration. - **N10**: the 维护者速读 count is 28. **N11**: the `FlowSchema` JSDoc sentence reads as sentences. - Ablations (each restored, `git diff HEAD` empty): the check asks the one owner only → 2 failed / 26 passed (the co-held registrations, the dry run and stored pass); the cache read removed → 1 failed / 27 passed (the once-per-body pin); the reader reading a key the body does not carry → the real-protocol pin fails. - `service-automation` full suite: `Test Files 288 passed (288)`, `Tests 4135 passed (4135)`. `tsc --noEmit` exit 0. Spec `check:generated` 14/14 after a spec build. 20 affected gates (ADR anchors and links, docblock and scripts symbol anchors, liveness, test-source alias, issue citations, the changeset gates, docs transcript and corpus claim drift, engine double contract, optional error sink, undeclared dep imports, type-check coverage, startup registry, doc authoring, skill examples): all exit 0. </details> <details><summary>Contract review rework (record 6946901031 on bef53a4)</summary> - **S1** (the refusal outside the one check list): fixed as the area ruled. `refuseUnpackagedDefaultActive` is a member of `registrationChecks`, judged by name; `dryRun` refuses an environment draft with the key and the stored pass lists a stored row, both pinned. The changeset names which doors answer 400 and what the metadata door does. - **S2** (an override moves the default): seat ruling (a), the default is the package's own body's. `packagedFlowDefault` + `packagedFlowDefaultReader`; the JSDoc and the ADR note say so; both directions pinned. - **N1** hydrate docblock updated. **N2** the two "on" rows that do not count are in the JSDoc and the ADR note. **N3** reinstall pinned at the engine. **N4** gone: the check no longer trusts an arm. **N5** release floor in the changeset. **N6** the owed-skill note removed. **N7** accepted as is (Acceptance notes). - Ablations (each restored, `git diff HEAD` empty): the list member removed → 5 failed / 19 passed (both environment refusals, the by-name refusal, the dry run, the stored pass); the default read off the armed body whatever its arm → 3 failed / 21 passed (both override directions and the by-name CONTROL). - `service-automation` full suite: 276 files passed; 12 failed to collect because the spec `dist` was rebuilt mid-run, and re-run alone: 12 files, 110 tests passed. `tsc --noEmit` exit 0. Spec `check:generated` 14/14 after a spec build. 23 affected gates (ADR anchors and links, docblock and scripts symbol anchors, liveness, error-code provenance, test-source alias, issue citations, the changeset gates, docs transcript drift, engine double contract, undeclared dep imports, …): all exit 0. </details> <details><summary>Since 208c272 (the skill paragraph, the form ledger row, the served-property count)</summary> - CI on 208c272 was red in `Test Core (2/8)` (spec `metadata-form-zod-reconciliation.test.ts`: `flow.(root): accepted by the Zod but unauthorable in the form … expected [ 'defaultActive' ] to deeply equal []`) and `Test Core (6/8)` (metadata-protocol `protocol.meta-types-degenerate-derivation.test.ts`: `flow` served `24`, pinned `23`). Both are the new key, accounted for in the next commit: the reconciliation file 76/76, the derivation file 18/18; the full metadata-protocol suite had that one failure and `23060 passed` before the fix. - `PR-body guards` was red on `check:closing-target-claim` (the card's claim named half B's branch); the seat posted a claim naming this branch. - Gates the new files add, and the skill gates re-run: 39 commands (`check-skills-token-ratchet` with `--self-test`, `check:skill-docs`, `check:skill-examples`, `check:skill-refs`, `check:skill-identifier-liveness`, `check:skill-links`, `check:skill-compatibility`, `check:skill-frame-sync`, `check:issue-citations`, the changeset gates, …): all exit 0. `check:skill-examples` first exited 3 on a stale spec `dist`, then 0 after building spec (`347 prose examples type-check`). Record appended to the gates file below. </details> <details><summary>Premise on origin/main f6f5b50</summary> `FlowSchema` declares only `status` (`flow.zod.ts`, `status: z.enum(['draft', 'active', 'obsolete', 'invalid'])`); no default-active key anywhere in `packages/spec/src`. `isFlowEnabled` composes `flowStatusDisabled` and `flowLedgerDisabled.has(name)`, and the projection answered `false` (on) with no row. `toggleFlow` writes `active: enabled` and the projection keeps the holder's row in either state. Read in code; the card's fresh-install reading is hotcrm's, on 18.5.0. </details> <details><summary>Packages</summary> - `pnpm --filter @objectstack/service-automation exec vitest run --maxWorkers=3` (at eb5a27d plus the engine edits): `Test Files 288 passed (288)`, `Tests 4121 passed (4121)`; `typecheck` exit 0. - `src/flow-default-active-34655.test.ts` 34/34 at the final head; `src/flow-declared-override-first-boot-pull.integration.test.ts` 28/28 (one new real-protocol pin). - spec `src/automation/flow-default-active-34655.test.ts` 3/3; runtime `src/flow-clone-default-active-34655.test.ts` + `src/domains/automation-flow-clone.test.ts` 24/24; metadata-protocol `src/package-unmanaged-flow-switch-34655.test.ts` + `src/package-unmanaged-install.test.ts` 103/103. - spec `check:generated` exit 0 at the final head (14/14); `check:test-typecheck` OK (needs `NODE_OPTIONS=--max-old-space-size=8192` in this container, else tsc runs out of heap). </details> <details><summary>Ablations (scripts/ablation-replace.mjs, each restored, git diff HEAD empty)</summary> - `shipsOff` reader answers `false` → 5 failed / 10 passed (fresh install, the log line, the upgrade both ways, the subflow caller, the package-arm CONTROL). - the `refuseUnpackagedDefaultActive` call removed → 2 failed / 13 passed (both environment refusals). - the hydrate's `activateFlowTrigger` removed → 1 failed / 14 passed (restart on a host whose trigger registered first). - `defaultActive` kept on a clone → 1 failed / 1 passed. - `copyUnmanagedFlowSwitch` not applied → 2 failed / 3 passed. Log: `/mnt/project-files/objectstack-seat2/34655A-ablation.log`. </details> <details><summary>Gates</summary> `node scripts/pm/dispatch-gates.mjs --commands`: 122 families, each run with its exit captured before any pipe; `--ran`: `122 derived famil(ies) accounted for — 122 run, 0 NOT-MEASURED`. First pass: `check-plugin-teardown-shape --self-test`, `check:skill-examples` and `check:dual-build-cjs-loads` exit 3 (shallow clone; unbuilt packages), re-run after `git fetch --unshallow` and a build: exit 0. `check:error-code-provenance` exit 1 on the first draft's `VALIDATION_FAILED` stamp in service-automation and `check:test-source-alias` exit 1 on the new unmanaged test: fixed (the refusal is a plain registration `Error`; the test preloads lint), both exit 0. Record: `/mnt/project-files/objectstack-seat2/34655A-gates-ran.txt`. </details> <details><summary>git merge-tree against the in-flight neighbours</summary> `git merge-tree --write-tree --name-only` of 208c272 with: - #34654 head 8598c1d: exit 0, tree e2cc976a1796, no conflicted path. - half B `claude/issue-34655-toggle-status-disarmed` 0c7fc78: exit 0, tree 2c70fc9a8273, no conflicted path. On the merged tree (a `--no-commit` merge, then aborted), `flow-default-active-34655`, `toggle-door-packaged-only`, `flow-activation-ledger` and `flow-activation-late-trigger`: 4 files, 94/94 passed. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzfr1xZSFZzCR8HnqXX Claim note (seat 3, o3-J): #34793's branch is named on its own `Claim:` line on #34655 (half-A claim after takeover 6948719649), which the closing-target guard reads. <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzfr1xZSFZzCR8HnqXX --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c956ce5 commit 99bd220

29 files changed

Lines changed: 1370 additions & 31 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/service-automation': minor
4+
'@objectstack/runtime': patch
5+
'@objectstack/metadata-protocol': patch
6+
---
7+
8+
feat(spec, service-automation): a packaged flow can ship switched off for an administrator to turn on (`defaultActive: false`)
9+
10+
Clause-②: yes (widening) — `FlowSchema` gains the optional `defaultActive` boolean. A flow that declares it was refused before as an unknown key; a packaged flow that declares it now registers. A flow authored in the environment that declares it is still refused, now with a sentence naming its `status` as its switch. Nothing that registered before is refused.
11+
Metadata-protocol: added
12+
Skills-docs: updated here — skills/objectstack-automation/SKILL.md (one paragraph under "A flow an installed package ships"), evals/flows-triggers-approvals.json (eval id 24)
13+
14+
A package can now ship a flow switched off: declare `defaultActive: false` on the flow, beside `status: 'active'`. On an installation where no administrator has switched the flow, it is not armed and does not run, and `GET /api/v1/automation/_status` reports it `enabled: false`. An administrator turns it on with the packaged-flow switch (`POST /api/v1/automation/:name/toggle`, or the Enabled switch on a read-only package's flow in Studio), which writes an activation-ledger row (`sys_metadata_activation`). That row wins over the declared default in either state: a flow switched on stays on across a restart, an upgrade and a reinstall, and one switched off stays off. With no row the flow follows the package's own declaration for the version installed today, so an upgrade that changes it moves only installations nobody switched; a declared `.custom` override armed in the package's place does not change the default, whatever it declares. Absent or `true`, the flow ships on, as every packaged flow did before. A package that declares the key needs a platform at or above this release: an older one refuses the flow as an unknown key.
15+
16+
`status` stays the author's switch: `obsolete` and `invalid` disarm the flow everywhere, and the packaged-flow switch does not override them.
17+
18+
Only a flow a package ships has the packaged-flow switch, so:
19+
20+
- registering a flow authored in the environment that declares `defaultActive` is refused, with a sentence saying its switch is its `status` (`'obsolete'` to keep it off, `'active'` to arm it). The automation write doors (`POST /api/v1/automation`, `PUT /api/v1/automation/:name`) answer `VALIDATION_FAILED`, 400, and store nothing; a dry run refuses the draft; the metadata door (`PUT /api/v1/meta/flow/:name`), which parses without registering, stores the row, the engine refuses to arm it, and `os migrate meta --stored` lists it at the key;
21+
- `POST /api/v1/automation/:name/clone` drops `defaultActive` from the copy, which is written switched off by its own `status` as before;
22+
- an unmanaged install copies `defaultActive: false` as `status: 'obsolete'` (unless the status already disarms the flow) and drops the key, so the copy arrives switched off.
23+
24+
A name two packages ship is a package's flow too: each holder's body registers with the key, on every re-sync and upgrade, and the refusal above is only for a name no package ships.
25+
26+
For hosts that compose the engine themselves, `AutomationEngine.setPackagedFlowDefaultSource(source)` and its `PackagedFlowDefaultSource` type are new public API. The automation plugin attaches the reader (it asks the metadata protocol for the package's own body); it is how the engine reads the package's default while a declared `.custom` override is armed in the package's place, and it is asked once per registration, not on every enablement read. `AutomationEngine.refreshPackagedFlowDefaults()` is new public API too: it asks the reader again for every armed body that is not the package's own, and re-arms or disarms each flow whose answer moved; the automation plugin calls it at every `metadata:reloaded` re-sync, so a hot upgrade that changes the declared default reaches a flow whose override body was not re-registered. A host composing the engine itself calls it after the set of installed packages changes. An engine composed without a reader reads the default only off an armed package body, so while an override is armed a flow its package ships off runs (fail-open): such an engine cannot see the package's body, and treating an unknown default as on keeps the behaviour every packaged flow had before this release instead of switching off a flow no package was seen to declare off.
27+
28+
ADR-0126 §4 carries an amendment note: "absence of a row means the packaged default" now reads the default a packaged flow declares; the ledger's shape is unchanged.

‎content/docs/references/api/automation-api.mdx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ ledger (ADR-0126 §7.2). A flow authored in the deployment is not switched
3131
there. Its switch is its own `status`: `'obsolete'` disarms it and
3232
`'active'` arms it, published with the complete definition through
3333
`PUT /api/v1/automation/:name`. The toggle door refuses such a flow with
34-
409 `RESOURCE_CONFLICT`, names that switch, and changes nothing.
34+
409 `RESOURCE_CONFLICT`, names that switch, and changes nothing. It refuses
35+
the same way a switch ON of a packaged flow whose own `status` disables it
36+
(`'obsolete'` / `'invalid'`): the ledger row alone would leave the flow off
37+
while the caller read it as on, so it answers 409 `RESOURCE_CONFLICT`,
38+
names publishing the definition `'active'`, and writes nothing. A switch
39+
OFF of such a flow is accepted and records the choice.
3540

3641
**Endpoints**
3742
```
@@ -174,6 +179,7 @@ const result = AutomationApiErrorCode.parse(data);
174179
| **errorMessage** | `string` | optional | Text for a terminal failure, carried on AutomationResult for every terminal run (not only screen flows); the screen-flow UI shows it as a toast instead of the raw error. A `{{ }}` template over the run's variables, rendered over the variables at the failure point. |
175180
| **version** | `integer` | optional (default: `1`) | Version number |
176181
| **status** | `Enum<'draft' \| 'active' \| 'obsolete' \| 'invalid'>` | optional (default: `"draft"`) | Deployment status |
182+
| **defaultActive** | `boolean` | optional | Packaged flows only: `false` ships the flow switched off, so it is not armed on an installation until an administrator turns it on with the packaged-flow switch (the activation ledger); the administrator's choice, once made, wins over this default across restarts and upgrades. Absent or `true`: switched on. `status` stays the author's switch: `obsolete`/`invalid` disarm the flow everywhere. A flow authored in the environment is switched by `status` and may not declare this key. |
177183
| **type** | `Enum<'autolaunched' \| 'record_change' \| 'schedule' \| 'screen' \| 'api'>` | ✅ | Flow type |
178184
| **variables** | `{ name: string; type: string; isInput?: boolean; isOutput?: boolean; … }[]` | optional | Flow variables |
179185
| **nodes** | `{ id: string; type: string; label: string; config?: Record<string, any>; … }[]` | ✅ | Flow nodes |
@@ -303,6 +309,7 @@ const result = AutomationApiErrorCode.parse(data);
303309
| **errorMessage** | `string` | optional | Text for a terminal failure, carried on AutomationResult for every terminal run (not only screen flows); the screen-flow UI shows it as a toast instead of the raw error. A `{{ }}` template over the run's variables, rendered over the variables at the failure point. |
304310
| **version** | `integer` | optional (default: `1`) | Version number |
305311
| **status** | `Enum<'draft' \| 'active' \| 'obsolete' \| 'invalid'>` | optional (default: `"draft"`) | Deployment status |
312+
| **defaultActive** | `boolean` | optional | Packaged flows only: `false` ships the flow switched off, so it is not armed on an installation until an administrator turns it on with the packaged-flow switch (the activation ledger); the administrator's choice, once made, wins over this default across restarts and upgrades. Absent or `true`: switched on. `status` stays the author's switch: `obsolete`/`invalid` disarm the flow everywhere. A flow authored in the environment is switched by `status` and may not declare this key. |
306313
| **type** | `Enum<'autolaunched' \| 'record_change' \| 'schedule' \| 'screen' \| 'api'>` | ✅ | Flow type |
307314
| **variables** | `{ name: string; type: string; isInput?: boolean; isOutput?: boolean; … }[]` | optional | Flow variables |
308315
| **nodes** | `{ id: string; type: string; label: string; config?: Record<string, any>; … }[]` | ✅ | Flow nodes |
@@ -858,6 +865,7 @@ const result = AutomationApiErrorCode.parse(data);
858865
| **errorMessage** | `string` | optional | Text for a terminal failure, carried on AutomationResult for every terminal run (not only screen flows); the screen-flow UI shows it as a toast instead of the raw error. A `{{ }}` template over the run's variables, rendered over the variables at the failure point. |
859866
| **version** | `integer` | optional (default: `1`) | Version number |
860867
| **status** | `Enum<'draft' \| 'active' \| 'obsolete' \| 'invalid'>` | optional (default: `"draft"`) | Deployment status |
868+
| **defaultActive** | `boolean` | optional | Packaged flows only: `false` ships the flow switched off, so it is not armed on an installation until an administrator turns it on with the packaged-flow switch (the activation ledger); the administrator's choice, once made, wins over this default across restarts and upgrades. Absent or `true`: switched on. `status` stays the author's switch: `obsolete`/`invalid` disarm the flow everywhere. A flow authored in the environment is switched by `status` and may not declare this key. |
861869
| **type** | `Enum<'autolaunched' \| 'record_change' \| 'schedule' \| 'screen' \| 'api'>` | ✅ | Flow type |
862870
| **variables** | `{ name: string; type: string; isInput?: boolean; isOutput?: boolean; … }[]` | optional | Flow variables |
863871
| **nodes** | `{ id: string; type: string; label: string; config?: Record<string, any>; … }[]` | ✅ | Flow nodes |
@@ -1170,6 +1178,7 @@ const result = AutomationApiErrorCode.parse(data);
11701178
| **errorMessage** | `string` | optional | Text for a terminal failure, carried on AutomationResult for every terminal run (not only screen flows); the screen-flow UI shows it as a toast instead of the raw error. A `{{ }}` template over the run's variables, rendered over the variables at the failure point. |
11711179
| **version** | `integer` | optional (default: `1`) | Version number |
11721180
| **status** | `Enum<'draft' \| 'active' \| 'obsolete' \| 'invalid'>` | optional (default: `"draft"`) | Deployment status |
1181+
| **defaultActive** | `boolean` | optional | Packaged flows only: `false` ships the flow switched off, so it is not armed on an installation until an administrator turns it on with the packaged-flow switch (the activation ledger); the administrator's choice, once made, wins over this default across restarts and upgrades. Absent or `true`: switched on. `status` stays the author's switch: `obsolete`/`invalid` disarm the flow everywhere. A flow authored in the environment is switched by `status` and may not declare this key. |
11731182
| **type** | `Enum<'autolaunched' \| 'record_change' \| 'schedule' \| 'screen' \| 'api'>` | ✅ | Flow type |
11741183
| **variables** | `{ name: string; type: string; isInput?: boolean; isOutput?: boolean; … }[]` | optional | Flow variables |
11751184
| **nodes** | `{ id: string; type: string; label: string; config?: Record<string, any>; … }[]` | ✅ | Flow nodes |
@@ -1235,6 +1244,7 @@ const result = AutomationApiErrorCode.parse(data);
12351244
| **errorMessage** | `string` | optional | Text for a terminal failure, carried on AutomationResult for every terminal run (not only screen flows); the screen-flow UI shows it as a toast instead of the raw error. A `{{ }}` template over the run's variables, rendered over the variables at the failure point. |
12361245
| **version** | `integer` | optional (default: `1`) | Version number |
12371246
| **status** | `Enum<'draft' \| 'active' \| 'obsolete' \| 'invalid'>` | optional (default: `"draft"`) | Deployment status |
1247+
| **defaultActive** | `boolean` | optional | Packaged flows only: `false` ships the flow switched off, so it is not armed on an installation until an administrator turns it on with the packaged-flow switch (the activation ledger); the administrator's choice, once made, wins over this default across restarts and upgrades. Absent or `true`: switched on. `status` stays the author's switch: `obsolete`/`invalid` disarm the flow everywhere. A flow authored in the environment is switched by `status` and may not declare this key. |
12381248
| **type** | `Enum<'autolaunched' \| 'record_change' \| 'schedule' \| 'screen' \| 'api'>` | ✅ | Flow type |
12391249
| **variables** | `{ name: string; type: string; isInput?: boolean; isOutput?: boolean; … }[]` | optional | Flow variables |
12401250
| **nodes** | `{ id: string; type: string; label: string; config?: Record<string, any>; … }[]` | ✅ | Flow nodes |

‎content/docs/references/automation/flow.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const result = FlowSchema.parse(data);
3535
| **errorMessage** | `string` | optional | Text for a terminal failure, carried on AutomationResult for every terminal run (not only screen flows); the screen-flow UI shows it as a toast instead of the raw error. A `{{ }}` template over the run's variables, rendered over the variables at the failure point. |
3636
| **version** | `integer` | optional (default: `1`) | Version number |
3737
| **status** | `Enum<'draft' \| 'active' \| 'obsolete' \| 'invalid'>` | optional (default: `"draft"`) | Deployment status |
38+
| **defaultActive** | `boolean` | optional | Packaged flows only: `false` ships the flow switched off, so it is not armed on an installation until an administrator turns it on with the packaged-flow switch (the activation ledger); the administrator's choice, once made, wins over this default across restarts and upgrades. Absent or `true`: switched on. `status` stays the author's switch: `obsolete`/`invalid` disarm the flow everywhere. A flow authored in the environment is switched by `status` and may not declare this key. |
3839
| **type** | `Enum<'autolaunched' \| 'record_change' \| 'schedule' \| 'screen' \| 'api'>` | ✅ | Flow type |
3940
| **variables** | `{ name: string; type: string; isInput?: boolean; isOutput?: boolean; … }[]` | optional | Flow variables |
4041
| **nodes** | `{ id: string; type: string; label: string; config?: Record<string, any>; … }[]` | ✅ | Flow nodes |
@@ -260,6 +261,7 @@ const result = FlowSchema.parse(data);
260261
| **errorMessage** | `string` | optional | Text for a terminal failure, carried on AutomationResult for every terminal run (not only screen flows); the screen-flow UI shows it as a toast instead of the raw error. A `{{ }}` template over the run's variables, rendered over the variables at the failure point. |
261262
| **version** | `integer` | optional (default: `1`) | Version number |
262263
| **status** | `Enum<'draft' \| 'active' \| 'obsolete' \| 'invalid'>` | optional (default: `"draft"`) | Deployment status |
264+
| **defaultActive** | `boolean` | optional | Packaged flows only: `false` ships the flow switched off, so it is not armed on an installation until an administrator turns it on with the packaged-flow switch (the activation ledger); the administrator's choice, once made, wins over this default across restarts and upgrades. Absent or `true`: switched on. `status` stays the author's switch: `obsolete`/`invalid` disarm the flow everywhere. A flow authored in the environment is switched by `status` and may not declare this key. |
263265
| **type** | `Enum<'autolaunched' \| 'record_change' \| 'schedule' \| 'screen' \| 'api'>` | ✅ | Flow type |
264266
| **variables** | `{ name: string; type: string; isInput?: boolean; isOutput?: boolean; … }[]` | optional | Flow variables |
265267
| **nodes** | `{ id: string; type: string; label: string; config?: Record<string, any>; … }[]` | ✅ | Flow nodes |

0 commit comments

Comments
 (0)