Skip to content

feat(spec, plugin-sharing): ownership-queue reads take the caller package, so a declared rule's queue recipient resolves by ADR-0150 D3 - #31789

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-llj89i
Nov 9, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-llj89i

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread

Fixes #31734

Clause-②: yes (widening); narrowing per ADR-0150 D3 declared below
Metadata-protocol: none
Narrowing (ADR-0150 D3): a declared sharing rule whose package P depends on a disabled package D, where an unrelated package U declares a queue of the same name. Before (main 43fb4822): the rule granted to U's queue members, silently. After: the recipient is refused, outside-closure, naming U, logged once at warn (D3 never reaches U, and a disabled package holds nothing for this read); U's members gain no grant, grants the rule already holds are kept, as for any refused recipient. Pin: refuses when the holder the caller reaches is disabled, naming the unrelated holder as outside the closure — never serving it, never silent (ablations A4–A6). First-party: 0 (no first-party package declares a queue). Seat 3 ruled it the D3 answer.

维护者速读

  • 改了什么:所有权队列服务契约(IOwnershipQueueService)的三个按队列名读取的方法(resolveQueue、expandMembers、isMember)加了一个可选的「调用方软件包」参数。共享插件在读「声明的共享规则」的队列接收方时,把规则所在的包传进去,队列就从这个包出发解析:本包的队列,否则它声明依赖的包里唯一持有者,否则拒绝并列出全部候选。不传参数时与今天完全一样。
  • 为什么改:E4(feat(plugin-sharing)!: declared sharing rules, queues and assignment rules resolve on (package, name) #31728)落地时契约里没有调用方,只能整环境解析,所以「规则的依赖包和一个无关包都有同名队列」会被拒绝。这比 ADR-0150 D3 更严。本卡把这半补上(专题 design(metadata): address behavioural metadata by package — key flows, actions, jobs and other non-object types by (package, name); re-open ADR-0028 (replaces #30806 phase 3 renames) #31527)。
  • 风险与回滚:只影响「两个已安装的包声明了同名队列,且某个包里的共享规则把它当接收方」的部署。第一方实测 0 个包声明队列。另有一个边角情形(规则依赖的那个包被禁用、无关包有同名队列):以前悄悄发给了无关包的成员,现在拒绝,日志 warn 一次,点名那个无关包。回滚即 revert 本 PR。
  • 先看:packages/plugins/plugin-sharing/src/package-scoped-declarations.ts 的 resolveDeclaredName(调用方分支);sharing-rule-service.ts 的 queueRecipientCaller;packages/spec/src/contracts/ownership-queue-service.ts 的新可选键。
  • 两分钟验证:pnpm --filter @objectstack/plugin-sharing exec vitest run src/package-scoped-declarations.test.ts,预期 23 个用例全绿(新增 6 个)。
  • 需要你做的:无,席位落地。

What changes

  • Contract (@objectstack/spec/contracts). resolveQueue, expandMembers and isMember take an optional callerPackageId (new exported type OwnershipQueueCallerPackage = string | null). With a package id the name resolves from that package (ADR-0150 D3). Omitted, null or '', the read is environment-wide, as before. queuesOf and hasAnyQueue name no queue and take none. declaredQueueNamed (the activation door's lookup) is unchanged: the door belongs to no package. An implementation written before the key still satisfies the contract (pinned).
  • Resolution (package-scoped-declarations.ts). resolveDeclaredName takes an optional caller package. With one and a registry that carries the package-scoped slice, the answer is objectql's resolvePackageScopedName from that package, final: no one-listed-item shortcut (the one listed item may be outside the package's reach), and no first-registered fallback. The listing still bounds it: the resolver is asked over listedHoldersView(registry), which leaves out a holder whose package is disabled (the filter listItems applies) and changes nothing else. So a package whose one reachable holder is disabled gets the resolver's own outside-closure refusal naming every holder still served, never the disabled holder's item and never silence. Without a caller package nothing changes.
  • Queue service (ownership-queue-service.ts). The three reads pass callerPackageId to that resolution. Refusals answer as E4's do: null / [] / false, or under onFailedRead: 'refuse' a PackageScopedNameRefusedError (409 RESOURCE_CONFLICT, every candidate named), reported once per name and caller.
  • Rule service (sharing-rule-service.ts). assertQueueRecipientReachable becomes queueRecipientCaller: the same P-side check (now over the same listedHoldersView), which still throws and reports its refusal first, and then it hands the rule's package to isMember / expandMembers. The check stays ahead of the read on purpose, so a queue service written before the key (environment-wide) can never serve a holder outside P's reach. New queueRecipientPackageOf(rule) answers the rule's package for a look-through that grants nothing.
  • BU look-through (sharing-plugin.ts). "Does this queue recipient read the BU tree?" now resolves the rule's queue from the rule's package, so it reads the queue the grants are read from.
  • Position look-through (queuesNaming). It reads every declared holder's specifications, not only the names an environment-wide read serves. Without this, a rule served by D's q (a name U also declares) would not be re-evaluated when a position moves in D's queue, and its grants would go stale. Including a name more often only re-evaluates a rule, which then answers as before.
  • Changeset: patch for @objectstack/spec and @objectstack/plugin-sharing, with both declaration lines.

Step 0: every implementer and caller of the contract

Measured at 43fb4822 (main with E4).

Site Method Caller package after this PR
plugin-sharing OwnershipQueueService (the one registered implementation) implements all reads it
spec ownership-queue-failed-read.pin.test.ts legacy double implements, no key compiles unchanged (pinned)
plugin-sharing sharing-rule-service.ts (rule recompute, per-user pass) expandMembers, isMember the declared rule's package
plugin-sharing sharing-plugin.ts (BU-tree look-through) resolveQueue the declared rule's package
plugin-sharing sharing-service.ts (sitting-record access path) queuesOf, isMember none (no package asks)
plugin-security authz-middleware, explain-access isMember none
plugin-security ownership-queue-gate.ts, kernel-queue-membership.ts resolveQueue, queuesOf none
plugin-hono-server current-user-endpoints.ts hasAnyQueue none (takes no name)
runtime catalog-activation.ts (activation door) declaredQueueNamed none (unchanged method)
objectql assignment-rules.ts (assignment pool) resolveQueue, expandMembers none: see Acceptance notes
plugin-approvals approval-service.ts (approver slate) expandMembers none: see Acceptance notes

Every caller that passes no key compiles and answers as before. Test doubles in objectql, plugin-approvals and plugin-security are untouched.

Tests

New top-level describe in the E4 harness src/package-scoped-declarations.test.ts (6 cases, real SchemaRegistry):

  • P = ALPHA depends on D = BETA; U = GAMMA is unrelated; BETA and GAMMA each declare queue support. From ALPHA, resolveQueue answers BETA's queue, expandMembers answers ['u_beta'] (also under refuse), isMember is true for u_beta and false for u_gamma. Red on main.
  • The declared rule in ALPHA naming support: the standing grant to u_beta is still desired (revokeRuleGrantsForRetiredRecipients returns 0). Red on main (main throws the two-holder refusal).
  • ALPHA depends on BETA and GAMMA, both declare support: refused, ambiguous-in-closure, candidates BETA and GAMMA, 409 RESOURCE_CONFLICT under refuse, nothing under nobody.
  • No caller package (undefined, null, ''), same fixture as the first case: refused environment-wide naming BETA and GAMMA, exactly as main.
  • BETA disabled: from ALPHA resolveQueue is null and expandMembers []; under refuse a 409 outside-closure refusal naming GAMMA; the queue service warns once naming GAMMA; the declared rule's recompute throws the same refusal and the rule service warns naming GAMMA. Red on main (main serves GAMMA's members, silently).
  • queuesNaming('position', …) finds support from either holder's position. Red on main.

Forced test change: packages/spec/src/contracts/ownership-queue-failed-read.pin.test.ts pinned the exact option keys (_ExpandOptionKeys, _IsMemberOptionKeys); both now include callerPackageId. The file gains a second describe with the new key's type pins. No other existing test was edited.

Acceptance notes

  • Claim's "only the D-and-U case moves". Measured by running the new block against main's plugin source (git restore --source=43fb4822 on the four source files, then restored, git diff HEAD empty): 5 of the 6 new cases are red on main, 18 of 23 in the file green. The D-and-U case moves from refused to resolved, as the card asks. Two other cases also move, and both are declared here for the seat:
    • A disabled dependency. P depends on D, D is disabled, U holds the same queue name. Main serves U's queue to P's rule, silently (the P-side check passes through D, then the environment-wide listing sees only U). This PR refuses it, naming U as outside P's closure, and reports it. That is a narrowing of a wrong answer, first-party count 0 (no first-party package declares a queue). Seat 3 accepted it as the D3 answer; the epic seat asked that it be reported, naming U; declared on the Narrowing line above and in the changeset.
    • The position look-through. It now includes names two packages declare. A rule naming such a name re-evaluates on a position write; for a rule with no package that re-evaluation answers the refusal it already answers on every other recompute (its grants are kept and it warns), so the visible difference is that warning on one more path.
    • The two-holders-in-closure case refuses on both trees; only the refusal's vocabulary moves (ambiguous-in-environment with no caller on main, ambiguous-in-closure naming ALPHA here). Same candidates, same 409.
  • Other package-written queue references. A declared assignment rule's queue (objectql assignment-rules.ts) and an approval step's queue (plugin-approvals) are also written inside a package and still read environment-wide. That is stricter than D3, never looser, the same interim E4 accepted for this card. Outside this card's file surface; carrier: epic design(metadata): address behavioural metadata by package — key flows, actions, jobs and other non-object types by (package, name); re-open ADR-0028 (replaces #30806 phase 3 renames) #31527 seat.
  • New public name OwnershipQueueCallerPackage and the option key callerPackageId (the resolver's own PackageScopedQuery key). The seat's call.

Verification

Head f9c4e48b. Source last changed at d1d77686 (the listed-holders view and the disabled-dependency refusal); f9c4e48b only rewords the changeset, and check-adr-0087-registration, check-changeset-no-major, check-empty-changeset, check:issue-citations, check:nul-bytes and check:doc-authoring re-ran exit 0 on it.

  • On d1d77686: pnpm --filter @objectstack/plugin-sharing test (under the lock): Test Files 72 passed (72), Tests 1493 passed (1493). New block 6/6; harness file 23/23. typecheck exit 0. Root eslint --no-inline-config packages/plugins/plugin-sharing/src exit 0; packages/spec/src/contracts exit 0 (on 20a19d69, unchanged since).
  • @objectstack/spec: typecheck exit 0; check:test-typecheck OK (52 files / 240 errors / 131 signatures held, unchanged); contract pin file 2/2; check:generated after --fix: api-surface and export-origins regenerated (+OwnershipQueueCallerPackage, 1 added, 0 breaking).
  • Contract consumers (a spec contract changed): typecheck exit 0 for @objectstack/objectql, plugin-approvals, plugin-security, plugin-hono-server and runtime; their queue suites green: objectql ownership-queue.test.ts 41/41, plugin-security kernel-queue-membership + ownership-queue-gate 46/46, plugin-approvals approval-service.test.ts 463/463.
  • dispatch-gates --ran on d1d77686 (re-derived; a full turbo run build --filter=./packages/** ran first on 20a19d69, lock VERDICT exit 0): 94 derived, 94 run, 0 NOT-MEASURED, 0 UNRUN, every one exit 0. Also 94/94 exit 0 on 20a19d69.
  • Dogfood, full battery on 20a19d69 under the lock (not owed: no ! and no narrowing arm): Test Files 440 passed, 3 skipped (443); Tests 3652 passed, 41 skipped (3693); VERDICT command-exit 0. Not re-run on d1d77686: the only behaviour that moved since is the disabled-dependency refusal, which no first-party package can reach (0 queues declared).
Ablations: five legs, each red, each restored (scripts/ablation-replace.mjs)

plugin-sharing tests import its source directly; no dist leg. Each leg: anchor 1 to 0, blob changed, run red, restored with blob == HEAD and git diff HEAD empty.

  • A1, the caller-package refusal answered as the first listed holder (resolveDeclaredName): 1 red, refuses when the caller's closure reaches two holders, naming both.
  • (A2, run on 20a19d69 against the earlier silent not-found, is superseded: that code is gone.)
  • A3, the no-caller refusal answered as the first listed holder: 9 red, the 8 E4 two holders pins and reads environment-wide without a caller package ….
  • On d1d77686, for the epic seat's condition (the disabled-dependency refusal is reported, naming U):
    • A4, the caller-package refusal silenced (answered not-found): 2 red, refuses when the caller's closure reaches two holders … and refuses when the holder the caller reaches is disabled, naming the unrelated holder ….
    • A5, listedHoldersView unfiltered (a disabled holder counted): 1 red, the disabled-dependency pin (the disabled holder's queue served).
    • A6, the rule service's own check over the raw registry instead of the view: 1 red, the same pin (its warning naming GAMMA missing). That is the guard that holds for a queue service written before the key.

🤖 Generated with Claude Code

…red rule's queue recipient resolves from its package

Claude-Session: https://claude.ai/code/session_01ADHkmQs1r4citFGcqUhPZE
Co-authored-by: Claude <noreply@anthropic.com>
…cy wins, closure ambiguity refused, no package unchanged)

Claude-Session: https://claude.ai/code/session_01ADHkmQs1r4citFGcqUhPZE
Co-authored-by: Claude <noreply@anthropic.com>
…ueueCallerPackage

Claude-Session: https://claude.ai/code/session_01ADHkmQs1r4citFGcqUhPZE
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 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-sharing, @objectstack/spec, touching 18 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

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

  • content/docs/permissions/sharing-rules.mdx (via SharingRuleService (symbol, a top-level class))

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

  • content/docs/releases/implementation-status.mdx (via expandRecipient (symbol, a method of class SharingRuleService))

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

What this run could not see
  • 2 changed file(s) yielded no anchor (packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json) — pages documenting those are invisible to this run
  • 2 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 — 171 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 87d945873da8e13ae2b6ee5ac43c075203abc337 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 87d945873da8e13ae2b6ee5ac43c075203abc337

⚠️ 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 87d945873da8e13ae2b6ee5ac43c075203abc337 → 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: #31734 (E4 Q1 follow-up), head 20a19d6 · 2026-11-09T03:59Z

Verdict: PASS, once the one declaration below is in. No re-review is needed.

Red line Reading
1. Never loosens resolveQueue / expandMembers / isMember take an optional callerPackageId. Without it, the read is environment-wide as before. With it, the read is D3 from the rule's package: own, then the unique holder in the declared closure plus sys, then a refusal. The D-and-U case now resolving to D is the target D3 answer, which E4's interim refused on purpose ("stricter than D3, never looser", 6729421618). It is not a loosening.
2. Ambiguity reported, never guessed It goes only through resolvePackageScopedName, with no first-registered fallback. Two holders in the closure are refused ambiguous-in-closure, naming both (409 RESOURCE_CONFLICT under refuse). Ablations A1–A3 are red.
3. Independently releasable Clause-②: yes (widening) for the optional contract key, and an implementation written before it still satisfies the contract. Gates 94/94, plugin-sharing 1493/1493, dogfood VERDICT 0.

Required declaration:

  • Deviation (1) is a narrowing: a disabled dependency D, with an unrelated U holding the name, used to serve U's queue to P's rule and now serves nobody. That is the right D3 answer, since U is outside the closure, but the changeset's "every other answer is unchanged" does not cover it.
  • Add it to the PR body's Narrowing: line and to the changeset, with the first-party count of 0.
  • Make sure the refusal is reported with U named (outside-closure), not silent.

Accepted:

  • (2) The position look-through over every declared holder.
  • (3) The name OwnershipQueueCallerPackage, the seat's call.

(4) Carrier: yes, file the card. Assignment rules and approval steps still read package-written queue names environment-wide, which is stricter than D3. That is the same interim shape, and the reads should pass the declaring package's id. The card is domain:server, Part of #31527, Blocked-by: #31734.

Seat 3 accepts and lands this after the declaration and green CI. It is not a governed surface: packages/spec contracts are not on the governed list.

… disabled is refused, naming the holders the listing serves

Claude-Session: https://claude.ai/code/session_01ADHkmQs1r4citFGcqUhPZE
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, final: #31734, head f9c4e48 · 2026-11-09T04:33Z

Verdict: PASS. I re-read the source change in d1d7768.

listedHoldersView takes disabled packages out of the holder set before the resolver runs. That is the same population listItems serves, which E4's readers already bound to (6729421618), so a disabled package is never a holder here, neither for an answer nor for ambiguity.

  • The case of a disabled dependency D with an unrelated U holding the name now reaches the resolver's own outside-closure refusal naming U: a 409 under refuse, both loggers warn once, and U gains no grant.
  • Before this change, the read resolved to D and was then discarded as hidden, which reported nothing.
  • The pin is cited in the Narrowing: line, and ablations A4, A5 and A6 are red.

Seat 3 accepts and lands this after green CI, with CI's Dogfood Regression Gate standing in for a local re-run. It is not a governed surface.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#3 · os-steve · session_01ADHkmQXLfvyB5R53VDm3Ka

席位核对 · ACCEPT · #31789 (Fixes #31734, ADR-0150 E4 follow-up) · 2026-11-09T05:10Z

Head-sha: f9c4e48bb719c84107f3e6f4374da957b19f96b8

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 9, 2026 05:10
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 9, 2026 05:10
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit fdfcc7a Nov 9, 2026
71 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-llj89i branch November 9, 2026 05:40
rajeev-kumar-se pushed a commit to rajeev-kumar-se/objectstack that referenced this pull request Nov 10, 2026
… read the queue they name from their declaring package (ADR-0150 D3) (objectstack-ai#31850)

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

Fixes objectstack-ai#31790

Clause-②: yes (widening); narrowing per ADR-0150 D3 declared below
Metadata-protocol: none
Skills-docs: follow-up owed, filed as objectstack-ai#31853 (domain:skills, blocked by
objectstack-ai#31790) — skills/objectstack-automation/SKILL.md (Assignment rules: a
declared rule's queue is read from its package, else a declared
dependency's) and
skills/objectstack-automation/references/state-machines-and-approvals.md
(Approver Types: a `queue` approver likewise, from the flow's package).
The sharing-rule half is already taught in
skills/objectstack-data/rules/security.md.
Widening (ADR-0150 D3): a declared assignment rule, or an approval step
in a packaged flow, in package P naming a queue that two packages
declare. Before (main `fdfcc7ab`): refused `ambiguous-in-environment`.
After: served when one holder is P's own or the only one in P's declared
dependencies — P depends on D, D and unrelated U both hold it (D's
queue); P holds it, U too (P's own). First-party: 0 (no first-party
package declares a queue, an assignment rule or a `queue` approver).
Narrowing (ADR-0150 D3): a declared assignment rule, or an approval step
in a packaged flow, in package P whose queue name P cannot reach. Before
(main `fdfcc7ab`): served environment-wide. After: refused
`outside-closure`, naming every candidate. Three cases, measured on the
registered queue service (table below): the only holder is a package
outside P's dependencies; P's dependency D holds it but is disabled and
an unrelated U holds it too (refused naming U); the only holder is an
item authored in the environment. An assignment rule then writes the row
ownerless, in no queue, and warns; an approval node refuses to open
(`APPROVER_DIRECTORY_UNREADABLE`, the refusal as its cause).
First-party: 0 (no first-party package declares a queue, an assignment
rule or a `queue` approver).
Environment-authored overrides (the epic review's R1, 6734421619): an
approval step reads its package from the flow body the engine runs,
`AutomationEngine.armedFlowPackage` (objectstack-ai#31863). An environment-authored
`.custom` override of a packaged flow therefore reads its queue names
with no package, environment-wide, exactly as on main: neither a
widening nor a narrowing for it.

## 维护者速读

-
改了什么:软件包里声明的「分配规则」和流程里的「审批步骤」引用队列名时,现在把声明它的软件包(规则所在的包、流程所在的包)交给队列服务,队列从这个包出发解析:本包的队列,否则它声明依赖的包里唯一的持有者,否则拒绝并列出全部候选。组织自己建的分配规则、不属于任何包的规则和流程,照旧按整个环境查。
- 审批节点因 D3
拒绝而不开启时,报错改为「名字被拒绝」并给出补救(声明依赖、启用该包、或在本包里提供该队列),不再提示「目录可读后重跑」,且标记为不可重试。
- 环境里对包流程做的 `.custom` 覆盖:审批步骤按引擎实际运行的那份定义取包(`armedFlowPackage`,来自
objectstack-ai#31863),覆盖的步骤按「无包」查,与 main 一致(史诗评审 R1)。
- 为什么改:objectstack-ai#31789
给队列服务契约加了「调用方软件包」参数,但只有共享规则在用。这两处还按整个环境查,所以「规则依赖的包和一个无关包都有同名队列」会被拒绝,比
ADR-0150 D3 更严(专题 objectstack-ai#31527)。
- 风险与回滚:只影响「包里的规则或审批步骤引用队列,且队列名有多个持有者或持有者不在依赖里」的部署。第一方实测 0
个包声明队列、分配规则或队列审批人。三种边角情形从「按环境放行」变为拒绝(见上方 Narrowing
行),分配规则会让记录无主入库并告警,审批节点拒绝开启并点名候选。回滚即 revert 本 PR。
- 先看:`packages/objectql/src/assignment-rules.ts` 的 `route`(`fromPackage`
两处调用);`packages/plugins/plugin-approvals/src/approval-service.ts` 的
`flowPackageOf` 与 `expandQueueUsers`。
- 两分钟验证:`pnpm --filter @objectstack/plugin-approvals exec vitest run
src/approval-service.test.ts -t "ADR-0150 D3"`,预期 7 个用例全绿。
- 需要你做的:无,席位落地(R1 部分等 objectstack-ai#31863)。

## What changes

- **Assignment rules (`@objectstack/objectql`, `assignment-rules.ts`).**
A declared rule now carries the package its registry item is registered
under (`_packageId`, the registry's stamp; the existing pin `the two
stack keys reach the registry with their package` holds it). `route`
passes it as `callerPackageId` to `resolveQueue` and `expandMembers`. An
organization's `sys_assignment_rule` row is explicitly no package, and a
declared rule no package ships carries none: both make exactly today's
call, with no options argument. The "does not resolve" warning names the
rule's package when there is one. Module doc gains a "Which queue a name
means" section.
- **Approval steps (`@objectstack/plugin-approvals`,
`approval-service.ts`).** A step's package is the package of the flow
body the engine runs: `flowPackageOf(flowName)` asks the automation
engine's public `armedFlowPackage` (objectstack-ai#31863), the reader the engine's own
subflow addressing (ADR-0150 E1) takes a run's caller package from. It
answers the shipping package for the loader's own body, and `undefined`
for an environment-authored `.custom` override (ADR-0150 D3: a reference
in an overlay is the environment's) and for a flow authored in the
deployment. `ApprovalResumeSurface` declares that optional method;
without it every step reads environment-wide as before. ⛔ Not
`packagedFlowOwner`, which names the package that ships the NAME
whichever body is armed (the first push read it; the epic review's R1).
`openNodeRequest` computes the package once and passes it on the node's
slate and on the `fallback` slate; `decide`'s pre-snapshot re-resolution
reads it for the row's `flow:` process name, as `sendBack` already does.
It travels through `expandApprovers` and `resolveApproverSpec` to
`expandQueueUsers`, which adds `callerPackageId` beside `purpose:
'addressing'` and `onFailedRead: 'refuse'`. A deployment-authored flow
and an override make today's call unchanged.
- **A refused queue name on an approval node.** The node still refuses
with `ApproverDirectoryUnreadableError`
(`APPROVER_DIRECTORY_UNREADABLE`), the refusal as its cause, and still
routes past no one. When the cause is a D3 refusal (read by its shape,
`refusal.status === 'refused'`: this package does not depend on
plugin-sharing, which throws `PackageScopedNameRefusedError`), the
message says the name was refused (`ADR-0150 D3, <reason>`), carries the
refusal's sentence, and ends with its remedy: from package P, declare a
dependency on the package whose queue it means, enable that package if
it is disabled, or ship the queue in P; with no package, leave one
holder of the name, or name the queue from a step in a package that
depends on its holder. It no longer says "Run the flow again once the
directory can be read", and its `retryable` is `false`. A failed read
keeps its wording, byte for byte, and `retryable: true`. No new code:
reworded under the existing one (epic review R2).
- ⛔ No second resolver and no first-registered fallback: both readers
only name the package; the queue service (`IOwnershipQueueService`,
implemented by plugin-sharing over objectql's
`resolvePackageScopedName`) decides.
- Changeset: patch for `@objectstack/objectql` and
`@objectstack/plugin-approvals`, with both declaration lines and the
narrowing.

## Step 0: how each reader learns its declaring package

Measured on `origin/main` `fdfcc7ab` (with objectstack-ai#31789).

| Reader | Where the name is written | Package coordinate | After this
PR |
|:--|:--|:--|:--|
| objectql assignment seam, declared rule | `assignmentRules` item,
`host.listRules()` = `registry.listItems('assignment_rule')` | the
item's `_packageId` (stamped by `registerItem` / `applyProtection`;
already pinned in `ownership-queue.test.ts`) | passed |
| objectql assignment seam, organization rule | `sys_assignment_rule`
row | none (an organization's row) | not passed: environment-wide |
| plugin-approvals approver slate (`queue` approver) | approval node
config inside a flow; `openNodeRequest` gets `flowName` from the
engine-seeded `$flowName` |
`AutomationEngine.armedFlowPackage(flowName)` (objectstack-ai#31863: the package whose
own body is armed; `undefined` for an override or a deployment-authored
flow) | passed when the armed body is a package's own |
| plugin-approvals `decide` pre-snapshot tally | stored request row |
the row's `process_name` (`flow:NAME`) to `armedFlowPackage` | passed
when the armed body is a package's own |

The definition's own `_packageId` is deliberately not read for flows:
the engine documents it as the caller's bytes, and an override's served
copy carries the base's. Both readers have a coordinate, so no stop.

## Tests

objectql, new top-level `describe` in the D5 harness
`src/ownership-queue.test.ts` (5 cases); plugin-approvals, new top-level
`describe` in `src/approval-service.test.ts` (7 cases). Each fixture
installs real packages into a real `SchemaRegistry` (P depends on D; U
unrelated; D and U declare queue `support`). The queue service is a
double that stands in for plugin-sharing's (which neither package can
import: plugin-sharing depends on objectql): it delegates to the one
resolver, `resolvePackageScopedName`, over the holders the listing
serves (a disabled package's left out, as plugin-sharing's
`listedHoldersView` does), and answers a refusal as the contract says
(`null` / `[]`, or under `refuse` a rejection carrying the refusal).

| Pin | objectql | plugin-approvals |
|:--|:--|:--|
| P's rule/step naming `support`, held by D and U, reaches D's queue |
**red on main** | **red on main** |
| two holders in P's closure: refused, naming both | **red on main** |
**red on main** |
| D disabled + U: refused `outside-closure`, naming U, U never served |
**red on main** | **red on main** |
| CONTROL: no package (a declared rule no package ships / a
deployment-authored flow) reads as today, same call, same refusal |
green on main | green on main |
| CONTROL (objectql): an organization's own rule reads environment-wide
| green on main | — |
| fallback slate and pre-snapshot tally read the same package
(plugin-approvals) | — | **red on main** |
| a D3 refusal on the node reads as a refusal with its remedy, not
retryable (asserted in the two-in-closure pin and the CONTROL) | — |
**red on main** (failed-read wording) |
| an environment-authored override of P's flow (`armedFlowPackage`
undefined, `packagedFlowOwner` P) naming an environment-held queue P
cannot reach: served environment-wide, on the node slate and the
pre-snapshot tally | — | green on main; **red with `packagedFlowOwner`**
(refused `outside-closure`) |
| the same on the override's `fallback` slate | — | green on main; **red
with `packagedFlowOwner`** |

"Red on main" was measured by restoring the two source files to
`fdfcc7ab` (`git restore --source`), running the blocks, and restoring
(`git diff HEAD` empty): objectql 3 of 5 red, plugin-approvals 4 of 5
red, every CONTROL green.

Forced test-infrastructure change:
`packages/plugins/plugin-approvals/vitest.config.ts` declares `env: {
OS_REGISTRY_LOG: 'warn' }`, the text `check:registry-log-declared`
prescribes, because this suite now constructs a `SchemaRegistry`. No
existing test was edited.

## Acceptance notes

- **Widening, declared beside the narrowing.** Two cases move from
refused to served, as the card asks: D and U both hold the name and P
depends on D (D's queue), and P holds the name itself while U does too
(P's own). Declared `Clause-②: yes (widening)`, as objectstack-ai#31789 declared the
same movement (seat ruling; claim amended on the card, 6734711604), with
the narrowing stated beside it. Accepted by the epic review
(6734421619).
- **The package of a flow step is `armedFlowPackage`, one reader.**
objectstack-ai#31863 added it for every caller (E1's subflow addressing, E5's
connector_action, this step). An R1 first cut built a reader here before
objectstack-ai#31863 existed; it was withdrawn on the seat's instruction (`fe45524b`)
and never reached main. This PR only reads objectstack-ai#31863's.
- **An assignment rule never sees the candidates.** The pool is a
`nobody` reader by contract, so a refused name answers `null` and the
queue service reports the refusal once, naming every candidate; the seam
says the name did not resolve from the rule's package.
- **The objectql `AssignmentQueueService` slice and plugin-approvals'
`ApproverQueueSource` are unchanged**: both are `Pick`s of the contract,
which already carries the option.

## Verification

Head `00fb75d5`. It merges `origin/main` at `5d17aa6b`, which includes
objectstack-ai#31863's `armedFlowPackage`, through merge commit `f3864c02`. The first
push was `0dccea6c`.
- `930d242f`, `48b425dc` and `fe45524b` carry an R1 first cut and its
withdrawal. Net, they leave `packages/services/**` identical to main.
- `00fb75d5` switches the approval step to objectstack-ai#31863's reader.

- `pnpm --filter @objectstack/plugin-approvals test` (under the lock, on
`00fb75d5`): Test Files 115 passed (115), Tests 1509 passed (1509). The
new block is 7/7.
- Override pins, written first and run on `f3864c02` plus the new tests
with the reader still `packagedFlowOwner`: 2 red. After the switch:
green.
- `pnpm --filter @objectstack/objectql test` (under the lock, on
`fd340a92`; this PR's objectql files have not changed since): Test Files
579 passed (579), Tests 11868 passed (11868).
- `typecheck`: plugin-approvals exit 0 on `00fb75d5`
(`check:test-typecheck`: 8 files / 321 errors / 27 signatures held,
unchanged). objectql exit 0 at the first push.
- Lint: neither package has a `lint` script. Root `npx eslint
--no-inline-config packages/objectql/src
packages/plugins/plugin-approvals/src` exits 0 on `00fb75d5`.
- `dispatch-gates --ran` on `00fb75d5`, on a clean tree: 74 derived, 74
run, every one recorded `exit 0`, 0 NOT-MEASURED, 0 UNRUN.
- Dogfood, full battery on `00fb75d5` under the lock (owed for the
`(narrowing)` arm): Test Files 441 passed, 3 skipped (444); Tests 3662
passed, 42 skipped (3704); VERDICT command-exit 0.

<details><summary>Measured: what the registered queue service answers,
environment-wide (main's readers) and from P (this PR's)</summary>

A throwaway test (deleted, never committed) drove
`@objectstack/plugin-sharing`'s `OwnershipQueueService` over a real
`SchemaRegistry` on this tree. `resolveQueue('support')`, and
`expandMembers` under `refuse` from P:

| Case | environment-wide | from P | refuse from P |
|:--|:--|:--|:--|
| P depends on D; D and unrelated U hold it | null (refused) | D's queue
| ok |
| two holders in P's closure | null (refused) | null |
`ambiguous-in-closure` [D, D2] |
| only unrelated U holds it | **U's queue** | null | `outside-closure`
[U] |
| D disabled; U holds it too | **U's queue** | null | `outside-closure`
[U] |
| only an environment-declared item | **the environment's** | null |
`outside-closure` [environment] |
| P holds it, U too | null (refused) | P's own | ok |
| only D holds it | D's | D's | ok |
| no declared holder, an organization's `sys_queue` row | the row | the
row | ok |

The three bold rows are the narrowing; rows 1 and 6 the widening the
card asks for.
</details>

<details><summary>Ablations: six legs, each red, each restored
(scripts/ablation-replace.mjs)</summary>

Both suites import their package's source directly; no dist leg. A1–A4
ran on `0dccea6c`; R2 on the head below. Each leg: anchor 1 to 0, blob
changed, run red, restored with blob == HEAD and `git diff HEAD` empty.

- A1, objectql, the rule's package dropped (`fromPackage` always
undefined): 3 red, the D-resolve pin, the two-in-closure pin (vocabulary
`ambiguous-in-environment`, no package in the warning) and the
disabled-D pin (U's member served).
- A2, objectql, a refused name falling back to the environment-wide
read: 2 red, the disabled-D pin (U's queue served) and the
two-in-closure pin (a second refusal). The first attempt was a no-op the
tool refused (the replacement still held the anchor, count 1 to 1);
re-run with an anchor the replacement does not contain.
- A3, plugin-approvals, the flow's package dropped: 4 red, every package
pin.
- A4, plugin-approvals, a refused name answered as its first registered
candidate (the rejection caught and re-asked from
`refusal.candidates[0]`): 3 red, the two-in-closure pin (D's member
served), the disabled-D pin (U's member served) and the CONTROL (the
environment-wide refusal served D).

- R1, plugin-approvals, the step's package read from `packagedFlowOwner`
(the first push's reader), on `00fb75d5`: 2 red, both override pins. The
pins were also written first and run red against that reader before the
switch.
- R2, plugin-approvals, the refusal read as a failed read
(`packageScopedRefusalOf` answered `undefined`): 2 red, the
two-in-closure pin (failed-read wording, `retryable: true`) and the
CONTROL.

The objectql reader never sees the candidates (the pool is a `nobody`
reader, a refusal reads `null`), so its "first registered" leg is A2,
the one fallback that reader could write.
</details>

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

https://claude.ai/code/session_01ADHkmPfjQpqnk93rr9esh8

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

---------

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/l 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.

spec: IOwnershipQueueService reads take the caller package, so a queue recipient resolves by D3 from its rule (ADR-0150, follow-up of E4)

1 participant