fix(cli): sweep stale Bun-extracted temp libraries at startup - #568
fix(cli): sweep stale Bun-extracted temp libraries at startup#568WakaTaira wants to merge 1 commit into
Conversation
|
PR author is not in the allowed authors list. |
Bun single-file executables extract their embedded native libraries into the OS temp directory under a randomized hidden name on every launch and never remove or reuse them (oven-sh/bun#30962). Repeated invocations — e.g. hunk as a git pager or agents polling `hunk session` — can leak gigabytes per day (modem-dev#556). Add a best-effort startup sweep that removes stale copies: hidden `.{16hex}-{8hex}.(so|dylib|dll)` files in the temp directory root, owned by the current user and older than one hour. The sweep is rate-limited to one directory scan per hour via a stamp file, aborts on a suspicious stamp (symlink or foreign owner) to stay safe on shared /tmp, swallows all errors, and can be disabled with HUNK_DISABLE_TMP_SWEEP=1. Interim mitigation until Bun's extraction dedupe (oven-sh/bun#29587) ships, at which point this module can be deleted. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015eTSMVABBYeA6ona5khgKC
bed73cd to
e715204
Compare
|
@WakaTaira is attempting to deploy a commit to the Modem Team on Vercel. A member of the Team first needs to authorize it. |
|
Rebased onto the latest One honest observation: at some point the leak seems to have stopped occurring on my machine — I no longer notice new artifacts accumulating. I haven't investigated why (I'm on 0.17.7, which predates #590's headless lazy-load, so that shouldn't be the reason), so it may be environmental. Sharing as anecdotal signal in case it's useful when deciding how this and #577 fit together. |
What
Bun single-file executables extract their embedded native libraries into the OS temp directory under a randomized hidden name (
.{16hex}-{8hex}.so|dylib|dll) on every launch, and never reuse or remove them (oven-sh/bun#30962). For hunk this means every invocation leaks one copy of the OpenTUI native library — #556 documented 81,653 files (~190 GB) in three weeks via the lazygit pager integration; I hit a full 16 GB tmpfs overnight on Linux with an agent pollinghunk sessionevery 2 s.This PR adds a best-effort startup sweep that reaps hunk's stale leaked artifacts until Bun's extraction dedupe (oven-sh/bun#29587) ships — at which point this module can be deleted outright.
How
src/core/tmpArtifactSweep.ts(DI-friendly, colocated tests): removes hidden.{16hex}-{8hex}.(so|dylib|dll)regular files in the temp directory root, owned by the current user and older than one hour.main(): the sweep starts before argument parsing, and short-lived commands await it right beforeprocess.exit(which would otherwise drop the pending work). The app and daemon paths never block on it.HUNK_DISABLE_TMP_SWEEP=1.Verification
typecheck/test/lint/format:checkall pass (9 new unit tests).hunkbinary leaks exactly one new artifact per--helprun (reproducing the bug); with this patch it removes planted stale artifacts, keeps fresh ones, honors the opt-out, and respects the rate-limit stamp.Refs #556.