Preserve observation event identity and deduplication across restart
Problem
Observation deduplication is a five-minute process-local cache. Replaying the same host payload after restarting the worker creates another stored observation. This prevents reliable recovery of an ambiguous delivery and can duplicate later indexing or model processing.
Reproduced behavior
Live validation on main ab3e4efd282659b87d31b36c8514c6bc6b871f0b using the built post-tool hook, synthetic data and the default zero-LLM path:
- Invoke the hook twice with the same session, tool name, tool input and output.
- Export the isolated store: one observation exists.
- Force-stop and restart the instance against the same data directory.
- Replay the same host payload once.
- Export again: two observations exist.
The current hook creates a new timestamp for each delivery and does not propagate a stable host-event key. This test demonstrates that content-based deduplication does not survive replay; it does not imply that two genuinely distinct invocations with identical content should collapse into one.
Dedup cache, observation handling, hook envelope.
Required behavior
- Carry a stable event identity from the host or a deterministic transcript locator through initial capture and replay.
- Persist the event-to-observation relationship under explicit project/session boundaries.
- Atomically reserve or reconcile that identity with the observation write so concurrent deliveries cannot both commit.
- Distinguish in-progress, completed and retryable processing. A crash must not strand a reservation or repeat completed expensive stages.
- Preserve distinct genuine events even if their tool inputs or outputs are identical.
- Bound the idempotency record's retention by the supported replay horizon and expose expiration behavior.
Acceptance checks
Same event delivered sequentially, concurrently, after restart, and after a lost acknowledgment yields one observation. Different event IDs with identical content yield two. Crash between reservation and observation commit is recoverable. Retry of an already completed embedding or compression stage does not create a second chargeable operation. Resource growth remains bounded.
PR #1293 deliberately avoids ambiguous timeout retries. A persisted event identity would allow that case to be handled safely; this issue is not a request to remove its current timeout guard before the invariant exists. Consolidation-level deduplication is a different scope.
Source: rohitg00/agentmemory