Give each ntfy digest a reference of its own
Security / Vulnerability check (push) Successful in 47s
Test / Lint and test (push) Successful in 2m6s

Every digest went to the print queue under the fixed reference
"digest", so after a crash the queue could not tell a digest it had
queued from a new one. Once queued jobs survive a restart, a crash in
the second between queueing a digest and saving the subscription's
state would print it twice; the same window exists today for a digest
that printed in that second.

A digest now gets a reference of its own when it is made, "digest_"
and a TypeID, and is saved with it in the subscription's state, apart
from the held messages. It is offered to the queue only once that save
has succeeded, and dropped once the queue takes it; while the state
file cannot be written, digests wait. A restart with a saved digest
offers that digest again first, with the same rows and reference, and
the queue's duplicate check answers with the earlier job while it holds
it. Messages held after a digest is made wait for the next one, also
while quiet hours delay the saved digest after a restart: added to a
digest the queue already holds, they would never print. The digest is
submitted as unique, like a card.

A digest can cost one more state save, two fsyncs. The reference shows
in the log lines and Sentry reports where "digest" did.

This completes stage 1c of docs/plans/job-store.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 13:50:57 -06:00
1 parent 8b8b7da0c6
commit 64a72903d8
12 files changed
+431 -58

No files matched your search

+20 -9
View File
@@ -1,6 +1,6 @@
# Plan: persistent job store and image previews
Status: **in progress; stage 1a's measurements are done (Investigation findings), and so is stage 1b's `[state] dir`. The store itself is not built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item 1 records them. Each stage runs in its own session, briefed from its section: stage 1a follows decisions 1-3, stage 1b decision 4, stage 1c decisions 5-12, stage 1d decisions 13-15, phase 2 decision 16, phase 2b decisions 17 and 18, phase 3 decision 19 and phase 4 decision 20; phase 5 holds decisions 21-23. Phases 3a-3c need nothing from phases 1 and 2, so they can come first if the owner wants previews sooner. Phase 2b needs phase 1 but not phase 2, so it can come before phase 2. Every check on the live printer needs the owner's OK.
Status: **in progress; stage 1a's measurements are done (Investigation findings), and so are stage 1b's `[state] dir` and stage 1c's state machine on the memory store. The store on disk is not built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item 1 records them. Each stage runs in its own session, briefed from its section: stage 1a follows decisions 1-3, stage 1b decision 4, stage 1c decisions 5-12, stage 1d decisions 13-15, phase 2 decision 16, phase 2b decisions 17 and 18, phase 3 decision 19 and phase 4 decision 20; phase 5 holds decisions 21-23. Phases 3a-3c need nothing from phases 1 and 2, so they can come first if the owner wants previews sooner. Phase 2b needs phase 1 but not phase 2, so it can come before phase 2. Every check on the live printer needs the owner's OK.
## Decisions (owner, 2026-11-30)
@@ -389,7 +389,7 @@ ACKNOWLEDGEMENT, WHERE THE PRINTER HAS IT (phase 5, decision 21)
- Holding the connection until the receipt prints would make `/healthz` time out (3 s) during long prints. While a job holds the connection, `/healthz` reports the status that connection last polled, with its age.
THE STORE INTERFACE (printqueue)
printqueue defines the interface and an in-memory implementation and imports no database. A new package, `internal/pkg/jobstore`, implements it on disk, and internal/app wires it in. The engine can change without touching the queue. A sketch; stage 1c settles the names:
printqueue defines the interface and an in-memory implementation and imports no database. A new package, `internal/pkg/jobstore`, implements it on disk, and internal/app wires it in. The engine can change without touching the queue. Stage 1c settled it as below; `printqueue/store.go` has the full doc comments:
```go
// Record is one job as the store keeps it, with its deliveries.
@@ -424,6 +424,14 @@ type Loaded struct {
Uncertain []uint64 // the deliveries this Load turned from sending into uncertain
}
// Prune names what Finish drops in its commit, by Seq. A job that goes is
// listed with each of its deliveries and with its content, if it still has it.
type Prune struct {
Jobs []uint64
Deliveries []uint64
Content []uint64
}
// Store keeps jobs across restarts.
type Store interface {
// Durable reports whether records outlive the process.
@@ -435,12 +443,13 @@ type Store interface {
// Add stores a new job, its queued deliveries and its content. With
// sync, the commit is durable when Add returns.
Add(ctx context.Context, r Record, job []byte, sync bool) error
// Sending records attempt n of a delivery on the printer it uses and
// returns once that is durable.
Sending(ctx context.Context, delivery uint64, printer string, attempt int, at time.Time) error
// Finish records a delivery's final state and drops the given jobs,
// deliveries and contents, in one commit; sync as for Add.
Finish(ctx context.Context, d Delivery, dropJobs, dropDeliveries, dropContent []uint64, sync bool) error
// Sending records d, an attempt about to write to its printer, in
// sending: its printer, attempts, StartedAt and SentAt. It returns once
// that is durable.
Sending(ctx context.Context, d Delivery) error
// Finish records d in its final state and drops what p names, in one
// commit; sync as for Add.
Finish(ctx context.Context, d Delivery, p Prune, sync bool) error
// Job returns a stored job's content, or ErrContentGone.
Job(ctx context.Context, seq uint64) ([]byte, error)
// Idle is called when the queue has nothing to do.
@@ -658,6 +667,8 @@ Docs
### Stage 1c: The state machine, without a database
Done on 2026-12-01.
**Goal.** The queue runs on the `Store` interface, with the memory store only: jobs with deliveries, the state machine, `sent_at` and `uncertain`, restoring at start, the shutdown rules, store failures, the duplicate check and digest references, and retention by content bytes. No new dependency. With the memory store the daemon behaves as today, apart from what the API and the logs add, the duplicate check on ntfy jobs, and a digest kept apart from later held messages once it is made.
**Work.**
@@ -858,7 +869,7 @@ internal/pkg/printqueue
- A store error stops the queue (decision 11).
- If docs/plans/printers.md stage 3 has shipped, a delivery with any `sending` mark is not cancellable, even while it waits on the next printer of an anycast list, and a move takes the delivery lock (its decision 26).
- A cancelled job counts as finished for retention. An ntfy job keeps its reference (decision 10), so a replay after a restart does not queue it again.
- store.go: `StoredState` gains `cancelled`, and `Store` gains `Cancel(ctx, deliveries []uint64, at time.Time, dropJobs, dropDeliveries, dropContent []uint64) error`, one synced commit. The memory store implements it.
- store.go: `StoredState` gains `cancelled`, and `Store` gains `Cancel(ctx, deliveries []uint64, at time.Time, p Prune) error`, one synced commit. The memory store implements it.
internal/pkg/jobstore
- `Cancel`: one synced transaction that sets each delivery's `state` and `finished_at` and drops the given jobs, deliveries and contents. The `sequence` column is in the schema and written from stage 1d (RECORDS), so there is no schema step.