One function

run_forever in leeguooooo/claude-code-usage-bar

The author described this change as fix: daemon 在慢渲染时崩溃 — time.sleep 收到负值 (v3.29.1). It counts as a record because the check below fails on the code as it stood at a5cc56a30 and passes on 5ff94cbcb, with nothing else changed between the two runs.

Fix saved2026-07-09
Sharing licenceMIT · LICENSE
Change size+7 2

What the code was meant to do, written into the code itself as a docstring

Block in the render loop until SIGTERM/SIGINT. `core.main()` already throttles its heavy claude-monitor subprocess behind cache.py's age-based invalidation, so we don't need a separate "heavy tick" — every render tick that triggers a refresh hits the cache, only the periodic invalidation pays the heavy cost.

The change

7777 last_gc = t0
7878 elapsed = time.time() - t0
7979 sleep_for = max(0.0, render_interval - elapsed)
80- # Sleep in small chunks so signals are responsive.
80+ # Sleep in small chunks so signals are responsive. Clamp at 0: the
81+ # loop guard and the `min()` each call time.time() separately, so
82+ # the clock advances between them and the remainder can go negative
83+ # — time.sleep() then raises ValueError and kills the daemon. That
84+ # fires whenever a tick overruns render_interval (sleep_for == 0,
85+ # end == now), which is exactly what a slow render does.
8186 end = time.time() + sleep_for
8287 while _running and time.time() < end:
83- time.sleep(min(0.2, end - time.time()))
88+ time.sleep(max(0.0, min(0.2, end - time.time())))
8489 _log("daemon shutting down")
8590 return 0
8691 finally:

The check that tells the two apart

failpass·tests/test_daemon.py::test_clock_advancing_between_guard_and_sleep_does_not_crash

Check file tests/test_daemon.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before ita5cc56a3055a76cded62caead8ab364efe555e13
Broken version dated2026-07-09
Moduleclaude_statusbar.daemon
Units changedrun_forever
Fingerprintb70613abb10ce24b
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in leeguooooo/claude-code-usage-bar