Skip to content

feat(plugin-security, plugin-sharing): security and sharing stored references gain a package column, backfilled at boot (ADR-0150 D8 S2) - #31872

Merged
objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/project-thread-05s465
Nov 9, 2026
Merged

objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/project-thread-05s465

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Fixes #31683

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:权限集授予(R1)、受众绑定建议(R3)、受管共享规则(R5)、队列成员(R6)、分配游标(R13)这五处按名字存的引用,在名字旁各加一列可空的软件包列,启动时按唯一持有者回填;R3 的建议从提出建议的那个包出发解析。
  • 为什么改:ADR-0150 D8 要求先把包坐标存下来,后续各读者子卡才能按 (包, 名) 读,而不是靠一个可能撞名的裸名字。
  • 风险与回滚:本 PR 没有读者读新列,权限、共享、队列的答复逐字节不变;唯一键一个不动。回填失败只记一条警告、下次启动再试。回滚即还原本 PR,新列留空无害。
  • 先看:stored-permission-set-package-backfill.ts 与 stored-declaration-package-backfill.ts 里「被拒(歧义)就留空并点名全部候选」那一支。
  • 两分钟验证:在 plugin-security 与 plugin-sharing 各跑一次本卡测试文件,看「两个持有者留空、点名两个」「第二次运行写 0 行」两条用例。
  • 需要你做的:无;席位与史诗线程评审即可。

What changes

Five stored references name a declared item by its bare name. Each gains a nullable, read-only package column beside the name (ADR-0150 D8, column names as D8 spells them):

Row Table Name column New column Package
R1 sys_user_permission_set permission_set permission_set_package plugin-security
R3 sys_audience_binding_suggestion permission_set_name permission_set_package plugin-security
R5 sys_sharing_rule (rows with managed_by package or platform only) name package_id plugin-sharing
R6 sys_queue_member queue queue_package plugin-sharing
R13 sys_assignment_cursor rule rule_package plugin-sharing

