fix(cli): sweep stale Bun-extracted temp libraries at startup#568
Open
WakaTaira wants to merge 1 commit into
Open
fix(cli): sweep stale Bun-extracted temp libraries at startup#568WakaTaira wants to merge 1 commit into
WakaTaira wants to merge 1 commit into
Conversation
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
Contributor
|
PR author is not in the allowed authors list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.