Skip to content

Commit 1081739

Browse files
committed
Merge origin/main into claude/issue-24340-rls-object-default-scope
Claude-Session: https://claude.ai/code/session_01Nk17Z26X5DB59iQztDBADH Co-authored-by: Claude <noreply@anthropic.com>
2 parents bc1e9e7 + 538f923 commit 1081739

35 files changed

Lines changed: 886 additions & 41 deletions

‎.changeset/24190-line-items-hydrated-check.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Clause-②: yes (narrowing)
1212

1313
**`@objectstack/spec`**
1414

15-
- **`defineStack`'s cross-reference check** now reaches a `record:line_items` block in a page region's components, in a container's component children and in a slot. A block under a `page:tabs` item's `children` is not yet judged. It judges a column that declares no `type` as the type it renders, and reports the column schema's own refusal (`STACK_CROSS_REFERENCE_INVALID`, 422). Today that means `scale` on an identity-only column over a `currency` field of the child object. The child object is the one the panel lists: the object `dataSource` binding's `object` when the node carries one, else `childObject`. A child object the stack does not declare, a column naming no field of it, and a column the column schema refuses on its own (left to the component-props gate) are not judged.
15+
- **`defineStack`'s cross-reference check** now reaches a `record:line_items` block in a page region's components, in a container's component children, in a slot and, since #24349, in a `page:tabs` or `page:accordion` item's `children`. It judges a column that declares no `type` as the type it renders, and reports the column schema's own refusal (`STACK_CROSS_REFERENCE_INVALID`, 422). Today that means `scale` on an identity-only column over a `currency` field of the child object. The child object is the one the panel lists: the object `dataSource` binding's `object` when the node carries one, else `childObject`. A child object the stack does not declare, a column naming no field of it, and a column the column schema refuses on its own (left to the component-props gate) are not judged.
1616
- The step-18 migration entry `ui-record-line-items-props-closed` now says so, and no longer says that this block draws a column exactly as declared.
1717

1818
## FROM → TO
@@ -25,4 +25,4 @@ The one-line fix: delete `scale` from a `record:line_items` column that renders
2525

2626
## Who is affected, measured
2727

28-
On `origin/main` `ec749fbb44`: two authored `record:line_items` blocks in the examples (the showcase project detail page, five typed columns, its block under a `page:tabs` item, so not yet judged; the showcase invoice document page, four `{ name, label }` columns, two of them over `currency` fields) and one in the published skills (four `{ name }` columns). None carries `scale`, so no example, skill or fixture outside this change's own pins changes verdict. Deployed metadata was not measured.
28+
On `origin/main` `ec749fbb44`: two authored `record:line_items` blocks in the examples (the showcase project detail page, five typed columns, its block under a `page:tabs` item; the showcase invoice document page, four `{ name, label }` columns, two of them over `currency` fields) and one in the published skills (four `{ name }` columns). None carries `scale`, so no example, skill or fixture outside this change's own pins changes verdict. Deployed metadata was not measured.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@objectstack/plugin-audit": patch
3+
"@objectstack/cli": patch
4+
---
5+
6+
fix: an activity row is written only when an organization is derivable, never with a NULL organization, and the v18 ownership ceremony deletes the existing NULL activity rows it cannot attribute (ADR-0131 D9)
7+
8+
Clause-②: no
9+
10+
- **`@objectstack/plugin-audit`.** The audit writer's activity mirror (`sys_activity`) takes its organization from the record, then from the acting session, then from the `tenancy` service's Default Organization under `single`. When none of them names one, the mirror now writes no activity row at all. Before, it wrote a row with `organization_id` NULL. Under a wall that row was readable by no organization member. The change is still recorded: the compliance ledger row (`sys_audit_log`) is written as before, with its `tenant_id` attribution. Under `single` the Default Organization is always derivable, so nothing changes there. A record that names its organization keeps its activity row, with that organization.
11+
- **`@objectstack/cli`.** `os migrate organization-ownership` still attributes a NULL `sys_activity` row when its record carries an organization. On a walled database (any posture but `single`), the mirror-deletion step now deletes the NULL rows no anchor attributes, such as activity about a sign-up's `sys_user`. Before, those rows were reported as unattributable and held certification. They are 14-day telemetry that the mirror no longer writes, and `sys_audit_log` keeps each change. The plan counts them as the departure `underivable-activity`, and warns before the first write that `--apply` deletes them. The apply report lists the count as the table's `deleted`. Under `single` the Default Organization takes these rows, as before, and nothing is deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
fix(spec)!: `defineStack`'s page cross-reference checks judge a component inside a `page:tabs` or `page:accordion` item's `children`, as they judge one at region level (#24349)
6+
7+
Clause-②: yes (narrowing)
8+
9+
<!-- adr-0087: registered ui-page-panel-children-cross-references-judged -->
10+
11+
**BREAKING** — an accept-set narrowing of what `defineStack` and `objectstack validate` publish, shipped as `minor` under the repo's launch-window convention for accept-set narrowings. `defineStack` reads a page's components through one traversal, shared by its inline-action target check and its inline grid column check. A tab or accordion item is a panel record (`{ label, value?, children }`), not a component, and the traversal stopped at it, so nothing inside a tab or an accordion panel was judged: a button whose modal target names no page built green in a tab and was refused one level up.
12+
13+
**`@objectstack/spec`**
14+
15+
- **`defineStack`'s page cross-reference checks** now reach a component in a `page:tabs` or `page:accordion` item's `children`, at any depth (tabs in an accordion panel, a panel in a container or under a slot). The traversal descends the panel positions the component rows declare (`pageComponentSlotPositions`), the list the other page walks already read, so it follows the declared shapes rather than naming tabs. A record under a key no row declares a panel list is not descended.
16+
- A component in a panel gets the region-level verdict and message, located through the panel: `STACK_CROSS_REFERENCE_INVALID` (422), for example `Inline action 'open_detail' on page 'invoice_record' (regions.0.components.0.properties.items.1.children.0) references page 'no_such_modal' (via modal target) which is not defined in pages.`
17+
- Two checks reach further: an inline action's `type: 'modal'` / `type: 'flow'` `target`, and an identity-only column (one that declares no `type`) carrying `scale` over a `currency` child field, on an `object-master-detail-form` block's `details[].columns` or a `record:line_items` block's `columns`. That includes a `record:line_items` block in a tab or accordion panel, a position the block's identity-only check did not reach before this change.
18+
- New step-18 migration entry `ui-page-panel-children-cross-references-judged`; the entry `ui-record-line-items-props-closed` now names the panel positions in its reach.
19+
20+
## FROM → TO
21+
22+
| you wrote, inside a `page:tabs` or `page:accordion` item's `children` | write instead |
23+
|:--|:--|
24+
| `{ type: 'element:button', properties: { action: { type: 'modal', target: 'no_such_page' } } }` | a `target` naming a page the stack declares (or a declared flow, for `type: 'flow'`) |
25+
| `{ type: 'record:line_items', properties: { childObject: 'invoice_line', relationshipField: 'invoice', columns: [{ name: 'amount', scale: 2 }] } }` where `amount` is a `currency` field of `invoice_line` | the same block with `columns: [{ name: 'amount' }]` |
26+
27+
The one-line fix: give the component inside the panel the same fix it would need at region level. Nothing about the panel or its items changes.
28+
29+
## Who is affected, measured
30+
31+
On `origin/main` `31e7d0ba2`: four authored pages nest components under a panel item (the showcase project detail page, whose `record:line_items` block declares a `type` on all five columns; the platform user and organization record pages; the approval request record page), one documentation example does (three tabs of record blocks), and the published skills carry none. None holds an inline action target or an identity-only column under a panel, so no example, skill or fixture outside this change's own pins changes verdict. Deployed metadata was not measured.

‎packages/cli/src/utils/organization-ownership-apply.ts‎

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
predicateSql,
2929
PRIMARY_DATABASE,
3030
Sql,
31+
underivableDepartureOf,
3132
type AttributionSink,
3233
type MetadataConflict,
3334
type MetadataKeyRow,
@@ -117,7 +118,11 @@ import type { DeclaredSharingRuleSkip } from '@objectstack/plugin-sharing';
117118
* C3 stage 9): every grant naming a mirror row is renamed to the rule's
118119
* NAME, which the registry must resolve, and only then is the mirror
119120
* deleted ({@link runDeclaredRuleMirrorDeletion}). It runs again on a
120-
* checkpointed run while a mirror stands.
121+
* checkpointed run while a mirror stands. Before them, a fate-3 table's
122+
* `underivableDeparture` (`sys_activity`, ruling record 6257510973 item
123+
* 3): the NULL rows no anchor attributes once attribution is done are
124+
* deleted — never under `single`, where the Default Organization takes
125+
* them ({@link runUnderivableDeletion}).
121126
* 4h. `history-renumber` — seat answer Q2 A: `sys_metadata_history`'s
122127
* `event_seq` and every `(type, name, version)` unique environment-wide
123128
* before the column goes. Every lineage still tagged to an organization
@@ -184,7 +189,7 @@ import type { DeclaredSharingRuleSkip } from '@objectstack/plugin-sharing';
184189
*
185190
* ## What it never does
186191
*
187-
* ⛔ Delete a row outside fate 2. ⛔ Give an unattributable row an owner:
192+
* ⛔ Delete a row outside fate 2 and a declared `underivableDeparture`. ⛔ Give an unattributable row an owner:
188193
* owners come only from the plan's anchors and, under `single`, the Default
189194
* Organization. ⛔ Create any organization but the Default Organization, and
190195
* that one only under `single` on a database that holds none. ⛔ Run at boot:
@@ -2526,6 +2531,11 @@ async function runMirrorDeletion(run: Run): Promise<StepReport> {
25262531
const kept = Math.max(0, table.rows!.total - (run.deleted.get(table.object) ?? 0));
25272532
if (kept > 0) notes.push(`${table.object}: ${kept} row(s) are not mirrors (a named category or their non-seeded provenance claims them) and stay.`);
25282533
}
2534+
const underivable = await runUnderivableDeletion(run);
2535+
total += underivable.deleted;
2536+
if (underivable.blockers.length) {
2537+
return { step: 'mirror-deletion', status: 'blocked', summary: { deleted: total }, blockers: underivable.blockers, notes };
2538+
}
25292539
const declared = await runDeclaredRuleMirrorDeletion(run);
25302540
if (declared.status !== 'done') return { ...declared, summary: { ...declared.summary, deleted: total }, notes: [...notes, ...declared.notes] };
25312541
return {
@@ -2537,6 +2547,65 @@ async function runMirrorDeletion(run: Run): Promise<StepReport> {
25372547
};
25382548
}
25392549

2550+
// ── Step 4, continued: the rows no anchor attributes (ruling record 6257510973 item 3) ─
2551+
2552+
/**
2553+
* The NULL rows of a fate-3 table that declares an `underivableDeparture`
2554+
* (`sys_activity`: activity is never a NULL row, and the existing ones are
2555+
* deleted): once attribution has written every owner it derives, every row
2556+
* still NULL is one of them. Read from a fresh plan, so the delete takes
2557+
* exactly what that plan classifies: a table on which it still derives an
2558+
* owner, or reports a row, blocks with nothing deleted. Never under `single`
2559+
* ({@link underivableDepartureOf}).
2560+
*/
2561+
/** Whether the plan this run started from counts a row an `underivableDeparture` deletes. */
2562+
function underivableRowsDue(run: Run): boolean {
2563+
return run.plan.tables.some((t) => {
2564+
const entry = mirrorEntry(run, t.object);
2565+
const id = entry ? underivableDepartureOf(entry, run.opts.posture)?.id : undefined;
2566+
return id !== undefined && t.departures.some((d) => d.id === id && d.rows > 0);
2567+
});
2568+
}
2569+
2570+
async function runUnderivableDeletion(run: Run): Promise<{ deleted: number; blockers: string[] }> {
2571+
const declares = (object: string): string | undefined => {
2572+
const entry = mirrorEntry(run, object);
2573+
return entry ? underivableDepartureOf(entry, run.opts.posture)?.id : undefined;
2574+
};
2575+
if (!run.plan.tables.some((t) => t.physical === 'present' && declares(t.object))) return { deleted: 0, blockers: [] };
2576+
const plan = await planFor(run);
2577+
let deleted = 0;
2578+
const blockers: string[] = [];
2579+
for (const table of plan.tables) {
2580+
const id = declares(table.object);
2581+
const leaving = id ? table.departures.find((d) => d.id === id) : undefined;
2582+
if (!leaving || leaving.rows === 0 || table.physical !== 'present') continue;
2583+
const deriving = Number(table.fateCounts.rowsToAttribute ?? 0);
2584+
if (deriving > 0 || table.unattributable.length > 0 || leaving.rows !== table.rows!.organizationNull) {
2585+
blockers.push(
2586+
`${table.object}: ${leaving.rows} row(s) no anchor attributes are due for deletion, but the table still holds ` +
2587+
`${table.rows!.organizationNull} NULL row(s) (${deriving} an anchor attributes, ${table.unattributable.length} ` +
2588+
'reported), so nothing was deleted. Re-run --apply: the attribution step runs again first.',
2589+
);
2590+
continue;
2591+
}
2592+
for (const physical of table.tables) {
2593+
const { sql } = databaseFor(run, physical);
2594+
const where = `${sql.q(ORG, physical)} IS NULL`;
2595+
const count = (): Promise<number> => sql.count(physical, `SELECT COUNT(*) AS n FROM ${sql.q(physical, physical)} WHERE ${where}`);
2596+
const before = await count();
2597+
if (before === 0) continue;
2598+
await execute(run, physical, `DELETE FROM ${sql.q(physical, physical)} WHERE ${where}`, []);
2599+
const left = await count();
2600+
if (left !== 0) throw new Error(`The delete on ${physical} left ${left} organization-less row(s) behind; nothing past this table was deleted.`);
2601+
run.deleted.set(table.object, (run.deleted.get(table.object) ?? 0) + before);
2602+
deleted += before;
2603+
run.opts.onProgress?.(`mirror deletion: ${before} organization-less row(s) of ${physical} no anchor attributes`);
2604+
}
2605+
}
2606+
return { deleted, blockers };
2607+
}
2608+
25402609
// ── Step 4, continued: the declared sharing-rule mirrors (ADR-0131 C3 stage 9) ─
25412610

25422611
const SHARING_RULES = 'sys_sharing_rule';
@@ -3097,6 +3166,23 @@ export async function applyOrganizationOwnership(opts: ApplyOptions): Promise<Or
30973166
// checkpointed run while one stands: a database whose ceremony completed on
30983167
// a release whose boot still seeded them carries them (advisory then), and
30993168
// the step that deletes them is this release's.
3169+
// So are the rows no anchor attributes, while one stands: a row written
3170+
// NULL since the run that finished the step is one too.
3171+
if (done && step === 'mirror-deletion' && underivableRowsDue(run)) {
3172+
const again = await runUnderivableDeletion(run);
3173+
const report: StepReport = again.blockers.length
3174+
? { step, status: 'blocked', summary: { deleted: again.deleted }, blockers: again.blockers, notes: [] }
3175+
: { step, status: 'done', summary: { deleted: again.deleted }, blockers: [], notes: [] };
3176+
steps.push(report);
3177+
if (report.status !== 'done') {
3178+
stopped = true;
3179+
continue;
3180+
}
3181+
checkpoint.completed[step] = { at: now().toISOString(), summary: report.summary };
3182+
await opts.ledger.write(checkpoint, { complete: false, blocking: 0, advisory: 0 });
3183+
run.columns.clear();
3184+
if (!(await declaredRuleMirrorsDue(run))) continue;
3185+
}
31003186
if (done && step === 'mirror-deletion' && (await declaredRuleMirrorsDue(run))) {
31013187
const again = await runDeclaredRuleMirrorDeletion(run);
31023188
steps.push(again);

0 commit comments

Comments
 (0)