Skip to content

[CTX-1791] fix(runtime,render,platform): resolve Hyprland workspace switch freeze and SwashSingle font RSS (#3116) - #3118

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1791/fix-hyprland-freeze-and-font-rss
Nov 10, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1791/fix-hyprland-freeze-and-font-rss

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Priority: P0 | Area: runtime, render, platform | Labels: fix, P0, area:runtime, area:render, area:platform | Milestone: v0.1.0 | RFC: OQ-none | Task: CTX-1791

Closes #3116

Summary

  1. Wayland Frame Callback & Hyprland Workspace Switch Freeze:
    • Move pre_present_notify() out of TerminalApp::drive_tick and into Surface::present / Surface::present_draw_list_color_classified immediately before frame.present() so ticks that defer or skip presenting never leave winit in FrameCallbackState::Requested without a wl_surface.commit.
    • In vendored winit: preserve FrameCallbackState::Received in request_frame_callback(), reset frame_callback_state when resuming from XdgWindowState::SUSPENDED, and suppress RedrawRequested while window.is_suspended().
    • Keep Runtime.speculative_present_reopen open across swapchain driver commits until compositor confirmation (note_present_confirmed) or explicit reveal, hold back additional frames while the single blind-repair frame awaits confirmation, and call restore_hidden_after_blind_repair when unconfirmed.
  2. SwashSingle Font Heap RSS Optimization:
    • Deduplicate Source::File font byte allocations (Arc<Vec<u8>>) across SwashSingle instances via process-wide weak cache SHARED_FONT_FILES.
    • Reuse a single scratch probe_buf: Vec<u8> across uncached file candidates during SwashSingle::scan_dynamic_face and promote only the matching face into Arc<Vec<u8>>.
  3. PR [CTX-1788] fix(terminal,runtime): close PR #3109 review residuals #3113 (PX-8623) Review Follow-ups:
    • Clear entry.failure_class on PluginRuntime::rollback, rewrite plugin body before recover_wall_failed_plugins() in plugin_timers, derive help_width coverage from cli::SUBCOMMANDS, and restore scratch-paths-exempt markers in component.rs.

@Xuepoo Xuepoo added this to the v0.1.0 milestone Nov 10, 2026
@Xuepoo Xuepoo added fix Bug fix P0 Priority: highest area:platform Area: platform / windowing area:render Area: rendering area:runtime Area: runtime orchestration labels Nov 10, 2026
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c9e2e149-6556-488a-87c6-34d4d91a2ca8
Commits

Reviewing files that changed from the base of the PR and between 0acc9a9 and f9e6df2.

Files selected for processing: 22

  • crates/bitty-platform/src/surface.rs
  • crates/bitty-render/src/gpu.rs
  • crates/bitty-render/src/shaped.rs
  • crates/bitty-runtime/src/plugin_runtime/mod.rs
  • crates/bitty-runtime/src/runtime/present.rs
  • crates/bitty-runtime/tests/plugin_timers.rs
  • crates/bitty-terminal/src/cli.rs
  • crates/bitty-terminal/src/completion.rs
  • crates/bitty-terminal/src/component.rs
  • crates/bitty-terminal/src/config_cli.rs
  • crates/bitty-terminal/src/doctor.rs
  • crates/bitty-terminal/src/help_width.rs
  • crates/bitty-terminal/src/list.rs
  • crates/bitty-terminal/src/shell_init.rs
  • crates/bitty-terminal/src/terminal_app.rs
  • crates/bitty-terminal/src/upgrade.rs
  • crates/bitty-terminal/src/x.rs
  • vendor/winit/PATCHES.md
  • vendor/winit/patches/0003-wayland-dispatch-pending-on-shared-display.diff
  • vendor/winit/src/platform_impl/linux/wayland/event_loop/mod.rs
  • vendor/winit/src/platform_impl/linux/wayland/state.rs
  • vendor/winit/src/platform_impl/linux/wayland/window/state.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…witch freeze and SwashSingle font RSS (#3116)

- Move pre_present_notify() into Surface::present* right before frame.present() so deferred/skipped ticks never leave winit in FrameCallbackState::Requested without a wl_surface.commit.
- Keep FrameCallbackState::Received intact across request_frame_callback(), reset frame_callback_state on resume from XdgWindowState::SUSPENDED, and suppress RedrawRequested while suspended in vendored winit.
- Keep speculative_present_reopen open across driver commits into free swapchain slots until compositor confirmation, hold back extra frames while awaiting confirmation, and close the visibility gate back when unconfirmed.
- Share Source::File font buffers across SwashSingle instances via SHARED_FONT_FILES and reuse a single scratch probe_buf during scan_dynamic_face().
- Land PR #3113 (PX-8623) review follow-ups and restore component.rs scratch-paths-exempt markers.

Priority: P0 | Area: runtime, render, platform | Labels: fix, P0, area:runtime, area:render, area:platform | Milestone: v0.1.0 | RFC: OQ-none | Task: CTX-1791

Closes #3116
@Xuepoo
Xuepoo force-pushed the ctx-1791/fix-hyprland-freeze-and-font-rss branch 3 times, most recently from 10a7104 to f9e6df2 Compare November 10, 2026 16:13
@Xuepoo

Xuepoo commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review by ctx-1791-reviewer (CarryCtx PX-8626, session 01M732RM4C6BFQ2X2VJ8DPNR75), head f9e6df2:

VERDICT: APPROVE

  1. Wayland Frame Callback & Suspended Workspace Handling:
    • pre_present_notify() moved out of TerminalApp::drive_tick into Surface::present and Surface::present_draw_list_color_classified immediately prior to frame.present().
    • Vendored winit preserves FrameCallbackState::Received in request_frame_callback(), resets frame_callback_state on resume from XdgWindowState::SUSPENDED, and suppresses RedrawRequested while suspended.
  2. Speculative Blind-Repair Gate Lifecycle:
    • speculative_present_reopen remains open across swapchain driver commits until compositor confirmation (note_present_confirmed) or explicit reveal, holds back additional frames while awaiting confirmation, and calls restore_hidden_after_blind_repair when unconfirmed.
  3. SwashSingle Font Buffer Deduplication & Scratch Reuse:
    • Cross-instance weak cache SHARED_FONT_FILES deduplicates Arc<Vec<u8>> allocations across SwashSingle instances, and scan_dynamic_face reuses a single probe_buf across uncached candidates.
  4. PR #3113 (PX-8623) review follow-ups and component.rs scratch-paths-exempt markers verified.

@Xuepoo
Xuepoo merged commit 53c58b4 into main Nov 10, 2026
23 of 24 checks passed
@Xuepoo
Xuepoo deleted the ctx-1791/fix-hyprland-freeze-and-font-rss branch November 10, 2026 16:55

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review — PR #3118 (CTX-1791)

Reviewer: independent third-party review (Hermes Agent subagent, Nous Research) — not the PR author, not the lane owner.
Model: deepseek-v4.1-flash · Date: 2026-11-11 (CST)
Head reviewed: f9e6df2f · Base: main 0acc9a9a · 22 files, +856/−154

Method. The lane worktree was treated as read-only (git status clean, no writes). Every
mutation/discrimination proof ran in a byte-identical copy at
$HOME/.hermes/cache/scratch/r3118-proof with its own CARGO_TARGET_DIR; origin/main was
built separately from git archive origin/main so rendered help could be diffed binary-to-binary
(.target/debug/bitty, 20 surfaces). CI on this head is fully green (gh pr checks 3118:
Linux Wayland 14m34s, Linux X11 20m6s, Windows 35m12s, macOS ARM64 22m5s, MSRV 1m22s,
Quality gates ×2, AUR, CodeQL, supply chain).


1. Help gate still enumerates from crate::cli::SUBCOMMANDS and fails closed — PASS

  • Table: crates/bitty-terminal/src/cli.rs:2817 (SUBCOMMANDS, 18 entries).
  • Gate derives coverage: crates/bitty-terminal/src/help_width.rs:129 → sources() maps every
    table entry through surface() (help_width.rs:93) and panics on an unregistered name
    (help_width.rs:134). Alias resolution is asserted too (help_width.rs:151-173), including the
    parser-only component → extension alias.
  • Discrimination proof: in the scratch copy I appended ("frobnicate", &[]) to SUBCOMMANDS
    and ran cargo test -p bitty-terminal --bin bitty help_width:
    test result: FAILED. 2 passed; 4 failed
    panicked at crates/bitty-terminal/src/help_width.rs:134:17:
    help_width: no rendered help surface registered for `bitty frobnicate`
    
    Red in 4 tests (every_subcommand_help_surface_is_covered,
    every_help_tier_fits_the_documented_width, verbose_tier_differs_and_carries_the_contract,
    each_contract_tier_states_its_own_boundary). Probe reverted; tree byte-identical to head again.
  • On the unmodified head: cargo test -p bitty-terminal help_width --offline → 6 passed, 0 failed
    (help_width::*, 1521 filtered out, 0.04s).

2. The five residual risks on THIS head — all non-blocking

# Risk Present? Class
1 HELP_WRAP_COLUMNS (96) equals/outside HELP_MAX_COLUMNS (100) No — fixed. cli.rs:2886 = 96, help_width.rs:30 = 100, and help_width.rs:35-38 is a const assert HELP_WRAP_COLUMNS <= HELP_MAX_COLUMNS that fails compilation if it regresses. resolved
2 push_wrapped_line collapses internal space runs; shell-init nushell row loses alignment No. The nushell row is hand-wrapped, not passed through the helper (shell_init.rs:475-495), and the continuation (then \source` it from config.nu)starts at column 15 — the same value column as bash: . Both helper callers pass single-spaced input (cli.rs:2962, x.rs:322), so split_whitespace` is lossless in practice. cosmetic
3 No post-wrap re-check of indent+word → an 81-col token under a 20-space indent renders 101 cols Narrower form only. Tokens are hard-split to max - width (cli.rs:2923-2937), so no token escapes. But the head prefix is never measured: a legal 121-char plugin id (validate_plugin_id allows 2×64 [a-z0-9_-], bitty-plugin-host/src/manifest.rs:40,134-191) renders 135 columns at x.rs:317-328 and hard-splits the first command one character per line (probe test in scratch copy: over_wide=[(12, 135)]). Pre-existing on main (no wrapping at all there), so not a regression. cosmetic (edge)
4 Gate maps help→help_help_text() and x→bundled catalog, so "18 surfaces" overstates coverage Yes. help_width.rs:115 measures help_help_text() (only reachable as bitty help help); bitty help --help and bitty --help render help_text_short() instead. help_width.rs:113 measures x_help_text() (safe mode) while bitty x --help calls x_help_text_with_store() (main.rs:593). Same renderer (x_help_text_for), so only the row set differs — and the synthetic wide-row test covers that (help_width.rs:287-309). cosmetic
5 columns() counts scalars, so CJK/emoji under-count Code present (help_width.rs:56-58), no live exposure. All 20 rendered surfaces contain exactly one non-ASCII code point per title: U+2014 EM DASH, east_asian_width=A (1 column). Measured unicode-aware widths equal scalar widths everywhere. cosmetic

Measured rendered widths (head binary, --help)

surface max surface max surface max
run 87 list 91 version 81
ctl 90 ls 91 completion 99
config 79 inspect 96 cmd 76
init 94 dev 98 x 69
doctor 75 plugin 96 shell-init 98
upgrade 73 extension 100 help (bitty help help) 89
reload 85 bitty --help / bitty help --help 109

-v tiers (6): ctl 90, plugin 96, inspect 96, dev 98, extension 100, list 91 — all ≤ 100.

Lines over 100 columns on this head: exactly one, and it is not in the gate:
bitty --help line 28 = 109 columns, crates/bitty-terminal/src/cli.rs:2782
( list <kind> Enumerate themes|…|services (alias ls)). Identical on origin/main
(109), so pre-existing; it is the one real over-wide line in the product and it is outside the
measured set because help is registered as help_help_text() (risk 4).

3. plugin_runtime::rollback() class reset — PASS

  • Reset: crates/bitty-runtime/src/plugin_runtime/mod.rs:4768.
  • Every reader traced. failure_class has exactly one reader —
    recover_wall_failed_plugins (mod.rs:3731, filter at mod.rs:3747). It has four writers:
    insert (mod.rs:2787), successful activation (mod.rs:3434), fail_runtime_classified
    (mod.rs:4727), and the new reset (mod.rs:4768). There is no reporting/diagnostic reader, so no
    path loses a verdict for display.
  • No typed verdict is lost. The only producer of WallSliceTimeout is
    fail_runtime_on_suspend (mod.rs:4738-4746, fed by the timer pump at mod.rs:2370,2413),
    which calls fail_runtime_classified → rollback (mod.rs:4721) → re-stamps the class on
    the next statement (mod.rs:4727). Every other rollback caller is an activation/validation
    error with no SuspendReason in hand, where Unclassified is the correct verdict.
  • No deterministic failure is now retried — the opposite: pre-fix, a generation that once hit a
    wall slice kept WallSliceTimeout across a later plain Lua error and was auto-retried. Post-fix
    the class is cleared, recover_wall_failed_plugins selects nothing, and the test at
    mod.rs:5701 pins it. wall_recovery_attempts is deliberately not reset (asserted at
    mod.rs:5746), so the budget still counts real wall failures.
  • Revert proof (scratch copy, reset line deleted, everything else untouched):
    test plugin_runtime::tests::rollback_clears_the_previous_failure_class ... FAILED
    panicked at crates/bitty-runtime/src/plugin_runtime/mod.rs:5743:9:
    assertion `left == right` failed: a rollback must not inherit the previous generation's wall class
      left: WallSliceTimeout
     right: Unclassified
    
    Restored → cargo test -p bitty-runtime rollback --offline → 6 passed, 0 failed.
  • Note (non-blocking): the proof is a white-box field assertion. The companion integration test
    (tests/plugin_timers.rs:519-555) was also strengthened in this PR (fixture body rewritten so a
    retry would succeed, closing the "passes for the wrong reason" hole), but it does not itself
    depend on the reset.

4. list.rs compact/verbose — PASS

Binary diff of bitty list --help and bitty ls --help, head vs origin/main:

######## list      (1 diff line)
43d42
< Version: 0.0.39
######## ls        (3 diff lines)
1c1
< bitty list — enumerate resources (local or runtime)
---
> bitty ls — enumerate resources (local or runtime)
43d42
< Version: 0.0.39

Exactly the two permitted deltas and nothing else — alias-aware title (list.rs:404) and the
removed compact Version: line. -v still carries it: bitty list --help -v line 44 =
Version: 0.0.39 (list.rs:453), placed between the body and the contract tier, so
verbose.starts_with(compact) still holds (help_width.rs:230).

5. The #3116 half — PASS on code, implemented-only on evidence

Addressed in code, all three layers:

  • Ordering: pre_present_notify() removed from TerminalApp::drive_tick
    (terminal_app.rs:2415-2422) and called immediately before frame.present() in both render
    paths — gpu.rs:1654 (present) and gpu.rs:1963 (present_draw_list_color_classified) — via
    a defaulted, cross-platform trait method (bitty-platform/src/surface.rs:117,157,256). Every
    wl_surface.frame request is now issued when state is None and is immediately followed by a
    commit.
  • winit: request_frame_callback() no longer re-arms from Received
    (vendor/winit/.../window/state.rs:253-262), frame_callback_state is reset on
    SUSPENDED→resumed (state.rs:293-301), and RedrawRequested is suppressed while suspended
    (event_loop/mod.rs:513-516). The match over FrameCallbackState stays exhaustive over its
    three variants (no #[non_exhaustive]), so there is no sentinel constant and no
    unreachable_patterns suppression
    . Patch hash and tree digest in vendor/winit/PATCHES.md
    verify: sha256(patch 0003)=82a2948… and the tree digest 7304ebac… both recompute exactly;
    scripts/check-vendored-winit.sh → OK.
  • Runtime gate: speculative_present_reopen is no longer cleared by a driver commit
    (present.rs:8146-8152, 8652-8656); frames are held back while the blind repair awaits
    confirmation (present.rs:2336, 3552); the gate closes back on an unconfirmed repair
    (present.rs:2470). The wake is real, not self-healing by luck: present_confirm_wake()
    (terminal_app.rs:1597-1603) is joined into AboutToWait (pinned by
    tests.rs:1146 about_to_wait_arms_the_present_confirm_deadline), so the deadline is guaranteed
    to fire even while present_owed() is false.
  • RSS: SHARED_FONT_FILES weak cache + probe_buf reuse (shaped.rs:206-222, 496-556, 1021-1117) are real; the new test proves Arc::ptr_eq across two SwashSingle instances and
    that a scan miss retains nothing.

Platform-cfg correctness: clean. The diff adds zero cfg(...) attributes (grep over
origin/main...HEAD), so there is no definition whose only consumer is cfg(target_os="linux");
SurfaceSource::pre_present_notify has a no-op default for headless fakes and the wgpu consumer is
unconditional. CI Windows (35m) and macOS ARM64 (22m) both pass.

Assertions the code does not support (flagging, all non-blocking):

  1. "resolve the Hyprland workspace switch freeze" — no automated repro exists for the freeze.
    The only new test (present.rs:14535 a_committed_blind_repair_that_stays_unconfirmed_closes_the_gate_again)
    covers the runtime gate, not the winit/ordering change; the PR body carries no manual
    Hyprland validation record
    . This half is implemented-only.
  2. "SwashSingle font RSS optimization" — no before/after RSS numbers anywhere in the PR body.
    The in-code claim "[heap] RSS stays at ~167 MiB Private_Dirty" (shaped.rs:1028) is a
    measurement that no test or CI job reproduces; the test proves sharing, which is necessary
    but not sufficient for the RSS claim.
  3. "the default --help output is unchanged from origin/main" (list.rs:449-451) is false
    as written — origin/main prints Version: 0.0.39 in the compact body and this head does not.
    The removal is intended (see check 4); the comment's justification is not.
  4. Cosmetic: SurfaceKind::Gpu.target still carries #[allow(dead_code)] with the comment "Keep
    the window alive" (gpu.rs:971-973) although the field is now the notify handle. Stale.

6. MSRV 1.85 — PASS

$ cargo +1.85 check -p bitty-terminal -p bitty-runtime --offline
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.78s
MSRV_EXIT=0

No let-chains in the new code (the const assert at help_width.rs:35-38 is a plain
assert! in const context, legal on 1.85; HELP_WRAP_COLUMNS is also read at runtime by
push_wrapped_line, so it is not const-eval-only).

7. Gates — PASS

$ cargo fmt --all -- --check                      → exit 0 (no output)
$ cargo clippy -p bitty-terminal -p bitty-runtime --tests --offline -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.36s   → exit 0
$ cargo test -p bitty-terminal help_width --offline
    test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 1521 filtered out
$ cargo test -p bitty-runtime rollback --offline
    test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 1556 filtered out
$ ./scripts/check-scratch-paths.sh                → scratch-paths: OK
$ ./scripts/check-vendored-winit.sh               → tree digest and patch hash match

just check soak was not run (host-speed-sensitive; every gate it aggregates that this PR can
move — fmt, clippy, MSRV, vendored-winit, scratch-paths, help_width, rollback — was run
individually above, and the CI Quality gates (1)/(2) jobs pass on this head).


Residual risks (all non-blocking)

  1. bitty --help renders 109 columns (cli.rs:2782) and is not measured by the gate because
    help is registered as help_help_text() (help_width.rs:115). Pre-existing on main. —
    cosmetic (coverage)
  2. bitty x --help head prefix is unbounded: a legal ~120-char plugin id renders 135 columns
    and hard-splits a command one char per line (x.rs:317-328, cli.rs:2923-2937). Pre-existing
    shape (main rendered it unwrapped), and the PR strictly improves the common case. —
    cosmetic (edge)
  3. columns() counts scalars (help_width.rs:56): correct today (only U+2014 appears), but a
    wide-glyph plugin id would under-count. — cosmetic
  4. Hyprland freeze fix is unverified by test (see 5.1); the pre_present_notify() call moved
    from the event-loop thread to the presenter thread for the async path (gpu.rs:1963), which the
    PR body does not discuss. Needs one manual workspace-switch soak on Hyprland before/after
    release. — non-blocking, manual validation owed
  5. RSS claim unmeasured (see 5.2); the dedup is real, the MiB figure is not reproduced. —
    non-blocking, measurement owed
  6. A slow-but-visible compositor can be treated as hidden: an unconfirmed blind repair closes
    the gate (present.rs:2470) even if the surface is actually mapped, costing one
    HIDDEN_REPAIR_INTERVAL_MS cycle. Bounded and self-healing (hidden_repair_deadline), but it is
    a new failure mode introduced by the stricter "commit ≠ confirmation" rule. — non-blocking
  7. False code comment at list.rs:449-451 ("unchanged from origin/main"); ctl and reload
    still print Version: in their compact bodies, so the "version belongs to -v" tiering is not
    applied consistently. — cosmetic
  8. #[allow(dead_code)] on the now-used SurfaceKind::Gpu.target (gpu.rs:971-973). — cosmetic

Bottom line

All seven checks pass on f9e6df2f. The gate is genuinely table-derived and provably fails closed;
the five prior residual risks are either fixed or reduced to cosmetics; the rollback reset is
correct against every reader and is proven by a revert; the CTX-1788 follow-ups (help_width gate,
alias-aware list title, Version tiering, rollback class reset, scratch-path markers) are all
present and behave as described. The #3116 half is coherent, platform-clean and CI-green, but its
central claim (no more workspace-switch freeze) rests on design reasoning rather than a test or a
recorded manual repro — worth one manual Hyprland soak, not a merge blocker.

VERDICT: APPROVE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area: platform / windowing area:render Area: rendering area:runtime Area: runtime orchestration fix Bug fix P0 Priority: highest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(runtime,render,platform): resolve Hyprland workspace switch frame freeze and reduce font heap footprint

1 participant