Skip to content

fix(primitives): a table and a file store can no longer share a name across versions - #360

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/333-name-collision
Sep 24, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/333-name-collision

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Stacked on #359 (branch fix/320-runtime-success-encoding).

Omitting a table from a later manifest keeps it in the inventory, but that manifest could still add a file store with the same name (or add a table with an omitted store's name). The publish succeeded and left one name holding both a table and a store, which the product rule forbids. Closes #333.

Now, before running any DDL, the provisioner's diff refuses a new store whose name belongs to a table in the inventory, and a new table whose name belongs to a store. It reports this with the existing not_additive error and tells the user to pick a different name. The check inside a single manifest is unchanged, and omitted resources are still kept. I also updated the publish route description, docs/API.md, docs/product.md and the patchy-tables project skill.

Test evidence

  • New contract test crossKindNames, run on Postgres and PGlite. It failed on both before the fix, where version 2 provisioned the store and kept the table. After the fix it passes and shows no DDL and an unchanged inventory.
  • Tables.test.ts 18/18, pnpm typecheck and pnpm lint clean.
  • Full pnpm test: 947 passed, 1 failed. The failure was packages/integrations/src/postgres/Runtime.test.ts hitting its 5s timeout under machine load, which is unrelated to this change. It passes when run alone.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).

@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area area:primitives Patch tables and files size:s Under 100 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed 3dc4b2a against origin/fix/320-runtime-success-encoding at d5511f0, using the three-dot diff and issue #333. One pass, no subagents. Only merge blockers considered.

Standards

No merge-blocking method or YAGNI findings. The two cross-kind membership checks reuse the existing cumulative inventory maps and NotAdditive aggregation. They belong in the shared diff used by publish preflight, locked provisioning and local development. No new abstraction or future-facing behavior is needed or introduced.

Spec

No merge-blocking intent findings. Both table-to-store and store-to-table name reuse are refused before DDL, with the existing not_additive error and a different-name remedy. Same-manifest validation remains unchanged. Omitted resources remain preserved, and same-kind reintroduction remains allowed. The API description, product docs and table skill describe the new refusal.

Verification: pnpm exec vitest run packages/primitives/src/Tables.test.ts passed all 18 tests across PostgreSQL and PGlite. This includes both cross-kind refusals, unchanged inventory, no companion-table creation on refusal, and the existing omission/reintroduction cases.

