Skip to content

[0.0.32] Bitty becomes unresponsive after long uptime #2830

Closed
2 of 2 issues completed
Closed

Description

@Xuepoo

Priority: P0 | Area: runtime | Labels: fix,P0,area:runtime | Milestone: v0.0.32 | RFC: none | Task: TBD

Symptom

Bitty becomes unresponsive after running for a long time: the window stops repainting and accepting input, no crash and no error. Reported by the owner on the real desktop (Hyprland). Not yet reproduced under instrumentation.

What we need to distinguish

  1. Poll-loop stall (a single event/tick blocks, e.g. a blocking syscall, a lock held across I/O, a plugin call that never returns).
  2. Live-lock / starvation (loop spins, CPU high, but no redraw; a queue never drains or a timer re-arms in the past).
  3. Resource exhaustion (fd leak, memory growth, unbounded queue, PTY backlog, orphan/worker handles, event ring retention).
  4. Renderer stall (GPU/wgpu surface lost, frame callback never fires, compositor interaction).
  5. Deadlock between the app thread, plugin supervisor, worker pool, or daemon bridge.

Work

  • Add a built-in hang watchdog: if a tick or a command exceeds a named bound, write a one-shot diagnostic (stage, tick duration, queue depths, worker/lease counts, fd count, RSS, thread states) to the log/state dir, and expose bitty inspect runtime (or a SIGUSR1 dump) that prints the same while hung. Debug builds may abort with a backtrace.
  • Audit long-run accumulation paths: event pending_deliveries, ring retention for live sessions, content buffers/backpressure, LIVE_CHILDREN, orphan journal, scene/glyph caches, plugin parked commands, timers/deadlines that overflow or re-arm in the past.
  • Add a soak/repro harness (headless, multi-hour compression via injected clocks and repeated attach/detach, plugin activation, panel drag/resize, daemon events) and run it in CI with a bounded budget.
  • Fix every confirmed cause; each fix must come with a regression test that fails on the parent.

