Skip to content

feat(patches): the lifecycle model: expiry goes; retire, delete with a recovery window, restore, rollback; the owner verbs on the wire; the deletion sweep #248

Closed

Description

@allisonmahmood

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_lifecycle in the Patches record, applied by all three migrator call sites (apps/server, scripts/dev, the vitest template): drop expires_at; add retired_at/by, deleted_by, reassigned_at/by, description (TEXT NOT NULL DEFAULT ''), description_updated_at/by, last_changed_at/by, with users(id) references and a partial index on deleted_at. Runtime's replay test applies it after 0007. 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's LoadedVersions; 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_at set is deleted, else retired_at set is retired, else live. notExpired, the visit top-up and every expires_at mirror go; recordVisit keeps counting visits only.
  • Moves, each an Effect.fn on Patches taking 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_at is the clock), restore (clears both stamps, lands live, requires now < purgeAt from 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 and last_changed_by/at on the Effect clock; wrong_state on an invalid move. retire and delete-from-live compute the live dependants (distinct patches with a live declaration across retained versions) and fail has_dependants unless force; restore computes the sources the current version declares and fails sources_off unless force, with each source's patch id, name when it exists, table and state (gone included); has_dependants carries dependants: [{ patchId, name, owner: { id, name } }]. Publish's unshare gains the same has_dependants refusal unless force. 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; then patch_retired and patch_deleted (409, with purgeAt); 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 a force field in the request. Another company keeps the 404. reserved_name (422) refuses patches and connections at create.
  • The deletion sweep replaces ExpirySweep (DeletionSweep, same schedule, same batch bounds): rows with deleted_at + 30 days <= now, rechecked FOR 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/retire and /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_description 422; refused on a deleted patch), each answering the documents in spec §14 with purgeAt where a delete is involved; the refusal bodies carry dependants, sources, owner, state, purgeAt beside code. Publish accepts manifest.description, file mode's metadata.description and force, stores them with the stamps, and returns description and descriptionUpdatedAt. docs/API.md regenerates.

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; TestClock winds 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 and force proceeds; 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/at is stamped by every act.
  • pnpm test has no expires_at left 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions