Repository navigation
test(spec): pin the union-branch projection refusal for a mark nested in a surviving union branch - #17804
Merged
Conversation
`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
Contributor
📓 Docs Drift CheckNothing 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
Coarse fallback — 0 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): |
This was referenced Sep 12, 2026
os-bill
marked this pull request as ready for review
September 12, 2026 06:18
This was referenced Sep 12, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #17107 — F2 only. F3 (
x-unprojectable-brancheshas 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.The defect
projectByPruningUnionBranchesrefuses a projection when a marked (unprojectable) node survives anywhere but as a direct member of ananyOf/oneOf. The suite pinned that clause only at the root. Loosening the guard fromfindSurvivingMark(schema) !== nulltofindSurvivingMark(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:=== '#'Why the existing pins could not see it — measured, not assumed
Every other "refuses outside a union" assertion returns
nullthrough thepruned.length === 0early-out, never through the guard:z.object({ handler: z.function() })#/properties/handlerz.record(z.string(), z.function())#/additionalPropertiesz.array(z.date())#/itemsPersistenceAdapterSchema#/properties/loadz.union([z.date(), z.function()])#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:
z.union([z.function(), z.object({ handler, name }), z.string()])#/anyOf/0)#/anyOf/0/properties/handlerAutomation.FlowFunctionEntrySchema(the real export)#/anyOf/0/properties/handlerBoth halves are asserted directly in the test, in both
iodirections, 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 theexpect(pruned).toEqual(...)line reds first.Discrimination proof
Test-only change, committed first, then the guard mutated on disk under a trap:
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:schemarun twice in the same tree, the one changed file swapped to its base content in between:json-schema/9675d5f4c959d63a9675d5f4c959d63aByte-identical, and
git statusreports 0 checked-in generated artifacts moved.The instrument is lit. Under M1b the same measurement moves: 1529 files, manifest
472d131ac42de3ee, andgen:schemaexits 1 naming five ledger entries that now emit —all five written to disk carrying
x-os-unprojectable. The card named one export; the measured population is five.Changeset:
skip-changeset, measuredpackages/spec'sfiles[]isdist, json-schema, liveness, prompts, llms.txt, README.md, src/**/*.zod.ts, CHANGELOG.md, api-surface, spec-changes.json—scripts/is not in it.FlowFunctionEntrySchemadist/scripts/test's text)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 siblingobjectuicheckout at3fbdd4a2d.x-unprojectable-branchesbuild-schemas.ts:494). Zero reads.x-schema-countbuild-schemas-check-mode.test.ts, plus a doc pagejson-schemaas a consumed surfaceThe probe finds readers where they exist, in both spaces.
build-docs.tsreads nox-annotation off the artifact at all, so the reference pages cannot say a branch was dropped.json-schemais infiles[], so the marker is genuinely published to npm with no consumer anywhere.Same class, not in the card:
x-ioalso has zero readers — one write site (build-schemas.ts:485) and one prose mention, which is theunion-branch-projection.tsdocblock asserting that "thex-ioflag already tells a reader which shape they are looking at". Nothing reads it either. Left for F3.Verification
vitest run scripts/union-branch-projection.test.tsVERDICT command-exit 0— 21 passed (21)pnpm --filter @objectstack/spec testVERDICT command-exit 0— 473 files / 13439 tests passedpnpm --filter @objectstack/spec typecheckVERDICT command-exit 0pnpm --filter '@objectstack/spec^...' build+ spec buildVERDICT command-exit 0pnpm lint(whole repo,eslint . --no-inline-config)dispatch-gates.mjs --commands, 57 commands)The
typecheckgreen is measured to cover the changed file:tsconfig.test.jsonincludes onlysrc/**/*, so the file is compiled bytsconfig.scripts.jsoninstead — confirmed present withtsc --listFiles, andtypecheckrunscheck: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 nodist/), which CI builds before running them. None reads the changed file.验收备注
Noted, not filed — each names its successor:
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 publishFlowFunctionEntrywith anx-os-unprojectablemarker leak;x-unprojectable-brancheshas no reader #17107, which already owns the emission-site question.repairedratchet'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 publishFlowFunctionEntrywith anx-os-unprojectablemarker leak;x-unprojectable-brancheshas no reader #17107.x-iohas 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 publishFlowFunctionEntrywith anx-os-unprojectablemarker leak;x-unprojectable-brancheshas no reader #17107.No card filed: every observation lands inside #17107's own still-open F3.
Generated by Claude Code