Acceptance

  • A hung process produces a diagnostic without external tooling.
  • The soak harness runs the compressed long-run workload with no unresponsiveness, bounded RSS/fd/queue growth, and a green run in CI.

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added this to the v0.0.32 milestone on Oct 30, 2026
  2. added
    fix
    P0
    area:runtime
    on Oct 30, 2026
  3. Xuepoo commented on Oct 30, 2026

    @Xuepoo
    ContributorAuthor

    Owner detail: the hang happens while running opencode inside Bitty after a while, and the process uses no CPU while frozen — so this looks like a blocking wait or a lost wakeup rather than a spin, live-lock, or pure memory growth.

    Targeted hypotheses to test first:

    1. Blocking write to a full PTY/content path: a large opencode redraw while the pane is not drained parks the loop writer with no wakeup (content write path and the Worker::drain budget interaction).
    2. Lost paint request: alternate-screen flip or a scrollback/geometry change leaves request_redraw unarmed, so the compositor never gets another frame (CPU-idle, window frozen).
    3. Lock held across I/O: plugin host-call, daemon bridge, or event-ring lock taken on the input thread and held while waiting for a worker or socket.
    4. Quiet accumulation: pending_deliveries or event-ring retention across repeat attach/detach, or fd exhaustion from openpty per pane making a later poll block.
    5. OSC/DSR query without reply: an opencode terminal query (DSR/DA1/OSC 52) answered only on a later tick that never runs once the loop parks.

    Repro should approximate opencode: continuous large redraws, mouse tracking (DECSET 1000/1002/1003/1006), alternate screen, OSC 0/2 title and OSC 52, growing scrollback, plus repeated pane attach/detach; capture the watchdog dump at the stall.

  4. Xuepoo commented on Oct 30, 2026

    @Xuepoo
    ContributorAuthor

    Diagnosis campaign update (55 min live load, 0.0.30 and 0.0.31, opencode-shaped stream plus a real opencode --standalone pane): the owner's CPU-idle freeze did not reproduce, but one mechanism is now proven to be capable of a permanent idle stall.

    Proven mechanism (hypothesis 2) — set_surface_visibility_at(false) retains damage and arms no timed wake (occlusion_gate_never_attempts_a_present_while_hidden). If the reveal edge never arrives (lost visibility event, compositor quirk, focus/workspace edge dropped), the loop parks at ControlFlow::Wait with retained damage forever. 20+ away/resize cycles recovered in the campaign, so it is rare, not impossible.

    Not reproduced: blocking PTY/content write (local PTYs, no bittyd client; forwarder sends block on their own thread), lock-across-I/O (no unbounded join; ptrace_scope blocks live backtraces, stacks came from /proc sampling), quiet accumulation (fds oscillate 58–70 across 30 attach/detach cycles, RSS 182–355 MiB), query-reply-lost-tick (replies drain every poll; DSR/DA1/XTWINS every 20 frames answered).

    Diagnostics now in place: separate monitor thread (a main-thread watchdog cannot observe its own stall), parked-work bitset (pty, replies, hidden-damage), and a no-present detector (trigger=no-present when presented_frames is stuck while progress advances). Out-of-band dump works even while the loop claims idle.

    Artifacts: recording/ctx-2830-hang/ (README, harness, run matrix, instrumented build). The fix branch adds an occluded-repair wake so a missed reveal self-heals, and reuses the parked-work/no-present fields in the SIGUSR1 dump. If it recurs, set BITTY_STALL_WATCHDOG=1; the report will name the blocked phase or trigger=no-present with present_stale_ms.

  5. 6 remaining items

  6. Xuepoo commented on Oct 31, 2026

    @Xuepoo
    ContributorAuthor

    Self-heal + diagnostics landed in #2834 (de965a8b, merged after the delta review):

    • Occlusion repair wake: a hidden surface that retains paint work now arms a 1 s repair deadline; the gate reopens only when the compositor actually serves the redraw probe (5 s TTL), so a still-occluded surface never spins. This closes the one mechanism the campaign proved reachable (a missed reveal edge previously parked forever with damage retained and no timed wake).
    • Watchdog: separate monitor thread, parked-work bitset (pty, replies, hidden_damage), no-present detector (trigger=no-present), single SIGUSR1 trigger, abort only in debug builds and only for stall/no-present, VmRSS (not smaps/statm), gauges refreshed after the post-tick reply flush.
    • Soak in CI: opencode_soak (~2 min on unoptimized runners, 240 s guard) with bounded RSS/fd/queue/presented frames, and the daemon longrun_hang now asserts the event-ring caps in-loop at every 400-cycle interval peak (256 events / 256 KiB / 512 KiB accounted) before the terminal transition.
    • Diagnostics: BITTY_STALL_WATCHDOG=1 (+ SIGUSR1) produces trigger, pending, present_stale_ms; token-shaped values are scrubbed and gitleaks-clean.

    Not reproduced: the original freeze (55 min campaign, opencode-shaped and real opencode) — so this is a coverage fix plus instrumentation, not a confirmed root cause. Next step if it recurs: capture the watchdog report and the last present/damage timestamps from the frozen process.

  7. Xuepoo commented on Nov 1, 2026

    @Xuepoo
    ContributorAuthor

    New deterministic instance of the same mechanism, caught in CI (evidence for the freeze class):

    Linux X11 (xvfb), run 41280906272, step cargo test -p bitty-platform --test headless_run --test winit_window:

    06:39:45  ok: headless owned checks passed (dpi, extent, config)   <- winit_window entered App::run
    06:57:42  ##[error]The operation was canceled.                    <- 18 min later, job timeout
    

    The test creates a hidden window, requests a redraw from Resumed, and then waits for Resized/RedrawRequested. When that request is lost, the loop's default ControlFlow::Wait blocks with no pending events, so about_to_wait is never invoked again — the existing watchdog counted AboutToWait ticks, so it stayed at 1 and could not fire. Passing runs show the fast path (created=true resized=None redraw=true).

    That is exactly the long-uptime shape: a lost redraw plus a Wait loop with no armed wake has no bounded recovery. The app's AboutToWait arms set_wait_until only when a deadline exists (terminal_app.rs, the wake array: hover/animation/bell/capture/kitty/coalesced/timers/parked/shell_exit/selection/surface_retry); when that array is empty it calls set_wait(). If damage is retained but no deadline is armed, nothing wakes the loop until external input — matching "unresponsive until I click".

    Test-side bound is now in #2843 (issue #2842): keep the handle, retry the redraw, re-arm a 50 ms wake, and fail after 20 s instead of hanging. Product-side safety net (arm a bounded wake whenever damage is retained and no other deadline exists) stays in scope here.

  8. Xuepoo commented on Nov 3, 2026

    @Xuepoo
    ContributorAuthor

    Acceptance closeout (guard tick, 2026-11-03)

    Verifying the two acceptance criteria against main (f0a6d252) rather than the prose:

    1. A hung process produces a diagnostic without external tooling — met.
    crates/bitty-terminal/src/stall_watchdog.rs ships a default-on-in-release monitor
    (BITTY_HANG_WATCHDOG, BITTY_HANG_WATCHDOG_MS, BITTY_HANG_WATCHDOG_ABORT,
    BITTY_HANG_WATCHDOG=0 to disable): one continuous stall writes exactly one bounded
    report (phase marks, parked-work bitset pty / replies / hidden_damage,
    no-present trigger=no-present, VmRSS, queue depths); SIGUSR1 writes the same
    report on demand, and a stall-watchdog.dump.req file is polled by the monitor.
    Wired from crates/bitty-terminal/src/main.rs; crash_report.rs is rendered by the
    same monitor path. No external tooling is required.

    2. Compressed long-run soak runs in CI with bounded growth and green — met.

    • Harnesses in main: crates/bitty-runtime/tests/longrun_hang.rs
      (SOAK_BUDGET_CI = 150 s, FRAMES = 800, bounded RSS/fd/queue assertions),
      crates/bitty-runtime/tests/opencode_soak.rs,
      crates/bitty-runtime/tests/pty_reply.rs,
      crates/bitty-daemon/tests/longrun_hang.rs (per-interval peak assertions via
      assert_stream_bounded before terminate()); per-test budget overrides in
      .config/nextest.toml.
    • Green evidence: CI run 41603598898
      on f0a6d252 — conclusion success; compressed_long_run_stays_bounded
      measured 35.5 s (Quality gates 1), 68.9 s (Linux X11 xvfb), 56.4 s (Linux Wayland),
      96.1 s (Windows), 61.5 s (macOS ARM64) — all inside the 150 s budget, and the
      Quality gates (1)/(2), Linux X11 (xvfb), Linux Wayland, Windows,
      macOS ARM64, and both compat-matrix jobs are success.
    • CodeQL: 0 open rust code-scanning alerts on the soak tests (the two high alerts
      from the earlier review were removed when panic messages stopped formatting
      session state); the CodeRabbit thread on bitty-daemon/tests/longrun_hang.rs is
      answered and resolved.

    Proven mechanisms and their regression tests (each landed with a test that fails
    on the parent): occlusion repair wake for a hidden surface with retained damage
    (#2853), bounded wake whenever damage is retained with no other deadline
    (#2853), long-run accumulation fixes and self-heal (#2834, de965a8b), and the
    compressed soak campaign itself (#2854). The winit hidden-window deterministic
    instance from the 2026-11-01 comment is covered by the bounded-wake fix and by
    #2856-era test bounding (#2852/#2854 line); the owning test no longer parks
    for the 18-minute job timeout.

    Residual risk, stated honestly: the owner's original CPU-idle freeze on the real
    desktop never reproduced under instrumentation (55-minute live load, 0.0.30/0.0.31).
    What closes here is the proven class — every reachable parking path now has a
    bounded wake and a diagnostic — not a reproduction of the exact symptom. If the
    freeze recurs, the watchdog now writes the report that names the stage.

    Closing as completed on that basis; reopen with the watchdog report if it recurs.

    — guard tick (hermes-planner), independent of the implementing lanes CTX-1661/CTX-1672

  9. Xuepoo commented on Nov 3, 2026

    @Xuepoo
    ContributorAuthor

    Additional owner reports on v0.0.31 (release build, Hyprland):

    1. Freeze after idle. A window that had been idle for a while stopped responding right after the owner opened a file in neovim. Nothing was captured: BITTY_STALL_WATCHDOG is opt-in (config_from_values returns None when unset), and the state file still holds the 2026-10-26 phase=window-create report, so the frozen process was killed without evidence.
    2. Bar clock frozen. A running window shows its clock capsule stuck (the owner reports it "never updates"). Plugin timers are what drive that repaint, and v1 timer creation is bounded to what the activation window admits, so a module that stops ticking and a window that stops repainting can share the same "no armed wake" root cause.

    Follow-up in flight (CTX-1678): watchdog default-on in release (opt-out with BITTY_STALL_WATCHDOG=0) and a SIGUSR1 on-demand dump written by the monitor thread (phase, progress, per-thread state/wchan, surface telemetry, redraw_pending_ms), bounded so a signal storm cannot grow a queue and with the signal only wired when the monitor runs.

    What to capture next time, before killing the process:

    cat ~/.local/state/bitty/stall-watchdog.log
    ps -o pid,stat,pcpu,etime,wchan:32 -p <pid>
    for t in /proc/<pid>/task/*; do cat "$t/comm" "$t/wchan"; done
    

    A parked state=S in ppoll/futex and a busy state=R point at different classes (blocked main thread vs. loop alive but not presenting), and presented_frames/redraw_pending_ms in the dump separates "no wake armed" from "frame submitted but never presented".

  10. Xuepoo commented on Nov 5, 2026

    @Xuepoo
    ContributorAuthor

    First live capture with the process left running. The freeze is a renderer stall (hypothesis 4), not a poll-loop deadlock or a leak.

    Environment

    Bitty 0.0.32 (started 2026-11-05 17:00:32), Hyprland 0.57.1 / aquamarine 0.16.0 (drm: Explicit sync supported), NVIDIA 615.78.08 (RTX 4060), single eDP-1 @ scale 1.6. The window was on workspace 2 while the active workspace was 3, so the surface was not being composited.

    Evidence

    • Main thread (tid = pid) blocked in drm_syncobj_timeline_wait_ioctl; all PTY threads, the stall watchdog, and the IPC thread healthy. 23 threads, RSS ~92 MB, ~7 % of one core — not a spin.
    • 200 ms wchan sampling: 19:46:48 dur=17.49s, 19:47:01 dur=13.09s in the DRM timeline wait, with ~0.2 s of progress between them; by 19:50 the loop had returned to normal do_epoll_wait/running alternation without a restart.
    • bitty ctl instance/view/workspace list answered throughout, so the event-loop thread alone was blocked.
    • Kernel journal has no NVRM/Xid/drm reset entry: the fence is simply not signalled while the surface is not composited.
    • A scratch instance moved to a hidden workspace idled in do_epoll_wait, so the [0.0.29] P0: Hyprland workspace switch-away/back freezes or terminates Bitty #2570 visibility gate holds in the steady state; the failure is a present already in flight (or issued at the transition), not a permanently open gate.

    What this means

    The UI thread blocks inside the Wayland/NVIDIA explicit-sync swapchain wait. The compositor signals that fence only when it next composites the surface (workspace shown again, or unrelated composition activity), so the window shows a frozen frame for many seconds - indefinitely if the user never returns to that workspace - while the process is otherwise healthy. Input, PTY pumping, plugin timers and compositing share that thread, which is exactly the reported "stops repainting and accepting input".

    Diagnostic gap (separate defect)

    ~/.local/state/bitty/stall-watchdog.log is unchanged since 2026-10-26. 0.0.32 arms the watchdog by default in release with a 3 s bound for RuntimeTick, and the stall lasted 13-17 s per iteration, so a report should exist. It does not. Two things to pin with a regression test:

    1. a synthetic present block longer than the RuntimeTick bound must produce exactly one report;
    2. a repeated block-and-return cycle (the shape above) must not look like progress.

    Fix direction

    • Never let the UI thread wait on the compositor: bound the acquire/present or move it off the event loop; a stuck present must not stop input or timers.
    • Keep the visibility gate and close it on the transition, so the first present after a surface stops being composited does not enter the wait at all.
    • Add the two watchdog regressions above, so the next incident is self-describing.

    Artifacts: recording/ctx-freeze-live-20261105/ (thread table, wchan timeline, workspace experiments).

  11. Xuepoo commented on Nov 5, 2026

    @Xuepoo
    ContributorAuthor

    Second live capture, same process, now with the built-in SIGUSR1 dump (0.0.32 has the truthful registration; the monitor thread was running, so this was a non-destructive capture).

    Raw evidence (abridged)

    phase=runtime-tick, idle 383 ms
    parked: present_stale_ms=110994
    surface: last=retry-armed visible=true probe_seen=true probe_occluded=false
      acquire_ok=340327 acquire_timeout=764 acquire_outdated=0 acquire_lost=0
      present_ok=340327 present_err=764 retry_failures=764 retry_attempts=757
      retry_recoveries=6 retry_last_delay_ms=1000
    runtime: tick_count=1818690 last_tick_ms=1023 max_tick_ms=1659
      pending_input_bytes=0 panes=4 leaves=1
    [main] wchan=drm_syncobj_timeline_wait_ioctl syscall_number=16
    

    What this pins down

    • The block is a bounded acquire timeout, retried on the UI thread for minutes. acquire_ok == present_ok == 340327 and acquire_timeout == present_err == retry_failures == 764: every get_current_texture that timed out fed the [0.0.29] P0: Hyprland workspace switch-away/back freezes or terminates Bitty #2570 retry chain. With retry_last_delay_ms=1000 and each attempt blocking ~1 s in the compositor fence wait, the event loop reaches a ~0 % duty cycle; max_tick_ms=1659 is one such tick.
    • No frame committed for 111 s (present_stale_ms=110994) while input was not lost (pending_input_bytes=0). That is exactly the ANR the compositor reported: the window keeps its last frame, the loop is alive between 1 s timeouts, and it never gets to paint.
    • The visibility gate is a false negative. visible=true, probe_seen=true, probe_occluded=false, redraw_pending_ms=none while the window was on workspace 2 and the active workspace was 3. Hyprland keeps serving frame callbacks for the hidden surface, so the redraw-starvation probe never fires, and repeated acquire timeouts are not treated as occlusion evidence.
    • Kernel journal still shows no NVRM/Xid/drm reset: the fence is simply not signalled while the surface is not composited.

    Fix implications

    1. The off-thread presenter (CTX-1711) removes the UI-thread acquire entirely, which breaks the retry-storm shape.
    2. Independent, smaller mitigation: treat repeated SurfaceError::Timeout with no committed frame as occlusion evidence and close the surface-visibility gate, so the retry loop stops instead of spinning at 1 Hz. Reopen on the next frame callback or explicit reveal.
    3. Follow-up: the same dump reports cold_dropped=6293691 and plugin_side_dropped=12206859. Those are cumulative counters; confirm whether a stalled loop is dropping six-to-twelve million events/bytes and whether the counters are bounded or symptomatic of a separate retention bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0area:runtimefix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions