fix(workers): bound the heartbeat skip by heartbeat age on the monotonic clock; deadline covers the enqueue; a reply that wins the timeout race is returned (WRK-001, WRK-003, WRK-004, WRK-005, #253)

This commit is contained in:
Joseph Doherty
2026-12-03 09:52:19 -05:00
parent 159524edd9
commit 2c22ae6bd4
6 changed files with 345 additions and 21 deletions
+15
View File
@@ -647,6 +647,21 @@ Pending command handling:
Timeouts should not assume the COM call stopped. A timed-out command may still
finish inside the worker.
The command timeout is one deadline for the whole call, the outbound enqueue
included. The outbound channel is bounded, and a write loop parked in a pipe
write the worker is not draining leaves it full; an enqueue bound only to the
caller's token then waited indefinitely for a caller with no deadline. The
common case (room in the channel) is a non-allocating `TryWrite`; only a full
channel waits, under the deadline, and the reply wait gets what is left of it.
An enqueue that runs out of time fails the command as `CommandTimeout` with no
`WorkerCancel`, because the worker never saw it.
When the deadline fires, the timeout arm owns the outcome only if it removes the
pending entry. If the read loop removed it first (the reply landed right at the
deadline), the caller gets that reply, which is what the metrics already counted,
instead of a `CommandTimeout` that would make it retry a write the worker
performed.
On timeout **and on caller cancellation** the client also forwards a
`WorkerCancel` carrying the abandoned correlation id, best-effort: the gateway
has stopped waiting, but the worker has not stopped working, and the worker owns