Move legacy job repair to migration 0011 and keep archived dinners pending
CI / ci (push) Successful in 2m35s
CI / ci (pull_request) Successful in 2m20s

R1-A: Migration 0010 is back to its round-2 content, the ALTER TABLE only,
since a database that already applied 0010 never runs it again. The
repair that writes revision 0 into ground_dinner job payloads without one
is now migration 0011, applied by the same boot Migrate call, so before
the job runner starts and before FailInterruptedGroundings.
TestUpgradeKeepsLegacyQueuedGrounding now upgrades from 0009 and from a
database with 0010 already recorded, each with a pending Regular and a
queued legacy job; both keep the dinner pending through the boot cleanup
and then ground it.

R2-A: The boot cleanup no longer fails archived dinners. Archiving stops a
running job and leaves the dinner pending, which the cleanup relabelled
failed with interrupted. TestRestartKeepsArchivedPendingDinner archives a
pending Regular while its job runs and checks the cleanup leaves it
pending with no error.

Maestro task 5037ff86-181d-448e-927b-c2fd2258a25d.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 19:49:06 -04:00
co-authored by Claude Opus 5.5
parent dff58d491f
commit 35ceb3985b
9 changed files with 92 additions and 32 deletions
@@ -5,12 +5,3 @@
-- earlier job — queued or running — can no longer write the dinner.
ALTER TABLE dinners ADD COLUMN grounding_revision INTEGER NOT NULL DEFAULT 0;
-- Every dinner starts at revision 0, so a ground_dinner job enqueued
-- before this migration, whose payload has only dinner_id, is for revision
-- 0. Recording it lets the boot cleanup, which matches a pending dinner to
-- its job by revision, see a job still queued for its dinner.
UPDATE jobs
SET payload = json_set(payload, '$.revision', 0)
WHERE kind = 'ground_dinner'
AND json_type(payload, '$.revision') IS NULL;
@@ -0,0 +1,11 @@
-- 0011_ground_dinner_job_revision: every dinner starts at grounding
-- revision 0 (0010), so a ground_dinner job enqueued before 0010, whose
-- payload has only dinner_id, is for revision 0. Recording it lets the boot
-- cleanup, which matches a pending dinner to its job by revision, see a job
-- still queued for its dinner. This is a migration of its own, not part of
-- 0010, so it also runs on a database that has already applied 0010.
UPDATE jobs
SET payload = json_set(payload, '$.revision', 0)
WHERE kind = 'ground_dinner'
AND json_type(payload, '$.revision') IS NULL;
+6 -4
View File
@@ -134,15 +134,17 @@ WHERE id = ?
AND grounding_revision = ?;
-- name: FailOrphanedPendingDinnerGroundings :execrows
-- Fails every dinner still pending whose grounding job for its current
-- grounding_revision is no longer queued or running: the process stopped
-- before the job, or before its handler recorded a result. Run at boot,
-- after the job runner fails the jobs a previous process left running.
-- Fails every unarchived dinner still pending whose grounding job for its
-- current grounding_revision is no longer queued or running: the process
-- stopped before the job, or before its handler recorded a result. An
-- archived dinner is left as it is; archiving stopped its grounding. Run at
-- boot, after the job runner fails the jobs a previous process left running.
UPDATE dinners
SET grounding_status = 'failed',
grounding_error = sqlc.arg(grounding_error),
updated_at = sqlc.arg(updated_at)
WHERE grounding_status = 'pending'
AND status <> 'archived'
AND NOT EXISTS (
SELECT 1 FROM jobs
WHERE jobs.kind = sqlc.arg(kind)