Skip to content

DR backup: copy loops refuse a None read instead of ending the copy short (BACKLOG #6687) - #3254

Merged
wshallwshall merged 8 commits into
mainfrom
w12-6687
Nov 24, 2026
Merged

wshallwshall merged 8 commits into
mainfrom
w12-6687

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

BACKLOG #6687, item 1 in part. From Manager runbook-batch-manager-fa3030 (account 9).

Merge danger

  • Reversible: yes, by a revert.

  • Blast radius: messagefoundry/pipeline/dr_backup.py: a new shared copy loop, _read_chunks, used at three sites:

    • the no-key build;
    • the plaintext verify;
    • the config-member restore.

    Also the :210 comment, a changelog fragment, and the new tests/test_dr_backup_none_read.py.

  • Behaviour change: a None read (a stream with no data yet) at those three sites is now refused through the codec's _read_once and raised as OSError(EIO). Before, it was treated as end of stream and ended the copy short.

    • The no-key build reports kind write.
    • The plaintext verify reports a FAIL, which the backup's own verify quarantines to .failed, as main does for any OSError there.
  • Reach: no current caller can return None at these sites. They read files opened rb and the tar's extractfile.

Evidence

  • 5 tests fail on origin/main and pass at head:
    • the plaintext build case;
    • the plaintext verify case;
    • the config restore case;
    • two _read_chunks unit tests.
  • The tests check the failure kind and the rollback list, not only the message text.
  • 529 related backup tests pass. ruff and mypy (linux and win32) are clean. The full suite was not run.

QA

  • code-review skill at xhigh.
  • Nonces: round-70fc7350, round-89eaf180, round-84ccc3f4, round-69bdc37c, then round-c02119ea on 13a4da5669b..9720c56f132.
  • Each tag reads xhigh effort → 10 inline angles → dedup (no verify) → sweep → ≤15 findings, and review_tag.py exited 0 on each.
  • Head 380b8d8f114 changes text only.
  • Two Manager decisions are logged:
    • refuse a None read rather than wait it out, the same rule as the codec's keyed branch;
    • report the failure kinds main reports.

Remaining difference from main (only on the unreachable None path)

  • On main, a None on the first read gave an empty .part file. Verify renamed it to .failed, and the message named it.
  • Now the build fails with kind write, and the message does not name the .part.
  • A refused build leaves a partial .part file, as main does for any OSError in that copy.

Banner

#6687 PARTIAL.

  • Item 1: the no-key build, plaintext verify and config-restore copy loops share _read_chunks, which refuses a None read. Tests: tests/test_dr_backup_none_read.py.
  • Already met on main: items 2, 3, 4, 5, 6, 7, 9 and 10.
  • Left:
    • item 1 at _extract_member and the plaintext branch of _restore_blocking, because open PR 3202 edits both functions;
    • item 8, a fill loop shared with the codec, sandbox.py and dicom.py, which is a design item.

Open findings (one R2 row)

  1. A failure kind of write does not tell a source-read stall from a destination write error.
  2. EIO names the wrong cause; EAGAIN would be accurate.
  3. The except also catches codec errors raised inside src.read.
  4. The keyed paths still report a None read as encrypt or decrypt failed.
  5. _extract_member, the plaintext branch of _restore_blocking, and copyfileobj in _place_restored_store are still open. So is _sha256_file.
  6. dr_backup imports _read_once, which is private to backup_codec.
  7. Untested: the leftover-staging arm, and the non-bytes and oversize refusals.
  8. The plaintext verify limb has no byte cap of its own.

BACKLOG #6687 (batch 668), added item 1 and the dr_backup half of item 8.
One shared fill loop, dr_backup._read_chunks, replaces the bare
`if not buf: break` copy loops in _build_archive_blocking (no-key build),
_verify_in_staging (plaintext verify) and _extract_config_members. A None
read (a non-blocking source with no data ready) is waited out and read
again rather than ending the copy short. A blocking source does not answer
None, so its reads are unchanged.

Left, by the wave's overlap rule (open PR 3202 edits these functions):
the copy loops in _extract_member and _restore_blocking (plaintext branch).

Tests: tests/test_dr_backup_none_read.py.
BACKLOG #6687, review round 1 (round-70fc7350). _read_chunks waited out a
None read with no limit, so a stalled non-blocking source would hold the
worker thread. It now raises TimeoutError (an OSError) once None has been
the only answer for _NO_DATA_YET_LIMIT_SECONDS (30 s); a byte arriving
restarts that limit. Tests pin the sleep per None read, the refusal, and
the restart. The test module's docstring no longer reads as if every copy
loop moved to the helper: two remain, left by the overlap rule.

Corrects the previous commit body: item 8 (one fill loop shared with the
codec, sandbox.py and dicom.py) is not met by this branch.
…ck in its tests

BACKLOG #6687, review round 2 (round-89eaf180). The _read_chunks
docstring now says the limit bounds one unbroken run of None reads, not
the whole copy. _HashingReader.read is annotated bytes | None, the None
pass-through engine PR 3033 built. The tests drive the wait and the limit
through a fake clock patched onto dr_backup's own time name, so nothing
sleeps or races a real clock, and drop a check that could not fail. The
test module's docstring names at least four reads this branch leaves.

Proposed PR title: DR backup: copy loops wait out a None read instead of
ending the copy short (BACKLOG #6687)
Proposed banner, #6687: PARTIAL. Item 1: the no-key build, plaintext
verify and config-restore copy loops share _read_chunks (None waited
out, refused after 30 s with no byte), tests/test_dr_backup_none_read.py.
Items 2, 3, 4, 5, 6, 7, 9 and 10 met on main (evidence in the PR body).
Left: item 1 at _extract_member and the _restore_blocking plaintext
branch (open PR 3202 edits both functions); item 8, one fill loop shared
with the codec, sandbox.py and dicom.py (design).
BACKLOG #6687. Text only, from review round-84ccc3f4 (the unrepaired
round): one docstring line ran to 195 columns. No code changes.

Proposed PR title: DR backup: copy loops wait out a None read instead of
ending the copy short (BACKLOG #6687)
Proposed banner, #6687: PARTIAL. Item 1: the no-key build, plaintext
verify and config-restore copy loops share _read_chunks (None waited
out, refused after 30 s with no byte), tests/test_dr_backup_none_read.py.
Items 2, 3, 4, 5, 6, 7, 9 and 10 met on main (evidence in the PR body).
Left: item 1 at _extract_member and the _restore_blocking plaintext
branch (open PR 3202 edits both functions); item 8, one fill loop shared
with the codec, sandbox.py and dicom.py (design).
BACKLOG #6687, per the Manager's decision under the owner's instruction
of 2026-11-23. _read_chunks now reads through backup_codec._read_once,
so the no-key build, plaintext verify and config-restore copies refuse
a None read (and a non-bytes or over-long read) with the codec's
BackupCodecError, the same rule as the keyed branch. The 30 s wait, its
restart logic and their tests are gone. _restore_config_members now
names a BackupCodecError as a restore refusal, as it does an OSError.
The comment on _MAX_RESTORE_PLAINTEXT_BYTES no longer says the plaintext
verify copy is bounded by the archive's size: that limb has no byte cap
of its own.

Proposed PR title: DR backup: copy loops refuse a None read instead of
ending the copy short (BACKLOG #6687)
Proposed banner, #6687: PARTIAL. Item 1: the no-key build, plaintext
verify and config-restore copy loops share _read_chunks, which refuses
a None read through the codec's _read_once;
tests/test_dr_backup_none_read.py. Items 2, 3, 4, 5, 6, 7, 9 and 10 met
on main. Left: item 1 at _extract_member and the _restore_blocking
plaintext branch (open PR 3202 edits both functions); item 8, one fill
loop shared with the codec, sandbox.py and dicom.py (design).
…elog

BACKLOG #6687. Text only, from review round-69bdc37c. The _read_chunks
docstring says it shares only the codec's per-read checks: it
authenticates nothing and caps no total. The plaintext-verify comment no
longer gives a false reason for that limb's missing cap. Adds a changelog
fragment, including the codec wording an operator sees on a no-key box.
No code changes.
… one

BACKLOG #6687, per the Manager's decision under the owner's instruction
of 2026-11-23. _read_chunks raises the codec's refusal as an OSError
(EIO), with the BackupCodecError chained, so each site reports it the
way it already reports a read failure there: kind write at the build
(it read encrypt), a verify FAIL worded without "decrypt failed", and a
restore refusal through _restore_config_members' existing OSError arm.
That function is back to main's text. A refused build leaves its .part
exactly as main does for any OSError in that copy. The tests now assert
the failure kind, and that the refused config file is on the rollback
ledger. The changelog fragment drops the codec-wording sentence.

Proposed PR title: DR backup: copy loops refuse a None read instead of
ending the copy short (BACKLOG #6687)
BACKLOG #6687. Text only, from review round-c02119ea. The _read_chunks
docstring, the test prose and the changelog no longer say the sites
record a read failure: each handles the refusal as it handles any
OSError from that copy, which its own except arms define. "All this
shares with the keyed copies" becomes "at least". No code changes.
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 24, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander: enqueuing at pinned head 380b8d8. Its five QA rounds (exit 0) cover the code; the commits after the last round are docstring, comment and changelog only. All required contexts are green. QA findings 1-3 and 6-7 are ORDINARY and 4, 5 and 8 are MAIN; all are queued for filing under R2.

@wshallwshall
wshallwshall added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit c118ad1 Nov 24, 2026
64 checks passed
@wshallwshall
wshallwshall deleted the w12-6687 branch November 24, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant