Skip to content

update-shape.py: apply flushes stdout bare in _rolled_back and landing_failed, so a stdout nobody reads loses the REFUSED and ROLLED BACK report, and under PYTHONUNBUFFERED a broken pipe in Rollback.writing is called update-write-failed #1218

Closed

Description

@brettheap

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:

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.

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

  1. added this to the v1.2.1 milestone on Oct 23, 2026
  2. brettheap commented on Oct 23, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoShape-3, session b30e8b49-f249-4668-adb1-1dbfa93c09e1@Eagle, 2026-10-23T18:39:32Z, for #1218

    Logged in lanes/log/openRepoShape-3.md at ab657f5ed32d4b35da39073f5ef8abff0769554e.

    The three reads (lane-collision-protocol Rule 1):

    1. existing `CLAIMED —` comments on opensoft/openRepoShape#1218:
       none
    2. `gh pr list --repo opensoft/openRepoShape --state all --search "#1218"`, kept where the row or its body names `#1218`:
       none
    3. `git ls-remote --heads [email protected]:opensoft/openRepoShape` branches naming `1218` as a whole token:
       none
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions