Skip to content

Commit e681d49

Browse files
committed
fix(lint, metadata-protocol)!: the object_extension door folds the written entry among other packages' extensions by priority
The door's target carried every other package's extension field as a plain field with no priority, so the gate served the written entry's definition of every field it adds, and its formula-cycle verdict differed from os build on a tie, on an outranked entry, and on a higher sibling's cycle through another field of the entry. The host now states the target's other packages' published extensions (registry contributors, disabled packages left out), and objectExtensionsByTarget / objectsAsServed fold the written entry among them, the build's own fold, ties dropped. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5pZiFTTaXqbY34YRcV
1 parent 41b64bb commit e681d49

14 files changed

Lines changed: 438 additions & 61 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/metadata-protocol': minor
4+
'@objectstack/spec': minor
5+
---
6+
7+
fix(lint, metadata-protocol): the `object_extension` publish door folds the written entry among the other packages' extensions of its target by priority, so it judges the field definition `os build` judges
8+
9+
Clause-②: no (narrowing) — at the runtime `object_extension` publish door (Studio, `PUT /api/v1/meta/object_extension/TARGET`, the MCP and AI authoring doors) the expression rule now reads each field of the target as `os build` serves it when another package's published extension adds the same field: one write it accepted is now refused (a higher-priority package's definition of a field the written entry also adds closes a formula cycle through another field of the entry), and two it refused now publish (the written entry ties with another package on that field, or another package outranks it there). `os build` is unchanged. The new gate input (`storedObjectExtensions` on `runRuntimeAuthoringRules` and `evaluateRuntimeAuthoringGate`, the `StoredObjectExtension` type from `@objectstack/lint/runtime`) is optional. Measured first-party exposure: no two first-party packages extend the same object (`examples/app-showcase` one entry on `showcase_account`, `packages/plugins/plugin-auth` one on `sys_sso_provider`, HotCRM `origin/main` 2492ac6 one module, o2c, extending `crm_contract` and `crm_account`), so no first-party write changes verdict.
10+
Metadata-protocol: narrowed
11+
Skills-docs: none owed — this PR edits `content/docs/deployment/validating-metadata.mdx` (the object extension paragraph states the door's fold); the skills teach `defineObjectExtension({ extend, fields, priority })` and formula fields, and say nothing of how the door read a field two packages add.
12+
13+
<!-- adr-0087: registered object-extension-formula-cycle-refused -->
14+
15+
**BREAKING** accept-set change of the runtime `object_extension` publish door (narrowing in one shape, widening in two).
16+
17+
**Before:** the door's target carried every other package's extension field as a plain field with no package and no priority, and the gate folded the written entry over it, so the door judged the written entry's own definition of every field it adds. A self-reading formula the written entry adds under a field another package adds at the same priority, or at a higher one, was refused although `os build` accepts it; and a higher-priority package's formula closing a cycle through another field of the written entry was not seen, although `os build` refuses it.
18+
19+
**Now:** the host states the target's other packages' published extensions (each with its package, priority and fields; a disabled package's left out), and the gate folds the written entry among them by priority through the build's own fold (`objectsAsServed`). The door judges the definition `os build` judges: the written entry's where its priority decides the field, another package's where that one outranks it, and none where two packages add it at the priority that decides it. This corrects the `@objectstack/lint` 33153 note's **Now** clause "(at the door, a name the target already serves included: the written definition is the one served)" and its **Unchanged** sentence "The publish door judges the written entry's own definition of every field it adds, whatever priority another package's extension adds the same field at, so it can refuse a tie, or an entry another package outranks, that `os build` lets through": the written definition is the one judged where the written entry's priority decides the field, and the door no longer refuses a tie or an outranked entry that `os build` accepts. Where that note says "at the same priority", read "at the priority that decides it".
20+
21+
**Unchanged:** `os build`, `os validate` and `os lint`; a write the door judges with no other package extending the same field; a host that states no extensions (the written entry is folded over the target as served); a draft save (never gated).
22+
23+
**Fix:** a write refused for the new shape: break the cycle, so the formula the entry adds does not read a field that another package's higher-priority formula computes from it, or rename the entry's field so it is not outranked.

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,13 @@ through another formula, is refused as one the object declares is (#33153):
623623
the cycle is found on the target as served, each member the entry adds is
624624
located at the entry (`object 'TARGET' · objectExtensions[0] · field 'FIELD'
625625
expression`), and in `os build` a member the target declares keeps its
626-
location at the object. The door judges the written entry's own definition of
627-
every field it adds, so a name the target already serves is refused at the
628-
entry too, whatever priority another package's extension adds it at; `os build`
629-
judges the definition the registry serves, and on a declared object leaves out
630-
a field two packages add at the same priority.
626+
location at the object. The door folds the written entry among the other
627+
packages' published extensions of the target by priority, as `os build` folds
628+
every package's entry (#33494), so both judge the same definition of each
629+
field: the written entry's where its priority decides the field (a name the
630+
target already serves included), another package's where that one outranks it.
631+
On a declared object neither judges a field two packages add at the priority
632+
that decides it.
631633

632634
**Declared enforcement that cannot run** is two rows for the mirror-image
633635
reason, and #4716 is where it split. That heading covers four rule ids, and

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ import {
172172

173173
import type { IObjectQLEngine } from '@objectstack/spec/contracts';
174174
import type { UserTextParams } from './finding-user-text.js';
175+
import type { StoredObjectExtension } from './object-graph.js';
175176

176177
type AnyRec = Record<string, unknown>;
177178

@@ -356,6 +357,15 @@ export interface AuthoringRuleContext {
356357
* platform names, a platform-prefixed name advised at `warning`) applies.
357358
*/
358359
runtimeWriteType?: string;
360+
/**
361+
* [#33494] Set by the runtime gate on an `object_extension` write only: the
362+
* written entry's target's other packages' published extensions, as the
363+
* host's registry holds them. Read by one rule, `validateStackExpressions`,
364+
* whose extension walk folds the written entry among them by priority (the
365+
* build's own fold, `objectsAsServed`), so the door judges the definition
366+
* the build judges (`StackExpressionOptions.storedObjectExtensions`).
367+
*/
368+
storedObjectExtensions?: readonly StoredObjectExtension[];
359369
/**
360370
* [#32666] Set by the runtime gate on its SUBJECT pass only, which judges
361371
* the subject collections it withholds from every other pass
@@ -850,7 +860,10 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
850860
surfaces: CLI_AND_RUNTIME,
851861
runtimeTypes: ['flow', 'action', 'hook', 'object', 'view', 'page', 'object_extension'],
852862
run: (stack, ctx) =>
853-
runStackExpressionPasses(stack, { runtimeWriteType: ctx.runtimeWriteType }).map((i) => ({
863+
runStackExpressionPasses(stack, {
864+
runtimeWriteType: ctx.runtimeWriteType,
865+
...(ctx.storedObjectExtensions !== undefined ? { storedObjectExtensions: ctx.storedObjectExtensions } : {}),
866+
}).map((i) => ({
854867
severity: i.severity ?? 'error',
855868
// [#32529, #32554] The stored-expression input member names its own
856869
// two ids; every other finding of the pass is `expression-invalid`.

‎packages/lint/src/formula-cycle-issues.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,28 @@ export function formulaCycleIssues(
9898
* elsewhere. The build passes the names the authored target declares (the
9999
* object walk locates those at the object, so a cycle closing through a
100100
* declared formula keeps that location); the `object_extension` door passes
101-
* none, since it judges the written entry's own definition of every name the
102-
* entry adds, over everything the target served before the write.
101+
* none, since its target is served before the write and the object walk does
102+
* not run there.
103+
*
104+
* [#33494] A `stored` entry (another package's published extension, which the
105+
* door folds in among the written one by priority) locates nothing: a name it
106+
* adds later in fold order than the written entry is the stored entry's
107+
* definition, served over the written one, so no locus is left for it, and a
108+
* cycle it closes through another field of the written entry is named on
109+
* that field alone.
103110
*/
104111
export function extensionFormulaLoci(
105112
target: string,
106-
entries: ReadonlyArray<{ path: string; fields: readonly AnyRec[] }>,
113+
entries: ReadonlyArray<{ path: string; fields: readonly AnyRec[]; stored?: true }>,
107114
left: ReadonlySet<string>,
108115
): Map<string, string> {
109116
const loci = new Map<string, string>();
110117
for (const entry of entries) {
111118
for (const field of entry.fields) {
112119
const name = field.name;
113120
if (typeof name !== 'string' || left.has(name)) continue;
114-
loci.set(name, `object '${target}' · ${entry.path} · field '${name}' expression`);
121+
if (entry.stored) loci.delete(name);
122+
else loci.set(name, `object '${target}' · ${entry.path} · field '${name}' expression`);
115123
}
116124
}
117125
return loci;

‎packages/lint/src/object-graph.ts‎

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,32 @@ export interface VisibleObjectExtension {
396396
*/
397397
label: unknown;
398398
fieldPatches: Record<string, AnyRec>;
399+
/**
400+
* [#33494] Set on an entry the host's registry already holds
401+
* ({@link StoredObjectExtension}), folded in at its priority but never
402+
* located: its fields are no field of the stack, so no walk names one.
403+
*/
404+
stored?: true;
405+
}
406+
407+
/**
408+
* [#33494] Another package's published extension of an object, as the host's
409+
* registry holds it (each `extend` contribution of the object: its package,
410+
* its merge priority, its fields). The `object_extension` publish door states
411+
* them for the written entry's target, so {@link objectExtensionsByTarget}
412+
* folds the written entry among them by priority, as the build folds every
413+
* package's entry, instead of over their fields carried as plain fields with
414+
* no priority. Never stated by the build, whose stack carries every entry.
415+
*/
416+
export interface StoredObjectExtension {
417+
/** The object it extends. */
418+
extend: string;
419+
/** Its merge priority; absent reads as the registry's default, 200. */
420+
priority?: number;
421+
/** Its field records (a record keyed by name, or an array). */
422+
fields?: unknown;
423+
/** The package it belongs to, for the record; the fold reads only the order. */
424+
packageId?: string;
399425
}
400426

401427
/**
@@ -428,17 +454,25 @@ export interface VisibleObjectExtension {
428454
* earlier one whole, its fields included.
429455
* - Fold order: ascending `priority` (default 200), equal priorities in
430456
* package order. Each list is returned in that order.
457+
* - [#33494] `stored`: the entries the host's registry already holds for
458+
* another package (the `object_extension` door states them, the build never
459+
* does), each its own package, registered before every entry of the stack
460+
* and marked `stored`. They fold as any entry does, so the stack's entry
461+
* that one outranks is not the one served and a tie between them is a tie.
431462
*
432463
* Which targets to judge is the caller's question: an entry is listed here
433464
* whether or not the stack declares its target.
434465
*/
435-
export function objectExtensionsByTarget(stack: unknown): Map<string, VisibleObjectExtension[]> {
466+
export function objectExtensionsByTarget(
467+
stack: unknown,
468+
stored: readonly StoredObjectExtension[] = [],
469+
): Map<string, VisibleObjectExtension[]> {
436470
const byTarget = new Map<string, VisibleObjectExtension[]>();
437471
if (!isRec(stack)) return byTarget;
438472
// The receivers are named as `validate-security-posture.test.ts`'s key-read
439473
// meta-test tables them (`stack`, `entry`, `body`, `ext`, `obj`, `f`): that
440474
// scan reads this fold as part of the rules that read through it.
441-
const collect = (entries: unknown, carrier: number, at: string) => {
475+
const collect = (entries: unknown, carrier: number, at: string, held = false) => {
442476
if (!Array.isArray(entries)) return;
443477
entries.forEach((ext: unknown, i: number) => {
444478
if (!isRec(ext) || typeof ext.extend !== 'string') return;
@@ -455,10 +489,14 @@ export function objectExtensionsByTarget(stack: unknown): Map<string, VisibleObj
455489
Object.entries(ext.fieldPatches).filter((pair): pair is [string, AnyRec] => isRec(pair[1])),
456490
)
457491
: {},
492+
...(held ? { stored: true as const } : {}),
458493
});
459494
byTarget.set(ext.extend, kept);
460495
});
461496
};
497+
// [#33494] Registered before the stack's own entries: carriers below 0, one
498+
// per stored entry, in the order the host states them.
499+
stored.forEach((entry, k) => collect([entry], k - stored.length, `stored[${k}].`, true));
462500
if (Array.isArray(stack.packages)) {
463501
stack.packages.forEach((entry: unknown, j: number) => {
464502
const body = isRec(entry) ? entry.manifest : undefined;
@@ -492,17 +530,23 @@ export function objectExtensionsByTarget(stack: unknown): Map<string, VisibleObj
492530
* verdict depends on which definition wins: registration order decides that,
493531
* and a stack does not state it.
494532
*
533+
* [#33494] `stored` ({@link objectExtensionsByTarget}): the host's registered
534+
* entries of other packages, folded in among the stack's own by priority.
535+
*
495536
* Contract, which `indexObjectFields` (validate-hook-body-writes.ts) joins on
496537
* by position: `objects` is one to one and in order with
497538
* `recordsOf(stack.objects)`. `objectsAsServed(stack).objects[i]` is the
498539
* served form of `recordsOf(stack.objects)[i]`, on the early return (nothing
499540
* extends anything: the declared array itself) as on the fold. No object is
500541
* dropped, added or reordered.
501542
*/
502-
export function objectsAsServed(stack: unknown): { objects: AnyRec[]; tied: Map<string, Set<string>> } {
543+
export function objectsAsServed(
544+
stack: unknown,
545+
stored: readonly StoredObjectExtension[] = [],
546+
): { objects: AnyRec[]; tied: Map<string, Set<string>> } {
503547
const objects = isRec(stack) ? recordsOf(stack.objects) : [];
504548
const tied = new Map<string, Set<string>>();
505-
const extensions = objectExtensionsByTarget(stack);
549+
const extensions = objectExtensionsByTarget(stack, stored);
506550
if (extensions.size === 0) return { objects, tied };
507551

508552
const served = objects.map((obj) => {

0 commit comments

Comments
 (0)