Skip to content

fix(patches): retired and deleted patches keep their former names - #361

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/329-former-names
Sep 24, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/329-former-names

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

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).

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

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed git diff origin/fix/333-name-collision...HEAD, base 3dc4b2a and head ae80ec8, against #329. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The shared SQL predicate implements the reuse requested by the issue without adding machinery. Final claiming stays in the existing transaction; publish and lifecycle transitions already share the company-level lock.

Spec

No merge-blocking intent findings. Preflight and final claim both reserve former names while their holder is retired or deleted. Live former-name reuse and release after reclamation remain supported. The API description and docs/API.md agree with the behavior. No unrelated scope added.

Verification

Seven focused tests passed across Patches.test.ts and PatchesApi.test.ts, covering former-name reservation and restoration, reclamation, the recovery deadline, derived-name collisions, opposing renames, and lifecycle transaction fencing. The filter skipped 66 other tests; the full suite was not run.

Summary: Standards 0 blockers; Spec 0 blockers. No worst issue on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed PR 361 against issue 329 and the diff from 3dc4b2a (the stack base) to ae80ec8.

Standards

The diff follows the documented standards. Findings: 0.

nameAvailable is a SQL fragment inside Patches.make, and both claimName and publish preflight use it. That matches the Effect service rules in .agents/skills/effect-service-conventions/SKILL.md: helper next to its caller, dependencies from the environment, no new service, error type, or runtime. NameTaken is unchanged. The new case is one it.effect on the existing it.layer, which is what a behavior change in this package should add.

The publish description matches in packages/api/src/api.ts and docs/API.md. The CLI readme, skills/patchy/SKILL.md, docs/product.md, and packages/patches/CONTEXT.md already say retire and delete reserve every name until reclamation, so they stay as they are. No command, --json shape, migration, or vocabulary change.

No Fowler smells in the delta. The fragment is the shared rule issue 329 asked for, with two callers that had already drifted.

Spec

The diff matches issue 329. Missing requirements: 0.

Preflight and claimName share one rule. Another patch may take a name when it is a former name of a live patch. A retired or deleted patch keeps every name until reclamation deletes the rows. The claim stays inside record's transaction (Patches.ts around 1660). purgeDeleted still runs DELETE FROM patch_names by patch id.

The new test follows the reproduction for both states. Create, rename, retire or delete, then both preflight and record fail with NameTaken. Restore still resolves the old name to the original patch. That is issue step 5. After restore, the retired arm takes the old name, which is the live-alias reuse the issue says to keep. The deleted arm advances 30 days, purges, and then takes the name.

Live-alias reuse is only taken on the retired arm. The deleted arm restores, checks ownership, then deletes and purges. Both arms use the same predicate, so a second live-reuse case would repeat the first.

The new test does not resolve renamed-* after the take. Current names of a deleted patch staying reserved, and restore keeping that current name, are already in PatchesApi.test.ts ("reserves the name on deletion") and DeletionSweep.test.ts. Retire and delete only stamp patches. They do not rewrite patch_names. A still-current name also cannot pass this new test. After restore the retired arm takes the old name, and a live patch's current name is still NameTaken.

backfillNames still claims with WHERE NOT patch_names.current. Issue 329 asked to share the rule between preflight and the final claim. Detail is under Method.

The API sentence used to say a taken current name conflicts, including deleted patches. That was the buggy contract, and the new sentence matches the predicate. No other behavior landed.

Method

The shared predicate is the right shape.

(patch_names.patch_id = $claimant
 OR NOT patch_names.current AND EXISTS (
   SELECT 1 FROM patches holder
   WHERE holder.id = patch_names.patch_id
     AND holder.retired_at IS NULL AND holder.deleted_at IS NULL))

AND binds tighter than OR, so a row is available when it already belongs to this patch, or when it is a former name of a live holder. The outer parentheses are load-bearing. Preflight is AND NOT around the whole fragment. Without them, NOT would apply only to patch_id = $claimant.

When the ON CONFLICT DO UPDATE condition is false, Postgres updates nothing and RETURNING is empty. claimName is None. An explicit name raises NameTaken. A create with no manifest name still walks -2, -3, and so on through the same claimName (Patches.ts around 1723–1744).

${patchId} stays a bind parameter. Company scope stays outside the fragment. Preflight filters company_id, and the claim conflicts on (company_id, name).

Preflight can still lose to a concurrent publish. The upsert inside the publish transaction is what decides, under the unique index. That is the split the issue already accepts.

backfillNames (Patches.ts around 880) is the only other writer, and it still treats any non-current row as free. Its select is patches with deleted_at IS NULL and no current name row. Publish inserts the patch and its current name in one transaction. Retire and delete do not clear names. The dev supervisor and the vitest template run this seed after the identity seed, when that select returns nothing. It would still take a reserved former name if a nameless non-deleted patch appeared. Current publish does not create one. I would leave the seed alone. Sharing nameAvailable with it means lifting the helper out of make for a population this code no longer produces.

A partial unique index on current names would make retired former names free, which is this bug. A check in TypeScript would race and split the rule again. A reserved column would need a write on retire, delete, restore, and rename. This predicate does not.

YAGNI

This is the small version of the fix.

nameAvailable has two callers, preflight and claimName. Those checks had drifted, one on current and the other on NOT current. A policy type, a join, or another package would be more than the job needs. The comment names both callers and the rule, and it matches the SQL.

The test loop is one scenario. Retired and deleted share the refusal. Only the deleted arm moves the clock and purges. Calling both preflight and record is the check that those two sites agree.

Standards: 0 findings.
Spec: 0 missing requirements. The leftover backfillNames predicate is the only wider gap, and issue 329 did not ask to change that seed.

Reviewed by Grok 4.7 in Grok Build.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review triage for ae80ec8. Nothing needed a code change. Kept as is:

  • backfillNames still claims with WHERE NOT patch_names.current (Grok, Method). It stays. scripts/dev/src/supervisor.ts is its only non-test caller: the dev supervisor runs it once at startup, after migrations and the seed and before the server starts. The production server never runs it. It picks only non-deleted patches that have no current name row. Current code cannot produce such a patch:

    • publish inserts the patch and its current name in one transaction;
    • rename claims the new current name before it clears the old one;
    • retire, delete and restore only stamp patches;
    • purge removes a patch and its names together;
    • the dev seed inserts no patches.

    So the loop runs only for legacy rows from before names existed. It cannot run while a retired or deleted holder has former names under the new rule, because every later publish goes through claimName. Sharing the predicate would mean moving nameAvailable out of make for rows this code no longer creates. patches: former names of retired or deleted patches can be reused before reclamation #329 asked only for preflight and the final claim to share the rule.

  • Only the retired arm of the new test checks live former-name reuse (Grok, Spec). Kept. Both arms use the same predicate, so a second live-reuse check would repeat the first. The deleted arm covers release on reclamation instead.

  • The new test does not resolve renamed-* after the name is taken (Grok, Spec). Kept. PatchesApi.test.ts ("reserves the name on deletion") and DeletionSweep.test.ts already cover that a deleted patch keeps its current name and gets it back on restore.

  • Astra review. No findings.

Checks on ae80ec8: all green (test 22/24, lint, postgres-concurrency, cli-smoke, clerk-live, dependency-review, label). The PR is mergeable and its merge state is clean.

Base automatically changed from fix/333-name-collision to main September 24, 2026 13:52
…il reclamation

Publish preflight and the final name claim now share one lifecycle-aware
rule: another patch's name is free only when it is a former name of a live
patch. A retired or deleted-but-recoverable patch keeps its former names, so
restoring it recovers their redirects; reclamation still releases them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 2ce1606 into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/329-former-names branch September 24, 2026 14:01
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
… took its name (#362)

Stacked on #361 (branch fix/329-former-names).

Closes #339.

A Retire or Delete confirmation page looked up its patch by name when you submitted it. If the patch was renamed and another patch took its old name while the page was open, submitting the untouched form retired or deleted the other patch.

The confirmation form now carries the ID of the patch it was rendered for. Submitting it requires that ID. If the ID is missing (a tab opened before this change) or the name now belongs to a different patch, the request stops on the card with 409 and nothing is done. It never shows a fresh confirmation for whichever patch holds the name now. Only the checked ID reaches the existing mutation. The owner, state, dependant and typed-name checks are unchanged. Restore, Reassign and the card's inline forms still find their patch by name and are left for a follow-up.

Tests: a new portal test for both Retire and Delete takes the page's real hidden fields, renames the patch, publishes a new patch under the old name and posts the old form. On the old code it got 303 and retired or deleted the new patch. It now gets 409 on the card, with no confirmation form and both patches unchanged, whether the ID is mismatched or missing. The portal suite passes 51/51, and `pnpm typecheck` and `pnpm lint` pass. In the full `pnpm test` run, 950 of 951 tests passed. The one failure was a 5-second timeout in `packages/integrations/src/postgres/Runtime.test.ts` while the machine was under load, and that file passes when 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:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

patches: former names of retired or deleted patches can be reused before reclamation

1 participant