Log the reason a late command result carries

The warning for a result with no pending command discarded `ok` and
`error` and said only that the id was unknown or expired - which is
exactly the information the gateway now sends when a long-running
command fails after being acknowledged. A `start_print` can only ever
report its real outcome late, since it is answered on acceptance and
this side times out after ten seconds.

Nothing else changes: the job never reaching `printing` is what fails
it. This is the difference between an operator seeing "job failed" and
seeing which half of a download-then-upload failed and what the printer
said.
This commit is contained in:
2026-10-18 20:00:00 +00:00
parent b7792ad335
commit 8848e396cf
+19 -4
View File
@@ -501,11 +501,26 @@ export const edgeWsRoute = new Elysia()
case "command_result": {
const pending = conn.pending.get(message.command_id);
if (!pending) {
// Either the command already timed out, or this gateway answered
// something we never asked. Both are worth saying out loud.
// Three ways to get here, and the third is the useful one.
//
// The command timed out; or this gateway answered something we
// never asked; or a long-running command that was acknowledged
// up front has now actually failed, and this is the gateway
// telling us why. A `start_print` is answered the moment it is
// accepted, because the transfer takes minutes and this side
// gives up after ten seconds - so its real outcome can only ever
// arrive late.
//
// The reason is logged rather than dropped. It is the difference
// between an operator seeing "job failed" and seeing which half
// of a download-then-upload failed and what the printer said.
// It does not change the job's fate: the job never reaching
// `printing` is what fails it, and that already works. Recording
// it against the job needs a column print_jobs does not have.
const reason = message.ok ? "reported success" : `failed: ${message.error ?? "no reason given"}`;
console.warn(
`[edge] gateway ${conn.gatewayId} sent a result for unknown or ` +
`expired command ${message.command_id}`,
`[edge] gateway ${conn.gatewayId} sent a result for unknown, ` +
`expired or already-answered command ${message.command_id} - ${reason}`,
);
return;
}