Record a job done only once the printer confirms it
Breaking: a job reads done only once the printer has confirmed that it ran it, and holds the printer's connection until then. A job written in full that the printer does not confirm within printer.write_timeout now reads uncertain and is not sent again; before, it read done. Before each job, nothing is sent until the printer answers that it can print, so with its cover open or no paper a job is retried and fails, with no sent_at, as when the printer is unreachable, where before it read done. Receipts that take longer than write_timeout to print need a larger one. With confirmation the daemon also turns the printer's automatic status off (GS a 0) before each job and before its confirmation, so another client that relies on automatic status from the same printer stops getting it. printer.confirm = false keeps the old meaning of done and sends none of this. The third paper check of the job store showed why: with the TM-T88IV's cover open, Windows took all of a 128 KB receipt into its send buffer, so the job read done; the daemon stopped, and once the cover closed only the first third printed, without its cut. The printer was then left inside the image command, waiting for the rest, until it was switched off and on. The daemon now turns on the printer client's confirmation. The queue treats an unconfirmed send as written but unknown: it records the delivery uncertain, with an error that says the printer did not confirm it and that it may have printed in full, in part or not at all, logs it at WARN with the printer, and neither retries it nor reports it as a failure. Its commit is not synced: lost, it rolls back to sending, which the next start turns uncertain too. A printer that is not ready gives a plain error before the sending mark, which the queue retries as a failed dial. The new key printer.confirm, on by default, turns confirmation off for a printer that does not answer GS r with bits 4 and 7 clear, or does not answer DLE EOT on receipt; only the TM-T88IV is checked. The key's comments in config.go and the example config say what it sends and needs. docs/api.md warns that raw bytes which make the printer answer can be taken for the confirmation, and says that /healthz answers 503 timeout while a job holds the connection. It and design.md say that each job waits about 200 ms for answers still owed, for DLE EOT 1 to say that the printer is online, and for no answer to come late. design.md says why each connection opens with DLE EOT 1, GS a 0 and GS r 1, and names what stays open: a raw job holding a command answered with bits 4 and 7 clear, such as GS r, GS I, ESC v or ESC u 0, with printing after it, and an answer taken for the ready answer that is not it, one still queued when the fence arrived or one owed from before a late DLE EOT answer that stood in for the fence, followed by a pause of more than 100 ms while the printer reads online, as might happen during the TM-m50II's feed and cut at cover close. It relies on the printer answering DLE EOT on receipt and running GS a 0 in order, unverified beyond the TM-T88IV until stage 4a's raw-byte probe, and now says a send that fails part-way can print a whole receipt twice. The unit and install.md give the stop timeout with and without state.dir: without it the job being sent runs on from its rendering, image fetches included, up to the job's 2-minute cap, so such hosts keep systemd's default or set state.dir. configuration.md says the online check can add 2 s to write_timeout. The printers plan says what Send now does before a job, and its table of what a failed send can mean gains the ready wait and the confirmation. The tests' fake printers answer DLE EOT 1 and GS r 1 as an online printer with paper does; a test runs the daemon against one that answers that it is ready but never confirms the job. On paper, a receipt read done 884 ms after it was written, when the printer answered, and a receipt whose daemon was killed while it waited, with the cover open, read uncertain after the restart and printed once, cut short. With GS a 0 and DLE EOT 1, a receipt printed once with nothing extra and read done 888 ms after it was written; after a power cycle, with /healthz polled every 250 ms, one sent with the cover open waited 15.7 s with nothing sent and printed once, cut once, when the cover closed. With the fence, a receipt printed once with nothing extra and read done 921 ms after it was written. Part of stage 1d of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9376653e1a
commit
d3c3025e64
19 files changed
+429
-68
No files matched your search
+11
-6
@@ -153,13 +153,13 @@ For stage 3:
|
||||
- A write error after which `Write` had taken nothing counts as nothing sent and fails over at once. That needs `Send` to report what it wrote, which it discards today. The printer stays in `sent_to` all the same: over-reporting is the safe direction, and dropping it would cost one more store write.
|
||||
- `attempts` counts every attempt on every printer, and each mark's attempt number goes on from the last.
|
||||
- The risk: the next printer prints the whole receipt. A first printer that took all of it before the error, or buffered it and prints it once its fault clears, prints it too.
|
||||
- Some sends that will not print show no error at all. `Write` returns once the kernel holds the bytes, so a printer that goes offline after taking them, or one that another host holds, takes the receipt without a word, and no failover happens (Investigation findings, WHAT "THE PRINTER FAILED" CAN MEAN).
|
||||
- With `printer.confirm`, the default, `Send` opens each connection with `DLE EOT 1`, `GS a 0` and `GS r 1` and writes nothing without an answer to that `GS r 1`, after the `DLE EOT` answer, and a second `DLE EOT 1` that says online, so a printer that is offline, has its cover open or is held by another host gets no byte, and the delivery counts as nothing sent. A printer that takes the job and then does not confirm it leaves the delivery `uncertain`, which never fails over. With `printer.confirm = false`, `Write` returns once the kernel holds the bytes, so such sends show no error at all, and no failover happens (Investigation findings, WHAT "THE PRINTER FAILED" CAN MEAN).
|
||||
- docs/plans/remote-printers.md decision 17 builds on this: a remote `partial` outcome is today's write error, and `nothing` matches `NothingWritten`.
|
||||
23. **A status check before an anycast send.** After the dial and before the `sending` mark, on the same connection and inside the printer's slot, anycast reads `DLE EOT`. It reads a not-ready answer again 750 ms later, as `/healthz` does.
|
||||
- The read runs over the connection already open, so it never waits on its own slot.
|
||||
- It reads `DLE EOT` only. Stage 4a's `GS r 1` is not real-time, adds up to 500 ms, and could close the connection the job is about to be written on (decision 28). Near-end never decides a failover.
|
||||
- It reads `DLE EOT` only, before `Send`'s ready wait. Stage 4a's `GS r 1` is not real-time, adds up to 500 ms, and could close the connection the job is about to be written on (decision 28). Near-end never decides a failover.
|
||||
- A printer still not ready (offline, cover open, paper out, an error) counts as nothing sent. It is marked down (decision 24), and the delivery fails over at once.
|
||||
- A timeout or no answer sends anyway: a timeout is never a printer fault, and a printer busy with an earlier job may answer late.
|
||||
- A timeout or no answer goes on to the send: a timeout is never a printer fault, and a printer busy with an earlier job may answer late. With `printer.confirm`, the send then writes nothing until the printer answers `GS r 1` and says it is online to `DLE EOT 1`, and anything less counts as nothing sent, as a failed dial does.
|
||||
- Unicast and multicast do not check, as today, so a job for a printer that is briefly offline is still buffered for it. The check and `/healthz` share one settle function, moved from the server to `printer`, which takes the read to use.
|
||||
- Without the check, a printer out of paper most likely still takes the connection and the bytes, so the main anycast case would fall into decision 22's path. That is an inference, and a paper check tests it before stage 3 starts. With the owner's OK, one short receipt goes unicast to the TM-T88IV with its paper out (or its cover open). Does the printer take the connection and the bytes, and print the receipt once the paper is loaded?
|
||||
- docs/plans/remote-printers.md decision 19 reads a remote printer's status through the same settle function at the agent, and this paper check decides the anycast check there too.
|
||||
@@ -326,7 +326,7 @@ REAL-TIME STATUS (`DLE EOT`) PER MODEL
|
||||
- `GS r 1` reports near-end on all three, but it is not real-time: it is answered after the printing before it has finished, and at paper end the TM-T88IV to VII go offline and do not run it. Its fixed bits differ from `DLE EOT`'s (bit 4 is 0, where `DLE EOT` has 1), so `Status.Apply` would refuse it; Epson's page also says to accept `0xx1xx10`, contradicting its own table.
|
||||
|
||||
WHAT "THE PRINTER FAILED" CAN MEAN
|
||||
"Sent" means bytes the kernel took from `Write`. Whether they printed is unknowable without an acknowledgement (job-store phase 5). A text receipt of a few KB is usually taken whole at once, so a write error mostly shows on large image jobs or blocked or reset connections (an inference).
|
||||
"Sent" means bytes the kernel took from `Write`. With `printer.confirm = false`, whether they printed is unknowable without an acknowledgement (job-store phase 5). With `printer.confirm`, the default, the printer's answer to the `GS r 1` after the job says that it ran every byte, though the answer names no job, so design.md's residuals remain. A text receipt of a few KB is usually taken whole at once, so a write error mostly shows on large image jobs or blocked or reset connections (an inference).
|
||||
|
||||
| Signal | Bytes of the job sent | Printer at fault |
|
||||
|---|---|---|
|
||||
@@ -336,10 +336,15 @@ WHAT "THE PRINTER FAILED" CAN MEAN
|
||||
| A status check before the first byte (proposed), read again: offline, cover open, paper out, an error | none | yes |
|
||||
| The same check shows near-end only | none | no: it still prints |
|
||||
| The same check times out, or gets no or a malformed answer | none | unknown; a timeout is never a fault |
|
||||
| `printer.confirm`: no answer to the ready request (`DLE EOT 1`, `GS a 0`, `GS r 1`) within `write_timeout` (cover open, paper out, another host holding the printer, a printer stuck inside an earlier job) | none | yes, or held elsewhere |
|
||||
| `printer.confirm`: the ready wait cut short by its deadline or the connection's end after an answer | none | unknown |
|
||||
| `printer.confirm`: `DLE EOT 1` after the ready answer reports the printer offline, or goes unanswered | none | yes |
|
||||
| `Write` fails having taken nothing | none | depends |
|
||||
| `Write` times out, or the connection resets, after part of the job | part | unknown, or yes |
|
||||
| The dial succeeds while another host holds the printer; a small job's `Write` returns | all, held | unknown: it may print when the other host lets go |
|
||||
| `Write` returns, then the printer goes offline (cover, paper end); the data prints when the cause clears | all | yes, but failing over prints it twice |
|
||||
| `printer.confirm`: the job written in full, then the answer to the `GS r 1` after it | all, run by the printer | no |
|
||||
| `printer.confirm`: the job written in full, but no answer before the write deadline, or the connection fails | all; it may have printed in full, in part or not at all | unknown: the delivery is `uncertain`, neither retried nor failed over |
|
||||
| A render error | none | no: a fault of the job, unless that printer's options cause it |
|
||||
|
||||
WHERE THE REPORTS DISAGREE OR ARE UNSURE
|
||||
@@ -969,7 +974,7 @@ internal/app/uberbringer/server
|
||||
|
||||
internal/pkg/printer
|
||||
- printer.go:
|
||||
- `readStatus(ctx, conn)`: the `DLE EOT` reads on an open connection. `Status` calls it after `connect`; the checked send calls it on its own connection, so it never waits on its own slot. `GS r 1`, once stage 4a adds it, belongs to `Status` alone.
|
||||
- `readStatus(ctx, conn)`: the `DLE EOT` reads on an open connection. `Status` calls it after `connect`; the checked send calls it on its own connection, so it never waits on its own slot. `GS r 1` belongs to `Send`'s ready wait and confirmation and, once stage 4a adds its near-end read, to `Status`; the checked send never asks it.
|
||||
- `Settle(ctx, read, delay)` (name assumed): the read again of a not-ready answer, moved from server/handlers.go's `settledPrinterStatus`. `/healthz` passes `Client.Status` and its `HealthRecheckDelay`; the checked send passes a read over its own connection, and the 750-ms delay internal/app gives each lane.
|
||||
- The checked send: after the dial and before `beforeWrite`, the settled read of decision 23.
|
||||
- `Send` returns an error type (`SendError`, name assumed) holding the count `Write` took, with a method `NothingWritten() bool`.
|
||||
@@ -1065,7 +1070,7 @@ First, before any code, with the owner's OK. These are status reads only, nothin
|
||||
|
||||
internal/pkg/escpos
|
||||
- profile.go: `Model` and the status capabilities (decision 27); `LookupProfile` keeps the exact name.
|
||||
- status.go: the `GS r 1` request and its decoder (decision 28); decision 29's bits in `Status`, `Normalized()` and `Ready()`; the comment on the TM-T88VII.
|
||||
- status.go: the decoder of the `GS r 1` reply (decision 28), whose request is `escpos.TransmitStatusRequest`, as `Send` asks it. `Status` reads the reply through its connection's `line`, so a status block split across reads stays skipped, and leaves a missed answer to `Send`'s ready wait, which drops it with everything before its fence, or with its own answer; decision 29's bits in `Status`, `Normalized()` and `Ready()`; the comment on the TM-T88VII.
|
||||
|
||||
internal/pkg/printer
|
||||
- printer.go: `Status` sends `GS r 1` last when the profile says so, only when online and ready, under its own deadline, and closes the connection after a missed answer. If stage 3 has shipped, `readStatus`, which the checked send uses, stays `DLE EOT` only.
|
||||
|
||||
Reference in new issue
Block a user