Skip to content

fix(portal): an old retire or delete form no longer hits a patch that took its name - #362

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/339-stale-confirmation
Sep 24, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/339-stale-confirmation

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

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

@github-actions github-actions Bot added area:docs Touches the docs area area:ui Portal and first-party browser pages, shared rendering and styles size:s Under 100 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed git diff origin/fix/329-former-names...HEAD, base ae80ec8, PR head eafeeb4c, against #339. One pass, no subagents; merge-blocking findings only.

Standards

No merge-blocking method or YAGNI findings. The change uses the existing escaped hidden-field helper, form decoders, refusal rendering and lifecycle mutations. It adds no routing redesign or future-facing abstraction.

No UI consistency findings. No Effect service findings.

Spec

No merge-blocking intent findings. Both Retire and Delete confirmations carry a required stable patch ID. Submission rejects a changed name-to-ID binding before mutation and passes only the checked ID to the existing service. Actor, lifecycle-state, dependant and typed-name checks remain intact. Leaving other portal actions unchanged matches the Retire/Delete scope of #339.

The regression cases submit the rendered hidden fields after normal rename and name reuse. They verify 409 for the stale identity, 422 for a missing ID, and unchanged original and replacement patches.

Verification

Ran pnpm exec vitest run packages/portal/src/PortalPages.test.ts: 51/51 passed, including the new stale-identity regressions and existing confirmation behavior.

Applicable cross-checks were served HTML, its POST consumers, regression coverage and the updated product documentation. No API/CLI contract, dev-loop, migration, company-resource, reverse-state or repository-layout change.

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

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed PR 362 against issue 339, on fix/329-former-names...HEAD (ae80ec8..eafeeb4). The change is the small fix the issue describes, and the method is the right one. One refusal page still leaves a submit pointed at the replacement.

Spec

Issue 339 asks a Retire or Delete confirmation to carry the patch id it was rendered for. Submit must require that id, refuse when the name now resolves to a different patch, and pass only that id to the existing mutation. Actor, state, and dependant checks stay. Routing stays by name.

The rendered form does this. renderConfirmation writes expectedPatchId for retire and delete. When that id is not the patch post just resolved by name, the handler returns 409 and does not call retire or delete. When it matches, patches.retire and patches.delete receive that id and still enforce state and dependants in their own transactions. A rename that frees no name still 404s. Restore, reassign, and the inline card forms sit outside the issue, and the new product sentence does not claim they changed.

The hole is a post with no expectedPatchId. Decode fails with SchemaError, the shared handler turns that into 422, and redisplay builds a new confirmation for whoever holds the name now (PortalPages.ts around the SchemaError arm, invalid, and redisplay). The notice is "Check the submitted fields and try again. Nothing was done." The new form's hidden id is the replacement's. On Delete, the name from the old page is already filled in, and that string is the replacement's current name. The next submit is an ordinary confirmation, so the replacement is retired or deleted.

Tabs open before this ships have no expectedPatchId. Those are the confirmations the issue is about, until the page is loaded again.

Issue 339 says a stale act should do nothing. The 409 card does that. stale() would describe the replacement, because selected is the patch the name points at now. The name-reuse sentence should stay as it is.

Standards

Effect service conventions hold. UI consistency holds. The new control is the existing hidden() helper, the value is escaped, and there is no new class or page CSS.

The same id compare sits in the retire branch and the delete branch. That is a duplicated-code smell, and a judgement call. It should stay. Delete still has its own typed-name check, and a wrapper would only hide those two lines.

expectedPatchId is Schema.String, same as expectedOwnerUserId. A PatchId brand would only check the twelve-character shape. Any other string is already refused by the compare.

The comment above decodeRetire says a reused name never reaches the other patch. The compare does that when the id is present. The 422 page renders a confirmation for that other patch. I would delete the comment.

Method

Resolve the name, compare ids, then call retire or delete with the submitted id. That handoff is right. Both mutations update WHERE id = …. If the name moves after the handler's read() and the ids still matched, the write still hits the form's patch. The new holder is a different id.

nameReused returning the portal card at 409 is the right page. That card does not post the old action. Its Retire and Delete controls are fresh GETs. Rendering the confirmation again would post straight at the replacement.

A missing id should end on a card too. Keep "This name now belongs to a different patch. Nothing was done." for a present id that does not match. A missing id is a different case, including an old tab whose patch was never renamed, so that sentence would be false there. "This confirmation is out of date. Nothing was done." on the same 409 card covers it. Stop on that card.

Reassign still trusts the name plus expectedOwnerUserId. The same rename and republish, same owner, reassigns the replacement. Restore is a different case. A retired or deleted name stays reserved on this stack, so there is no free name for a second patch to take. That is a follow-up. This diff should stay on retire and delete.

Tests

The new test follows the issue. It reads the confirmation, renames the live patch, publishes another patch under the old name, and posts the hidden fields the page rendered. Both readPatch snapshots have to match. The rename is of a live patch, so the test does not depend on the former-names branch. If the template dropped the id, expectedPatchId would not equal original.patchId. If the handler ignored the id, the status assertion would fail, because the old behavior was 303 and the replacement changed.

The 422 half of that test locks the dangerous page in. It checks the sentence and that the first post wrote nothing. The body is still a Retire or Delete form for the replacement. Once the refusal is a card, that arm should expect 409 and no confirmation-form.

The older retire and delete posts send expectedPatchId from the fixture. They stay green if the template stops emitting the field. This new test is the one that reads the field from the HTML, which is enough.

The regex wants type, then name, then value. hidden() emits that order today. The file already has an order-independent hidden() helper. A reorder fails this test closed.

Standards: no hard violations. One judgement, the duplicated compare, and it should stay.
Spec: one hole. A missing id re-renders a confirmation for the replacement and tells the reader to try again.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Addressed the reviews in 699574a.

Fixed

  • Missing expectedPatchId re-rendered a confirmation for the replacement (grok, Spec). Confirmed against the source: without the field, decoding failed with SchemaError, and invalid/redisplay then built a Retire/Delete form for whichever patch now holds the name, with Delete's typed name already filled in. Retire and delete now compare the submitted id before decoding. A missing id stops on the card at 409 with "This confirmation is out of date. Nothing was done." I picked 409 over 422 because this is a stale page, not a bad entry: the product answers stale fields with 409 on a fresh card, and 422 is for text the reader can fix and resubmit, which is exactly what must not happen here. A present but mismatched id keeps "This name now belongs to a different patch. Nothing was done."
  • The test now covers this. The missing-id case expects 409, the card heading, no form posting to the confirmation path, and both patches unchanged. Against the previous handler it fails with expected 422 to equal 409.
  • The comment above decodeRetire over-promised (grok). Deleted. A short comment above the refusal helper in post explains why both cases end on the card.

Kept as is

  • Duplicated id compare in the retire and delete branches. It is two lines each, and Delete runs its own typed-name check right after. A shared wrapper would hide the order of checks without saving anything.
  • expectedPatchId as Schema.String, not a PatchId brand. It matches expectedOwnerUserId. The exact compare with the resolved patch's id already refuses any other string, so a brand would only add a shape check that can't change the outcome.
  • Order-dependent hidden-field regex in the new test. It matches what hidden() emits today and fails closed if that ever changes.
  • Restore, Reassign and the card's inline forms still resolve by name. Outside portal: stale Retire/Delete confirmation can mutate a different patch after name reuse #339, left for a follow-up as the description says. Grok's note that Reassign is exposed the same way under same-owner name reuse is the main candidate.

Verification: portal suite 51/51, pnpm typecheck and pnpm lint clean.

Base automatically changed from fix/329-former-names to main September 24, 2026 14:01
allisonmahmood and others added 2 commits September 24, 2026 16:02
… patch that took its name

A Retire or Delete confirmation resolved its patch by name at submission, so
after the original patch was renamed and another patch took the old name, the
untouched form retired or deleted the new patch. The confirmation now carries
the patch id it was rendered for; the POST requires it, refuses with 409 and
nothing done when the name resolves to a different patch, and passes only that
id to the existing mutation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… on the card

A form posted without expectedPatchId, such as a tab opened before the id
was added, failed decoding and re-rendered a confirmation for whichever patch
now holds the name, with Delete's typed name already filled in. It now ends
on the card at 409 with nothing done, the same page a mismatched id gets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/339-stale-confirmation branch from 699574a to 379c813 Compare September 24, 2026 14:02
@allisonmahmood
allisonmahmood merged commit ba95850 into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/339-stale-confirmation branch September 24, 2026 14:09
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
…#363)

Stacked on #362 (branch fix/339-stale-confirmation).

Closes #330.

The root `dev` script bundled the shell broker before handing off to the runner, so every subcommand depended on it. If you were halfway through a broker edit and it had a syntax error, `pnpm dev stop` exited 1 and left the instance running. `status`, `logs` and `--dry-run` had the same problem.

Now `package.json` runs the runner directly. `pnpm dev` (when it actually starts) and `pnpm dev reset` build the broker first, before they record, stop or wipe anything. A failed build prints esbuild's errors to stderr, then one `BrokerBuildFailed` line, and exits 1 with the instance and `.local/dev` untouched. Management commands and confirming a healthy instance never compile it. `docs/DEVELOPMENT.md` (under the subcommand table) and the `patchy-dev-loop` skill say so.

**Tests.** `scripts/dev/src/main.test.ts` runs the root `dev` script, as pnpm does, in a throwaway worktree whose broker doesn't compile:
- `stop` with a recorded idle process as the supervisor: on the old code it exited 1 and the process stayed alive; now it exits 0 and stops the process.
- `reset` with the same recorded process: exits 1, the process stays alive, and `plan.json` is still there. On the first version of this PR it stopped the process and wiped the state.
- A plain start: exits 1, stderr names `broker.ts`, and no `plan.json` is written.

`pnpm typecheck` and `pnpm lint` are clean, and the `scripts/dev` tests pass (15/15). On the first commit, `pnpm test` passed 952 of 953. The one failure was `packages/integrations/src/postgres/Runtime.test.ts` timing out at 5s under machine load; on its own it passes.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).
allisonmahmood added a commit that referenced this pull request Oct 2, 2026
Closes #371.

#362 bound the Retire and Delete confirmations to the patch's ID. The
other portal forms (Restore, Reassign, and the card's description,
sharing and rollback forms) still looked their patch up by name when
submitted. A live patch's former name can be claimed by another patch,
so a form left open across a rename and name reuse acted on the
replacement. An owner's stale sharing form could make a different patch
public.

Every portal POST form now carries `expectedPatchId`. That includes the
Restore button on an off patch's own address page, which posts into the
same handler. The forms open through one `actionForm` helper that writes
the ID, so a new form can't leave it out. The handler checks the ID
once, before anything else:

- If the ID is mismatched, it answers 409 on the card with "This name
now belongs to a different patch. Nothing was done."
- If the ID is missing (a tab opened before this change), it answers 409
with "This form is out of date. Nothing was done."
- If it matches, only that ID reaches the `Patches` mutation. Every
existing precondition still runs, and the mutation signatures are
unchanged.

The ID check runs before the owner/admin check. Otherwise an owner's
stale form at a name now held by someone else's patch would get "Only
the owner or an admin can do that", which is misleading. A form whose ID
matches still gets the same 403 as before.

Tests: #362's name-reuse test now covers all seven actions, using each
page's real hidden fields. On the old code, description, sharing,
restore and reassign returned 303 and changed the replacement patch, and
rollback refused with the wrong notice. Now each gets 409 on the card,
for both a mismatched and a missing ID, with both patches unchanged. A
new test covers a different owner's patch taking the name. `pnpm verify`
passes all 8 stages.

Made by Claude Opus 5.5 via Claude Code; reviewed by GPT 6.1 Sol via
codex.

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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:ui Portal and first-party browser pages, shared rendering and styles size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

portal: stale Retire/Delete confirmation can mutate a different patch after name reuse

1 participant