Skip to content

Commit 7365c82

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-dv67oe
Claude-Session: https://claude.ai/code/session_01ADHkmQEc6KnPaxi9d3soLZ Co-authored-by: Claude <noreply@anthropic.com>
2 parents 281d91a + c44c8ac commit 7365c82

28 files changed

Lines changed: 1653 additions & 160 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"@objectstack/core": patch
3+
"@objectstack/objectql": patch
4+
"@objectstack/service-automation": patch
5+
---
6+
7+
fix(objectql)!: a `runAs: 'system'` flow's record writes keep the reference check while keeping their authorization elevation (#28881)
8+
9+
Clause-②: no (narrowing) — a `runAs: 'system'` flow's `create_record` / `update_record` (and any custom node writing through `resolveRunDataContext`) that names a lookup, user or master-detail id resolving to no row is refused, which it admitted before. Nothing is widened.
10+
Metadata-protocol: none
11+
12+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped. The write-time reference check the user path already applies now also applies to an elevated flow's record writes, with the same reference_not_found refusal; the mark that keeps it on is an internal symbol on the run's context, not an authorable key, so there is nothing for a migration to rewrite and no tombstone. -->
13+
14+
**BREAKING** accept-set narrowing at an elevated flow's record writes (`@objectstack/objectql`, `@objectstack/service-automation`).
15+
16+
- **Before.** The write-time reference check returned early for every system context. A flow that runs as system writes with `isSystem: true`, so its `create_record` / `update_record` stored a reference to a deleted row with no error, while the same write on the user path was refused `reference_not_found`.
17+
- **Now.** `resolveRunDataContext` marks a system run's data context (`markFlowWriteReferenceCheck`, `@objectstack/core`: a symbol, in no schema, not authorable), and the check keeps checking a marked write. The refusal is the user path's own: `VALIDATION_FAILED` with the field's `reference_not_found` error, carried as the node's inner refusal.
18+
- **Unchanged.** The run's authorization elevation: it still writes rows other people own, past RLS and FLS, inside the trigger's organization. Every system writer outside a flow run keeps the exemption: seed replay, package install, boot provisioning, import under a system principal, restore and migration, the cascade and set-null legs of a delete no flow made, and a hook's or action body's writes when no flow-run write set them off.
19+
- **Writes a flow write sets off.** They carry the mark too and are checked as the flow's own, as on the user path: a hook's `ctx.api` (and its `runAs: 'system'` or `ctx.api.sudo()` elevation) under a flow's write, and the engine's cascade legs under a flow's delete. A cascade leg writes no new link, so only the value it writes is judged.
20+
- **Who sees it.** A system flow that writes an id naming no row in its organization, including the owner it stamps from its trigger user when that user has no `sys_user` row. A flow that wants to tolerate a missing target clears the field first. One case surfaces data that is already wrong: a flow's `delete_record` whose `set_null` cascade removes the deleted id from a `multiple: true` reference field rewrites the members that remain, so if one of them already names a row that is gone, the cascade write is refused `reference_not_found` and the delete fails. The same delete on the user path fails the same way; a multi-value field keeping a deleted id is tracked in #29062.
21+
22+
**The remedy.** Write an id that resolves, or leave the field empty.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli): a `define*` helper that refuses its input while the config loads is reported as one located refusal (file, line, helper, path, the issue in words), not a raw JSON array
6+
7+
Clause-②: no — CLI output text only. No schema, export or accepted input changes; a refused config is refused with the same exit code as before.
8+
Metadata-protocol: none
9+
10+
`defineView`, `defineAction` and the other strict helpers call `Schema.parse` and throw the `ZodError` as is. `os validate`, `os build`, `os lint`, `os dev` and `os serve` printed that error's message, which is its issues as a JSON array, with no file and no helper. The config module now loads through one seam that turns such an error into a refusal rendered by `formatZodError`:
11+
12+
```text
13+
✗ src/views/ticket.view.ts:5:28 · defineView validation failed (1 issue):
14+
15+
✗ list.columns: Invalid input
16+
✗ list.columns.0: Invalid input: expected string, received object
17+
```
18+
19+
The file and line come from the evaluated bundle's source map. When the stack cannot tell which module threw, the refusal names the config entry and says so. The `--json` envelope's `error` carries the same text. Every other load failure (a syntax error, a missing import, a helper's own prose refusal, `defineStack`'s formatted refusal) is unchanged.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'create-objectstack': patch
3+
---
4+
5+
fix(create-objectstack): the scaffolded AGENTS.md lists only the `src/` directories the project's `objectstack.config.ts` loads
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The "Project Structure" block of the `AGENTS.md` a new project gets named `src/reports/`, `src/agents/`, `src/i18n/` and `src/handlers/`, which the scaffolded `objectstack.config.ts` never imports, so metadata a coding agent wrote there was never loaded and `npm run validate` still passed. It left out `src/skills/` and `src/picklists/`, which the config does load. The block now lists exactly the eight wired directories (objects, views, actions, flows, dashboards, apps, skills, picklists) and says that a new `src/` directory is never loaded or validated until its barrel is imported in `objectstack.config.ts`. What the config loads is unchanged.
11+
12+
An existing project keeps the `AGENTS.md` it was created with; to adopt the fix, edit its Project Structure block to match the directories its own `objectstack.config.ts` imports.

‎AGENTS.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ See `ui/AGENTS.md` for the app-id / localStorage / auth gotchas.
250250
"be liberal in what you accept" does **not** apply. Change the **spec** only when the spec itself is genuinely
251251
wrong, and then deliberately (edit the Zod schema + migrate). When an alias must be tolerated at all, declare it
252252
as an **ADR-0087 conversion-layer entry** (never a bare `??`, no executor shims) so it is declared, loud, tested,
253-
and *removable on a schedule*. Stored `sys_metadata` rows are covered from the other side: every rehydration seam
254-
replays the **full** conversion chain — retired entries included — via `applyConversionsToStoredItem` (ADR-0087
255-
addendum), so a consumer never needs its own accommodation for a legacy stored shape either. Strengthens #5.
253+
and *removable on a schedule*. Stored rows: `applyConversionsToStoredItem` replays the chain the installed release
254+
carries, retired entries included; kits age out one major after retiring (ADR-0087 as amended, ruling 6434038284),
255+
so run `os migrate meta --stored --apply` before leaving a release that still converts the row. Strengthens #5.
256256
13. **An accepted ADR binds until a superseding ADR says otherwise.** Reversing a recorded decision is itself a
257257
decision: it needs a **new ADR** (or an amended status line on the old one), not a changeset that quietly does the
258258
opposite. Before changing behaviour in `docs/adr/`-governed territory, **grep the ADRs for the surface you are

‎content/docs/getting-started/build-with-claude-code.mdx‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,24 @@ The scaffolder does more than copy files. It:
7272
◆ New Environment
7373
────────────────────────────────────────
7474
Environment: support-desk
75-
Namespace: support_desk
76-
Template: blank — Minimal starter — one object, REST API, ready to extend
75+
Namespace: support_desk
76+
Template: blank — Minimal starter — one object, REST API, ready to extend
77+
…
78+
→ Installing AI skills for your coding agent from @objectstack/skills@<version>...
7779
…
78-
→ Installing AI skills for your coding agent...
7980
✓ Environment created!
8081
8182
Next steps:
8283
cd support-desk
83-
npm install
84-
npm run dev # Start development server
85-
npm run validate # Verify metadata: schema + predicates + bindings
84+
npm run dev # Start development server
85+
npm run validate # Verify metadata: schema + predicates + bindings
86+
# (run after every metadata edit — see AGENTS.md)
8687
```
8788

89+
`npm install` appears under *Next steps* only when the dependency install was
90+
skipped (`--skip-install`) or failed. Where `pnpm --version` answers, the
91+
scaffolder installs with pnpm and its *Next steps* name `pnpm` instead of `npm`.
92+
8893
This is why AI authoring is reliable rather than a guessing game: **the agent
8994
starts with the protocol's schemas and rules already loaded**, not with generic
9095
"write me some TypeScript" priors. See [AI Skills](/docs/ai/skills) for how the
@@ -394,7 +399,10 @@ roll-ups, name fields). Ask the agent to keep the project lint-clean — "run
394399
## Beyond the first app — one skill per metadata domain
395400

396401
The loop above never changes; what changes is **which skill the agent loads**.
397-
The bundle ships nine, one per metadata domain, and the agent picks by task
402+
The bundle ships one skill per metadata domain (the table below names them),
403+
plus `objectstack-platform` (runtime setup, plugins, the `os` CLI),
404+
`objectstack-upgrade` (moving a project across a protocol major) and `objectui`
405+
(the `@object-ui/*` renderer), and the agent picks by task
398406
context (the trigger table lives in your project's `AGENTS.md`). To grow the
399407
support desk into a full application, keep describing — each row is a real
400408
prompt you can give verbatim:

‎content/docs/permissions/system-context.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bugs — it is the protection or the side effect that silently does not happen.
134134
| 21 | **`readonly` strip bypassed — INSERT** | objectql | Same, on create — one gate over BOTH create-side passes since the 2026-09-03 ruling moved the static-`readonly` strip in beside the runtime-owned one and deleted the DataProtocol ingress copy. `isSystem` is the **only** exemption on this path: `preserveAudit` is deliberately not read on create, so a non-system historical import is still stripped. A second read in the same symbol gates the pass that withholds those caller values from `beforeInsert` before the strip, the same exemption, so a system caller's hook still sees what it sent | `insert` |
135135
| 21b | **`readonly` strip bypassed — the write PREVIEW (`ObjectQL.validate`)** | objectql | Same as 19–21, in the preview: it runs the write's caller-write strips under the write's own gate, so a system preview reports no `readonly` drop and judges the value a system write would store. The `computed` strip of a `formula` value is NOT gated here or on either write verb — no driver has a column for it, so it runs for every caller | `validate` |
136136
| 22 | Strict-drop refusal never fires | objectql | Lose: a caller that opted into loud refusal gets **silence** — strict refuses exactly what the strip would have taken, and the strip took nothing. Two exceptions, both judged in every context: a `formula` value, which the `computed` strip takes from every caller, and a value for a stored field that declares `expression` when it differs from the value the engine computes in its place (`stored_expression`), so strict still refuses both | `insert`, `packages/objectql/src/readonly-strict-errors.ts#READONLY_CLASS_REASONS` |
137-
| 23 | **Referential-integrity check skipped** | objectql | Get: writes proceed against unreachable/unresolvable targets. Lose: an `isSystem` caller can write a **dangling reference** | `assertReferencesResolve` |
137+
| 23 | **Referential-integrity check skipped** — except a `runAs: 'system'` flow's record writes, which keep it | objectql | Get: writes proceed against unreachable/unresolvable targets — a seed replay, an import, a restore or a cascade may store a reference to a row that does not exist yet. Lose: an `isSystem` caller can write a **dangling reference**. A flow run's elevated context (`resolveRunDataContext`) carries an internal mark that keeps the check, so a flow's `create_record` / `update_record` naming a row that does not exist is refused `400 VALIDATION_FAILED` / `reference_not_found`, as on the user path; its authorization elevation is unchanged. A write the flow's write sets off (a hook's `ctx.api`, its `sudo()`, a cascade leg of a flow's delete) spreads the run's context and is checked as the flow's own, as on the user path. The mark is a symbol no flow definition or request can spell, and `ExecutionContextSchema.parse` drops it | `assertReferencesResolve` |
138138
| 23b | **Position-catalog check skipped** — a `sys_user_position` write whose `position` names no position in the security catalog is not refused | plugin-security | Get: a system writer can store an assignment naming no position — the seed loader writes `stack.data` from `AppPlugin.start()` under a system context, as invitation acceptance and the platform's own bootstraps do. Lose: such a row grants nothing and nothing says so. A non-system insert, or a non-system update that changes `position`, is refused `400 VALIDATION_FAILED` / `reference_not_found` instead when the security catalog holds no position of that name: the environment registry (ADR-0131 D3), one per deployment, which takes no organization, so a name only a `sys_position` row carries — any organization's — is refused like one nobody carries. It is the same stand-down as the engine's referential-integrity check for a lookup column | `assertPositionNamesCatalogRow` |
139139
| 23c | **Grant-name catalog check skipped** — a `sys_user_permission_set` write whose `permission_set` names no permission set in the security catalog is not refused | plugin-security | Get: a system writer can store a grant naming a set not yet registered — seed replay and boot provisioning may write the grant before the definition it names is registered. Lose: such a row grants nothing and nothing says so. A non-system insert, or a non-system update that changes `permission_set`, is refused `400 VALIDATION_FAILED` / `reference_not_found` instead when the security catalog holds no set by that name; a grant that names no set at all is refused `required` for every caller. The grant names its set by name alone, and nothing derives the name from `permission_set_id` (ADR-0131 D4, D10) | `packages/plugins/plugin-security/src/grant-permission-set-name.ts#onInsert`, `packages/plugins/plugin-security/src/grant-permission-set-name.ts#onUpdate` |
140140
| 23d | **Grant-holder membership check skipped** — a `sys_user_position` or `sys_user_permission_set` write naming a user with no `sys_member` row in the row's organization is not refused | plugin-security | Get: a system writer can store such a grant — invitation acceptance writes the membership and its placement together, and seed replay, the organization-admin reconcile and the platform bootstraps write grants as the system. Lose: such a row takes effect once its user is admitted to the organization. A non-system insert, or a non-system update that moves `user_id` or `organization_id`, is refused `400 VALIDATION_FAILED` / `reference_not_found` at `user_id` instead, for every caller, a platform administrator included; the membership is read as `{ isSystem: true, tenantId }` with `tenantId` the row's own organization, never another one. A row stored with no organization is not judged. Under `single`, 18.0 stamps a new grant with the Default Organization, so such a row is one an earlier release wrote | `packages/plugins/plugin-security/src/grant-holder-membership-refusal.ts#onInsert`, `packages/plugins/plugin-security/src/grant-holder-membership-refusal.ts#onUpdate` |
@@ -147,7 +147,7 @@ bugs — it is the protection or the side effect that silently does not happen.
147147
| 28 | Dependent-count disclosure on a blocked delete | objectql | Get: the count of blocking children. Nothing was elevated past the caller, so nothing is withheld | `dependentCountIsDisclosable` |
148148
| 29 | Reference-cleanup log attributes the write to `'system'` | objectql | Get: an honest actor label instead of `anonymous` when the context carries neither `userId` nor `actor` | `recordReferenceCheckElevation` |
149149
| 29b | A traversing validation rule's related read skips the **caller's bounds** | objectql | Get: no row bound from the caller's own read on a related object no organization wall scopes, no read door on a header the rule reads through a `master_detail` field, and a related read even with no organization under a walled posture (a `tenantId` on the context still scopes it). Every caller that is not system is held to all three: a header its read door does not return is unavailable to the rule exactly as a header that exists nowhere is, whatever it holds, and a header it can read is judged on its stored values. A plain `lookup` to an object an organization wall scopes asks no read door, system caller or not | `resolveOneHopRelated` |
150-
| 29c | A detail write's master-detail header read asks **no read door** | objectql | Get: the write binds the header a parent-scoped `requiredWhen` / `readonlyWhen` reads as `parent` from the header's stored row whoever can read it, as before. Every caller that is not system meets its own read door first: a header that read does not return answers as a header that exists nowhere — an unbound `parent`, and `reference_not_found` on the reference check (which a system caller's write skips altogether) | `masterDetailHeadersCallerReads` |
150+
| 29c | A detail write's master-detail header read asks **no read door** | objectql | Get: the write binds the header a parent-scoped `requiredWhen` / `readonlyWhen` reads as `parent` from the header's stored row whoever can read it, as before. Every caller that is not system meets its own read door first: a header that read does not return answers as a header that exists nowhere — an unbound `parent`, and `reference_not_found` on the reference check (which a system caller's write skips, a flow run's excepted) | `masterDetailHeadersCallerReads` |
151151
| 30 | **Bulk data event `organizationId` OMITTED** — the batch is published "not asserted" | plugin-security | Get: nothing — the `data.records.*` event still publishes. Lose: the per-organization attribution: this exit is taken before the security middleware composes any tenant wall, so it records no Layer 0 verdict on the operation (`OperationContext.tenantLayer0Verdict`, #15813), and the engine's bulk producer — which reads that recorded verdict and nothing else — omits the key rather than filling it from the caller's `tenantId`; a tenant-scoped consumer then does not deliver the event inside an organization wall (#15225) | `registerAuthzMiddleware` |
152152
| 30b | **The import doors admit a control opt-out** — `runAutomations: false` and `treatAsHistorical: true` on `POST /data/:object/import` and `/import/jobs` | rest | Get: an import whose rows are written with `skipAutomations` (no metadata-bound hook, no record-change trigger: an app's approvals and record freezes among them) or with `skipStateMachine` and `preserveAudit`. Every other caller, every signed-in user and administrator included, is refused `403 PERMISSION_DENIED` before the body is parsed, so nothing is written and no job is created. Inbound HTTP never carries the flag, so this is an in-process caller's door. Note: the flag still suppresses none of those controls by itself (see below); it only admits the opt-outs that do | `importControlOptOutRefusal` |
153153
| 30c | **The import undo keeps the control skips** — `POST /data/import/jobs/:jobId/undo` | rest | Get: an undo whose deletes and restores are written with `skipAutomations` and `skipStateMachine`, so no metadata-bound hook, record-change trigger or `state_machine` rule refuses a reversal. Every other caller, every signed-in user and administrator included, undoes under those controls: a reversal one of them refuses is reported per row in the undo answer's `failures` and kept in the job's undo log, and the job is stamped reverted only once every row is. A historical job's `preserveAudit` belongs to the job, not the caller, and rides every undo. Inbound HTTP never carries the flag, so this is an in-process caller's door | `importUndoWriteContext` |

0 commit comments

Comments
 (0)