Skip to content

Fix relabelling, triple flush and lost text regressions from 4.7.0 - #336

Merged
wolph merged 3 commits into
developfrom
fix/stream-multibar-regressions
Nov 16, 2026
Merged

wolph merged 3 commits into
developfrom
fix/stream-multibar-regressions

Conversation

@wolph

@wolph wolph commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Three behaviours that 4.7.0 changed against 4.6.0 without a changelog line. Each one was found by running the public API of both releases side by side:

behaviour 4.6.0 4.7.0 this PR
MultiBar: pop or clear a bar, then add it again 1 label 2 labels 1 label
target.flush() calls for one start_capturing + stop_capturing 1 3 1
the same, with an update_capturing override that calls super() 1 3 2
a WrappingIO.flush() override raises once: captured text kept lost kept

What changed

MultiBar labels leave with the bar. _label_bar records the label objects it inserts, and _forget_bar (pop, del, clear, a replacement, remove_finished) removes exactly those objects from bar.widgets, matched by identity, so a label of the bar's own that renders the same text stays. The prefix is searched from the front and the suffix from the back, because '{label}'.format() returns the key object itself and the bar may hold that same string as a widget of its own. A bar that is removed while its labels are being formatted ends up unlabelled. 4.6.0 only avoided the double label on pop by accident: pop did not forget the bar at all, del did and labelled twice too.

One flush when capturing stops. stop_capturing() no longer drains and delivers itself when update_capturing is the default hook: the hook drains and delivers through flush(), as it did in 4.6.0. A replaced hook, which may not call super(), still gets the stop's own delivery first, so the error chaining and the hook order pinned by the existing tests are unchanged. When such a hook does call super(), the original stream is flushed twice, the second time on an empty buffer. Getting that to one flush would cost either the delivery 4.7.0 guarantees to a hook without super(), or the public flush() call that a flush() override saw on the last stop in 4.6.0. Flag propagation is split out of _apply_capturing into _propagate_capturing, with the private signatures left as they were.

A failing flush() costs no text. WrappingIO._deliver calls the public flush() after the buffer was drained. When that call raises, the taken text now goes back in front of anything written since, and the next flush delivers it in order. A failed target.write() still drops its text, so a retry cannot write it twice.

Verification

The test and lint results come from this tree, rebased on develop at 12f734a. The benchmark numbers were measured on the first version of this PR (9e1fa2d). The commit added since only changes which end a label is removed from when a bar leaves, a path none of the benchmarks runs.

  • pytest with coverage: Python 3.10 and 3.14t, both 100 percent (see the CI runs for the full matrix).
  • ruff check and format, pyright on Linux and Windows, codespell, sphinx-build -W: clean.
  • The 4.6.0 test files against this tree: the same three colour-default failures as 4.7.0, nothing new.
  • README benchmarks interleaved with 4.7.0 (min of two rounds each):
metric 4.7.0 this PR
A iterator overhead, plain (ns/iter) 26.10 27.32
A iterator overhead, fast (ns/iter) 3.51 3.44
B forced redraw, plain (us) 17.98 18.01
B forced redraw, FastProgressBar (us) 4.89 4.89
FormatLabel render (us) 1.23 1.25
Timer widget (us) 0.99 1.01
captured write (us) 0.12 0.13
C import, plain (ms) 3.55 3.54
C import, fast (ms) 3.49 3.48

The iterator paths are untouched by this change and the two rounds disagree on the direction there, so that spread is run-to-run noise.

  • Stream micro benchmarks against 4.7.0: captured write, flush, start plus stop capturing and a MultiBar render of three bars are at parity, a wrap plus capture plus unwrap cycle went from 4.5 to 3.8 us.

The compatibility script of the release skill could not run (its scripts directory is gone from ~/.claude/skills), so the compatibility result above rests on the 4.6.0 test files, 4.7.0's own test suite and the probes.

Where this comes from

A Codex session (29 Oct to 3 Nov) left an 8700-line uncommitted rewrite of the stream wrapper and MultiBar in the main checkout, pinned to these three regressions among 395 failing asserts, most of them bound to private names and hostile subclasses. That rewrite made start_capturing plus stop_capturing 27 times slower and MultiBar.render twice as slow, so it was declined as a whole. The three regressions it was right about are fixed here in 105 added lines of code.

A bar that leaves a MultiBar takes its generated label widgets with it, so adding it again labels it once. The stop_capturing() that brings the count to zero flushes the original stream once, as in 4.6.0. A WrappingIO.flush() replacement that raises no longer costs the captured text.
`'{label}'.format()` returns the key object itself, so a bar that holds
the same string as a widget of its own carries the label object more
than once. The forward search then removed the bar's own widget when
the label was appended, and the widgets changed order. The prefix is
now searched from the front and the suffix from the back.

A replaced `update_capturing()` hook that calls `super()` flushes the
original stream twice on the last stop. That is pinned by a test and
stated in the changelog.
@wolph
wolph force-pushed the fix/stream-multibar-regressions branch from 9e1fa2d to 1b21ef8 Compare November 16, 2026 12:31
@wolph
wolph merged commit 212b912 into develop Nov 16, 2026
19 checks passed
@wolph
wolph deleted the fix/stream-multibar-regressions branch November 16, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant