Skip to content

test(spec): pin the union-branch projection refusal for a mark nested in a surviving union branch - #17804

Merged
os-bill merged 1 commit into
mainfrom
claude/issue-17107-union-branch-nested-mark-pin
Sep 12, 2026
Merged

os-bill merged 1 commit into
mainfrom
claude/issue-17107-union-branch-nested-mark-pin

Conversation

@os-bill

@os-bill os-bill commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Part of #17107 — F2 only. F3 (x-unprojectable-branches has no reader) stays open by design: triage is explicit that removing a published field is a separate question from pinning a guard. F3 is measured below, not resolved.

  • Clause-②: no — this PR puts no new key on any published payload.

The defect

projectByPruningUnionBranches refuses a projection when a marked (unprojectable) node survives anywhere but as a direct member of an anyOf / oneOf. The suite pinned that clause only at the root. Loosening the guard from findSurvivingMark(schema) !== null to findSurvivingMark(schema) === '#' passed 19/19 — the suite could not tell the strong guard from the weak one.

Mutation table, re-run on this branch's own base (8fa3fe63d9), not inherited:

mutation result
M2 — projection disabled 8 fail
M3 — strict re-conversion removed 4 fail
M1 — guard deleted 1 fail
M1b — guard loosened to === '#' 19/19 PASS

Why the existing pins could not see it — measured, not assumed

Every other "refuses outside a union" assertion returns null through the pruned.length === 0 early-out, never through the guard:

pin branches pruned surviving mark refused by
z.object({ handler: z.function() }) 0 #/properties/handler early-out
z.record(z.string(), z.function()) 0 #/additionalProperties early-out
z.array(z.date()) 0 #/items early-out
PersistenceAdapterSchema 0 #/properties/load early-out
z.union([z.date(), z.function()]) 2 # guard, but at the ROOT

None of those schemas contains a union at all, so the guard is never consulted; the one that reaches it carries its mark at the root, which a root-only guard still refuses. That is the whole of the 19.

The pins this adds

A shape that defeats both escapes at once — one branch really is dropped, and the surviving mark sits below the root:

shape branches pruned surviving mark
z.union([z.function(), z.object({ handler, name }), z.string()]) 1 (#/anyOf/0) #/anyOf/0/properties/handler
Automation.FlowFunctionEntrySchema (the real export) 1 #/anyOf/0/properties/handler

Both halves are asserted directly in the test, in both io directions, so the refusal is attributable to the guard and to nothing else. Non-vacuity is a pinned fact, not a claim: if the early-out ever starts firing for these shapes the expect(pruned).toEqual(...) line reds first.

Discrimination proof

Test-only change, committed first, then the guard mutated on disk under a trap:

== M1b == HEAD blob 1b23049dcf39… ; pre-mutation blob 1b23049dcf39… (equal)
mutation M1b: anchor count 1 -> 0 ; replacement count 0 -> 1
== M1b == post-mutation blob 89c23453fc0d… (differs) => LANDED ON DISK
     × refuses a marked node NESTED inside a SURVIVING union branch
     × leaves Automation.FlowFunctionEntrySchema skipped, marker and all
 Test Files  1 failed (1)
      Tests  2 failed | 19 passed (21)
== M1b == restored blob 1b23049dcf39… ; HEAD blob 1b23049dcf39… ; git diff HEAD bytes: 0
== M1b == RESTORE PROVEN byte-identical

The 19 pre-existing assertions stay green under M1b — the two new ones are the only discriminator. Restored, the suite is 21/21.

The value the first new pin receives under M1b is the marker leak itself:

{"anyOf":[{"type":"object","properties":{"handler":{"x-os-unprojectable":"function"},
 "name":{"type":"string"}},"required":["handler","name"],"additionalProperties":false},
 {"type":"string"}]}

Does the published artifact move? No — regenerated and diffed

gen:schema run twice in the same tree, the one changed file swapped to its base content in between:

run files under json-schema/ manifest sha256
this branch 1525 9675d5f4c959d63a
base content of the changed file 1525 9675d5f4c959d63a

Byte-identical, and git status reports 0 checked-in generated artifacts moved.

The instrument is lit. Under M1b the same measurement moves: 1529 files, manifest 472d131ac42de3ee, and gen:schema exits 1 naming five ledger entries that now emit —

❌ 5 ledger entry(ies) in unemitted-schemas.baseline.json now EMIT a JSON Schema:
     - Automation.FlowFunctionEntrySchema
     - System.EnvironmentArtifactSchema
     - UI.ViewMetadataSchema
     - UI.AssembledViewArtifactSchema
     - UI.FieldWidgetPropsSchema

all five written to disk carrying x-os-unprojectable. The card named one export; the measured population is five.

Changeset: skip-changeset, measured

packages/spec's files[] is dist, json-schema, liveness, prompts, llms.txt, README.md, src/**/*.zod.ts, CHANGELOG.md, api-surface, spec-changes.json — scripts/ is not in it.

probe occurrences in the published set
the changed text (subject) 0 (2 in the working tree, so the probe is aimed)
positive control FlowFunctionEntrySchema 62 across dist/
negative control (another scripts/ test's text) 0 (1 in the working tree)

And json-schema/, which is published, is byte-identical above. Nothing released moves.

F3 — measured, not resolved

Space searched: every tracked file in this repo at dcea991f12, and the sibling objectui checkout at 3fbdd4a2d.

probe this repo objectui
x-unprojectable-branches 3 — the changeset prose, one comment, one write site (build-schemas.ts:494). Zero reads. 0
control x-schema-count read at five bracket sites in build-schemas-check-mode.test.ts, plus a doc page —
control: json-schema as a consumed surface — 69

The probe finds readers where they exist, in both spaces. build-docs.ts reads no x- annotation off the artifact at all, so the reference pages cannot say a branch was dropped. json-schema is in files[], so the marker is genuinely published to npm with no consumer anywhere.

Same class, not in the card: x-io also has zero readers — one write site (build-schemas.ts:485) and one prose mention, which is the union-branch-projection.ts docblock asserting that "the x-io flag already tells a reader which shape they are looking at". Nothing reads it either. Left for F3.

Verification

check result
vitest run scripts/union-branch-projection.test.ts VERDICT command-exit 0 — 21 passed (21)
pnpm --filter @objectstack/spec test VERDICT command-exit 0 — 473 files / 13439 tests passed
pnpm --filter @objectstack/spec typecheck VERDICT command-exit 0
pnpm --filter '@objectstack/spec^...' build + spec build VERDICT command-exit 0
pnpm lint (whole repo, eslint . --no-inline-config) exit 0, 2m45s — full population, no narrowing
derived gate families (dispatch-gates.mjs --commands, 57 commands) 54 exit 0
control-character self-scan on the changed file no hits

The typecheck green is measured to cover the changed file: tsconfig.test.json includes only src/**/*, so the file is compiled by tsconfig.scripts.json instead — confirmed present with tsc --listFiles, and typecheck runs check:scripts-typecheck.

Declared narrowing. Three of the 57 derived gates exited 3 = PREREQUISITE NOT MET and are recorded as NOT MEASURED, neither pass nor fail: check:dual-build-cjs-loads, check:lean-entry-closure, check:type-check-debt. Each reads built output for the whole workspace (80-plus packages with no dist/), which CI builds before running them. None reads the changed file.

验收备注

Noted, not filed — each names its successor:

  1. Under a loosened guard the five poisoned artifacts are written to disk before the ledger adjudication rejects the build, so the gitignored json-schema/ tree stays poisoned after a build that exited 1. I hit this and had to regenerate. Successor: F3 on [finding] union-branch projection (PR #17085): the 「refuse a marked node anywhere but a direct anyOf/oneOf member」 clause is pinned only at the root — loosening the guard to root-only passes 19/19 and would publish FlowFunctionEntry with an x-os-unprojectable marker leak; x-unprojectable-branches has no reader #17107, which already owns the emission-site question.
  2. The repaired ratchet's own text under that failure reads "Good news, and the line has to go with it — in this same PR", i.e. it prescribes deleting the five ledger lines — which, when the emission is a marker leak, is the wrong remedy. It is only reachable through an already-broken guard, which is what this PR pins. Successor: F3 on [finding] union-branch projection (PR #17085): the 「refuse a marked node anywhere but a direct anyOf/oneOf member」 clause is pinned only at the root — loosening the guard to root-only passes 19/19 and would publish FlowFunctionEntry with an x-os-unprojectable marker leak; x-unprojectable-branches has no reader #17107.
  3. x-io has zero readers (above). Successor: F3 on [finding] union-branch projection (PR #17085): the 「refuse a marked node anywhere but a direct anyOf/oneOf member」 clause is pinned only at the root — loosening the guard to root-only passes 19/19 and would publish FlowFunctionEntry with an x-os-unprojectable marker leak; x-unprojectable-branches has no reader #17107.

No card filed: every observation lands inside #17107's own still-open F3.


Generated by Claude Code

`projectByPruningUnionBranches` refuses a projection when a marked
(unprojectable) node survives anywhere but as a direct member of an
`anyOf` / `oneOf`. The suite pinned that only at the ROOT: loosening the
guard from `findSurvivingMark(schema) !== null` to `=== '#'` passed
19/19, so the suite could not tell the strong guard from the weak one.

Measured why. The four existing "refuses outside a union" assertions —
`z.object({ handler })`, `z.record`, `z.array(z.date())` and
`PersistenceAdapterSchema` — all prune ZERO branches, because none of
those schemas contains a union at all, so each returns null through the
`pruned.length === 0` early-out and never consults the guard. The one
assertion that does reach it carries its mark at the root, which a
root-only guard still refuses.

Adds the shape that discriminates: a union whose first member is dropped
(so the early-out cannot fire) and whose SURVIVING member carries a
marked node in a property position (so the mark sits below the root).
Both halves are asserted directly, so the refusal is attributable to the
guard and to nothing else. Pinned twice — once minimally, once on
`Automation.FlowFunctionEntrySchema`, the real export this holds back,
whose pruned-but-unrefused projection still carries the marker.

Test-only; the guard itself is unchanged and the published artifact is
byte-identical.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MkQhmuuJAVDjmeWNixwDDH
@os-bill os-bill added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Sep 12, 2026 — with Claude
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

Nothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs.

What this run could not see
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.

Coarse fallback — 0 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 482d34d60c1d7bdc808c09a9d4edd152443bb101 → packageMentionDocs.

@github-actions github-actions Bot added tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Sep 12, 2026
@os-bill
os-bill marked this pull request as ready for review September 12, 2026 06:18
@os-bill
os-bill added this pull request to the merge queue Sep 12, 2026
Merged via the queue into main with commit 2eab3be Sep 12, 2026
40 checks passed
@os-bill
os-bill deleted the claude/issue-17107-union-branch-nested-mark-pin branch September 12, 2026 07:14
akarma-synetal pushed a commit to akarma-synetal/framework that referenced this pull request Sep 28, 2026
…ader (objectstack-ai#19135)

Fixes objectstack-ai#17107

Clause-②: no

F3 of objectstack-ai#17107, the card's only live half — F2 landed in objectstack-ai#17804 and was
verified on `origin/main`. `x-unprojectable-branches` is written onto
every JSON Schema the per-branch projection publishes, and
`packages/spec/package.json` ships `json-schema/` in `files[]`, so it is
a **published** field. It had **one writer and no reader**: nothing in
this repo could tell a faithful record from one naming branches the
projection never dropped.

## The premise, re-derived (hits printed, with a lit control)

Tree: `objectstack-ai/objectstack` at `a675ad4ef0` (`origin/main`,
2026-09-18T21:59Z). `git grep -n` over the whole tree.

**Subject — `x-unprojectable-branches`, 5 hits, 0 of them a reader:**

```
.changeset/filter-operator-schema-projection.md:33   changeset prose
packages/spec/scripts/build-schemas.ts:435           comment
packages/spec/scripts/build-schemas.ts:546           THE WRITER
packages/spec/scripts/build-schemas.ts:554           comment
packages/spec/scripts/lib/dropped-refinements.ts:24  docblock prose
```

**Lit control, same instrument — the sibling marker
`x-os-unprojectable`, which really is read:**

```
packages/spec/scripts/lib/union-branch-projection.ts:71  export const UNPROJECTABLE_MARK = 'x-os-unprojectable';
packages/spec/scripts/union-branch-projection.test.ts:208
```

The control fires and resolves to a named constant the projection
branches on, so the zero beside it is a reading, not a dead instrument.
This matches the table in comment 5732887703 that the triage
adjudication (5733358188) adopted in place of the card's own now-inexact
sentence; `dropped-refinements.ts:24` is prose, added after filing, and
is not a reader.

## Which kind of reader — and why the docs page was the wrong one for
this card

Triage ruled verbatim that a reader need **not** be a docs page: reading
route A as "render it in the docs" is the card's two named pages, not
the definition of the word. Both kinds were available. This PR builds
the **checking** reader, for four reasons that are properties of this
card rather than preferences:

1. **A docs note cannot fail.** Rendering the record into `filter.mdx` /
`hook.mdx` prints whatever the record says. If the record named a branch
the projection never dropped, the page would print that too —
faithfully. The card's class is (a), *an incomplete pin: an assertion
never observed to fail*, so a reader that cannot disagree with the
writer does not close it.
2. **`content/docs/references/**` carries `merge=os-regen`**
(`.gitattributes:153`), where a conflict resolves silently. ⛔ **This PR
regenerates nothing under that tree** — the diff is three files under
`packages/spec/scripts/`, and `content/docs/references/` is untouched.
3. **`build-docs.ts` is outside the file surface this card was
dispatched with.** The dispatch cleared `union-branch-projection.ts`,
its test, and `build-schemas.ts`.
4. It strengthens an existing gate rather than adding a required one:
the audit runs inside `gen:schema`, which every spec build already runs.

The docs half of the card's original ask stays unbuilt and is called out
in the acceptance notes rather than silently dropped.

## What the reader is

`auditUnprojectableBranchRecord` reads the record **off the artifact, by
its key**, and checks it in two directions — either alone passes a
record that lies:

- **Replay.** Removing exactly the branches the record names from the
unpruned projection must reproduce the published file. Only root
**annotation** is allowed on top (`$id`, and `x-` keywords, which every
validator ignores); anything structural stays in the comparison. This
catches a pointer whose index shifted — the hazard
`pruneMarkedUnionBranches` records the pre-removal index to avoid — an
entry for a branch that was never dropped, and a missing entry for a
union that collapsed whole.
- **Completeness.** Every marked direct union member of the unpruned
projection must appear under the type it was marked with. The replay
cannot see this on its own: a collapsed union is removed wholesale, so
the members inside it reproduce the published file whether the record
names them or not.

`build-schemas.ts` calls it in the one place that still holds the tree
the record describes, and the build **fails** on a disagreement. The key
also moves from a bare literal at the writer to
`UNPROJECTABLE_BRANCHES_KEY`, declared beside the prune that produces
the record, so writer and reader cannot drift to two spellings.

`BranchProjection` gains `unpruned`, a clone taken before the prune
mutates the tree in place — the record states what is *missing* from the
published schema, and the only tree that can answer whether it states it
correctly is the one the branches came out of.

## Ablation — the reader really fails when the marker and the real
dropped branches disagree

Three legs, all against the real generator on the real corpus (1541
schemas, 5 of them branch-pruned, 31 recorded branches). Mutations
landed through `scripts/ablation-replace.mjs`, which proves each write
on disk (anchor count 1 to 0, `git hash-object` blob moved) and proves
each restore against `HEAD`. No `dist` leg: `gen:schema` runs
`build-schemas.ts` through tsx from source, so `dist/` is not on the
resolution path.

**Leg A — record tampered (`prunedBranches.slice(1)`), reader present ⇒
`gen:schema` exits 1:**

```
ablation-replace: ok mutation landed: anchor 1 -> 0, blob e5f42c7 -> 4efb4df32134
❌ 5 `x-unprojectable-branches` record(s) disagree with the schema they annotate:
   ⤷ Data.ComparisonOperatorSchema: #/properties/$gt/anyOf/1 was dropped as "date" and the record does not say so
   ⤷ Data.FieldOperatorsSchema: #/properties/$gt/anyOf/1 was dropped as "date" and the record does not say so
   ⤷ Data.NormalizedFilterSchema: #/properties/$and/items/anyOf/0/additionalProperties/properties/$gt/anyOf/1 was dropped as "date" and the record does not say so
   ⤷ Data.RangeOperatorSchema: #/properties/$between/prefixItems/0/anyOf/1 was dropped as "date" and the record does not say so
   ⤷ Data.HookSchema: x-unprojectable-branches is [], not the non-empty array of dropped branches this projection has
Exit status 1
ablation-replace: ok restored: blob == HEAD (e5f42c7) and `git diff HEAD` is empty
```

**Leg B — the same tamper with the reader deleted, i.e. today's code ⇒
`gen:schema` exits 0 and the wrong record ships unremarked:**

```
ablation-replace: ok mutation landed: anchor 1 -> 0, blob e5f42c7 -> 61086c23e26a
✅ Successfully generated 1541 schemas.
data/ComparisonOperator.json carries:
  [{"at":"#/properties/$gte/anyOf/1","type":"date"},
   {"at":"#/properties/$lt/anyOf/1","type":"date"},
   {"at":"#/properties/$lte/anyOf/1","type":"date"}]
ablation-replace: ok restored: blob == HEAD (e5f42c7) and `git diff HEAD` is empty
```

Leg B is the defect itself, executed: `$gt`'s dropped Date branch
vanishes from the record, the file publishes anyway, and nothing
anywhere objects. Leg A is the same run with the reader in place.

**Restore leg — unmutated tree, real generator ⇒ exit 0, correct record
back, whole tree clean:**

```
✅ Successfully generated 1541 schemas.
record now: [{"at":"#/properties/$gt/anyOf/1","type":"date"}, {"at":"#/properties/$gte/anyOf/1","type":"date"},
             {"at":"#/properties/$lt/anyOf/1","type":"date"}, {"at":"#/properties/$lte/anyOf/1","type":"date"}]
git status --porcelain: (empty)
```

## Tests

`packages/spec/scripts/union-branch-projection.test.ts` — 21 tests
before, **28 after**, all passing. The seven new ones pin: the record
`build-schemas.ts` actually writes, for all four exports objectstack-ai#16431 measured
(asserted non-vacuous — each has a record to audit); a shifted pointer;
an under-reporting and an inventing record; a record that renames what
was dropped; a malformed record; the annotation carve-out and a
structural addition beside it; and the collapsed-union case, where the
completeness direction is the only one that can report the loss.

## Local verification

Gates derived mechanically from the change set with `node
scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` (3 paths vs merge base `a675ad4ef0`), not
from a hand-written list.

- `pnpm --filter @objectstack/spec typecheck` — green (`tsc --noEmit`,
`check:scripts-typecheck`, `check:test-typecheck`; the scripts layer is
a real tsc program here, `tsconfig.scripts.json`).
- `pnpm --filter @objectstack/spec exec vitest run
scripts/union-branch-projection.test.ts` — 28/28.
- `pnpm --filter @objectstack/spec gen:schema` — 1541 schemas, 5
branch-pruned exports, 31 recorded branches, zero record defects.
- Dependency closure ①: `packages/spec` has no workspace dependencies,
so the closure is empty and ① is a no-op here.
- `eslint . --no-inline-config` — the repo-wide scan ran in full rather
than narrowed: **6881 files, 0 errors, 0 warnings**, exit 0 (file count
read from eslint's own `--format json` output), measured at
`fbc6c5ad90`, the final commit, on a clean tree. All three changed files
appear in that run at 0/0.

## Does anything published move? Measured

`skip-changeset`, on the stated criterion — nothing in any package's
`files[]` moves.

- **Subject:** `auditUnprojectableBranchRecord` and
`UNPROJECTABLE_BRANCHES_KEY` — **0 hits** across every `files[]` path of
`@objectstack/spec` that exists on disk (`json-schema`, `liveness`,
`prompts`, `llms.txt`, `README.md`, `src/**/*.zod.ts`, `CHANGELOG.md`,
`api-surface`, `api-surface-declarations`, `spec-changes.json`).
- **Lit control, same instrument and same trees:**
`x-unprojectable-branches` — **6 files**. The instrument fires.
- `dist` is the one `files[]` entry not on disk here; measured
structurally instead — 0 of `tsup.config.ts`'s 22 entry-shaped paths is
under `scripts/`, so no byte of `scripts/` can reach it.
- The emitted `json-schema/**` content itself is unchanged: the audit is
pure (it clones before replaying and returns `string[]`), and the
writer's only edits are a literal replaced by the constant of the same
value and a null-guard on an already-equivalent condition. A
byte-for-byte BASE-vs-HEAD diff of the emitted tree was **not** run and
is not claimed.

## Acceptance notes

- **The docs half of the card's original F3 ask is not built here.** The
card asked for either a `build-docs.ts` one-line note or a docblock
stating artifact-only reach; triage established the docblock option is
prose and not a reader, and this PR takes the third route triage named.
`filter.mdx` and `hook.mdx` still show the projected type with nothing
on the page saying a branch was dropped. Left deliberately: it is a
separate change to a `merge=os-regen` tree and to a file outside this
card's surface.
- **One sentence on the card's face is inexact and was already corrected
before this PR:** "grep only finds the writer and the changeset" — there
is now also the `dropped-refinements.ts:24` docblock, added after
filing. Prose, not a reader; the premise is unaffected. Re-derived
above.
- **Noted, not filed:** `x-io` is the same shape one key over — written
at `build-schemas.ts:537`, mentioned once as prose at
`union-branch-projection.ts:268`, and read by nothing in this repo (lit
control, same trees: `x-spec-version`, 3 hits including `llms.txt`).
Reported to the dispatching seat with dedupe words rather than filed
here; it differs from F3 in that a two-state flag set from the variable
that chose the direction cannot disagree with itself, so its remedy is
likely the enforce-or-remove channel rather than a reader, and that
routing is not this PR's to decide. Radius of the zero: the
`objectstack` tree at `a675ad4ef0`, excluding generated `json-schema/`;
outside it, and therefore not measured, are `objectui`, `cloud` and any
consumer of the published tarball.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01JbZnqu8bt6YqfJsr9vaFb3)_

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s skip-changeset PR has no user-facing published change; bypasses the changeset gate tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants