Repository navigation
Description
Part of #247. Implements spec §3 (the lifecycle), §4's refusals, §5's stamps, §13 (the schema and the deletion sweep) and the owner verbs of §14; decisions The patch lifecycle, Admin authority (the ownership refusal, restore's warning) and the prototype (expiry goes, two predicates, per-act stamps, purgeAt).
What to build
The prefactor every later ticket stands on: one state model in packages/patches, its schema, and the owner's verbs on the wire. The list, detail and primitive schemas belong to ticket 3.
- Migration
0008_patches_lifecyclein the Patches record, applied by all three migrator call sites (apps/server,scripts/dev, the vitest template): dropexpires_at; addretired_at/by,deleted_by,reassigned_at/by,description(TEXT NOT NULL DEFAULT ''),description_updated_at/by,last_changed_at/by, withusers(id)references and a partial index ondeleted_at. Runtime's replay test applies it after0007. ADR-0003's ledger gains the row. - Three gates replace the one write predicate (spec §1):
serving(deleted_at IS NULL AND retired_at IS NULL AND disabled_at IS NULL) for the address, shared reads,sharedSources, the dependant count and the runtime'sLoadedVersions;openable(same company,disabled_at IS NULL, within the credential's sharing reach, any state) for reads;publishable(openable, owner, live) for publish. The state is derived:deleted_atset is deleted, elseretired_atset is retired, else live.notExpired, the visit top-up and everyexpires_atmirror go;recordVisitkeeps counting visits only. - Moves, each an
Effect.fnonPatchestaking an actor{ userId, admin }and checking ownership or admin in the same transaction under the patch-row lock:retire,delete(from live or retired; names stay reserved;deleted_atis the clock),restore(clears both stamps, lands live, requiresnow < purgeAtfrom deleted, takes the row lock the sweep takes),rollback(versionNumber)(pointer only, live only),reassign(newOwner)(active user of the company),setDescription. Each stamps its own actor columns andlast_changed_by/aton the Effect clock;wrong_stateon an invalid move.retireanddelete-from-live compute the live dependants (distinct patches with a live declaration across retained versions) and failhas_dependantsunlessforce;restorecomputes the sources the current version declares and failssources_offunlessforce, with each source's patch id, name when it exists, table and state (goneincluded);has_dependantscarriesdependants: [{ patchId, name, owner: { id, name } }]. Publish's unshare gains the samehas_dependantsrefusal unlessforce. Nothing physical changes on retire or delete-in-window. - Publish refusals:
not_owner(403, naming the current owner) for a same-company non-owner on publish, share and every verb above, evaluated first; thenpatch_retiredandpatch_deleted(409, withpurgeAt); ownership and state are checked before the bytes and again when the version commits, under the row lock. Publish's unshare refusal is lifted by aforcefield in the request. Another company keeps the 404.reserved_name(422) refusespatchesandconnectionsat create. - The deletion sweep replaces
ExpirySweep(DeletionSweep, same schedule, same batch bounds): rows withdeleted_at + 30 days <= now, recheckedFOR UPDATE(still deleted, still past the window), queue object keys durably, delete versions, names and the row in the platform transaction, then drop the namespace and its file objects through Company database's reclamation; a namespace a crash leaves behind is an orphan the existing sweep drops after a day. - The wire in
packages/api:POST /api/patches/:patchId/retireand/restore({ force? }),DELETE /api/patches/:patchId?force,POST /api/patches/:patchId/rollback { versionNumber },PUT /api/patches/:patchId/description { description }(500 code points after whitespace collapse, one paragraph, no control characters;invalid_description422; refused on a deleted patch), each answering the documents in spec §14 withpurgeAtwhere a delete is involved; the refusal bodies carrydependants,sources,owner,state,purgeAtbesidecode. Publish acceptsmanifest.description, file mode'smetadata.descriptionandforce, stores them with the stamps, and returnsdescriptionanddescriptionUpdatedAt.docs/API.mdregenerates.
Admitted at merge
Every verb above under a machine token for the owner; admin actors through the service only (the portal comes with ticket 8). PatchesApi.delete keeps its route and now reserves the name. The address of a retired or deleted patch answers 404 until ticket 11 renders the notice.
Done when
- Every move from every state is tested, including the refused ones; names survive delete and free at the sweep;
TestClockwinds 30 days and the sweep reclaims exactly the rows past the window with both locks held; a dependant inside the same company breaks a retire andforceproceeds; restore lists a retired, a deleted and a gone source with its state; rollback moves only the pointer; a publish authorised before a reassign cannot commit after it;last_changed_by/atis stamped by every act. pnpm testhas noexpires_atleft anywhere in product code, migrations, the seed or the docs the ticket owns.
Surfaces
The wire (docs/API.md), migrations (three call sites, ADR-0003's ledger, ADR-0009's sweep paragraph), reverse states (retire↔restore, delete↔restore, rollback↔publish), the Patches glossary (Retire, Delete, Restore, Rollback, Recovery window, Deletion sweep replaces Expiry sweep; Retention clock, Patch expiry and Visit's top-up removed), docs/product.md § Updating, retiring, deleting turned from decided to built, docs/DEVELOPMENT.md where the seed names expiry.
Activity