Skip to content

fix(retain): resume a partially written oversized document slice by slice - #5676

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/retain-delta-recovery-bounded
Oct 16, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
fix/retain-delta-recovery-bounded

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5485

What was wrong

An oversized document is retained one slice at a time. If that retain was interrupted and then recovered, slice 1 took the delta path instead. Delta compares the whole body with what is stored and extracts every chunk not yet written in one step, saving nothing until the end. In the issue that was 463 and 716 LLM calls queued at once, which blocked other banks for over an hour. Every interrupted retry lost all of it.

Fix

In _try_delta_retain: if the stored document already has this body's hash but some chunks still differ, it is a half-written copy of the same body. Delta now returns None. The normal streaming path then resumes slice by slice. Its recovery check matches the same hash and skips chunks already saved, so each slice is saved as it finishes.

Real edits to a stored document are not affected (different hash). Neither is an identical re-retain (nothing to extract, so it stays on the metadata-only path).

Test

test_recovering_partially_written_oversized_document_resumes_slice_by_slice: crash a sliced retain after 3 extraction calls, then retain the same body again.

  • before: the retry sent all 17 remaining chunks in one extraction call (calls: [17])
  • after: one chunk per call, only the missing ones

Not in this PR

The other points in the issue still stand: a big edit to a stored document still runs as one unbounded delta step (option a), there is no fairness between operations in the shared LLM queue (d/e), and cancelling does not stop queued calls (f).

…lice

A sliced retain that was interrupted part-way is retried with the same body.
Slice 1 took the delta path, which diffs the complete body and extracts every
unwritten chunk of the whole document in one step that commits only at the end:
hundreds of LLM calls queued at once ahead of every other bank, and all of them
lost if the retry is interrupted too.

When the stored document already carries this body's hash but some chunks still
differ, delta now steps aside. The streaming path resumes slice by slice: its
recovery probe matches the same hash and skips the committed chunks.

Fixes #5485
@nicoloboschi
nicoloboschi merged commit 06a964d into main Oct 16, 2026
231 of 234 checks passed
@nicoloboschi
nicoloboschi deleted the fix/retain-delta-recovery-bounded branch October 16, 2026 14:02
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant