← Back to Pull requests

refactor(tui): one render path for text and image plots #328

Closed
unknown closed this pull request without merging on Nov 21, 2026 01:52 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 22:12 UTC
Author

:robot: _AI text below_ :robot:

Items 19, 9, part of 12, and App._exit from 23 of the review issue.

  • Plotext and MPLPlot subclass one frozen PlotItem dataclass with the shared fields and with_* methods. The caches have compare=False and copies share them. The item compares by value, so "already rendered" is item == self._rendered and the key tuples are gone. The size goes into a copy of the item (dataclasses.replace), which the handler puts in view_widget.item without the watcher.

  • One RequestRender message, one on_request_render handler, one threaded exclusive render_item worker. The worker catches the errors and posts RenderFailed(source, error, render_id). on_render_failed branches on the error type and keeps the stale-report drop and the failed-expression retry guard. The item does not hold app now, and run_posting_errors, EmptyMessage, ErrorMessage, ExpressionErrorMessage, RequestPlot and RequestImage are removed.

  • _render_failed uses the public return_code is not None instead of _exit. exit() sets both.

  • Item 9: render_canvas and MPLPlot.render build the histogram outside _PLOTEXT_LOCK and RENDER_LOCK. Only the draw holds a lock. The worker installs progress.cancel_when(...), so a progress report in a cancelled worker raises progress.CancelledError (a BaseException, like asyncio.CancelledError) and the chunked read stops. The worker ignores this exception. New tests check both modes with a slow fake read.

  • The image path does not put warnings.catch_warnings around the histogram build now. The filters are global for the process, so the build can only change them while it holds the lock. The text path did not suppress these warnings before this change, and the tests run with filterwarnings = error.

  • ViewWidget handles the Plot button and the entry box with @on (Button.Pressed, Input.Submitted, Input.Changed). PlotButton is removed, and PlotInput keeps only its binding.

  • A render failure report and the failed-expression guard compare to the current item by value. Before, a second selection of the same plot made an equal item that was not rendered again, and the report of the first item was dropped, so no error showed. A new test holds the worker to make this sequence certain.

  • Each started render gets a render ID, and on_render_failed drops a report with an old ID. Thus after A → B → A, the error of the cancelled first A render does not replace the new plot. An equal selection uses the running render and keeps its ID, so A → A still shows the error.

  • The text plot pane (PlotCanvas) posts Resized, and ViewWidget renders again (debounced). Before, the plot did not render in the smaller pane when the request after the entry box toggle came before the layout (a CI failure of test_entry_box_rerenders_plot).

  • The dead dev block at the end of browser.py and the __package__ workaround are removed.
  • The tests that kept a reference to an item and then read its size now read the item from the view again.

    Refs #322

    Diff: 384 lines (+288 / -96) across 4 files Reviewer: henryiii Review duration: 219m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 384 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.356
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #328"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43% (MEDIUM) · Higher = larger blast radius
    43%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.0% · Safe to merge
    17.0%