P254 · Tool use

Use a deadline independent of stream activity

Use a total operation deadline as well as inactivity detection so keepalives cannot occupy a worker indefinitely.

Editorially reviewed

These examples and illustrative results are independently authored teaching materials, not measured model results.

Use case

A stream emits keepalives without completion. Teaching case starts UTC10:00 with absolute 10:02 deadline plus separate inactivity timer. Resetting the only timeout permits indefinite occupancy.

Mechanism

Use nonresetting total deadline and separate liveness. On expiry end local wait, record timeout/attempt and release capacity. Pass deadline before retries/judging; retain underlying request identity and separately verify cancellation/remote status. Race completion does not abort remote work.

Bad example

Reset two minutes for every heartbeat, retry after timeout and call the remote job cancelled.

Good example

Keep teaching 10:02 fixed. At expiry record timeout, not business zero, release local slot and issue no retry/judge past the shared deadline. Preserve request/possible-remote-running state and use actual cancellation/reconciliation without Promise.race cancellation claims.

Why the change matters

Traffic establishes activity rather than completion. Deadlines bound local resources and prevent abandoned retry chains continuing calls.

Observable expectation

Heartbeat at 10:01 with no terminal by 10:02 times out; no later retry/judge. Inspect local release versus remote unknown and actual timing/identity.

No streaming service runs.

Limits

Deadlines/recovery are task-specific. Local capacity release does not release remote resources/cost/effects; frozen SDK/runner examples promise no current cancellation.

Sources and evidence

Read the editorial criteria