Repository navigation
Commit 43edf90
fix(plugin-security,organizations): seed-ownership claims re-own by row when a stored expression reads owner_id (#25724)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X5kePHewF7u1mfD8BHmUxYd)_
Fixes #25668
Clause-②: no
Metadata-protocol: none
## What changed
Both seed-ownership claims re-owned seeded rows with one `multi: true`
predicate update. A stored computed field (a non-formula field with an
`expression`) that reads `owner_id`, directly or one hop through the
lookup, computes a different value on each row once the owner is set.
The engine refuses such a predicate update ("update those rows by id"),
so every seeded row of that object stayed ownerless. Triage `6385814124`
keeps that refusal and routes the fix to the two claim sites. This PR
does that.
- `packages/plugins/plugin-security/src/claim-seed-ownership.ts`: a new
`storedExpressionReadsOwner(schema)` decides, per object, whether a
stored expression reads `owner_id`. It counts a direct read, a hop
through `owner_id`, and a read through another stored field that does.
An expression whose reads cannot be named counts as a reader. Reads come
from `analyzeRelationshipTraversals` (`@objectstack/formula`), the
member reader the engine's stored-expression planning uses. Such an
object goes to `claimPredicateByRow`:
- The NULL arm writes each seeded id it already names, with no read.
- The `usr_system` arm reads ids a page at a time (`CLAIM_PAGE_ROWS`,
the bound the paged fallback already reads by) and writes them. It stops
when a read is empty, or when a page re-owns nothing.
- Each write is a compare-and-set: the arm's owner term plus the row's
`id`, `multi: true`. The engine evaluates that as a predicate over one
row and computes the stored value from that row. A row someone owned in
the meantime is not taken.
- Every other object keeps the predicate write and its paged fallback,
unchanged.
- `packages/plugins/organizations/src/claim-org-seed-ownership.ts`: the
same check (a twin, as the two files already twin their helpers) and
`claimChunkByRow`. It writes one compare-and-set per seeded id of each
chunk: `{ organization_id, owner_id: null, id }`.
- A row whose own write is refused stays unowned. It is reported once
per batch with the claim's existing warning (`claimSeedOwnership failed
for …` / `claimOrgSeedOwnership failed for …`), with the refused count,
up to 20 ids and the first refusal's message. The object's other rows
are still claimed.
- `@objectstack/organizations` gains the `@objectstack/formula`
dependency (`package.json`, `pnpm-lock.yaml`). Its `vitest.config.ts`
gains the matching source alias, which `pnpm check:test-source-alias`
asked for.
File surface: the claim's two files, their tests, one changeset, plus
the three organizations manifest/config lines above. Nothing under
`packages/objectql/**`.
## Evidence
Head `1e608716`. Every number below was read on this branch.
- New pins, real engine:
-
`plugin-security/src/claim-seed-ownership-stored-expression.pin.test.ts`,
on `SqlDriver` (better-sqlite3).
-
`organizations/src/claim-org-seed-ownership-stored-expression.pin.test.ts`,
on `SqliteWasmDriver`.
- Each pins: the direct and the one-hop shape (the hop is HotCRM's
`display_title` expression), each with four seeded rows that compute
different values. The plugin-security pin adds two seed-identity rows.
After the claim every such row is owned and its stored `display_title`
is its own expression over its own row. The guest row the seed never
reported, another organization's row and a human-owned row are
untouched. A control object whose stored expression reads no owner keeps
the bulk path: plugin-security makes 2 predicate writes and
organizations 1. A row refused by a code-registered hook stays unowned
and reported while the rest are claimed.
- Result: `Tests 4 passed (4)` in each file.
- Ablation (restore the bulk write via `scripts/ablation-replace.mjs`,
run, restore; the tool verified the blob back to HEAD and `git diff
HEAD` empty):
- plugin-security: `const claim = claimPredicate;` gives `Tests 3 failed
| 1 passed (4)`. The failures carry the engine's own refusal:
`'display_title' on 'probe_forecast_direct' is computed from its
expression on every write, and this update changes its inputs on rows
where it then computes different values, … update those rows by id`.
That is the card's measured symptom.
- organizations: `const claim = claimChunk;` gives `Tests 3 failed | 1
passed (4)`, with the same refusal. This measures the organizations
claim, which the card had only read.
- Package suites: `@objectstack/plugin-security` `Test Files 223
passed`, `Tests 4632 passed | 45 skipped`. `@objectstack/organizations`
`Test Files 17 passed`, `Tests 243 passed` (re-run at `1e608716`).
`typecheck` exit 0 on both. `eslint --no-inline-config` over both
packages exit 0.
- Derived gates: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 84 families on this diff, and all 84
exit 0 at `1e608716`. Reconciled: `dispatch-gates --ran` reads "84
derived famil(ies) accounted for — 84 run, 0 NOT-MEASURED (a DERIVED
zero — all 84 recorded an exit code and none of them is 3)". The first
round, at `5aa93aa9`, found one real red, `check:test-source-alias` (the
new `@objectstack/formula` import had no source alias in organizations),
fixed in `1e608716`. It also had three prerequisite exits (3):
`check:dual-build-cjs-loads` and `check:i18n` (some packages had no
`dist/`) and `check-plugin-teardown-shape --self-test` (shallow clone;
its pinned fixture commit fetched). All three exit 0 on the final run.
Repo-wide families (`pnpm lint` and the CI roster) are CI's.
## Acceptance notes
- **Row-by-row cost.** It is a full engine write per row, paid only on
objects whose stored expressions read `owner_id`. The NULL arm is
bounded by the seed's own report (chunks of `CLAIM_PAGE_ROWS`). The
seed-identity arm is bounded by pages of `CLAIM_PAGE_ROWS` and
`MAX_CLAIM_PAGES`. Not measured at seed sizes beyond the pins.
- **Spellings.** The routing reads `owner_id` with the platform's one
member reader. A stored expression that reaches `owner_id` through a
spelling that reader does not name would still get the predicate write
and the existing warning. No such spelling is known. Noted, not filed.
- **Twin helpers.** `storedExpressionReadsOwner` / `expressionReads`
exist in both claim files, as `affectedRowCount` and `hasField` already
do. The two packages share no runtime dependency that could host them.
Noted, carrier: none.
- **Not measured here.** The card's second "Done when" line, HotCRM's
patched `display_title` booting with 0 ownerless forecasts, needs a
release that carries this. It is the `repo:hotcrm` seat's reading on
hotcrm#2242.
- The card's "Context, not asked here" item (a stored title reading a
lookup goes stale when the lookup target is renamed) is untouched.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01T8djanm8XBb36LFwcQEXJP)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 888d686 commit 43edf90
8 files changed
Lines changed: 807 additions & 5 deletions
File tree
- .changeset
- packages/plugins
- organizations
- src
- plugin-security/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
0 commit comments