Skip to content

fix(plugin-sharing): stamp an assignment rule created from Setup with the caller's organization - #39454

Draft
objectstack-fleet[bot] wants to merge 7 commits into
mainfrom
claude/issue-39415-wip
Draft

objectstack-fleet[bot] wants to merge 7 commits into
mainfrom
claude/issue-39415-wip

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread
Fixes #39415

Clause-②: no
Metadata-protocol: none

维护者速读

  • 组织管理员在设置里新建分配规则,以前点创建就报「组织不能为空」,现在直接建成,规则自动归入管理员当前所在的组织。
  • 属于分派与审批这一块,替每个要配置分配规则的新公司管理员解决「根本建不了规则」的问题。
  • 出错时管理员会看到规则建不了或建到别的组织;本改动只改了这张系统表的组织列,撤回这次合并即可恢复原样。
  • 无。

What changes

sys_assignment_rule stopped declaring its own organization_id (a required: true lookup). Its organization is now the platform's tenant column, the same one sys_queue carries and is stamped through. No second mechanism:

  • registration injects the column: applySystemFields in packages/objectql/src/registry.ts, called from packages/objectql/src/registry-object-registration.ts, using TENANT_SCOPE_FIELD_DEF (packages/spec/src/data/injected-system-column-provenance.ts);
  • the insert stamps the caller's active organization onto an absent value: SqlDriver#injectTenantOnInsert (driver-sql). A system write's organization is resolved first by packages/objectql/src/tenancy/system-write-organization.ts.

With its own declaration, required: true let the record validator refuse the write before the stamp could run. The Setup form has no organization input, so every create answered 400 VALIDATION_FAILED on organization_id.

The non-null rule still holds where it is enforced. The tenant column is created NOT NULL (ADR-0131 D1). The save guard (assignment-rule-hooks.ts) still refuses a row that lands in no organization, naming organization_id. The object's comment "a stored rule always belongs to one organization. A rule that reaches every organization is a DECLARED rule, never a row here" stays, unchanged in meaning. The object's own { fields: ['organization_id'] } index entry is gone too: the platform provisions the tenant index with the column on a walled deployment, as on sys_queue.

The 11 translations/*.objects.generated.ts bundles were regenerated (check-i18n-bundles.mjs --write). They drop the column's own label and help, as sys_queue's bundles carry none.

Tests

packages/plugins/plugin-sharing/src/objects/sys-assignment-rule.organization-stamp-39415.test.ts: the shipped sys_assignment_rule, sys_queue and sys_queue_member run through a real ObjectQL over SqlDriver on better-sqlite3 :memory: with the save guard bound. There are 7 cases:

  1. an org admin's create with no organization_id is stored in that admin's organization;
  2. two admins' rules each land in their own organization;
  3. the registered column equals sys_queue's field for field, and has exactly one tenant index;
  4. a system write that names its organization keeps it;
  5. a create that lands in no organization is still refused (VALIDATION_FAILED, organization_id / required) and stores nothing;
  6. the created rule lists for its organization and routes that organization's new ticket into its queue, and leaves another organization's ticket alone;
  7. an update by the rule's own admin cannot move it to another organization: the value is dropped and the rule stays.
Red first: the object file restored from the merge base, the rest at head
× an organization administrator's create with no organization_id is stored in that organization
× each administrator's rule lands in their own organization
× the rule rides the same platform tenant column as sys_queue
× the created rule lists for its organization and routes that organization's new records, and no other's
× an update by the rule's own administrator cannot move it to another organization: the value is dropped, the rule stays
Tests  5 failed | 2 passed (7)
WARN Insert operation failed {"object":"sys_assignment_rule","fields":[{"field":"organization_id","code":"required"}],"reason":"Organization is required"}
Green at head
pnpm --filter @objectstack/plugin-sharing exec vitest run --maxWorkers=2   ->  Test Files 82 passed (82) · Tests 1787 passed | 11 skipped (1798)
pnpm --filter @objectstack/plugin-sharing run typecheck                    ->  exit 0 (tsc, scripts tsconfig, check:test-typecheck OK)

Acceptance notes

  • A body naming another organization. This was measured at engine level, with no security plugin composed, and the object file was swapped to compare. An org-A admin's create naming org B is stored in B both on the merge base and at head. Nothing changed there. On a walled deployment the security plugin's write wall (composeWriteTenantWall) refuses a supplied foreign organization_id on insert. The wall reads the column by name and the posture, never the field's declaration, so its verdict is the same before and after. Not pinned here: plugin-security is not a dependency of this package.
  • Update is now stricter. On the merge base, an org-A admin's update setting organization_id: B moved the rule to B at engine level. At head the value is dropped with the engine's read-only warning and the rule stays in A, as on sys_queue. Under the group posture the wall admits a re-point to another of the caller's organizations (its documented rule, not measured here), so such a move used to be possible and now is not. Pinned by case 7.
  • Served schema. organization_id stays in the registered and served field list, under the same name, type and reference. Its attributes change from the object's own (required: true, group: 'System', its own description and translated label and help) to the platform tenant column's (required: false, hidden, readonly, system, the platform description). A data-API create gets wider: it no longer needs the key. A data-API update gets narrower: the key is dropped. What a metadata author can write is unchanged, because the object is a platform table.
  • Not measured. An upgraded single-tenant database still holds the physical index from the removed { fields: ['organization_id'] } entry. Whether os migrate plan lists it as an index drop was not measured.

Verification

Read first:

  1. packages/plugins/plugin-sharing/src/objects/sys-assignment-rule.object.ts: the removed field and index entry, and the comment that now carries the non-null rule.
  2. The test file above, cases 5 and 7: the non-null refusal and the update drop.
  3. .changeset/39415-assignment-rule-organization-stamp.md.

Two-minute check: pnpm --filter @objectstack/plugin-sharing exec vitest run --maxWorkers=2 src/objects/sys-assignment-rule.organization-stamp-39415.test.ts should show Tests 7 passed (7).

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4czHUJLmdQAqm4fdDs9

…ization

sys_assignment_rule declared its own required organization_id, so the
record validator refused a create that named no organization before the
platform's tenant stamp could run: every rule created from Setup answered
400 "Organization is required". The object now rides the platform's tenant
column, the one sys_queue carries, which the driver stamps from the
write's organization. Non-null still holds: the column is created NOT NULL
and the save guard refuses a row that lands in no organization.

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

The sys_assignment_rule block no longer carries organization_id: the
object stopped declaring the column, so check-i18n-bundles --write drops
its label and help text. Generator output only.

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

The object no longer declares organization_id, so its own index entry on
that column named a column only the platform provides
(check:keyed-text-bounds cannot classify it). The registry provisions the
tenant index with the column on a walled deployment; the test pins that
it is there exactly once.

Claude-Session: https://claude.ai/code/session_016WV4czHUJLmdQAqm4fdDs9
Co-authored-by: Claude <noreply@anthropic.com>
…keeps its organization on update

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

Claude-Session: https://claude.ai/code/session_016WV4czHUJLmdQAqm4fdDs9
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-sharing, touching 3 documentable anchor(s).

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

  • content/docs/automation/flows.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/automation/queues-and-assignment-rules.mdx (via sys_assignment_rule (symbol, a field of const object arObjects; a field of const object deObjects; a field of const object enObjects; a field of const object esESObjects; a field of const object frObjects; a field of const object jaJPObjects; a field of const object koObjects; a field of const object ptBRObjects; a field of const object ruObjects; a field of const object zhCNObjects; a field of const object zhHantObjects))
  • content/docs/data-modeling/seed-data.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/deployment/cli.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/deployment/seed-tenancy-repair.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/permissions/administrator-guide.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/protocol/kernel/config-resolution.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/protocol/objectql/schema.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))

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

  • content/docs/releases/implementation-status.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/releases/v17/17-1.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/releases/v17/17-4.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/releases/v17/17-5.mdx (via sys_organization (literal, a string literal in SysAssignmentRule))
  • content/docs/releases/v18/18-4.mdx (via sys_assignment_rule (symbol, a field of const object arObjects; a field of const object deObjects; a field of const object enObjects; a field of const object esESObjects; a field of const object frObjects; a field of const object jaJPObjects; a field of const object koObjects; a field of const object ptBRObjects; a field of const object ruObjects; a field of const object zhCNObjects; a field of const object zhHantObjects))

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

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: organization_id (literal, 43 pages)
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 71 of 256 client-bound route-ledger rows — the other 185 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 185: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 60 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 125 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 — 12 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 c9ea363d71087bd9d16e0a8ee6de0c5f76331e0c → packageMentionDocs.

Which tree this was computed on

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

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

⚠️ 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 c9ea363d71087bd9d16e0a8ee6de0c5f76331e0c → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@github-actions github-actions Bot added 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 Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assignment rules: creating one from Setup fails with "组织不能为空" because organization_id is required and never stamped

2 participants