Repository navigation
pool: honor CleanOnFinish - #249
Merged
Merged
Conversation
The pool hides finished CleanOnFinish bars and erases their lines when the frame shrinks. Hidden bars stay in the pool, so a restarted bar shows up again; the height clamp and the finished check only count visible bars. Pool.Add stops the own writer of an already started bar and wipes its line, so a pb.StartNew bar no longer writes into the pool's frame. The bar's finish channel carries whether the writer draws the final state or wipes, and each writer owns its ticker, so Start and Finish racing Add can't share state with a dying writer. Add detaches bars before taking the pool lock. An empty frame doesn't move the cursor. Fixes #223 Claude-Session: https://claude.ai/code/session_01Bju1BfF4mCjLwfxG8Zm92u
cheggaaa
force-pushed
the
fix-pool-clean-on-finish
branch
from
September 21, 2026 15:28
5783a42 to
7a09106
Compare
Pool.Add stops a started bar's writer. A Start or Finish racing it saw no writer and ran while the writer was still drawing: Start reset the render state under it, Finish returned before the last write. A mutex makes the three take turns on the handshake, and the bar stays IsStarted until its writer is gone.
The bar stays IsStarted until its writer acks, so Start already returns early while Finish or stopWriter waits on the handshake. Holding the lock there only blocks Start during a Finish, which then restarts the bar instead of staying a no-op, and deadlocks a Start issued from the bar's own output writer.
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A pool renders every bar on every frame, so a finished
CleanOnFinishbar stays on screen. A bar started beforePool.Add(pb.StartNew) also keeps its own writer and prints into the pool's frame.CleanOnFinishbars and erases their lines when the frame shrinks (\r\033[Jon unix, blank lines plus cursor rollback on windows). Hidden bars stay in the pool, so a bar that isFinished andStarted again shows up again. The terminal-height clamp skips hidden bars, so they don't take rows from live ones; the finished check counts every bar that isn't hidden, including bars clipped by the terminal height.Pool.Addstops the own writer of an already started bar and wipes its line; the bar is no longerIsStarted(), and its start time and speed stats are kept. The bar's finish channel now carries whether the writer draws the final state (Finish) or wipes the line (Add), each writer owns its ticker,FinishandAddtake turns on the writer handshake, and the bar staysIsStarted()until its writer is gone, so a racingStartsees a running bar and does nothing while the writer is still drawing.Adddetaches bars before taking the pool lock, so a bar blocked on its output can't stall the pool.\033[0A, which terminals treat as one line up.render(first, rows, cols), which the tests drive with a fixed terminal size.Behavior change:
IsStarted()reportsfalsefor a started bar once it is added to a pool, and such a bar'sFinish()writes nothing on its own; the pool draws its final state.Verified with the repro from #223 in a 100x24 terminal: only the root bar remains, output printed before the pool is intact when every bar is cleaned, and a started bar that finishes before the pool's next frame leaves no orphan line. The windows printer is compile-checked only.
Fixes #223
🤖 Generated with Claude Code
https://claude.ai/code/session_01Bju1BfF4mCjLwfxG8Zm92u