#5049·hindsight

Store-owned retain: a failed retain leaves its document committed with no facts, so a retry is a no-op delta

Author: nicoloboschiCreated Oct 1, 2026Updated Oct 1, 2026

Found with hindsight-system-tests run against a store that owns its memories (store_owned = True). Postgres is unaffected.

Story: test_62_operation_failures.py::test_a_failed_operation_can_be_retried_after_the_cause_is_fixed — extraction fails, the cause is fixed, retry_operation runs, and the fact never appears.

What happens

  1. retain_batch_async opens a retain session. The streaming producer session.adds the document's chunk texts (with the full content_hash) before extraction finishes.
  2. Extraction raises. The finally in _run_retain_execution still calls retain_session.commit() — deliberately ("a retain that fails part-way must not discard what its earlier parts already produced"), and test_retain_outbox_session.py pins it (failure == "retain" → steps == ["commit"]).
  3. The store now holds the document, with its full content hash and zero facts.
  4. The retry runs _try_delta_retain, which loads that document, sees an identical hash, and takes the DELTA RETAIN (no changes) path — nothing is re-extracted.

On Postgres the document row is written in the same transaction as the facts, so a failed extraction leaves no document and the retry does a full retain.

Possible fixes

  • Abort the session (instead of committing) when the single-sub-batch path fails — the chunked path keeps commit-on-failure for the sub-batches that did finish.
  • Or commit partial work without stamping the final content_hash, so a later retain cannot mistake a failed document for a complete one.