Stop claiming a summary is pending when auto-read is off

The upload path enqueued a summary job and stamped PENDING without
consulting the owner's auto-read opt-in; the job's opt-out branch then
deliberately left the state alone, so a document uploaded with the
opt-in off said "summary is being generated" forever. Two writers,
contradictory assumptions.

Both ends of the contract now agree. enqueueDocumentSummary checks the
opt-in first and refuses to mint a job (or a PENDING) it knows the job
cannot resolve; the job keeps its own check for a pref flipped between
enqueue and run and heals a stranded PENDING back to NONE, scoped so
READY / WITHHELD / UNAVAILABLE stay untouched. Migration 0333 drains
the rows already orphaned. The view needs nothing: NONE already
renders the manual summary action.

Refs #788
This commit is contained in:
Marc-André Bombeck committed 2026-08-13 12:07:39 +02:00
1 parent c8b3f49915
commit 2a85da67f7
3 files changed
+123 -12

No files matched your search

@@ -0,0 +1,12 @@
-- Refs #788 — heal phantom summary PENDING rows.
-- `enqueueDocumentSummary` used to claim PENDING even when the owner's
-- auto-read opt-in was OFF; the job's opt-out branch then left the state
-- alone, so the detail view said "being generated" forever. Both writers now
-- agree (the enqueue end no longer claims what the job cannot resolve, the
-- job end heals PENDING→NONE on opt-out); this one-time data fix drains the
-- rows already stranded. Safe by construction: READY / WITHHELD / UNAVAILABLE
-- are never touched, and a job that is genuinely mid-flight rewrites its
-- terminal state after this UPDATE anyway.
UPDATE "inbound_documents"
SET "summary_state" = 'NONE'
WHERE "summary_state" = 'PENDING';