Record the owner's acceptance of the printers plan

The owner accepted every proposed default of docs/plans/printers.md on
2026-12-01. Its open questions become numbered decisions, without the
alternatives, and design.md's Planned next item 2 records them.
Decisions 6, 10 and 17 keep the wording that the remote-printers and
templates plans had already settled. Decision 14 amends the owner's
earlier wording: a rule that fails to compile stops the start rather
than being skipped.

The plan's acceptance edits are made, and its list of them goes.
formatters.md loses its open question, which the routing example
answers, and points to this plan for a second printer and per-model
line spacing, without the printer pool's tests. job-store.md points to
these decisions for the deliveries array, the stored route, failover
after a sending mark, the lanes and their content bound, and a printer
removed from the config. Its invariant 2 speaks of the job's bytes,
since an anycast check sends DLE EOT before the mark. Its findings
confirm the TM-m50II's command list and the power-on part of the
automatic-status side finding. Phase 2b, phases 3c and 4 and phase 5
say how they meet several printers.

The other plans cite printers decisions in place of questions, and
templates decision 1 now follows printers decisions 12, 14, 15 and 17
rather than leaning on assumed defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 11:07:58 -06:00
1 parent f302b76ef4
commit 68bce4db59
6 files changed
+224 -263

No files matched your search

