You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Research: what the repo already decided about a patch's lifecycle #236
Inventory the current state model as built and as documented, so the lifecycle grilling starts from facts: retention and expiry and their top-ups, the sweep, disabled_at / disabled_reason and how disable is used, owner delete, name redirects and name freeing, numbered version URLs, the version pointer and every mention of rollback, what shared-table declarations check at publish and at runtime when a source is deleted or disabled, what deactivation does to patches and tokens, and every ADR or doc line that a retire/restore/delete/rollback model would contradict. Cite file paths and doc sections. Findings in the resolution comment.
Two independent passes (astra with tools, an Opus subagent) over this checkout at dfc2e94; they agree on every fact below. Paths are repo-relative.
What is built
One row, three take-out predicates.patches carries current_version_id (nullable, no FK), expires_at, deleted_at, disabled_at, disabled_reason (packages/patches/src/migrations.ts:19-36). Every serving, write, quota, scope and shared-source query filters deleted_at IS NULL AND disabled_at IS NULL AND expires_at >= now (Patches.ts:624-664, 844-853, 1224-1236). All five refusals collapse into one PatchUnavailable, "Patch not found."
Expiry. Publish sets 90 days; a visit within the last 30 days moves expiry to 30 days out, never shorter, never reviving (Patches.ts:52-58, 1263-1275). Token revocation and sharing changes do not touch the clock. ADR-0003 keeps every retention rule in SQL.
Disable is dead code. Nothing in product code writes disabled_at or disabled_reason; only tests do. docs/product.md:296 says operator disable is a hand SQL statement. packages/patches/CONTEXT.md:45 reserves disable for the operator and forbids it as a synonym for retire. Disable hides the patch, blocks updates and top-ups, releases quota, and does not free names.
Owner delete (Patches.ts:1305-1324, DELETE /api/patches/:id): sets deleted_at and deletes every patch_names row in the same transaction, so all names are free at once and no redirect survives. Nothing clears deleted_at. Admins have no delete authority. The CLI drops its cache; a deleted repo keeps its patchy.json id and later publishes 404 until the id is removed (ADR-0004:271-286).
What survives a delete. Versions and bundle bytes stay until the expiry clock runs out; the company-database namespace, rows and file index outlive the platform row and are reclaimed by the orphan sweep a day after the row is gone (ADR-0009:49-51). So the data a restore would need still exists for the retention window, by accident rather than design.
The sweep (ExpirySweep.ts, hourly plus startup): batches of 100, at most 1,000 per pass, rechecks expiry under FOR UPDATE, queues object keys durably, hard-deletes versions then the patch. Deleted and disabled rows are swept only once their clock expires. The orphan sweep's one-day age is measured from namespace creation or object modification, not from deletion; it is not a recovery window.
Names. Company-scoped; rename leaves a 308 redirect until another patch claims the name; a disabled or expired patch's current name stays occupied until owner delete or the sweep; deleting the claimant does not resurrect the redirect (Patches.ts:707-716, 1126-1130; serving/src/Pages.ts:107-114).
Versions and the pointer./<company>/<name> follows current_version_id; /~v/<n> selects an immutable version; /~content/<patchId>/<versionId> serves bytes. Public is only the current version. The pointer moves forward only, in record (Patches.ts:1200-1207); no route, command or SQL moves it back. Tests move it with locked SQL. Every rollback mention in docs is future or a negative guarantee: rollback never changes sharing, files, cumulative provisioning or rows (docs/product.md:27, 249, 449, 490, 515; api.ts:178, 346; ADR-0009:43). Historical versions keep their own tier and wire version; a retired wire shows the needs-rebuild door.
Shared tables. Declarations bind stable patch id and table. Publish requires a live same-company source whose cumulative inventory marks the table shared, else patch_not_openable (deliberately indistinguishable). Every runtime read rechecks source liveness and the shared flag, so deleting, disabling or expiring a source denies consumers on their next read, whole call, access_denied, with their own rows untouched (TableOperations.ts:294-338). Unsharing reports distinct live declaring patches across retained versions; deleted, disabled and expired consumers are excluded. Reusing a deleted source's name never rebinds consumers.
Deactivation (companies/src/Users.ts:151-204): one transaction stamps the user and revokes every machine token; reactivation clears the stamp only, keys stay revoked; the last active admin is protected. Patches keep serving, keep their owner, keep topping up their clock; findPatch never joins users. No reassignment, no dependency warning.
What a retire / restore / delete / rollback model contradicts
docs/product.md:164, patches/CONTEXT.md:47-49, docs/API.md:112-114, ADR-0004:321-326: delete has no restore and frees names in-transaction. A restorable state must not free names, or restore must reclaim a name another patch may now hold.
patches/CONTEXT.md:45: disable is the operator's, not retire, yet disabled_at is the only kept-but-off column and nothing writes it. Retire needs its own state or the glossary changes.
patches/CONTEXT.md:83-85, docs/product.md:166, ADR-0003 consequences: expiry's removal is final; every expiry mirror (docs/API.md:114, patchy/README.md:552-558, skills/patchy/SKILL.md:279-283, README.md:67, CONTEXT-MAP.md, apps/server/CONTEXT.md:3) goes when expiry goes.
docs/product.md:27, 249, 449, ADR-0009:43, api.ts:178, 346, the three SDK skills: rollback is a pointer move only; provisioning, sharing and files are pointer-independent. Keep.
CLAUDE.md:81 already calls today's one-way delete a bug; CLAUDE.md:77 requires contradicted ADRs be updated or deleted.
ADR-0004 and ADR-0002: a new verb (retire, restore, rollback) is a new CLI contract entry with exit codes and --json; ADR-0011 pins release and wire stability across it.
Two wording bugs already present
Patches.ts:414 says deleted bytes go with "the next sweep"; the SQL waits for expiry.
skills/patchy/references/welcome-patch.html:275-284 calls inactivity expiry "retired" and deletion permanent, the opposite of the intended restorable retirement.
Gaps neither pass could close from the tree
Cached or downloaded copies of a public current version cannot be recalled by any transition (60-second public cache).
Replaying a committed publish returns its stored result without revalidating shared-table sources.
Activity
allisonmahmood commentedon Sep 12, 2026
Resolution
Two independent passes (astra with tools, an Opus subagent) over this checkout at
dfc2e94; they agree on every fact below. Paths are repo-relative.What is built
patchescarriescurrent_version_id(nullable, no FK),expires_at,deleted_at,disabled_at,disabled_reason(packages/patches/src/migrations.ts:19-36). Every serving, write, quota, scope and shared-source query filtersdeleted_at IS NULL AND disabled_at IS NULL AND expires_at >= now(Patches.ts:624-664, 844-853, 1224-1236). All five refusals collapse into onePatchUnavailable, "Patch not found."Patches.ts:52-58, 1263-1275). Token revocation and sharing changes do not touch the clock. ADR-0003 keeps every retention rule in SQL.disabled_atordisabled_reason; only tests do.docs/product.md:296says operator disable is a hand SQL statement.packages/patches/CONTEXT.md:45reserves disable for the operator and forbids it as a synonym for retire. Disable hides the patch, blocks updates and top-ups, releases quota, and does not free names.Patches.ts:1305-1324,DELETE /api/patches/:id): setsdeleted_atand deletes everypatch_namesrow in the same transaction, so all names are free at once and no redirect survives. Nothing clearsdeleted_at. Admins have no delete authority. The CLI drops its cache; a deleted repo keeps itspatchy.jsonid and later publishes 404 until the id is removed (ADR-0004:271-286).ExpirySweep.ts, hourly plus startup): batches of 100, at most 1,000 per pass, rechecks expiry underFOR UPDATE, queues object keys durably, hard-deletes versions then the patch. Deleted and disabled rows are swept only once their clock expires. The orphan sweep's one-day age is measured from namespace creation or object modification, not from deletion; it is not a recovery window.Patches.ts:707-716, 1126-1130;serving/src/Pages.ts:107-114)./<company>/<name>followscurrent_version_id;/~v/<n>selects an immutable version;/~content/<patchId>/<versionId>serves bytes. Public is only the current version. The pointer moves forward only, inrecord(Patches.ts:1200-1207); no route, command or SQL moves it back. Tests move it with locked SQL. Every rollback mention in docs is future or a negative guarantee: rollback never changes sharing, files, cumulative provisioning or rows (docs/product.md:27, 249, 449, 490, 515;api.ts:178, 346; ADR-0009:43). Historical versions keep their own tier and wire version; a retired wire shows the needs-rebuild door.patch_not_openable(deliberately indistinguishable). Every runtime read rechecks source liveness and the shared flag, so deleting, disabling or expiring a source denies consumers on their next read, whole call,access_denied, with their own rows untouched (TableOperations.ts:294-338). Unsharing reports distinct live declaring patches across retained versions; deleted, disabled and expired consumers are excluded. Reusing a deleted source's name never rebinds consumers.companies/src/Users.ts:151-204): one transaction stamps the user and revokes every machine token; reactivation clears the stamp only, keys stay revoked; the last active admin is protected. Patches keep serving, keep their owner, keep topping up their clock;findPatchnever joinsusers. No reassignment, no dependency warning.What a retire / restore / delete / rollback model contradicts
docs/product.md:164,patches/CONTEXT.md:47-49,docs/API.md:112-114, ADR-0004:321-326: delete has no restore and frees names in-transaction. A restorable state must not free names, or restore must reclaim a name another patch may now hold.patches/CONTEXT.md:45: disable is the operator's, not retire, yetdisabled_atis the only kept-but-off column and nothing writes it. Retire needs its own state or the glossary changes.patches/CONTEXT.md:83-85,docs/product.md:166, ADR-0003 consequences: expiry's removal is final; every expiry mirror (docs/API.md:114,patchy/README.md:552-558,skills/patchy/SKILL.md:279-283,README.md:67,CONTEXT-MAP.md,apps/server/CONTEXT.md:3) goes when expiry goes.docs/product.md:27, 249, 449, ADR-0009:43,api.ts:178, 346, the three SDK skills: rollback is a pointer move only; provisioning, sharing and files are pointer-independent. Keep.CLAUDE.md:81already calls today's one-way delete a bug;CLAUDE.md:77requires contradicted ADRs be updated or deleted.--json; ADR-0011 pins release and wire stability across it.Two wording bugs already present
Patches.ts:414says deleted bytes go with "the next sweep"; the SQL waits for expiry.skills/patchy/references/welcome-patch.html:275-284calls inactivity expiry "retired" and deletion permanent, the opposite of the intended restorable retirement.Gaps neither pass could close from the tree