You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d0348cf
Browse filesBrowse the repository at this point in the historyBrowse files
fix(runtime): an un-walled boot seed's person references resolve to the first admin once that admin exists (#34516)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi96QpUuH77yeiDEFd5Vi6Pg1)_Fixes#34458
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
改了什么:单租户(未开组织隔离墙)首次启动时,种子数据里指向首个管理员的人员字段(负责人、审核人等)在管理员账号创建后会被自动补上,不再永久留空。
- 为什么改:种子先于首个管理员落库,人员引用解析不到就写成空;此前只有 owner_id
会被交接,示例记录的负责人、审核人一直显示为"未分配",后续启动也不会修复。
- 风险与回滚:只回填种子自己写入、且该列仍为空的行;访客写的行和期间被人手动改过的值都不动。回滚即 revert 本
PR,已回填的值保留,不影响其它数据。
- 先看:packages/runtime/src/app-plugin.ts 的
registerSeedPersonReferenceHandoff(sys_user
插入后触发);packages/metadata-protocol/src/seed-loader.ts 的
resolveHeldPersonReferences(按行 id
加列为空条件写入);packages/plugins/organizations/src/default-organization-seed-owner.wall.test.ts。
- 两分钟验证:pnpm --filter @objectstack/organizations exec vitest run
src/default-organization-seed-owner.wall.test.ts,预期 5 个用例全绿,未开墙用例里
assignee、reviewer、owner_id 都等于管理员 id。
- 需要你做的:无,席位落地。
## What changes
On an un-walled (single-tenant) first boot the inline boot seed loads
before the first admin's `sys_user` row exists, so a `Field.user()` /
`Field.lookup('sys_user')` value naming that admin landed NULL. The
first-admin handoff (`claimSeedOwnership`) writes `owner_id` only, and a
later boot's replay of a create-only dataset leaves an existing row as
it is, so `assignee` / `reviewer` style columns stayed NULL for good.
- `packages/metadata-protocol/src/seed-loader.ts`: pass 2 now holds each
person reference it left NULL (target `sys_user`, row id known) as a
`HeldPersonReference`. New
`SeedLoaderService#resolveHeldPersonReferences()` retries them with the
loader's own `resolveReferenceItem` (same organization), and writes a
resolved value with a compare-and-set update by row id and `FIELD =
null`. So a row the seed did not write is never reached (ADR-0138 D1),
and a value set since is kept. Retries are serialized. A reference that
still misses stays held. `heldPersonReferenceCount()` reports how many
are held. The held list resets per `load`.
- `packages/runtime/src/app-plugin.ts`: after the inline boot seed,
`AppPlugin` keeps the loader while it holds references. A new ObjectQL
middleware (`registerSeedPersonReferenceHandoff`) runs the retry after
every `sys_user` create/insert and releases the loader once it holds
none. Failure is best-effort and logged at `warn`, like the tenancy
handoff beside it. The user insert always stands.
- The walled boot is unchanged: it writes no inline seed, and its
per-organization replay already waits for the owner's membership
(#34457).
- No change under `packages/spec/src/**`; no contract change. The new
loader methods are on the concrete `SeedLoaderService` class and are not
part of `ISeedLoaderService`.
- Changeset `.changeset/34458-unwalled-seed-person-refs.md`: `patch` on
`@objectstack/metadata-protocol` and `@objectstack/runtime`.
## Tests
`packages/plugins/organizations/src/default-organization-seed-owner.wall.test.ts`.
This is the forced test change the card names:
- The CONTROL describe is flipped as the card's Done-when requires. It
was titled `control: the same seed on an un-walled boot reads as it did
before the fix` and asserted `assignee: null, reviewer: null, owner_id:
adminId`. It is now titled `the same seed on an un-walled boot resolves
the first admin once that admin exists` and asserts `assignee`,
`reviewer` and `owner_id` all equal the admin id.
- New describe `un-walled: a held seed person reference fills only the
seed's own rows, and only while still NULL`. Its PREMISE leg shows the
reference is NULL before the named person signs up, and that the admin's
insert did not fill it. Its main leg covers three rows. The seed's row
resolves to the late person once they exist. A seeded row assigned by
hand in the meantime keeps that assignment. A guest-written row with a
NULL person stays NULL (the ADR-0138 D1 negative leg).
Ablation (one-shot, not kept). The handoff's loader read in
`app-plugin.ts` was replaced with an always-undefined read through
`scripts/ablation-replace.mjs`. The marker was proved in
`packages/runtime/dist` with `ablation-dist-preflight.mjs` (exit 0)
after a rebuild. The organizations suite then went red on exactly the
two new/flipped legs: `Tests 2 failed | 3 passed (5)`. Restore leg: blob
hash equal to HEAD, rebuild, preflight `--absent` exit 0, then `Tests 5
passed (5)`.
<details><summary>Suite readings (locked runs, on e2ab3fd; the later
merge of origin/main 6c7d730 touches none of these packages)</summary>
- `pnpm --filter @objectstack/metadata-protocol test`: exit 0, `Test
Files 346 passed | 9 skipped (355)`, `Tests 22968 passed | 45 skipped
(23013)`
- `pnpm --filter @objectstack/organizations test`: exit 0, `Test Files
20 passed (20)`, `Tests 264 passed (264)`
- `pnpm --filter @objectstack/runtime test`: exit 0, `Test Files 609
passed (609)`, `Tests 11271 passed | 19 skipped (11290)`
- `pnpm --filter @objectstack/metadata-protocol --filter
@objectstack/runtime --filter @objectstack/organizations typecheck`:
VERDICT command-exit 0, all three `Done`
- Focused re-run after the last code commit (build metadata-protocol +
runtime, wall test, three seed-loader suites): VERDICT command-exit 0;
wall test `Tests 5 passed (5)`; seed-loader suites `Tests 58 passed
(58)`
</details>
<details><summary>Ablation readings</summary>
- Mutation leg: anchor hit (injected marker count 1, original line count
0), `pnpm --filter @objectstack/runtime build` exit 0,
`ablation-dist-preflight.mjs @objectstack/runtime '__ABLATION_34458__'`
exit 0. Wall test: `× the wall is down, the seed landed once before the
admin existed, and every person reference naming the admin resolves to
the admin`, `× the seed's NULL reference resolves to the person once
they exist; the guest row and the hand assignment stand`, `Tests 2
failed | 3 passed (5)`.
- Restore leg: restored blob equals the HEAD blob, rebuild exit 0,
preflight `--absent`: marker absent from all 12 built files, then `Test
Files 1 passed (1)`, `Tests 5 passed (5)`.
</details>
## Acceptance notes
- The held references live in process memory. If the process restarts
between the boot seed and the first admin's sign-up, the references are
not retried. This PR covers the case the card names and the tests drive,
where the first admin's `sys_user` row is inserted by the same process
that ran the boot seed. A restart before sign-up was not measured. A
durable retry would need the seed-settlement contract to carry the held
references, which is a spec change this card does not take. Filed:
#34542.
- The retry runs after every `sys_user` insert only while the loader
still holds references; once none are held, the middleware returns at
its first check.
- The pass-2 `UNRESOLVED` error text still says "No further seed pass
retries this". That remains literally true, since the held retry is not
a seed pass, and its SCOPE clause already says a later boot step can
still write the column. Dropped: the sentence is still literally true,
because the held retry is a write after the seed, not a seed pass.
- `packages/metadata-protocol/src/seed-loader.ts` overlaps open PR
#34429: `git merge-tree --write-tree HEAD refs/pull/34429/head` at
2a00228 exits 0 (tree 0e6916848), with no conflict.
## Verification
Gate sweep: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 72 families for this diff. Each was
run with stdin closed and its exit code captured before any pipe.
Reconciliation with `--ran` reports `72 derived, 72 run, 0 NOT-MEASURED,
0 UNRUN`. Two families first answered exit 3 (PREREQUISITE NOT MET) and
were re-run once the prerequisite was met. `check-plugin-teardown-shape
--self-test` needed its pinned fixture commit fetched, then exited 0
with 48 cases. `check:dual-build-cjs-loads` needed every package built,
then exited 0 with 124 entry points across 72 packages.
<details><summary>Head and gate provenance</summary>
- Lines 1 to 67 of the sweep ran on e2ab3fd. The run was interrupted
by a container restart and resumed. The last 5 families and the two
re-runs ran on 0916d33, which is e2ab3fd plus a merge of origin/main
6c7d730. That merge touches none of the 4 files of this diff, and the
re-derivation on 0916d33 lists the same 72 commands.
- `check:type-check-debt`: exit 0, 0 ledger entries re-measured, 0 raw
tsc errors.
- CI has not been awaited; its check-runs are the record for the
families CI runs.
</details>
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmRXuRn93HphKp7kXEz -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(runtime): on an un-walled first boot, a seed person reference naming the first admin resolves to that admin
10
+
11
+
A single-tenant install loads its boot seed before the first admin's `sys_user` row exists. A `Field.user()` or `Field.lookup('sys_user')` value naming that admin therefore landed NULL, and the first-admin handoff wrote `owner_id` and no other column. Sample records assigned to the owner showed as unassigned, apart from the record owner. A later boot did not repair them either: a dataset in the default create-only mode leaves an existing row as it is.
12
+
13
+
The seed loader now holds each person reference its second pass left NULL, together with the row it landed on (`SeedLoaderService#resolveHeldPersonReferences`, `heldPersonReferenceCount`). `AppPlugin` retries the boot seed's held references after every `sys_user` insert. It resolves each one by the loader's own rule and writes it to that row only while the column is still NULL. A row the seed did not write keeps its value (ADR-0138 D1). A seeded row that someone assigned in the meantime keeps that assignment. A reference that still names nobody stays held until the next user insert of the process. The walled boot is unchanged: it writes no inline seed, and its per-organization replay already waits for the owner's membership.
0 commit comments