At kernel:bootstrapped, once the registry has sealed its holders (bareNameHoldersAreSealed, the gate S1 #31727 uses), each plugin walks its tables with a keyset walk over the rows whose new column is null. It asks each name the one D3 rule, from the package that wrote the reference (epic review 6735731423):

  • R1 grants, R5 rule rows, R6 queue members and R13 cursors are the environment's own rows, so they are asked with no caller package.
  • An R3 suggestion is the reference of the package that made it (package_id), so it is asked from that package, as position.permissionSets is from its declaring package (D7). Its own set answers first (step 1), then the one holder in its declared closure. A set only an unrelated package holds is refused (outside-closure) and left null, never bound to that package. A suggesting package's own set binds to it even beside a pre-phase-1 clash with an unrelated package: that is D3's answer for it, not a pick. A row with no package_id is asked with no package.

plugin-security uses core resolvePackageScopedHolders, as E3 does; plugin-sharing uses objectql resolvePackageScopedName, as E4 does. There is no third walk and no first-registered fallback.

  • One package holds the name: the column is set to that package, by id, and nothing else on the row is written.
  • The rule refuses (two or more holders; for R3 also two holders in the suggesting package's closure, or none in it): the column stays null, and one warning per table names the name, the refusal reason, its row count and every candidate.
  • Only the environment or the platform holds it, or nothing holds it: the column stays null, and the name is reported.
  • A row that already names a package is never read as a candidate, so a second boot writes 0 rows and reports the same names.
  • R3 only: a suggestion bound to a declared dependency of the suggesting package rather than the package itself (so permission_set_package differs from package_id) is reported at warn (seat ruling Q2 A). On first-party boots this is 0.
  • If a table cannot be read, a warning says so, its rows stay as they are, and the next boot tries again. The boot goes on.

The R5 pass runs before plugin-sharing's existing rule-grant passes, in the same kernel:bootstrapped handler.

What does not change

  • No reader reads the new columns. Who holds which permission set, which rule shares what, and who a queue routes to answer as before. The dogfood CONTROL checks this byte for byte (below).
  • No unique key changes (seat ruling Q1 A). Every index on the five tables is pinned byte-identical to main, and the store still refuses a second row on each key whatever either row's package column says. So the S1 bar (a widened key must not let two package-less rows coexist) does not arise here: no package column joins a key.
  • Writers do not stamp the columns yet (seat ruling Q3 A). A row written after boot stays null until the next boot binds it. Hand-off, one per reader child:
    • R1 grants: the B child that moves resolve-authz-context and the grant writers (data door, plugin-auth admin endpoints, demo staff, IdP group mapping, the CLI ownership ceremony) onto (package, name).
    • R3 suggestions: the same child, at syncAudienceBindingSuggestions and confirm/dismiss.
    • R5 managed rule rows: the sharing-rule reader child, at SharingRuleService.defineRule.
    • R6 queue members: the queue reader child, at the data door and ownership-queue-service.
    • R13 cursors: the assignment-rule reader child. R13's only writer and reader is objectql assignment-rules.ts, not plugin-sharing; this PR adds only the column and its backfill and does not touch objectql.
    • The ambiguous set's operator report and the reviewed bind command are S4 (D10).
  • No packages/spec change, no metadata shape an author writes, no export added to either package root.

ADR-0150 readings

  • (a) The phase-1 one-holder tests stay green. objectql registry-bare-name-one-holder*.test.ts and package-scoped-resolver.test.ts, and core package-scoped-resolution.test.ts and security/security-catalog.test.ts, run on 7b8cb65b: 5 objectql files, 231 passed; 2 core files, 49 passed.
  • (b) Bare-name behaviour is unchanged for every name with one holder. No reader reads a new column. The dogfood CONTROL reads /auth/me/permissions for the administrator with the column null, filled, and forged to a package that holds nothing: the three answers are byte-identical. The plugin suites pass unchanged on 7b8cb65b (plugin-security 252 files, 6068 passed, 45 skipped; plugin-sharing 73 files, 1504 passed).
  • (c) The migration is re-runnable and never guesses. A second run writes 0 rows (update is never called) and reports the same ambiguous, unheld and unpackaged names. A name two packages hold stays null and is reported naming both, and an R3 set outside the suggesting package's closure stays null and is reported naming its holder. Each of these is ablated below.
  • (d) Clause-②: no. Nothing accepted on main is refused or newly accepted. No protocol change, so no ADR-0087 migration entry.

Tests

New files only; no existing test changed.

  • plugin-security/src/stored-permission-set-package-backfill.test.ts (18 tests) and plugin-sharing/src/stored-declaration-package-backfill.test.ts (11 tests). Both run on a real ObjectQL engine over SqlDriver (better-sqlite3), with a stand-in registry where one name has one package holder, one has two, one is the environment's and one has none. They pin: the one-holder bind; null plus both candidates for two holders; null plus a report for no holder; the environment item left null; a preset column never moved; only the column written; second run writes 0; R5 managed rows only; R3 asked from the suggesting package (a set only an unrelated package holds stays null and is reported; a dependency's set binds to it and is reported as differing; the package's own set binds to it beside an unrelated clash; two holders in its closure stay null, both named); the boot run waiting for the seal; one warning per table naming every candidate; a table it cannot read; every index byte-identical; the store still refusing a duplicate on each key.
  • packages/qa/dogfood/test/stored-reference-package-column.dogfood.test.ts (7 tests): the showcase boot across restarts of one SQL database file. The first boot binds its own grants to plugin-security and its suggestion to the showcase. Rows written with no package (a grant, a managed rule row) are bound after the next boot. An organization's own rule, a queue member and a cursor naming nothing stay null. Then the CONTROL above, and a further boot that moves no forged value and rewrites no bound row (its updated_at is unchanged). A memory-driver boot binds the grants too.

Ablations

Each mutation was applied to the committed file with scripts/ablation-replace.mjs, the named tests went red, and the file was restored to its HEAD blob with git diff HEAD empty.

Mutation Red
plugin-security: the refused case takes the first candidate 5 tests, including "two holders: left null, both named" and the boot warning
plugin-sharing: the same 5 tests
plugin-security: drop the null filter and the re-check 4 tests, including "a second run writes no row"
plugin-sharing: the same 2 tests, including "a second run writes no row"
plugin-sharing: drop the managed-row filter (R5) "binds the managed rows only"
plugin-security: drop the seal wait "waits for the holder seal"
plugin-sharing: drop the seal wait "waits for the holder seal"
plugin-security: never report an R3 row that differs "reports a row whose set another package holds" (run before the R3 fix; that pin is now "a set a declared dependency holds … reported as differing")
plugin-security: R3 asked with no caller package again (the callerColumn line deleted) 5 tests: unrelated-only stays null, dependency binds, own binds beside a clash, closure clash, and the dry-run differs
plugin-security: take the first candidate, after the R3 fix 8 tests
plugin-sharing: add queue_package to the queue member's unique key both unique-key pins

Acceptance notes

  • The keyset walk and report shape are written once in each plugin (about 60 lines apiece) rather than shared. Sharing them would mean a new export from one package root or a new shared module, which this card does not need; the two walks ask different rules (core vs objectql, per E3 and E4).
  • The step 0 table (where each reference lives, writers and readers, first-party row counts) is in the card thread. First-party boots: showcase R1 2 rows and R3 1 row, all with one holder; app-crm R1 2 rows; R5, R6, R13 0 rows on both; 0 ambiguous.
  • New field labels and descriptions are added to the 21 i18n bundles of each plugin (check-i18n-bundles --write). Simplified and Traditional Chinese are translated (plugin-sharing's queue-pages-zh-cn test requires every sys_queue_member label in Chinese); the other locales carry the English source until translated, as the script does for every new key.
  • The tenant-audit census is recounted (node scripts/tenant-audit-census.mjs --write, plus the hand-written figures on its page): the two backfill writes are two more engine write sites, each with an elevated system context and an object name chosen at run time (after merging main: 277 to 279 sites, 154 to 156 elevated, 80 to 82 undecidable).

Verification

  • Gates: node scripts/pm/dispatch-gates.mjs --commands listed 103 commands on 7b8cb65b; all 103 exit 0 (four that need built dists were re-run after the build), and --ran reconciles 103 derived, 103 run, 0 not measured.
  • pnpm lint (eslint, --no-inline-config) on plugin-security, plugin-sharing and the new dogfood file: exit 0 on each.
  • Typecheck of both plugins: exit 0 on each.
  • Dogfood file on 7b8cb65b, through os-verify-lock after building its closure: 7 of 7 passed (lock VERDICT command-exit 0).

…ferences gain a package column, backfilled at boot (ADR-0150 D8 R1 R3 R5 R6 R13)

Claude-Session: https://claude.ai/code/session_01ADHkmS1BmMxdV2aSDgqVSR
Co-authored-by: Claude <noreply@anthropic.com>
…ge backfill on a real SQL engine

Claude-Session: https://claude.ai/code/session_01ADHkmS1BmMxdV2aSDgqVSR
Co-authored-by: Claude <noreply@anthropic.com>
…ge columns, and no reader reads them

Claude-Session: https://claude.ai/code/session_01ADHkmS1BmMxdV2aSDgqVSR
Co-authored-by: Claude <noreply@anthropic.com>
…ve tables byte-identical, and the store still refusing a second row on each key

Claude-Session: https://claude.ai/code/session_01ADHkmS1BmMxdV2aSDgqVSR
Co-authored-by: Claude <noreply@anthropic.com>
…or the package columns, and add the changeset

Claude-Session: https://claude.ai/code/session_01ADHkmS1BmMxdV2aSDgqVSR
Co-authored-by: Claude <noreply@anthropic.com>
…abels into Simplified and Traditional Chinese

Claude-Session: https://claude.ai/code/session_01ADHkmS1BmMxdV2aSDgqVSR
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/xl 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 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/plugin-security, @objectstack/plugin-sharing, touching 82 documentable anchor(s).

29 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json a57a007d81c819fc2fdf15e9c240e9f5e273b13f.

⛔ 13 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 13 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 231 client-bound route-ledger rows — the other 166 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 166: 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; 107 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 — 20 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 a57a007d81c819fc2fdf15e9c240e9f5e273b13f → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 025070464d143a890f661ec7b2fb34129adc2802 — the merge of head 7b8cb65be011a7b203c8440f157bd79158b1529f into base a57a007d81c819fc2fdf15e9c240e9f5e273b13f, 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 025070464d143a890f661ec7b2fb34129adc2802 && git checkout 025070464d143a890f661ec7b2fb34129adc2802
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin a57a007d81c819fc2fdf15e9c240e9f5e273b13f 7b8cb65be011a7b203c8440f157bd79158b1529f && git checkout -B drift-repro a57a007d81c819fc2fdf15e9c240e9f5e273b13f && git merge --no-ff 7b8cb65be011a7b203c8440f157bd79158b1529f

node scripts/docs-audit/affected-docs.mjs --json a57a007d81c819fc2fdf15e9c240e9f5e273b13f

⚠️ 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 a57a007d81c819fc2fdf15e9c240e9f5e273b13f → 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

epic:#31527#1 · os-steve · session_01ADHkmP7o3uDTti21wLTfPf

Epic red-line review of #31872 (S2 #31683) at head b5471c2: CHANGES, one required fix (R3 only).

What passes

  • The columns use D8's own names. They are nullable, users cannot write them, and no reader or writer moves onto them, which keeps red line 3. The CONTROL shows /auth/me/permissions byte-identical whether the column is null, filled or forged.
  • No unique key changes, so S1's package-less bar does not come up.
  • The backfill waits for the holder seal, asks the one D3 rule (core resolvePackageScopedHolders / objectql resolvePackageScopedName), and never takes the first holder.
  • A refusal stays null and names every candidate, so red line 2 holds. A second run writes 0 rows.
  • R1, R5, R6 and R13 asked with no caller package are right:
    • An R1 grant is the environment's.
    • The R5, R6 and R13 columns record which item the row is of (the rule, the queue, the rule's cursor), and none of those rows names an authoring package.
  • The duplicated walker, the census recount from 276 to 278, and the zh labels are fine.

R1 (required): an R3 suggestion is a package's own reference, so it is resolved from that package.

A sys_audience_binding_suggestion row has package_id, the package that made the suggestion. ADR-0150 D3 says a reference resolves from the package that wrote it, as position.permissionSets does from the declaring package (D7). Asking with no caller package can bind a package's reference to a holder outside its closure.

The case: P suggests s and only an unrelated U holds s. This head writes permission_set_package = U and then reports that it "differs". The column is the stored answer that the permission-set B child will trust, so a stored loosening would sit in the table waiting for its reader. Red line 1 forbids that, and a report does not undo a write.

Fix:

  • For R3, pass callerPackageId = the row's package_id, or null when the row has none.
  • A refusal for that caller (outside-closure, ambiguous-in-closure) stays null and is reported with its candidates, like any refusal.
  • The step-1 own holding binds P even beside a pre-phase-1 clash with U. That is D3's target answer, and the changeset should say so.
  • "Differs" then means only "held by a declared dependency of the suggesting package". Keep reporting it.

Pins:

  • A suggestion from P where only an unrelated U holds the set stays null and is reported. Run it with the fix ablated (red), then with it (green).
  • P→D, where D holds the set: bound to D and reported as differing.
  • P beside a U clash: bound to P.

R1, R5, R6 and R13 are unchanged.

Re-ping the epic seat with the new head.

…the package that made it, so a set only an unrelated package holds is never bound

Claude-Session: https://claude.ai/code/session_01ADHkmS1BmMxdV2aSDgqVSR
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

epic:#31527#1 · os-steve · session_01ADHkmP7o3uDTti21wLTfPf

Epic red-line review of #31872 (S2 #31683) at head 7b8cb65: PASS. It lands once CI is green and the seat ACCEPTs.

My R1 from 6735731423 is met.

  • R3 is asked with callerPackageId = the row's package_id (null when the row has none). The resolution goes through the same core resolvePackageScopedHolders and the same packageScopedHoldersOf slice, so there is still one rule.
  • The update is per row, by id, using that row's own caller. Rows that share a name but come from different packages are never bound together.
  • A refusal for the caller stays null and is reported with its reason, the writing package and every candidate.
  • Step 1 (P beside a clash with U) binds P, and the changeset states that as D3's answer.
  • "Differs" now means only a declared dependency of the suggesting package.
  • The pins cover U-only (null, outside-closure), P→D (D, reported as differing), P+U (P), and D+D2 (null, ambiguous-in-closure). Dropping the caller column turns 5 of them red; take-first turns 8 red.
  • R1, R5, R6 and R13 are unchanged and asked with no caller package.

Red lines 1–3 hold. Every stored answer is the writing package's own D3 answer or null, the backfill never takes the first holder, and no reader moves.

Owed to later children:

  • The permission-set B child and S4 read these columns. Each one's writer starts stamping in the same PR as its reader, so rows written after boot stop waiting for the next boot pass.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#3 · os-steve · session_01ADHkmQXLfvyB5R53VDm3Ka

席位核对 · ACCEPT · #31872 (Fixes #31683, ADR-0150 child S2) · 2026-11-09T09:16Z

Head-sha: 7b8cb65b

  • Form: draft to main. The whole card lands here under Fixes #31683. Clause-②: no: the columns are stored only, and no reader, route or authored shape changes. Metadata-protocol: none.
  • Seat ruling 6734560017, as narrowed by the epic for R3: the columns use D8's names. R1 and R3 get permission_set_package, managed R5 rows get package_id (admin rows stay null), R6 gets queue_package, and R13 gets rule_package. Each is nullable and read-only. No unique key changes: every index is pinned byte-identical, and the store refuses a duplicate on each key whatever the package column holds. Writers do not stamp yet; the body names the hand-off to each reader child.
  • Backfill: it runs at kernel:bootstrapped after bareNameHoldersAreSealed, walks only rows whose column is null, and asks the one D3 rule (core resolvePackageScopedHolders in plugin-security, objectql resolvePackageScopedName in plugin-sharing). R1, R5, R6 and R13 ask with no caller package, because each column identifies the row's own item or an environment grant. R3 asks from the suggesting package (callerPackageId = the row's package_id), per the epic's CHANGES. A unique holder binds. A refusal, environment or platform holder, or no holder stays null and is reported, a refusal naming every candidate. A second run writes 0 rows with the same report. The suggesting package's own set binds beside a pre-phase-1 clash (step 1), as the changeset says.
  • Pins and ablations: plugin tests on real ObjectQL and SqlDriver. R3: U-only stays null, P depending on D binds D and is reported as differing, P beside a U clash binds P, and a D+D2 clash in the closure stays null naming both. Dogfood 7/7 across restarts. CONTROL: /auth/me/permissions is byte-identical with the column null, filled and forged. 11 ablations across the two rounds (take-first, caller dropped, second run, R5 filter, seal wait, R3 differs, widened key) are each red, then restored.
  • Epic review: CHANGES at b5471c22 (R3 only), then PASS at 7b8cb65b. The duplicated row walker (paging and writing only, so no package root gains an export) is ruled not a second mechanism. ADR-0150 readings (a)–(d) are in the body.
  • Declared deviations: the tenant-audit census is recounted to 279 for the two new backfill write sites, and zh-CN and zh-Hant labels are translated because a queue test requires them.
  • Gates: check-governed-merges --pr 31872: NOT governed, 2000 changed lines. K = 3 first-parent commits on main since the PR base, and a local merge with main is clean. dispatch-gates: 103/103 exit 0, --ran reconciled. plugin-security 6068 and plugin-sharing 1504 pass; lint and typecheck exit 0. CI on this head is running; auto-merge waits for it.
  • Landing: ready and auto-merge in this stroke. On merge: a landing record on security/sharing stored references gain a package column, backfilled (R1, R3, R5, R6, R13) (ADR-0150 child S2) #31683, pm:dispatched removed, and the card closed by Fixes.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 9, 2026 09:16
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 9, 2026 09:16
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit 4fd8db3 Nov 9, 2026
57 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-05s465 branch November 9, 2026 10:46
rajeev-kumar-se pushed a commit to rajeev-kumar-se/objectstack that referenced this pull request Nov 10, 2026
…dule): automation stored references gain a package column, and a dispatch key names its flow's package (ADR-0150 D8 S3) (objectstack-ai#31903)

<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9G8vs4TWZnL2DqxZzpGY1rv)_

Fixes objectstack-ai#31684

Clause-②: no
Metadata-protocol: none

## 维护者速读

- 需要你做的:**审批本 PR**。它是 3011 行(+2963 / −48),超过人工合并线 3000 行 11 行,所以要
GOVERNED_APPROVERS 批准后才能由席位走队列合入。没有触及任何受治理面(0 of 68 路径命中登记表),超线只因体量。
- 体量构成:业务源码约 1 370 行(含注释);测试约 1 420 行(5 个新测试文件 + 2 个现有测试文件追加,含真实启动的
dogfood);生成物约 150 行(两个包的 11 种语言 i18n 包,tenant-audit census
两个文件);changeset、vitest 配置、lockfile 若干行。没有为压线删改测试。
- 改了什么:
- 五处按名字存的引用各加一列可空、只读、由平台填写的软件包列:审批请求 `process_package`(R7,只回填
pending/returned)、暂停的流程运行 `flow_package`(R8)、流程凭据
`flow_package`(R9)、连接器连接 `connector_package`(R11)、旧邮件模板行
`package_id`(R20,内置模板名绑到 `com.objectstack.service.email`)。
- 启动(`kernel:bootstrapped`)时按 ADR-0150 D3
的唯一持有者规则(不带调用方包)回填;两个包都持有的名字留空并告警列出全部候选,绝不取第一个;第二次启动不写任何行。
  - 定时与相对时间触发的派发键(R10)带上流程所属的包:`schedule:包:流程:窗口`。
- 为什么改:ADR-0150 D8 要求先把包坐标存下来,后续读者子卡才能按 (包, 名)
读;派发键带上包,两个包同名的流程就不会共用一个时间窗。
- 风险与为什么安全:
  - 新列目前没有任何读者,写入方也不填(交接点在 PR 正文点名);五张表和派发账本的唯一键一个不动,均有逐字节钉住。
- 派发键改形:启动时先把 30 天保留期内的旧键复制成新键,复制完成前账本的认领、结算、读取都等待(最多 120
秒);新版本节点认领时**先插旧键、再插新键**,谁先插入旧键谁赢得该时间窗,所以滚动升级期间新旧节点共用一个仲裁,无论先后同一时间窗只触发一次;旧键与新键一起结算,旧节点的重放保护也能读到已送达。唯一不插旧键的是两个包同名的流程(防撞),本版本注册时就会拒绝,到不了。
  - 回填某张表失败只记警告、保留原样,下次启动再试,不阻断启动。
- 回滚:还原本 PR 即可。新版本一直同时写旧键,旧版本照常读旧键;新列可空、无读者,留着无害。
- 已核验:ADR-0150 史诗红线评审 PASS(R1 滚动升级双触发已按根治修复后复审);119
个派发门禁全过;四个包全量套件、dogfood 12/12、CI 全绿;关键机制(先插旧键、防撞、账本等待、过渡读、不取第一个、覆盖绑到
P)各自消融后变红再复原,表在 PR 正文。
- 先看:`packages/triggers/trigger-schedule/src/schedule-trigger.ts` 的
`claimDispatch` /
`dispatchKeys`,`packages/services/service-automation/src/engine.ts` 的
`flowDispatchHolder`,以及 `flow-dispatch-store.ts` 的 `holdUntil`。
- 两分钟验证:看 `schedule-dispatch-claim.test.ts` 的 describe「one arbiter
across a rolling upgrade」(旧节点与新节点两种先后各只触发一次),以及 dogfood 文件
`automation-stored-reference-package-column.dogfood.test.ts`
的「启动中的认领在重键之后作答」。

## What changes

### Five stored references gain a package column (R7, R8, R9, R11, R20)

Each column uses the name D8 gives it. Each is nullable, read-only to
users, and filled in by the platform.

| Row | Table | Name column | New column | Rows asked | Package |
|:--|:--|:--|:--|:--|:--|
| R7 | `sys_approval_request` | `process_name` (`flow:NAME`) |
`process_package` | open: `pending`, `returned` (seat Q5) |
plugin-approvals |
| R8 | `sys_automation_run` | `flow_name` | `flow_package` | `paused`
only (seat Q4) | service-automation |
| R9 | `sys_flow_credential` | `flow_name` | `flow_package` | all |
service-automation |
| R11 | `sys_connector_connection` | `connector_name` |
`connector_package` | all | service-automation |
| R20 | `sys_email_template` | `name` | `package_id` | all (legacy
overlay rows) | platform-objects (declared), plugin-email (backfill) |

The backfill runs at `kernel:bootstrapped`, once the registry has sealed
its holders (`bareNameHoldersAreSealed`). It walks the rows whose new
column is null (keyset walk) and asks each name the one D3 rule with no
caller package. That answer is the item's one holder in this
environment, which is the D4 identity of the row (seat answer 2,
6736840427; epic input 6736817259):

- Flows (R7, R8, R9) ask through the new
`AutomationEngine.flowHolder(name)`, which is the resolver the plugin
already attaches (`flowNameResolver`) asked with no caller. An
environment override of P's flow is P's flow overlaid, not a second
item, so its runs, requests and credentials bind to P. ⛔
`armedFlowPackage` is not used here; it stays the caller-side reader.
- Connectors (R11) ask `connectorNameResolver`, the same resolver the
connector reader uses.
- Email templates (R20) ask objectql `resolvePackageScopedName` with
type `email_template`. A name only the email service's built-in
templates hold resolves to that baseline (D3 (b), `via: baseline`), so
the row binds to `com.objectstack.service.email` (seat Q6).

For every reference:

- One package holds the name: the column is set to that package, by id.
Nothing else on the row is written.
- The rule refuses (two or more holders): the column stays null, and a
warning names the name, its row count and every candidate. There is no
first-registered fallback.
- Only the environment or the platform holds it, or nothing does: the
column stays null and the name is reported.
- A row that already names a package is never read again, so a second
boot writes 0 rows and reports the same names.
- If a table cannot be read, a warning says so, its rows stay as they
are, and the next boot tries again. The boot goes on.

### The dispatch key names its flow's package (R10)

The `sys_flow_dispatch` key (its primary `id`) is built in
`packages/triggers/trigger-schedule`. A flow that one package holds is
now keyed

    schedule:PACKAGE:FLOW:WINDOW_START
    time-relative:PACKAGE:FLOW:SCOPE:RECORD_ID

A flow the environment holds, or nothing holds, keeps the bare shape
`schedule:FLOW:WINDOW_START` / `time-relative:FLOW:SCOPE:RECORD_ID`. A
flow name is snake_case and a window start or scope begins with a date,
so the shapes never collide. The package comes from the same
`flowHolder`, through the new `AutomationEngine.flowDispatchHolder`, so
an overridden P flow keys as P. Because the key is the primary key, a
package-less key is still one row per window. S1's NULL-distinct problem
does not arise, and no index changes.

The seat's condition is that a window never fires twice across the
change. Three mechanisms meet it:

1. **The boot re-key, and the ledger held until it finishes.** At
`kernel:bootstrapped`, each bare-shape key inside the ledger's 30-day
retention (by `created_at`, the field the Reaper ages by) whose flow one
package holds gets a copy under the scoped key. The copy keeps the same
`dispatched_at`, `outcome` and `settled_at`. The bare row stays: the
ledger never deletes, and the Reaper owns deletion. A second run finds
every copy present and writes nothing. If a scoped key already exists (a
claim got there first, or another replica's re-key did), it is reported
`present` and never overwritten.
From `start()` until that run finishes, `ObjectStoreFlowDispatchStore`
holds every `claim`, `settle` and `read` (`holdUntil`). The hold is
released when the run settles either way, or after 120 s, which is
logged. So a trigger's first claim or replay-guard read after an upgrade
sees the copied rows. A kernel that dispatches no boot-phase hook holds
nothing and runs no re-key.
2. **The bare claim first (one arbiter across a rolling upgrade).** A
node of an older release claims only the window's bare-shape key. A node
of this release now inserts the bare key first and the scoped key
second, in one claim (`ScheduleTrigger.claimDispatch`,
`TimeRelativeTrigger.claimDispatch`; the replay guard's re-dispatch runs
through the same claim). Whoever inserts the bare key wins the window,
on either release and in either order, and two nodes of this release are
arbitrated by the same insert. A bare row an older node wrote, or the
re-key copied from, loses the window, with nothing claimed under the
scoped key. The schedule trigger settles the bare claim beside the
scoped one, so an older node's replay guard, which reads only the bare
key, reads the window as delivered.
3. **The transition reads.** The schedule replay guard reads both keys
(delivered under either one is refused), and
`AutomationEngine.recordMissedRun` takes `legacyDispatchKey` (a claim
under either key is `dispatched`, not missed).

**The collision guard.** `AutomationEngine.flowDispatchHolder(name)`
answers `{ packageId, claimBare }`. When two or more packages hold the
flow, `claimBare` is false and the key is scoped to the armed body's
package: the bare key would be one row for every holder, the
cross-package collision R10 removes, so it is neither claimed nor read.
That case is unreachable in this release, because `registerFlow` refuses
a second package's same-named flow (objectstack-ai#31754), so the pins drive it
through a doubled holder answer.

**Retiring the bare claim** is a later card, independent of D9: with the
guard in place the bare claim stays safe once D9 narrows the flow
backstop. The transition reads retire once the ledger's retention (30
days) has passed since every node runs this release.

### R14: no change. D8's note is met on `main`

E7 (objectstack-ai#31679, PR objectstack-ai#31730) already keys `sys_job` by runtime's `jobKeyFor`:
the first holder keeps the bare name, a second holder gets
`PACKAGE_ID:NAME`, and E7 never attributes a bare row to a package. The
run history stays as written. Nothing in this PR touches `sys_job`,
`jobKeyFor` or service-job. The pins are E7's and objectstack-ai#8578's, and both pass
on this head:

- `packages/runtime/src/app-artifact-handlers.jobs.test.ts`, the
describe "ADR-0150 E7: a job's package coordinate keeps the key the job
catalogue holds for it, across a restart": the key shapes. 41 passed.
- `packages/platform-objects/src/audit/sys-job.global-unique.test.ts`:
one unique index on `(name)`, `'global'`, byte-identical physical shape.
10 passed.

## What does not change

- **No reader reads the new columns.** The approval revise and resubmit
checks, resume, the credential channel, the connection door and the v18
ceremony all read the name as before.
- **No unique key changes** (seat Q2 A). Every index on the five tables,
and on `sys_flow_dispatch`, is pinned byte-identical to main.
- **Writers do not stamp the columns** (seat Q7 A). A row written after
boot stays null until the next boot binds it. R10's key writers are the
exception, because they are the key change. Hand-off, one per reader
child:
- R7 `process_package`: the flow child B, at
`ApprovalService.openNodeRequest` and its readers (`assertReviseEdge`,
the resubmit window, `attachFlowSteps`, the stranded sweep, the labels).
- R8 `flow_package`: child B, at `ObjectStoreSuspendedRunStore` (write
and `listByFlow` / resume).
  - R9 `flow_package`: child B, at `flow-credential-channel.ts`.
- R11 `connector_package`: the connector reader child, at
`connector-connections.ts` and `connector-credentials-ui.ts`.
- R20 `package_id`: the v18 promotion ceremony's reader (cli
`organization-ownership-plan.ts` / `-apply.ts`).
- The ambiguous set's operator report and a reviewed bind command: S4
(D10).
- No `packages/spec` change, and no metadata shape an author writes. Two
new package-root exports from service-automation, `bareDispatchKeyFlow`
and `scopedDispatchKey` (the key grammar the re-key reads, imported by
trigger-schedule's tests), and three new public engine methods,
`flowHolder`, `flowHolderPackage` and `flowDispatchHolder`. The seat
ruled the first four names stand; `flowDispatchHolder` is new in this
round.

## ADR-0150 readings

- **(a) The phase-1 one-holder tests stay green.** objectql
`registry-bare-name-one-holder*.test.ts` and
`package-scoped-resolver.test.ts`: 5 files, 231 passed. core
`package-scoped-resolution.test.ts` and
`security/security-catalog.test.ts`: 2 files, 50 passed. Run on
`50bfaf16`.
- **(b) Bare-name behaviour is unchanged for every name with one
holder.** No reader reads a new column. The one key that changes shape
is R10's, which D8 names. Every trigger, replay and missed-run answer
for a window is pinned the same across the change (a bare claim still
holds its window). Full suites on `50bfaf16`: service-automation 268
files, 3544 passed; trigger-schedule 12 files, 252 passed (both on
`e3251a85`); plugin-approvals 116 files, 1507 passed; plugin-email 51
files, 834 passed; platform-objects 120 files, 1934 passed.
- **(c) The migration is re-runnable and never guesses.** For every
reference and for the re-key, a second run writes 0 rows (`update` /
`insert` never called), and the dogfood's third boot writes no dispatch
row and moves no bound row. A name two packages hold stays null, or
keeps the bare key, and is reported naming both. Each is ablated below.
- **(d) Clause-②: no.** Nothing accepted on main is refused or newly
accepted. The dispatch key is internal to the ledger (no route, no API,
no export reads it), so no externally visible identifier changes. No
protocol change, so no ADR-0087 migration entry.

## Tests

New tests are added to existing files where noted; no existing assertion
was changed.

- `service-automation/src/stored-reference-package-column.test.ts` (21,
new). It runs on a real `ObjectQL` over `SqlDriver` (better-sqlite3) and
a real `SchemaRegistry` asked through `flowNameResolver` /
`connectorNameResolver`, as the plugin wires them. Covers:
- R8: the paused-only bind, decided rows untouched, the preset column
never moved, two holders null with both named, the environment's and the
unheld names reported.
  - **A paused run of an overridden P flow bound to P.**
- Second run 0 writes, dry run, R9, R11, the boot pass (only carried
tables; a failing table not fatal).
- R10: key grammar; the re-key copies in-retention keys only, keeps
every bare row, **keys an overridden P flow as P**, writes 0 on a second
run, and never overwrites a scoped key a claim took first.
- The store hold: claim and read wait for the re-key and then see the
copy; the 120 s bound releases; CONTROL with no hold.
- `flowDispatchHolder`: one package, the environment's and nobody's
flow, and the collision guard for a name two packages hold (armed
package doubled).
- The missed-run transition read; every index byte-identical; the
columns nullable and read-only.
- `trigger-schedule/src/schedule-dispatch-claim.test.ts` (+14 in three
new describes, existing file): the scoped key agrees with the re-key's
grammar; a tick claims the bare key first, then the scoped key, and
settles both; an environment flow keeps one bare claim; CONTROL with a
ledger without `flowDispatchHolder`; a settled and an unsettled bare
claim both hold the window; the replay guard and the missed-run check
read both keys; **an older node and a node of this release fire the
window once in either order; an older node's replay guard reads the new
node's delivery; two nodes of this release fire once; a name two
packages hold fires once per package and writes no bare row**.
- `trigger-schedule/src/time-relative-trigger.test.ts` (+8 in one new
describe, existing file): the key builder, the bare-then-scoped claim,
the bare key for no single holder, an older node's bare claim holds the
record, **an older node and a node of this release fire the record once
in either order, two nodes of this release fire once, a name two
packages hold fires once per package with no bare row**, and CONTROL. It
reuses the file's own doubles.
- `plugin-approvals/src/stored-process-package-backfill.test.ts` (5,
new): open statuses only, an overridden P flow's request bound to P,
refusals, second run 0, indexes byte-identical.
- `plugin-email/src/stored-template-package-backfill.test.ts` (3, new):
a baseline-only name bound to `com.objectstack.service.email`, an app's
override of a baseline bound to the app, refusals, second run 0, indexes
byte-identical. Forced: `@objectstack/driver-sql` added as a
devDependency of plugin-email (lockfile +3 lines) for the real engine.
- **Forced edit to an existing object, named:**
`sys_approval_request.searchableFields` gains `process_package` beside
`process_name`. `sys-approval-request.search-fields.test.ts` (objectstack-ai#24625)
holds the declared search set to the ADR-0061 auto-default minus the
snapshot, so a new text column must be searched or that pin goes red.
The test file itself is unchanged. The column is platform-filled and
holds a package id; a `$search` for a package id now also matches the
open requests bound to it. This is the one reader-visible change outside
R10's key, and it is in `open_questions`.
- Forced config edits: plugin-approvals' `vitest.config.ts` declares
`OS_REGISTRY_LOG: 'warn'` (`check:registry-log-declared`: the new suite
boots a real `SchemaRegistry`), and plugin-email's aliases
`@objectstack/driver-sql` to source (`check:test-source-alias`).
-
`packages/qa/dogfood/test/automation-stored-reference-package-column.dogfood.test.ts`
(5, new). The showcase boots across restarts of one SQL file:
- **A probe plugin that starts after the automation service claims the
scoped key without waiting. Its claim answers only after the boot's
re-key, and reads the window as already claimed** (seat condition 1, on
a real boot with an in-retention old-key row).
- The scoped copy keeps `dispatched_at` and `outcome`; the bare row
stays; a key of an undeclared flow and a key outside retention are not
copied.
  - R8, R7 and R20 rows bind to the showcase and to the email baseline.
  - A third boot writes nothing.

## Ablations

Each mutation was applied to the committed file with
`scripts/ablation-replace.mjs`. The named tests went red, and the file
was restored to its HEAD blob with `git diff HEAD` empty.

| Mutation | Red |
|:--|:--|
| schedule `claimDispatch`: drop the bare-first claim | 6, including "an
older node first, then a node of this release: the window fires once",
"a node of this release first, then an older node …" and "an older
node's replay guard reads the window a node of this release delivered as
delivered" |
| time-relative `claimDispatch`: drop the bare-first claim | 3,
including "rolling upgrade: an older node and a node of this release
fire the record once, in either order" |
| schedule `dispatchKeys`: drop the collision guard (`claimBare`
ignored) | "the collision guard: a name two packages hold fires once per
package and writes no bare row" |
| time-relative sweep: drop the collision guard | "the collision guard:
a name two packages hold fires the record once per package and writes no
bare row" |
| engine `flowDispatchHolder`: a refusal answers `claimBare: true` |
"the collision guard: a name two packages hold never claims the bare key
…" |
| schedule replay guard: read the scoped key only | "the replay guard
reads both keys" |
| engine `recordMissedRun`: ignore `legacyDispatchKey` | "a window
claimed under its bare key … is dispatched, not missed" |
| `storedReferenceHolderOf`: a refusal takes the first candidate | 8
tests (R8, R9, R11 two-holder pins, second run, dry run, the re-key's
ambiguous report) |
| `flowHolder` answers from `armedFlowPackage` (the caller reading) | 11
tests, including "a paused run of an overridden P flow is bound to P"
and the re-key's "keys an overridden P flow as P" |
| the store hold removed (`holdUntil` sets nothing), unit | "a claim, a
settle and a read made while held answer only once the re-key settles",
"a re-key that never finishes releases the ledger at the bound" |
| **the store hold removed, dist leg on the real boot** (rebuilt;
`ablation-dist-preflight` saw the marker in 2 built files, then absent
after restore) | the dogfood "a claim made during the boot answers after
the re-key" (`expected true to be false`: the probe minted the window
again) and "gains its scoped copy" (the scoped row carries the probe's
new `dispatched_at`) |

## Acceptance notes

- **Surface.** Every changed source file is in the amended surface.
These are outside it, each forced:
- The dogfood test: the seat asked for the ordering pin "on a real
boot".
- `pnpm-lock.yaml` and plugin-email's `package.json`: the devDependency.
- The i18n bundles of platform-objects and plugin-approvals
(`check-i18n-bundles --write`, with Chinese for the two new labels).
- The tenant-audit census and its page: the four boot-pass writes are
four more engine write sites, each with an elevated system context and
an object chosen at run time; after merging main (S2 objectstack-ai#31872 included),
279 to 283 sites, 156 to 160 elevated, 82 to 83 undecidable
(`tenant-audit-census.mjs --write` plus the hand-written figures).
- **No rolling-upgrade residual.** The seat's earlier acceptance of one
is withdrawn (epic review, R1): the bare-first claim gives old and new
nodes one arbiter, so the changeset's "no window fires twice across the
change" holds as written. The one case that claims no bare key, a flow
two packages hold, is unreachable under phase 1 and named in the
changeset.
- **The key grammar is spelled twice.** The writer (`trigger-schedule`)
and the reader (service-automation's `bareDispatchKeyFlow` /
`scopedDispatchKey`) each spell it, held equal by tests, because
trigger-schedule has no runtime dependency on service-automation.
- **A resolver that throws keys by the bare shape.** If
`flowDispatchHolder` (or the resolver behind it) throws, both triggers
fall back to the bare key and one claim, as before the package segment
existed. For flow's B card: once a reader binds by package, that
fallback is where a resolver failure would show.
- **Step 0 and counts** are in the card thread (`31684-step0.md`). On
first-party boots every reference has 0 rows except R14's one
`approvals-sla-escalation` job, and there are 0 ambiguous names.
- The keyset walk and report are written per package rather than shared,
as S2 did: sharing them would need a new cross-package export. The email
walk pages by id by hand, because plugin-email does not depend on
`@objectstack/types`.

## Verification

- Gates: `node scripts/pm/dispatch-gates.mjs --commands` listed 119
commands on `50bfaf16`, and the same 119 on `e3251a85` (the R1 round),
all exit 0 on both, `--ran` 119/119, 0 not measured; all 119 exit 0
after a full build, re-run in full after merging main (the first round,
before the build, had two `PREREQUISITE NOT MET` exits and three
findings, fixed in this branch: a test stand-in carrying `update`,
plugin-approvals declaring no `OS_REGISTRY_LOG`, and plugin-email
importing `@objectstack/driver-sql` unaliased). `--ran` reconciles 119
derived, 119 run, 0 not measured, 0 unrun.
- `eslint --no-inline-config` on the 23 changed source and test files:
exit 0 (the six files the R1 round touched re-linted on `e3251a85`: exit
0; `tsc --noEmit` of trigger-schedule, service-automation and its test
config: exit 0).
- Typecheck (`tsc --noEmit`) of service-automation, plugin-approvals,
plugin-email, trigger-schedule and platform-objects: exit 0 each. The
test configs of service-automation and plugin-email: exit 0.
plugin-approvals' test config reports 321 errors, all in test files this
PR does not touch (0 in the new one).
- Dogfood files re-run on `e3251a85` under `os-verify-lock`: 12 of 12
(this file 5, S2's 7), VERDICT command-exit 0.
- Dogfood file on `50bfaf16`, through `os-verify-lock` after building
its closure (turbo 70/70): 5 of 5 passed, run beside S2's dogfood file
(7 of 7) after the merge (lock VERDICT command-exit 0). CI on
`50bfaf16`: every check run completed green or skipped.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01ADHkmQCZK8QWzn7ZRaop1P

<!-- signed: domain:server#3 · os-steve ·
session_01ADHkmQCZK8QWzn7ZRaop1P -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
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/xl 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/sharing stored references gain a package column, backfilled (R1, R3, R5, R6, R13) (ADR-0150 child S2)

1 participant