Recover observations captured while the local service is unavailable

Author: rohitg00Created Sep 29, 2026Updated Sep 29, 2026

Problem

A post-tool hook can exit successfully even though the observation never reaches storage. Restarting the service does not recover that event. A successful hook exit currently means the host can continue, not that capture succeeded, and those outcomes need separate visibility.

Reproduced behavior

Live validation on main ab3e4efd282659b87d31b36c8514c6bc6b871f0b, 29 September 2026, using the built CLI and built hook in an isolated synthetic instance with automatic compression and context injection disabled:

  1. Start the instance and confirm its health endpoint responds.
  2. Stop the instance.
  3. Invoke dist/hooks/post-tool-use.mjs with a synthetic session, project, tool input and output containing the unique marker offlinecerulean947.
  4. The hook exits with code 0.
  5. Restart the same instance, allow eight seconds for recovery, then search for the marker.
  6. No matching observation is returned.

The hook catches request rejection without recording a recovery action and schedules its exit after 500 ms. Capture path.

Required behavior

  • Keep the host interaction bounded and nonblocking, while exposing capture as accepted, pending recovery, or dropped.
  • Recover unaccepted events through host transcript replay with a persisted cursor where possible.
  • If a supported host cannot replay, make any local recovery buffer an explicit bounded policy with maximum bytes, maximum age, privacy filtering and observable overflow.
  • Forward recovered events through the existing capture pipeline with stable event identity, so ambiguous delivery cannot duplicate data or model work.
  • A failed capture must not require automatic summarization, context injection or an additional retry service.

Acceptance checks

  • Reproduce service-down capture, restart, and recovery using the actual built hook.
  • Test a short disconnect, an outage longer than the hook lifetime, and a timeout after the server committed.
  • Verify replay does not duplicate observations and does not re-run already successful model work.
  • Verify byte/age bounds and visible overflow when optional buffering is enabled.
  • Measure hook duration, retained bytes and idle resource cost in both enabled and disabled recovery modes.

Existing work

PR #1293 covers a short in-process retry for fast failures. This issue covers recovery after that bounded retry window and after the hook process has exited. Coordinate with that implementation rather than replacing it. Server-side acceptance and durable event identity are separate prerequisites.