docs/pkg/watchdog.md

pkg/watchdog capability operation timers

pkg/watchdog is the process-local keyed timer manager shared by service tool, plugin and macro calls and pkg/ezagentapi RPCs. It owns inactivity and explicit maximum timers, not pending calls, transport, retries or persistence. LLM provider stream watchdogs and retries are separate and unchanged.

A registration uses the exact (Key.Type, Key.ID) pair. Register leaves an existing key unchanged. Non-positive durations disable that timer. Heartbeats renew only inactivity, never an explicit maximum. Healthy calls have no default elapsed-time limit. Tools use their metadata; plugins have a five-second idle watchdog without an implicit maximum; default macros have the same policy. Explicit macro/tool max_timeout and caller context deadlines still apply. Go RPC inactivity thresholds are five or ten seconds according to the method.

The first terminal producer claims the pending call. Timer expiry removes its registration and stops the other timer before calling back outside the manager lock. Entry identity prevents stale timers claiming replacement registrations; an idle deadline check also protects against a callback already runnable when a heartbeat resets its timer. Cancel removes silently; CancelWithError and CancelAllByTypeWithError report cancellation.

Ownership and cancellation

The service checks the exact connection, kind and call ID before accepting a capability heartbeat, acknowledgement or result. RPC managers are local to one API connection. Unknown and completed keys cannot renew another call.

Go API receivers heartbeat admitted calls and RPCs every second until a matching terminal is enqueued or the connection closes. Asynchronous callback return and tool_ack are not terminal. Ruby reuses its provider heartbeat scheduler for metadata RPCs. Heartbeats and response correlation bypass blocked callback work.

Disconnect terminally fails outstanding calls on that connection. A new connection receives a fresh ID and handles only new calls. No dispatched request is inherited or replayed. Responses already correlated before EOF remain final. Caller cancellation retires the local waiter and does not assert rollback or require remote acknowledgement. Existing tool abort and process stop/kill paths remain authoritative; passive watchdog expiry does not send tool_abort.

Sources and focused coverage are in pkg/watchdog/watchdog.go, pkg/watchdog/watchdog_test.go, pkg/ezagentapi/heartbeat_test.go and pkg/service/watchdog_lifecycle_test.go. Wire semantics belong to the JSONL API catalog.