jsconsumer, backoff: drain in-flight handlers on SIGTERM instead of cancelling them (COR-2224)
Commit
Cancelling the consumer's context used to fail every in-flight handler with context.Canceled in the same instant: jsconsumer's callback took no context, so every caller closed over the process signal context, and Runner.Stop's "wait for the in-flight handler" waited for that fast failure. On a final delivery the failure then read as poison and the message was Termed or dead-lettered. Prod, 7 days: 1,600+ ctx-canceled naks; 51 analysis jobs and 20 runner runs dead-lettered on a cancelled context in 30 days.
jsconsumer:
- Start/Run take func(ctx, msg). The handler context is derived with context.WithoutCancel from the parent and cancelled by the scaffold only once the loop has wound down or Config.DrainWindow (default 10s, negative rejected) elapsed with the handler still running; the expiry is logged at Warn. Stop keeps its join semantics; buffered deliveries are dropped and redeliver on AckWait. The floor-monitor poll runs on the handler context so a Settle inside the window reads a fresh floor.
- Retry.Settle: an interrupted delivery with broker deliveries left is not evidence about the message. It feeds no failure clock and no breaker (so no quarantine budget is spent), and exhaustion on it is deferred as OutcomeRetried/CauseShutdown. At the broker's own cap the detached capture still runs: a replayable DLQ copy beats a message stranded on purpose. DeadLetter is unchanged.
backoff:
- NakOrTerm(ctx, msg) Naks instead of Terms on an interrupted delivery. On the broker's final delivery that Nak is dropped and the message is left un-acked: visible (pinned floor, pending gauge) and reapable by a MAX_DELIVERIES sweeper, chosen over a silent Term. Measured in internal/brokersemantics.
- IsInterrupted(ctx) is the shared rule: cancelled, never timed out, so a per-attempt deadline still reads as a failed attempt (slow poison).
nuts:
- DefaultJoinTimeout 10s -> 15s so a ShutdownGroup on defaults joins the default drain window. Shutdown ordering documented in doc.go/README: cancel -> stop pulling -> drain window -> cancel handlers -> join -> drain connections.
Breaking (v0): every Start/Run/NakOrTerm call site needs a touch. The migration is to use the context the callback receives instead of the captured process context; the old shape compiles, so check the body.
Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01CWT5ca8ntVxE2F8p1J3ugX Entire-Checkpoint: fdd2ae452327