+16 -15
View File
@@ -63,7 +63,7 @@ For stage 1c:
- Print contents now rest on disk: 0600 files in the 0700 state directory, `secure_delete=FAST`, and deleted content can linger in free pages and the WAL until they are overwritten.
9. **Retention.** Statuses as today, the last `queue.history` (1000) finished jobs. The content of finished jobs within a byte budget, a new key `queue.content_bytes`, default 64 MiB and at most 1 GiB, newest kept. The content of unfinished jobs is always kept, and so is that of `uncertain` jobs until their status goes, since a reprint needs it.
- A count alone cannot bound it: `webserver.body_limit` (4 MiB) × 1000 jobs is about 4 GB, too much for an SD card.
- Trade-off: unfinished content alone can reach `queue.size` 100 × 4 MiB, about 400 MiB, and with `auto_vacuum=NONE` the file never shrinks below its high-water mark.
- Trade-off: unfinished content alone can reach `queue.size` 100 × 4 MiB, about 400 MiB, and with `auto_vacuum=NONE` the file never shrinks below its high-water mark. With several printers the bound is per lane: about 1.2 GiB for three (docs/plans/printers.md decision 4).
- An age limit, for privacy, would be another key (phase 5).
10. **ntfy replays after a crash.** A subscription saves its state within a second of queueing a message. Today a job lost in a crash is replaced by the replay. Once queued jobs resume, a crash in that second would print the message twice. So:
- A `Submit` whose source and reference the queue already holds, from an ntfy subscription, returns the earlier job and queues nothing. Only ntfy jobs take part: on the HTTP routes the reference is a request ID, which a client may set, so a check on it could answer a new request with an old job.
@@ -126,7 +126,7 @@ For phase 5, later:
21. **Epson's process-ID acknowledgement** (`GS ( H` fn 48) on models that have it: not in phases 1-4; phase 5, if the owner says yes after a paper test. docs/plans/remote-printers.md decision 24 builds it at the agent with this phase 5 (its stage 6). The state machine is safe without it. Trade-off: it would turn most `uncertain` jobs into confirmed prints, but it holds the printer connection until the receipt is done, so `/healthz` needs another way to read status mid-job, and whether its answer gets through the printer's network board is unverified.
22. **ntfy state stays out of the store.** The JSON files stay. They write within a second of a change, and a keepalive-only cursor at most every 10 minutes, and the subscriber is built and tested on them. On a WebSocket each save also writes every seen ID within `max_backlog`, up to some 700 KB on a busy topic with a 12-hour backlog (docs/plans/ntfy.md decision 12). Trade-off: one file and one sync policy, against coupling ntfy to the store, which could write only the IDs that changed.
23. **A write error after part of a receipt went out.** Today such a send is retried, and design.md accepts that part of a receipt can then print twice, because retries let a job survive a printer that is briefly offline. That stays. docs/plans/remote-printers.md decision 17 builds on it: a remote `partial` outcome is today's write error. Once `Send` reports how many bytes `Write` took (docs/plans/printers.md stage 3's `SendError`, or phase 5's confirmed send), the owner may choose that such a job becomes `uncertain` and is never resent. Trade-off: fewer doubled fragments, against more jobs a person must check. With several printers, docs/plans/printers.md question 22 decides when such a delivery fails over to the next printer of an anycast list (Architecture, DELIVERIES AND SEVERAL PRINTERS). Its default, failover after the retries on the first printer, is a second double-print path: the next printer gets the whole receipt, so a receipt the first printer took in full before the write error prints in full on both.
23. **A write error after part of a receipt went out.** Today such a send is retried, and design.md accepts that part of a receipt can then print twice, because retries let a job survive a printer that is briefly offline. That stays. docs/plans/remote-printers.md decision 17 builds on it: a remote `partial` outcome is today's write error. Once `Send` reports how many bytes `Write` took (docs/plans/printers.md stage 3's `SendError`, or phase 5's confirmed send), the owner may choose that such a job becomes `uncertain` and is never resent. Trade-off: fewer doubled fragments, against more jobs a person must check. With several printers, docs/plans/printers.md decision 22 fails such a delivery over to the next printer of an anycast list after the retries on the first printer (Architecture, DELIVERIES AND SEVERAL PRINTERS). That is a second double-print path: the next printer gets the whole receipt, so a receipt the first printer took in full before the write error prints in full on both.
## Investigation findings
@@ -248,7 +248,7 @@ Only by not syncing. Badger's saving with `SyncWrites=false` comes from leaving
PRINT ACKNOWLEDGEMENT ON EPSON PRINTERS
- design.md says ESC/POS gives no acknowledgement of what printed. Epson documents one: `GS ( H` fn 48, the process ID response. The host sends `1D 28 48 06 00 30 30 d1 d2 d3 d4` after the data. For print data, the printer answers `37 22 d1 d2 d3 d4 00` "when the printing is completed" (ESC/POS reference Ver. 10.01, p. 428-429).
- The TM-T88IV Technical Reference Guide (Rev. C) lists the command, and so does the TM-T88V's (Rev. E). Epson's model pages list it for the TM-T88IV to TM-T88VII, seen only in search extracts, since the pages refuse direct fetches. TM-m50II support is unconfirmed.
- The TM-T88IV Technical Reference Guide (Rev. C) lists the command, and so does the TM-T88V's (Rev. E). Epson's model pages list it for the TM-T88IV to TM-T88VII, seen only in search extracts, since the pages refuse direct fetches. The TM-m50II's command list includes it too (docs/plans/printers.md, Investigation findings), still unverified over port 9100.
- Limits:
- If the host misses responses, the printer sends only the latest ID.
- Pending IDs are dropped when the buffers are cleared (`DLE DC4` fn 8, `DLE ENQ 2`) or the power goes off.
@@ -257,7 +257,7 @@ PRINT ACKNOWLEDGEMENT ON EPSON PRINTERS
- Unverified: whether the response reaches the host over port 9100 through the printer's Ethernet board (UB-E02 or UB-E03), and what happens to a response sent after the host closed the connection. Only a paper test can tell.
- No other mechanism on raw port 9100 reports a job's progress. `DLE EOT`, automatic status (`GS a`) and `GS ( H` fn 49 report the printer's state. `GS r 1` answers once the preceding lines have fed, without an ID. ePOS-Print on newer models reports a print result over HTTP, a different transport.
- Even a perfect acknowledgement leaves a window between the printer finishing and the daemon recording it, so the store must be safe without one.
- A side finding (an inference, unverified): the UB-E02 and UB-E03 boards turn automatic status on at power-on, and the `ESC @` that starts each job turns it off. Until the first job after a power-on, the printer may send unrequested 4-byte status frames, which `printer.Client.Status`, reading one byte per request, could take as "status unsupported".
- A side finding: the UB-E02 and UB-E03 boards turn automatic status on at power-on, and the `ESC @` that starts each job turns it off, as Epson's guides confirm (docs/plans/printers.md, Investigation findings). Until the first job after a power-on, the printer may send unrequested 4-byte status frames, which `printer.Client.Status`, reading one byte per request, could take as "status unsupported". Whether the frames reach a port 9100 client is unverified.
WHERE THE REPORTS DISAGREE OR ARE UNSURE
- WAL bytes per job: about 15 KB (spike: small table, no pruning), 20-40 KiB (the key-value track's estimate) and 57.7 KiB (SQLite track: full history with pruning). The setups differ; stage 1a measures the schema under RECORDS.
@@ -301,15 +301,15 @@ WHAT SHIPS WHEN
COMPATIBILITY
- Without `state.dir` the queue stays in memory and behaves as today, waiting jobs failing at shutdown included.
- Existing statuses keep their meaning; `uncertain`, `cancelled` (phase 2b) and the `sent_at` field are new.
- Job status keeps its shape until there are several printers; only then does it gain the `deliveries` array (Architecture, DELIVERIES AND SEVERAL PRINTERS).
- Job status gains the `deliveries` array with docs/plans/printers.md stage 1b, for every job, whatever the number of printers (its decision 8).
- What prints does not change. TestRenderCompat and TestPaperReceipts keep passing.
- The Docker image keeps a job store in `/var/lib/uberbringer`, so a container that cannot write there stops at start (decision 14, **Breaking**).
- A downgrade: an older binary refuses `[state] dir` and `queue.content_bytes` as unknown keys and ignores `jobs.db`. The CHANGELOG and docs/configuration.md say so.
INVARIANTS
1. Nothing reaches the printer unless the whole receipt rendered.
2. No byte goes to the printer before its delivery's `sending` mark is committed to the store, and synced when the store is durable.
3. A delivery that a client could have read as failed, `uncertain` or cancelled is never sent again without a new request. Nor, after a restart, is one that may have reached the printer. Within one run, before a delivery finishes, two paths resend one that may have reached the printer: the retries after a write error, as today, and an anycast failover after a `sending` mark, which the printers plan settles (decision 23).
2. No byte of the job goes to the printer before its delivery's `sending` mark is committed to the store, and synced when the store is durable.
3. A delivery that a client could have read as failed, `uncertain` or cancelled is never sent again without a new request. Nor, after a restart, is one that may have reached the printer. Within one run, before a delivery finishes, two paths resend one that may have reached the printer: the retries after a write error, as today, and an anycast failover after a `sending` mark, which docs/plans/printers.md decision 22 settles.
4. A status a client reads is never ahead of the store: memory changes only after the store's commit returns.
5. Print contents never reach logs or Sentry, and the store's errors never quote them.
6. printqueue never imports a database, so server and tools/genopenapi never compile one.
@@ -532,7 +532,7 @@ DELIVERIES AND SEVERAL PRINTERS
- broadcast: to every printer;
- anycast: to one printer of an ordered list, as a priority list with failover: the first, on failure the second, then the third.
- A job has one or more deliveries, one per printer it goes to, each tracked on its own. A multicast or broadcast job is one job with several deliveries; a unicast or anycast job has one. The state machine under JOB STATES applies to each delivery. The `Store` interface carries deliveries from stage 1c, and the database keeps them in a table of their own from stage 1d (RECORDS), so several deliveries per job need new rows, not new tables. Until the printers plan lands, every job has exactly one delivery, for the printer `default`.
- The printers plan settles whether it needs new columns, and so a schema step. A delivery's row stores one `printer` and nothing of its route: no mode, group or anycast list, so a restored anycast delivery's list must be derived again from the rules and the config. And a failover after a `sending` mark would overwrite `printer`, so the row would no longer show that the first printer got bytes, which TELLING WHICH RECEIPTS PRINTED relies on; keeping that needs a column or a row per printer tried.
- docs/plans/printers.md decision 18 stores the route: `route_by`, `route_rule` and `route_mode` on `jobs`, and `candidates` and `sent_to` on `deliveries`, in stage 1d's first schema or in a step to `user_version` 2. So a restored anycast delivery keeps its list, and a failover after a `sending` mark keeps the record that the first printer got bytes, which TELLING WHICH RECEIPTS PRINTED relies on.
- A job's API `status` derives from its deliveries (decision 12). A delivery counts as taken from when the worker picks it up until it finishes: while it renders, waits for the printer's slot, dials, waits between retries or sends (decision 12):
- Cancelled deliveries (phase 2b) are passed over unless every delivery is cancelled; then the job is `cancelled`. The rest of the rule reads the other deliveries.
- `queued` while every one waits, none taken and none finished;
@@ -540,11 +540,11 @@ DELIVERIES AND SEVERAL PRINTERS
- once every one has finished: `uncertain` if any is, since it means a receipt may have printed; otherwise `failed` if any is; otherwise `done`.
So `failed` and `uncertain` stay final, as today: a failed or `uncertain` delivery beside one that still waits or prints leaves the job `printing`, and one cancelled delivery beside done ones reads `done`. With one delivery, the job's status is the delivery's.
- Once there are several printers, the status gains a `deliveries` array, one entry per delivery with its `printer`, `status`, `sent_at` and `error`. Until then the status looks as this plan describes, its fields those of the one delivery. What the job's own `sent_at`, `attempts` and `error` hold beside the array is for the printers plan.
- Anycast: a delivery's printer is chosen when it is dispatched, and its row records the printer used. Before any byte was sent, a failure fails over to the next printer at once: the delivery moves to it and no `sending` mark is written, just as a dial failure writes nothing today. After a `sending` mark, the default is the existing retry rule on that printer, then failover to the next; the printers plan settles this. That failover can print a whole receipt on two printers (decision 23). A queued delivery restored after a restart starts again from the top of its list (assumed), which the rules and the config give again at restore, since the row stores no list.
- One store per instance. Each delivery names its printer, so the printers plan can use one store, with one queue and worker per printer, each loading its own unfinished deliveries.
- From docs/plans/printers.md stage 1b, every status gains a `deliveries` array, one entry per delivery with its `printer`, `status`, `attempts`, `started_at`, `sent_at`, `finished_at` and `error`, and the job's own fields sum or pick from them (its decision 8). Until then the status looks as this plan describes, its fields those of the one delivery.
- Anycast: a delivery's printer is chosen when it is dispatched, and its row records the printer used. Before any byte was sent, a failure fails over to the next printer at once: the delivery moves to it and no `sending` mark is written, just as a dial failure writes nothing today. After a `sending` mark, the existing retry rule on that printer runs, then failover to the next (docs/plans/printers.md decision 22). That failover can print a whole receipt on two printers (decision 23). A queued delivery restored after a restart starts again from the top of its stored list (printers decision 18).
- One store per instance. Each delivery names its printer, so one store serves every printer: one queue with a lane and a worker per printer, each loading its own unfinished deliveries (docs/plans/printers.md decision 4).
- Job IDs stay global, so `GET /api/v1/jobs/{id}` needs no printer.
- The stored job is printer-neutral (formatters invariant 1) and rendered bytes are not stored, so a queued delivery can move to another printer. A printer removed from the config while deliveries wait for it needs a rule; the printers plan settles it.
- The stored job is printer-neutral (formatters invariant 1) and rendered bytes are not stored, so a queued delivery can move to another printer. A queued delivery whose printer was removed from the config fails at restore (docs/plans/printers.md decision 5).
- Acknowledgement IDs are counted per printer.
- `cancelled` comes with phase 2b, as a delivery's state; the `deliveries.state` column takes it without a schema change.
- Two instances must not share a state directory. Exclusive locking makes the second fail at start; today they would also share the `ntfy-<name>.json` files. Until one instance drives several printers, each instance gets its own directory.
@@ -825,6 +825,7 @@ internal/pkg/printqueue
- The cancel leaves alone a delivery that has reached `sending` or finished. It commits the others `cancelled` in one synced commit (Architecture, JOB STATES), which drops what the cancel pushes out of retention as `Finish` does; then memory changes, they leave the waiting list, and their contexts end, so rendering, waiting for the printer's slot and dialling stop.
- The worker of a cancelled delivery stops with no retry, no `Finish`, no "job failed" line and no `OnFailure`, since the cancel's commit is its final state: `errCancelled` from `Send` is never retried, and an error after its context ended ("rendering: context canceled", "giving up after n attempts") finds the delivery `cancelled` under the lock.
- 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.
@@ -945,7 +946,7 @@ internal/pkg/paper
**Work.**
internal/pkg/receipt
- `Renderer.PreviewImage`: `base64` images from their data, `url` images fetched through safehttp under one 30-s deadline for the whole preview, a crossed box for each image that failed or is still loading.
- `Renderer.PreviewImage`: `base64` images from their data, `url` images fetched through safehttp under one 30-s deadline for the whole preview, a crossed box for each image that failed or is still loading. It draws with the profile the text preview uses: the named printer's, or the default printer's.
internal/app/uberbringer/server
- `Previewer` gains `PreviewImage`. handlers_preview.go answers `image/png` when asked; text stays the default. The cap's error answers `422` `preview_too_long` (errors.go). Check that the compress middleware leaves PNG alone.
@@ -983,7 +984,7 @@ internal/pkg/printqueue
- `Content(id)`: the stored job, `ErrNotFound` or `ErrContentGone`.
internal/app/uberbringer/server
- The route `GET /api/v1/jobs/{id}/preview` in the table, for full tokens. It decodes the stored job strictly and answers through the same negotiation as the POST preview. `Jobs` gains `Content`, and `fakeJobs` with it.
- The route `GET /api/v1/jobs/{id}/preview` in the table, for full tokens. It renders with the profile of its first delivery's printer. It decodes the stored job strictly and answers through the same negotiation as the POST preview. `Jobs` gains `Content`, and `fakeJobs` with it.
- errors.go: `410` `job_content_expired`.
Docs
@@ -1016,7 +1017,7 @@ Docs
- escpos: `ProcessIDRequest(id)` and a frame reader for real-time status, automatic status, process IDs, clear responses and unknown blocks.
- printer: a confirmed send with its four outcomes, using the count `Write` returns. `Status` reads through the frame reader and skips frames it did not ask for.
- `/healthz` while a job holds the connection.
- Config: `printer.confirm` (`auto`, `process_id` or `off`) and `printer.confirm_timeout`. Status gains `confirmed_at`. The store keeps the ID counter.
- Config: `printer.confirm` (`auto`, `process_id` or `off`) and `printer.confirm_timeout`, in each printer's table (docs/plans/printers.md decision 3). Status gains `confirmed_at`. The store keeps the ID counter.
- The partial-write choice (decision 23), once the confirmed send reports the bytes written.
- ntfy state in the store (decision 22).
- An `Idempotency-Key` header on `POST /api/v1/print`.