Repository navigation
Description
Goal: apply reports its failure on stderr whatever stdout is, so a stdout whose reader has gone away no longer costs the REFUSED and ROLLED BACK report, nor the account of a commit that stands, and a broken pipe on a progress line is never reported as a failed write of a copy.
Filed by lane openRepoShape-3, from RV1187's independent review of #1187 (#1173) at 7a9d397b (#1187 issuecomment-6354202129), its out-of-scope find, and the delta review at cc8a87ee (#1187 issuecomment-6354349484), which records the follow-up as still open. It did not hold the landing: both reviews are READY, and #1187 is open at cc8a87ee, next in lane 3's v1.2.1 landing chain. Line numbers are main's at ef619c74. #1187 adds _roll_back_before_raising above these functions, so at its head the first two flushes are at :5236 and :5324, as RV1187 wrote them; Rollback.writing is the same code at both (:3178, only its docstring differs). The defect is on main now, and #1187 does not change it.
Two flushes that raise over the report
State. _rolled_back (update-shape.py:5210) calls sys.stdout.flush() at :5232, once ledger.undo() has put the tree back and before it raises the refusal with the list under its detail, or prints the failed command and the list (:5233-5241). landing_failed (:5259) calls sys.stdout.flush() at :5290, before its two stderr prints (:5291, :5299) and its NEXT line (:5311). Both flushes are bare. Two guarded models exist:
adopt-project.py's_flush_stdout(:12976, acontextlib.suppress(OSError)around the flush), with its rowtest_a_closed_stdout_does_not_swallow_the_report(tests/test_adopt_late_failure.py:1110), which uses aClosedPipewhoseflushraisesBrokenPipeError(:153);- update-shape.py:
applyputs every byte back under anyOSErrorafter its first write, says what it put back on stderr, and raises the error as it was, so a file gone between itsstatand its read, a broken pipe or anEIOno longer leaves the tree half-written behind a traceback (#1173) #1187's own_roll_back_before_raising(update-shape.py:5249at its head, its flush guarded at:5275).
What happens. RV1187's probe (a local --upstream, a stub gh, no network; the comment states neither a Python version nor a uid) confirmed it "at main and at the head": with a read-only pin (update-write-failed) and stdout a closed pipe, the tree is restored, then the flush in _rolled_back raises, the exit is 120, and REFUSED and ROLLED BACK never reach stderr. For landing_failed, RV1187 says by reading that the same failure after the commit loses the refusal and the NEXT line. Read from the code, the raise skips both stderr prints; NEXT itself is a stdout print, so a closed pipe has nowhere to take it whatever is done, and what a guard saves is the stderr report that the step failed and that the commit stands with nothing rolled back. That part was not run.
A broken pipe on a progress line is called a failed write
State. Rollback.writing (update-shape.py:3178) wraps its block in try: yield (:3197-3198) and turns any OSError out of it into Refusal("update-write-failed", ...) (:3199-3208). cmd_apply runs _write_copies inside it (:5171), and _write_copies prints each copied <path> line there (:4899).
What happens. RV1187, measured at #1187's head: under PYTHONUNBUFFERED=1, a stdout broken pipe on the copied print is reported as REFUSED update-write-failed: writing the copies and the --add files failed: Broken pipe. The refusal blames the write of a copy for an error that came from stdout. By reading, the arm that answers a Refusal then rolls the tree back. It was not run at main; the code of writing and of that print is the same there.
Direction.
-
_rolled_backandlanding_failed: guard the stdout flush as the two models above do, so the report reaches stderr. The unflushed bytes stay buffered, and the interpreter retries the flush at exit and reports it, with exit 120 (RV1187, of update-shape.py:applyputs every byte back under anyOSErrorafter its first write, says what it put back on stderr, and raises the error as it was, so a file gone between itsstatand its read, a broken pipe or anEIOno longer leaves the tree half-written behind a traceback (#1173) #1187's guarded flush). -
Rollback.writing: aBrokenPipeErrorout of the block is not a failed write, so it should reach the arm that answers anOSErroras itself. Only once update-shape.py:applyputs every byte back under anyOSErrorafter its first write, says what it put back on stderr, and raises the error as it was, so a file gone between itsstatand its read, a broken pipe or anEIOno longer leaves the tree half-written behind a traceback (#1173) #1187 has landed, or on its branch. At maincmd_apply'sexcept OSErrorarm (:5197-5204) raises anyOSErrorthat is not an unreadable read as it was, with no rollback, so letting the pipe error through at main would leave the copies written. After update-shape.py:applyputs every byte back under anyOSErrorafter its first write, says what it put back on stderr, and raises the error as it was, so a file gone between itsstatand its read, a broken pipe or anEIOno longer leaves the tree half-written behind a traceback (#1173) #1187, that arm rolls back and raises (_roll_back_before_raising), which is the answer wanted. -
No command and no flag.
-
Tests: the pipe row update-shape.py:
applyputs every byte back under anyOSErrorafter its first write, says what it put back on stderr, and raises the error as it was, so a file gone between itsstatand its read, a broken pipe or anEIOno longer leaves the tree half-written behind a traceback (#1173) #1187 adds,test_a_stdout_nobody_reads_is_rolled_back_under_its_broken_pipe(tests/test_update_shape_unreadable.py:700at its head), runs the real tool with a closed pipe as stdout and blanksPYTHONUNBUFFERED; the new rows go beside it. Thelanding_failedrow goes intests/test_update_shape_messages.pybesidetest_the_bare_form_a_failed_push_prints_carries_the_words_too(:428), with a stdout whoseflushraises, as in the adopt row above. -
applyover a read-only pin with stdout a closed pipe: the tree is as it was, and stderr holds the REFUSED line and the ROLLED BACK list. It fails before and passes after. -
A step after the commit that fails (a refused push) with a stdout whose
flushraises: stderr holds the failed step and the sentence that the commit stands and nothing was rolled back. -
PYTHONUNBUFFERED=1and a closed pipe at thecopiedprint: the stderr is notupdate-write-failed, and the tree is as it was (after update-shape.py:applyputs every byte back under anyOSErrorafter its first write, says what it put back on stderr, and raises the error as it was, so a file gone between itsstatand its read, a broken pipe or anEIOno longer leaves the tree half-written behind a traceback (#1173) #1187 has landed). -
A run with a readable stdout prints byte for byte as before.
-
One mutant, the bare flush back in
_rolled_backand inlanding_failed, fails a row each; each mutant run is restored and checked withcmp.
Related: #1187, #1173 (the issue #1187 is for: apply rolls back an OSError after its first write), and #458 (the tracker for update-shape.py and bump-leg.py, keeping a project's shape copies and leg pins current).
Size: M.
Lane: openreposhape-3 (openRepoShape-3)
Activity
brettheap commentedon Oct 23, 2026
CLAIMED — lane openRepoShape-3, session b30e8b49-f249-4668-adb1-1dbfa93c09e1@Eagle, 2026-10-23T18:39:32Z, for #1218
Logged in
lanes/log/openRepoShape-3.mdatab657f5ed32d4b35da39073f5ef8abff0769554e.The three reads (lane-collision-protocol Rule 1):