fix(ingest): regroup revoke needs to work when number of sequences is greater than batch size, add tests - #7249
fix(ingest): regroup revoke needs to work when number of sequences is greater than batch size, add tests#7249anna-parker wants to merge 13 commits into
Conversation
The header was re-added by checking `record_counter % batch_chunk_size == 1`, which is never true for a chunk size of 1 because `n % 1` is always 0. Every batch from the second one on then went out as a metadata TSV whose first line was a data row. Whether a batch needs the header does not depend on the chunk size at all - it depends on whether the batch buffer is still empty, which the code already knows. With that, a chunk size of 1 works and the schema minimum can go back to 1. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xv8GMzy6r4dXGQZpemjAmU
…tters Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xv8GMzy6r4dXGQZpemjAmU
The tail-chunk submit was guarded by `record_counter % batch_chunk_size != 0`, the same modulo shape as the header bug. At a chunk size of 1 it never fires, so a metadata file with only a header left `response` unbound and the function raised UnboundLocalError. A completely empty metadata file did the same at every chunk size. Whether a tail chunk needs submitting is again a property of the buffer, not of the counter: submit if anything beyond the header is still unsent. On top of that, submit_or_revise now returns early for zero records instead of sending a request with no data - it already counts the lines and logs "Submitting 0 sequence(s)". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xv8GMzy6r4dXGQZpemjAmU
`record_counter` counted lines of the metadata file, so the header occupied tick 1 and every piece of arithmetic derived from it was off by one. That is what forced the two workarounds in the previous commits: the header re-append and the tail submit both had to be phrased as buffer-state checks because the counter could not be trusted. Counting records instead, and detecting the header by whether we have one yet rather than by the line number, makes the plain modulo arithmetic correct at every chunk size. Batches are now exactly batch_chunk_size records rather than one short for the first batch (2500 records at the default now go out as 1000/1000/500 rather than 999/1000/501), and the logged batch numbers start at 1 rather than 2 when the chunk size is 1. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xv8GMzy6r4dXGQZpemjAmU
…uences to revoke than the batch size
|
Claude finished @anna-parker's task in 3m 13s —— View job Claude Code Review
The core fix is correct and the diagnosis in the description is right: Four inline comments, in rough priority order:
Nothing security-relevant; The three tests are well constructed otherwise — building on the real CCHF pipeline output rather than hand-rolled fixtures means they exercise the actual Note: I was not able to run |
If more than
batch_chunk_sizerecords to regroup the new sequences are already POSTed to Loculus by the time the KeyError fires, and it fires before the revoke loop, so zero old accessions get revoked → the mis-grouped originals stay live alongside the new ones. Worse failure than just erroring out early.Screenshot
PR Checklist
🚀 Preview: Add
previewlabel to enable