Skip to content

Fix DM black-screen paint crash (HistoryFragment.retain_painted), 17.9x sticky-header threshold, and hoist 7 shared-frontend patterns - #2327

Merged
trissim merged 1 commit into
mainfrom
refactor/hoist-shared-frontend-parallel-patterns
Nov 27, 2026
Merged

trissim merged 1 commit into
mainfrom
refactor/hoist-shared-frontend-parallel-patterns

Conversation

@trissim

@trissim trissim commented Nov 27, 2026

Copy link
Copy Markdown

Summary

1. Fix DM / thread view solid-black render crash (HistoryFragment.retain_painted + QPainter.end())

  • Commit 6358df80a moved ReadMarkedHistory.retain_painted onto EvidencedFragment based on its narrowed parameter annotation, even though QtHistoryWindow.row_painted passes every painted HistoryFragment (tool calls, thinking blocks, context summaries, live turns). The first QtToolTranscriptFragment or QtThinkingTranscriptFragment raised AttributeError inside VirtualRowCanvas.paintEvent, leaking an active QPainter (QBackingStore::endPaint() called with active painter) and leaving the entire DM viewport solid black.
  • Added no-op HistoryFragment.retain_painted(self, owner) in src/toad/client/fragments.py (overridden by EvidencedFragment.retain_painted), widened ReadMarkedHistory.retain_painted parameter annotation to HistoryFragment, and wrapped VirtualRowCanvas.paintEvent in try: ... finally: painter.end().
  • Verified offscreen on live toad-qt DM at 412x915 (QtMailboxView, 160 rows, zero tracebacks, full tool/thinking transcript painted cleanly) and added regression test test_every_history_fragment_subclass_supports_retain_painted.

2. Qt scroll performance: HistoryRowDelegate.header_pin_threshold (17.9x wall-clock speedup)

  • Every BusMessageFragment has leading == (Gap(), Divider) (header_blocks == 2), and sticky_header(block, row) pins iff (block, row) > (header_blocks - 1, 0), i.e. y >= sum(height(blocks[0..k-2])) + line. Measuring the Divider via QTextDocument.setHtml + size() in block_row was mathematically redundant — only the single globally cached Gap() block ever needs measuring.
  • Alternating unprofiled wall-clock benchmark (40 BusMessage fragments x 5 y offsets, 1 warm-up + 5 alternating runs, 100% parity with block_row + sticky_header):
    • Before (block_row): median 20.42 ms ([17.95, 20.42, 22.49, 19.80, 24.98]), 81 QTextDocuments built
    • After (header_pin_threshold): median 1.14 ms ([1.03, 0.95, 1.14, 1.17, 1.20]), 1 QTextDocument built (17.9x speedup)
  • Live #comms 412x915 cProfile: repin_header/top_message_header/pinned_header/block_row dropped from 29 ms (top 35) to vanished from top 35 (<3 ms).
  • Decoupled arrival/follow notification refresh (AnimatesArrivals.refresh_visible_notifications -> SavedHistory.check_visible_notifications / SourceNotifications.check_visible_notifications) so arrival glides refresh receipts without re-arming source page reads.

3. Factor out 7 NRA-flagged shared-frontend parallel patterns (zero slop, REL_IMPORTS=0)

  • AnimatesArrivals.animated_travel & shift_travel (src/toad/arrivals.py, qt/history.py, widgets/history_anchor.py)
  • ModelSelectionCore.filter_models, search_changed, note_highlight_moved, submit (client/model_selection.py, qt/model_selection.py, widgets/model_selection.py)
  • WireView(ConversationActivity, ComposerPoolHost) owning composer_placeholder & show_mention_candidates once (client/history.py, qt/window.py, widgets/comms_chat.py)
  • RebindableComposer.rebind_conversation (client/composer_pool.py, qt/composer.py, widgets/prompt.py)
  • SubmissionView.refresh_composer over can_refresh_composer & apply_compose_access (client/bus_submission.py, delivery_failure_view.py, qt/submission_view.py)
  • OpensExpandedItem(SidebarItem) in src/toad/qt/window.py
  • RawTextPart & BodyTextPart in src/toad/client/structured_context.py

4. Test & tool fixes met on the path

  • Fixed tests/textual/test_worker_failed_toasts.py stub (retire_core, observe_core_callback, events).
  • Fixed tests/textual/test_channel_scrolling.py:210 race waiting for history.state.accepts_source_work after 4 pageups before asserting scroll stability.
  • Fixed tools/qt_scroll_profile.py processEvents(ExcludeSocketNotifiers) to avoid re-entering qasync socket notifiers.

Verification

  • REL_IMPORTS=0
  • tools/qt_inherit_ratchet.py: 0/0/0/0/0
  • tools/shadow_check.py: 0
  • tools/guarded_imports.py: 0
  • Focused pytest suite: 115 passed across 8 test files (including all 8 tests in tests/textual/test_channel_scrolling.py and the new header_pin_threshold & retain_painted tests).

…speedup, and hoist 7 shared-frontend parallel patterns
@trissim
trissim merged commit 4725892 into main Nov 27, 2026
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