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
+40
-14
@@ -123,17 +123,33 @@ curl -H @"$HOME/.uberbringer-auth" https://printer.example.com/api/v1/jobs/job_0
|
||||
}
|
||||
```
|
||||
|
||||
`status` is `queued`, `printing`, `done`, `failed` or `uncertain`. A failed job
|
||||
includes an `error` field. `uncertain` means the daemon stopped while it was
|
||||
sending the job to the printer, so the receipt may have printed; its `error`
|
||||
says so. Such a job is never sent again: if the paper shows it missing, send
|
||||
it again. `sent_at` is when the first attempt was about to write to the
|
||||
printer. A failed job with `sent_at` reached the printer, and part of it may
|
||||
have printed; one without it never reached the printer.
|
||||
`source` says where the job came from: `print` for
|
||||
`/api/v1/print`, `module:<name>` for a [module](#modules) route, or
|
||||
`ntfy:<name>` for an [ntfy subscription](ntfy.md)
|
||||
in the config. The last `queue.history` finished jobs are kept.
|
||||
`status` is `queued`, `printing`, `done`, `failed` or `uncertain`. A job is
|
||||
`done` once the printer has confirmed that it ran it: after each job the
|
||||
daemon asks the printer for its status, which it answers only once every
|
||||
byte before the question has run (with `printer.confirm = false`, `done`
|
||||
means only that the job was written to the printer's connection). The
|
||||
answer names no job, so before each job the daemon drops the answers
|
||||
the printer still owed to earlier questions: those it sent before its
|
||||
answer to a real-time question asked first, and those that come within
|
||||
100 ms of each other after it. It then checks with `DLE EOT 1` that the
|
||||
printer is online, and if another answer comes it sends nothing and
|
||||
tries again; each job waits about 200 ms for these checks. A
|
||||
[`raw`](#raw) element can still let a job read `done` before it has
|
||||
printed; docs/design.md describes the one other case, where the printer,
|
||||
still reporting online, pauses more than 100 ms between two answers,
|
||||
which is unverified.
|
||||
A failed job includes an `error` field. `uncertain` means
|
||||
the receipt may have printed in full, in part or not at all: the daemon
|
||||
stopped while it was sending the job, or the printer did not confirm it
|
||||
within `printer.write_timeout`, as when its cover is open; its `error`
|
||||
says which. Such a job is never sent again: if the paper shows it missing,
|
||||
send it again. `sent_at` is when the first attempt was about to write
|
||||
to the printer. A failed job with `sent_at` reached the printer, and
|
||||
part of it may have printed; one without it never reached the printer.
|
||||
`source` says where the job came from: `print` for `/api/v1/print`,
|
||||
`module:<name>` for a [module](#modules) route, or `ntfy:<name>` for an
|
||||
[ntfy subscription](ntfy.md) in the config. The last `queue.history`
|
||||
finished jobs are kept.
|
||||
|
||||
With [`state.dir`](configuration.md#state) set, jobs are kept on disk, so
|
||||
a job's status answers after a restart as before it, and a job still
|
||||
@@ -250,9 +266,11 @@ Details:
|
||||
- **Brief problems are re-checked.** A printer that looks not ready is read
|
||||
again 750 ms later, and only a problem that is still there gives `503`.
|
||||
While cutting or feeding, a printer can report a problem for a moment.
|
||||
- **Timeouts.** The printer accepts one connection at a time. While it is still
|
||||
taking in a large job, the 3-second health check can run out of time. That
|
||||
gives `503` with printer status `"timeout"`, because the printer's state is
|
||||
- **Timeouts.** The printer accepts one connection at a time, and a job holds
|
||||
it until the printer has printed it and confirmed so (`printer.confirm`),
|
||||
or, while the printer cannot print, as the job waits for it to be ready.
|
||||
When that takes longer than the 3-second health check, the check gives
|
||||
`503` with printer status `"timeout"`, because the printer's state is
|
||||
unknown.
|
||||
- **The cover flag** is only reported while the printer is offline. Epson
|
||||
printers always go offline when the cover opens.
|
||||
@@ -408,6 +426,14 @@ or link-local addresses (including cloud metadata endpoints) are refused unless
|
||||
|-------|--------|
|
||||
| `hex` | ESC/POS bytes as hex, spaces allowed, e.g. `"1B 61 01"` |
|
||||
|
||||
Bytes that make the printer answer with a byte whose bits 4 and 7 are
|
||||
clear, such as `GS r`, `GS I`, `ESC v` or `ESC u 0`, can be taken for the
|
||||
printer's confirmation of the job (`printer.confirm`) when printing follows
|
||||
them, so the job can read `done` before it has printed, or `uncertain`
|
||||
though it printed. Answers they leave owed can do the same to the next
|
||||
job: before each job the daemon drops the answers still owed to earlier
|
||||
requests, but only those that come within 100 ms of each other.
|
||||
|
||||
The bytes are sent as given, so a job with a `raw` element prints only with
|
||||
a token issued with `uberbringer token --raw`; any other token gets `403`
|
||||
`token_scope`. Previewing one needs no such token.
|
||||
|
||||
@@ -87,7 +87,8 @@ so on a host it set up, re-run it after changing them
|
||||
| `columns` | from the width | Font A characters per line, for word wrap; overrides the model |
|
||||
| `box_line_spacing` | `0` | The line spacing, in motion units (ESC 3, 0–255), used while a box prints. Lines of box drawing leave small gaps in the vertical borders at the printer's default spacing; a value checked on paper closes them. `0` keeps the default |
|
||||
| `cut_feed` | `3` | Blank lines, 0–255, fed before every cut, the one after each copy and `cut` elements alike, so that the last printed line does not sit right at the cut. They show in previews and count toward `format.max_lines` |
|
||||
| `dial_timeout`, `write_timeout` | `"5s"`, `"30s"` | How long connecting to the printer, and sending it a job, may take |
|
||||
| `dial_timeout`, `write_timeout` | `"5s"`, `"30s"` | How long connecting to the printer, and sending it a job, may take. With `confirm`, `write_timeout` also bounds the wait for the printer to be ready before a job, which the check that it is online can extend by up to 2 s, and the wait for its confirmation after it, which comes once the job has printed: raise it for receipts that take longer to print, and the stop timeout with it. A job's whole run is capped at 2 minutes, so a larger value changes nothing |
|
||||
| `confirm` | `true` | Ask the printer for its status with `GS r 1`, which it answers only once it has run every byte before it, and, on the TM-T88IV, only while it can print. Before each job, ask `DLE EOT 1`, which the printer answers at once, then `GS r 1`, drop whatever the printer sent before the `DLE EOT` answer, and wait up to `write_timeout` for the answer to `GS r 1`: without it, as with the cover open or no paper, nothing is sent and the job is retried, then fails, as when the printer is unreachable. Before each job, also turn the printer's automatic status off (`GS a 0`) and, once it has answered, check with `DLE EOT 1` again that it is online and that no answer comes late. These checks take about 200 ms per job. After each job, turn automatic status off again and ask again, and mark the job `done` only on the answer; one the printer does not confirm within `write_timeout` is `uncertain` and is not sent again. Checked on the TM-T88IV. `false`, for a printer that does not answer `GS r` with bits 4 and 7 clear or does not answer `DLE EOT` on receipt, sends none of these and marks a job `done` once the operating system has taken its bytes, which a stop or a crash can still lose |
|
||||
| `retries` | `3` | How many times a failed send is retried before the job fails |
|
||||
| `retry_delay` | `"1s"` | The wait before the first retry; it doubles after each |
|
||||
|
||||
@@ -261,6 +262,11 @@ Request bodies and the `Authorization` header are never sent to Sentry.
|
||||
so check the paper. A job that a stop catches before it reached the
|
||||
printer is logged at INFO as `job left queued` and prints after the
|
||||
start.
|
||||
- A job written to the printer in full that it does not confirm is logged
|
||||
at WARN, as `job may not have printed in full`, with the printer's
|
||||
error; it reads `uncertain` and is not sent again. If its receipt was cut
|
||||
short, the printer may still be waiting for the rest of an image and
|
||||
print the next receipt as noise: switch it off and on.
|
||||
- Each [ntfy subscription](ntfy.md) logs with its `subscription` name,
|
||||
never with what a message says or its topic. It logs at WARN when its
|
||||
connection is lost, when its credentials are refused and while the queue
|
||||
|
||||
+106
-9
@@ -47,8 +47,102 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
`ref`. It is never sent again; a person checks the paper, and a
|
||||
reprint is a new request. A crash between the mark and the write
|
||||
leaves an `uncertain` receipt that never printed, the safe direction.
|
||||
`queued` never reached the printer, `done` was written in full, and a
|
||||
`failed` job reached it only if `sent_at` is set.
|
||||
`queued` never reached the printer, and a `failed` job reached it only
|
||||
if `sent_at` is set.
|
||||
- **Done means the printer confirmed it (owner, 2026-12-01).** A write
|
||||
that returned says only that the operating system holds the bytes. On
|
||||
the TM-T88IV with its cover open, Windows took a whole 128 KB receipt
|
||||
into its send buffer at once; the daemon stopped, and once the cover
|
||||
closed only the receipt's first third printed, uncut, and the printer
|
||||
waited for the rest of the image, so the next receipt would have
|
||||
printed as noise until it was switched off and on. So the client asks
|
||||
with `GS r 1`, which the printer answers only once it has run every
|
||||
byte before it, and, on the TM-T88IV, only while it can print
|
||||
(`printer.confirm`):
|
||||
- Before the `sending` mark it sends `DLE EOT 1`, `GS a 0` and `GS r 1`
|
||||
in one write. The printer answers `DLE EOT` on receipt, ahead of
|
||||
anything it receives after it, so that answer is a fence: everything
|
||||
before it left the printer before the request reached it, and is
|
||||
dropped, however long a lost segment holds the request back. That
|
||||
takes care of answers owed to requests the printer ran earlier, on
|
||||
an earlier connection or for an earlier run of the daemon, and of the
|
||||
last bytes of an automatic status block whose header went to an
|
||||
earlier connection. A late answer to an earlier connection's
|
||||
`DLE EOT` looks like the fence's and can stand in for it; the last
|
||||
check below catches what follows from that. It then waits, up to
|
||||
`printer.write_timeout`, for an answer to `GS r 1` after the fence.
|
||||
Without it, as with the cover open, paper out or a printer stuck
|
||||
inside a cut-short image, nothing is sent, and the job retries as
|
||||
after a failed dial and fails with no `sent_at`. Requests still
|
||||
queued in the printer ahead of this one are answered first, and the
|
||||
answers carry nothing that tells them apart, so the wait reads every
|
||||
answer until 100 ms have passed since the last and drops them all.
|
||||
Only answers keep the wait open, and one that the deadline or the
|
||||
connection's end cuts short counts as not ready. A printer may run
|
||||
`GS r 1` while offline, as the TM-m50II's settings may allow, so it
|
||||
then asks `DLE EOT 1` again, for up to 2 s beyond
|
||||
`printer.write_timeout`, and sends the job only if the printer
|
||||
answers that it is online. Last, it reads on for 100 ms. Once the
|
||||
answers have settled none is owed, so an answer to `GS r 1` during
|
||||
the online check or after it means that one taken for the ready
|
||||
answer was not, as when a late `DLE EOT` answer stood in for the
|
||||
fence and an owed answer followed it; then nothing is sent, and the
|
||||
job is tried again. Each job waits about 200 ms for these checks.
|
||||
- After the job it sends `GS a 0` and `GS r 1` again, and the job is
|
||||
`done` only on that answer. Without it within
|
||||
`printer.write_timeout`, the job is `uncertain`, with a WARN line,
|
||||
and never sent again. A receipt that takes longer to print than that
|
||||
reads `uncertain` though it printed, and the job's 2-minute bound
|
||||
caps the timeout.
|
||||
- Automatic status blocks: the UB-E02 and UB-E03 boards turn them on
|
||||
at power-on, and a job's `ESC @` turns them off, but not on a
|
||||
TM-T88VII with DIP switch 2-1 on. A block's last three bytes have the
|
||||
`GS r` answer's fixed bits, and the board can send them on the next
|
||||
connection. So the client sends `GS a 0` before each `GS r 1`; the
|
||||
printer runs it in order, so no block follows the answer on that
|
||||
connection. Bytes of blocks before the fence are dropped with the
|
||||
rest; blocks after it are passed over by their header's fixed bits,
|
||||
a block split across reads included, and after the confirmation the
|
||||
client reads on for up to 100 ms for the rest of a block it ended
|
||||
inside. `Status` sends no `GS a 0`, which the printer does not run
|
||||
while offline; before it closes, it reads what has come, to the end
|
||||
of any block.
|
||||
- Not `DLE EOT` for the confirmation: it is answered at once, and an
|
||||
image's bytes can hold it, which the printer answers too; such
|
||||
answers are told from the `GS r` answer by their fixed bits (bits 4
|
||||
and 7 clear). The TM-T88IV answers `0x00`; Epson's pages also give a
|
||||
form with bit 4 set, which a model must not use unless it runs with
|
||||
`printer.confirm = false`, unchecked on the TM-T88VII and TM-m50II.
|
||||
`printer.confirm` also needs a printer that answers `DLE EOT` on
|
||||
receipt.
|
||||
- What remains open, which an acknowledgement that names the job,
|
||||
`GS ( H` fn 48 (phase 5), would close:
|
||||
- A `raw` job holding a command the printer answers with a byte
|
||||
whose bits 4 and 7 are clear, such as `GS r`, `GS I`, `ESC v` or
|
||||
`ESC u 0`, with printing after it, is confirmed by that answer
|
||||
before it has printed. Answers it leaves owed, far enough apart,
|
||||
can do the same to the next job. Only a token issued with `--raw`
|
||||
can send one.
|
||||
- An answer taken for the ready answer that is not it: the answer to
|
||||
a request still queued in the printer when the fence arrived, or,
|
||||
when a late `DLE EOT` answer stood in for the fence while this
|
||||
connection's request was held back, one the printer owed from
|
||||
before. The printer runs queued requests back to back, so the real
|
||||
ready answer follows within the settle, which drops both, or
|
||||
within 100 ms of the online answer, which sends nothing, unless
|
||||
printing comes between them, which only a `raw` job puts there, or
|
||||
the printer pauses longer while it reports online. The TM-m50II
|
||||
feeds and cuts when its cover closes; if it reports online before
|
||||
it has run the queued requests and pauses between them, the late
|
||||
ready answer confirms the job before it has printed.
|
||||
- The client relies on the printer answering `DLE EOT` on receipt,
|
||||
ahead of the `GS r 1` sent just before it, and running `GS a 0` in
|
||||
order, and on how the board routes bytes across connections. The
|
||||
TM-T88IV answers `DLE EOT`; the rest is unverified, and stage 4a's
|
||||
raw-byte probe (docs/plans/printers.md) checks it.
|
||||
- A job holds the printer's connection until it has printed, so
|
||||
`/healthz` answers `503` `timeout` during a receipt that takes more
|
||||
than 3 seconds.
|
||||
- **Deliveries.** A job has one delivery per printer, one for `default`
|
||||
until several printers are configured, each with its own state,
|
||||
attempts and times. A job's `status` derives from them: `queued` while
|
||||
@@ -141,10 +235,11 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
untested on ARM hardware: the owner has none, modernc's CI names no
|
||||
ARMv6 target, and older SIGSEGV reports for linux/arm exist. CI
|
||||
cross-compiles them on every push.
|
||||
- **Acknowledgement.** Epson documents one, `GS ( H` fn 48, answered
|
||||
once a job has printed, which would turn most `uncertain` jobs into
|
||||
confirmed prints. Whether the TM-T88IV's network board passes it to
|
||||
port 9100 is unverified, so it waits for a paper test
|
||||
- **Acknowledgement with an ID.** Epson also documents `GS ( H` fn 48,
|
||||
answered with an ID of the host's choosing once a job has printed,
|
||||
which would tell one job's answer from another's even across
|
||||
connections. Whether the TM-T88IV's network board passes it to port
|
||||
9100 is unverified, so it waits for a paper test
|
||||
(docs/plans/job-store.md, phase 5). The state machine is safe without
|
||||
it.
|
||||
- **Render, then send.** The handler validates the whole job, and a `400`
|
||||
@@ -153,8 +248,9 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
sends that stream over one connection. A failure before the send, such as a
|
||||
broken image, costs no paper and leaves no half-printed receipt. A retry
|
||||
resends the same bytes and does not render again. A send that fails
|
||||
part-way can print part of a receipt twice. That is accepted, because
|
||||
retries are what let a job survive a printer that is briefly offline.
|
||||
part-way can print a receipt, or part of one, twice. That is accepted,
|
||||
because retries are what let a job survive a printer that is briefly
|
||||
offline.
|
||||
- **Blank paper before the cut (owner, 2026-11-30).** The cut, `GS V 66 0`,
|
||||
feeds the last printed line just past the cutter, so the cut fell right
|
||||
under it. `printer.cut_feed` blank lines (3) now feed before every cut.
|
||||
@@ -579,7 +675,8 @@ before anything is built. They come in this order.
|
||||
the owner accepted every proposed default, 2026-12-01). The store is
|
||||
built (Decisions, "Jobs survive a restart"); what is left:
|
||||
- `GET /api/v1/jobs` lists the history, job status shows `ref`, and
|
||||
`/healthz` counts the jobs found `uncertain` at the latest start.
|
||||
`/healthz` counts the jobs that became `uncertain` since the latest
|
||||
start, at it or during the run.
|
||||
- `DELETE /api/v1/jobs/{id}` cancels a waiting job, for full tokens. An
|
||||
ntfy `message_delete` cancels the waiting receipts of its
|
||||
notification (`Queue.Cancel`); `message_clear` does not, and the
|
||||
|
||||
+6
-3
@@ -44,9 +44,12 @@ sudo UBERBRINGER_VERSION=v0.2.0 ./install.sh <domain> <acme-email> <printer-addr
|
||||
|
||||
- The unit keeps systemd's stop timeout, 90 seconds, so a receipt that is
|
||||
being written to the printer when the service stops can finish. If you
|
||||
lower it with `systemctl edit`, keep it above `printer.write_timeout`
|
||||
plus 10 seconds (40 at the defaults); a stop that kills the write leaves
|
||||
the job `uncertain`.
|
||||
lower it with `systemctl edit` and have `state.dir` set, keep it above
|
||||
`printer.write_timeout` plus 10 seconds (40 at the defaults); a stop that
|
||||
kills the write leaves the job `uncertain`. Without `state.dir`, the job
|
||||
being sent runs on from its rendering, image fetches included, through
|
||||
its dial and the wait for the printer to be ready, up to the job's
|
||||
2-minute cap, so keep the 90-second default there, or set `state.dir`.
|
||||
- Change the systemd unit with `systemctl edit uberbringer`.
|
||||
- The install log is `/var/log/uberbringer-install.log`.
|
||||
|
||||
|
||||
+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.
|
||||
|
||||
+2
-2
@@ -401,7 +401,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"finished_at": {
|
||||
"description": "finished_at is when the job was done or failed, or when a start found it uncertain.",
|
||||
"description": "finished_at is when the job was done, failed or found uncertain.",
|
||||
"format": "date-time",
|
||||
"type": "string"
|
||||
},
|
||||
@@ -428,7 +428,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"description": "status is where the job is in its lifecycle. uncertain is a job that was being sent to the printer when the daemon stopped: it may have printed, and it is never sent again.",
|
||||
"description": "status is where the job is in its lifecycle. done is a job the printer confirmed it ran, or with printer.confirm off, one written to it in full. uncertain is a job that was being sent to the printer when the daemon stopped, or that the printer did not confirm: it may have printed in full, in part or not at all, and it is never sent again.",
|
||||
"enum": [
|
||||
"queued",
|
||||
"printing",
|
||||
|
||||
Reference in new issue
Block a user