Summary: Standards 0 blockers; Spec 0 blockers. No merge-blocking issue on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed 3dc4b2a against issue 333. This is the top commit only. The parent stack (#359 and the commits under it) is out of scope.

Spec

Issue 333 asked for one change. Before any DDL, Tables.diff should refuse an incoming store name that is already in snapshot.tables, and an incoming table name that is already in snapshot.stores. Use the existing not_additive error and a fresh-name fix. Leave same-manifest validation alone. Keep omitted data.

That is what the diff does (packages/primitives/src/Tables.ts 328–348, failure at 478). The fixes are "give the file store a different name" and "give the table a different name". distinctPrimitiveNames in packages/api/src/schemas.ts is untouched. Omission still only fills unused. crossKindNames covers both directions after omission, on the existing Postgres and PGlite layers, and checks that the inventory is unchanged and that shouldNotExist was not created.

Nothing asked for is missing. The doc and skill edits state this rule.

Standards

No documented-standard violations. No baseline smells.

Effect. Reusing NotAdditive matches the convention. The failure stays on the existing wire code, and the message is still built from object, change, and fix. A second error tag would record the same distinction twice. The test's Effect.flip, assert.instanceOf, and _tag check match refusals in the same file. instanceOf throws, so the return only narrows the type. The new case is an it.effect on the suite's existing it.layer. No new service, layer, or runtime.

Surfaces. The publish description in packages/api/src/api.ts and docs/API.md gained the same sentence. docs/product.md now says reuse after omission is not_additive. patchy-tables says the kept name stays taken in both directions. Project skills are generated from packages/sdk/skills, so that edit is the distribution step. The files skill, the global skill, skills-lock.json, the CLI, ADR-0004, the glossaries, and migrations do not need a change. not_additive is already exit 2 on the CLI and already the 422 body on publish (packages/patches/src/PatchesApi.ts 471–478).

The two changes.push blocks look similar. They differ in both sentences an agent reads, and a shared helper would be more code. Inline is the smaller shape.

Method

Tables.diff is the right place. The manifest schema only sees one version, which is why a same-manifest collision was already rejected and this one was not. The check lives in the only planner:

  • Publish decodes the manifest, then Content.publish runs Patches.preflight, which diffs and, when a snapshot exists, validates (another diff).
  • Patches.record calls Patches.provision, which diffs under the patch lock and then calls Tables.provision.
  • Tables.provision reads the inventory and diffs before any CREATE, putTable, or putStore. The store write sits outside the schemaChanged block. A failed diff never binds plan, so that loop does not run.
  • The dev loop provisions through the same functions.

Inventory.read loads every patchy.tables and patchy.stores row. Omission does not delete those rows, so an omitted name is still in the sets this check reads.

Same-kind reintroduction still takes the oldStores.has continue or the existing-table branch. A new name is in neither set. A same-manifest clash stays invalid_manifest.

On a hit the name is still appended to newStores or newTables, and to provisioned, before the function returns NotAdditive. Those arrays are local and discarded with the plan. The table branch has to fall through so a colliding definition still reports column and index problems in the same error. This is safe because provision uses newTables and newStores only after diff returns a plan.

Rows that already have both kinds under one name are left as they are. Republishing the existing store takes the oldStores.has continue and skips the new check. Issue 333 does not ask for a cleanup.

YAGNI

This is the small version. The fix is the two pushes onto changes. The comment states the constraint the sets do not: an omitted name stays taken by its first kind. The test is one case each way, with the same DDL canary and inventory comparison as refusals. Leave the inline pushes, the fall-through, and this test.

Standards: 0 findings. Spec: 0 findings. No worst issue on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Both reviews on 3dc4b2a are clean. Astra and the Standards/Spec/Method review each report 0 findings, so there is nothing to fix.

One note, kept as is: grok's Method section points out that a patch that already has a table and a store under one name keeps both. Republishing the existing store skips the new check. Issue 333 only asks to refuse new collisions, not to clean up old ones, so this PR leaves them alone.

Checks on 3dc4b2a all pass: lint, test (22), test (24), postgres-concurrency, cli-smoke, clerk-live, dependency-review, label (run). GitHub reports the PR as mergeable (merge state CLEAN) into fix/320-runtime-success-encoding, which is #359.

@allisonmahmood
allisonmahmood force-pushed the fix/320-runtime-success-encoding branch from 60c539b to 0c56d74 Compare September 24, 2026 13:37
Base automatically changed from fix/320-runtime-success-encoding to main September 24, 2026 13:44
…across versions

Omitting a table keeps it in the cumulative inventory, but a later manifest
could add a file store under its name (and the reverse), leaving one name
with two kinds. Tables.diff now refuses an incoming store named after an
inventory table, and an incoming table named after an inventory store, as
not_additive with a fresh-name fix, before any DDL.

Closes #333

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 2f1ffeb into main Sep 24, 2026
8 of 16 checks passed
@allisonmahmood
allisonmahmood deleted the fix/333-name-collision branch September 24, 2026 13:52
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
Stacked on #360 (branch fix/333-name-collision).

A retired or deleted-but-recoverable patch reserved only its current name. Another patch could take one of its former names, and restoring the original did not get that address back. Fixes #329.

Publish preflight and the final name claim now share one availability rule (`nameAvailable` in `Patches.ts`): a name is free to a patch if the patch already holds it, or if it is a former name of a patch that is neither retired nor deleted. The claim still happens inside the existing publish transaction. A live patch's former names can still be reused, and reclamation still releases names by deleting their rows. The `name_taken` description in `packages/api` and `docs/API.md` now says this.

Test evidence: a new test in `Patches.test.ts` reproduces the ticket for both retired and deleted patches. Preflight and commit both return `NameTaken`, restore gets the former name back, and the name becomes free once the patch is live again or reclaimed. It failed before the fix and passes now. `pnpm typecheck` and `pnpm lint` are clean. `pnpm test`: 948 of 949 passed. One unrelated Postgres integration test timed out under machine load and passed when re-run alone.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Touches the docs area area:primitives Patch tables and files area:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

primitives: successive valid manifests admit a cumulative table and store name collision

1 participant