Repository navigation
Closed
2 / 22 of 2 issues completedClosed
2 / 22 of 2 issues completed
Copy link
Labels
Milestone
Description
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
- 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).
- Live-lock / starvation (loop spins, CPU high, but no redraw; a queue never drains or a timer re-arms in the past).
- Resource exhaustion (fd leak, memory growth, unbounded queue, PTY backlog, orphan/worker handles, event ring retention).
- Renderer stall (GPU/wgpu surface lost, frame callback never fires, compositor interaction).
- 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 aSIGUSR1dump) 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
Collapse Sub-issuesSub-issues
Loading 2 sub-issues
Activity
Xuepoo commentedon Oct 30, 2026
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:
Worker::drainbudget interaction).request_redrawunarmed, so the compositor never gets another frame (CPU-idle, window frozen).pending_deliveriesor event-ring retention across repeat attach/detach, or fd exhaustion from openpty per pane making a laterpollblock.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.
[CTX-1661] test(daemon): content read/write churn stays bounded (part…
Xuepoo commentedon Oct 30, 2026
Diagnosis campaign update (55 min live load, 0.0.30 and 0.0.31, opencode-shaped stream plus a real
opencode --standalonepane): 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 atControlFlow::Waitwith 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_scopeblocks live backtraces, stacks came from/procsampling), 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-presentwhenpresented_framesis 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 theSIGUSR1dump. If it recurs, setBITTY_STALL_WATCHDOG=1; the report will name the blocked phase ortrigger=no-presentwithpresent_stale_ms.[CTX-1661] fix(runtime): self-heal a hidden surface with retained dam…
[CTX-1661] test(runtime): port the opencode-shaped long-run soak (par…
[CTX-1661] fix(runtime): built-in hang watchdog and long-run accumula…
[CTX-1661] test(daemon): content read/write churn stays bounded (part…
[CTX-1661] fix(runtime): self-heal a hidden surface with retained dam…
[CTX-1661] test(runtime): port the opencode-shaped long-run soak (par…
6 remaining items
[CTX-1661] test(runtime): port the opencode-shaped long-run soak (par…
[CTX-1661] fix(runtime): apply #2834 review fixes (part of #2830)
[CTX-1661] fix(daemon): assert stream bounds inside the long-run loop…
[0.0.32] fix(runtime): built-in hang watchdog and long-run accumulati…
Xuepoo commentedon Oct 31, 2026
Self-heal + diagnostics landed in #2834 (
de965a8b, merged after the delta review):pty,replies,hidden_damage), no-present detector (trigger=no-present), singleSIGUSR1trigger, abort only in debug builds and only for stall/no-present,VmRSS(notsmaps/statm), gauges refreshed after the post-tick reply flush.opencode_soak(~2 min on unoptimized runners, 240 s guard) with bounded RSS/fd/queue/presented frames, and the daemonlongrun_hangnow asserts the event-ring caps in-loop at every 400-cycle interval peak (256 events / 256 KiB / 512 KiB accounted) before the terminal transition.BITTY_STALL_WATCHDOG=1(+SIGUSR1) producestrigger,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.Xuepoo commentedon Nov 1, 2026
New deterministic instance of the same mechanism, caught in CI (evidence for the freeze class):
Linux X11 (xvfb), run 41280906272, stepcargo test -p bitty-platform --test headless_run --test winit_window:The test creates a hidden window, requests a redraw from
Resumed, and then waits forResized/RedrawRequested. When that request is lost, the loop's defaultControlFlow::Waitblocks with no pending events, soabout_to_waitis never invoked again — the existing watchdog countedAboutToWaitticks, 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
Waitloop with no armed wake has no bounded recovery. The app'sAboutToWaitarmsset_wait_untilonly when a deadline exists (terminal_app.rs, thewakearray: hover/animation/bell/capture/kitty/coalesced/timers/parked/shell_exit/selection/surface_retry); when that array is empty it callsset_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.
[CTX-1669] fix(runtime): arm a bounded wake when damage is retained a…
[CTX-1672] fix(runtime): gate the campaign's pane constants to unix
[CTX-1672] fix(ci): bound the nightly campaign inside its job timeout
[CTX-1672] test(runtime): long-duration soak campaign and bounded-gro…
Xuepoo commentedon Nov 3, 2026
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.rsships a default-on-in-release monitor(
BITTY_HANG_WATCHDOG,BITTY_HANG_WATCHDOG_MS,BITTY_HANG_WATCHDOG_ABORT,BITTY_HANG_WATCHDOG=0to disable): one continuous stall writes exactly one boundedreport (phase marks, parked-work bitset
pty/replies/hidden_damage,no-present
trigger=no-present,VmRSS, queue depths);SIGUSR1writes the samereport on demand, and a
stall-watchdog.dump.reqfile is polled by the monitor.Wired from
crates/bitty-terminal/src/main.rs;crash_report.rsis rendered by thesame monitor path. No external tooling is required.
2. Compressed long-run soak runs in CI with bounded growth and green — met.
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 viaassert_stream_boundedbeforeterminate()); per-test budget overrides in.config/nextest.toml.on
f0a6d252— conclusionsuccess;compressed_long_run_stays_boundedmeasured 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 aresuccess.from the earlier review were removed when panic messages stopped formatting
session state); the CodeRabbit thread on
bitty-daemon/tests/longrun_hang.rsisanswered 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 thecompressed soak campaign itself (
#2854). The winit hidden-window deterministicinstance from the 2026-11-01 comment is covered by the bounded-wake fix and by
#2856-era test bounding (#2852/#2854line); the owning test no longer parksfor 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
Xuepoo commentedon Nov 3, 2026
Additional owner reports on v0.0.31 (release build, Hyprland):
BITTY_STALL_WATCHDOGis opt-in (config_from_valuesreturnsNonewhen unset), and the state file still holds the 2026-10-26phase=window-createreport, so the frozen process was killed without evidence.Follow-up in flight (CTX-1678): watchdog default-on in release (opt-out with
BITTY_STALL_WATCHDOG=0) and aSIGUSR1on-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:
A parked
state=Sinppoll/futexand a busystate=Rpoint at different classes (blocked main thread vs. loop alive but not presenting), andpresented_frames/redraw_pending_msin the dump separates "no wake armed" from "frame submitted but never presented".Xuepoo commentedon Nov 5, 2026
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
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.19:46:48 dur=17.49s,19:47:01 dur=13.09sin the DRM timeline wait, with ~0.2 s of progress between them; by 19:50 the loop had returned to normaldo_epoll_wait/running alternation without a restart.bitty ctl instance/view/workspace listanswered throughout, so the event-loop thread alone was blocked.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.logis unchanged since 2026-10-26. 0.0.32 arms the watchdog by default in release with a 3 s bound forRuntimeTick, 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:RuntimeTickbound must produce exactly one report;Fix direction
Artifacts:
recording/ctx-freeze-live-20261105/(thread table, wchan timeline, workspace experiments).Xuepoo commentedon Nov 5, 2026
Second live capture, same process, now with the built-in
SIGUSR1dump (0.0.32 has the truthful registration; the monitor thread was running, so this was a non-destructive capture).Raw evidence (abridged)
What this pins down
acquire_ok == present_ok == 340327andacquire_timeout == present_err == retry_failures == 764: everyget_current_texturethat timed out fed the [0.0.29] P0: Hyprland workspace switch-away/back freezes or terminates Bitty #2570 retry chain. Withretry_last_delay_ms=1000and each attempt blocking ~1 s in the compositor fence wait, the event loop reaches a ~0 % duty cycle;max_tick_ms=1659is one such tick.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.visible=true,probe_seen=true,probe_occluded=false,redraw_pending_ms=nonewhile 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.Fix implications
SurfaceError::Timeoutwith 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.cold_dropped=6293691andplugin_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.