Repository navigation
Sweep private CODEX_HOME directories left by dead owners - #241
Merged
Merged
Conversation
A codex app-server's private home is removed in Drop, which a kill -9 never runs, so leftovers accumulated in $TMPDIR (344 dead-owner homes, about 290 MB, on one machine). Each CodexAppServerBackend now sweeps them on a thread of its own when it is built: a hide-ai-codex-home-<pid>-<nanos> directory is removed only when it is a plain directory the user owns and no process has that pid, so a live or reused pid keeps its homes. At most 32 are removed per sweep, and the result is logged as ai.codex_home.swept with counts and bytes. CodexHome moves to its own module with the sweep and its fixture tests.
…failed hided built its provider routers and backends with a no-op log sink, so ai.codex_home.swept never reached any log in the product. The core now forwards every AI event to its diagnostic log (Logs/core.jsonl) as a record with component ai and the event name as kind; AiLogEvent serializes without its absent fields for that. The sweep now counts directory listing errors instead of dropping them and logs the kind of the first removal or listing error, and a test pins that a pid belonging to another user (EPERM) keeps its home.
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.
Related: #116, #92
Summary
Closes #116.
A codex app-server's private
CODEX_HOMEis removed inDrop, which akill -9never runs, so homes piled up in$TMPDIR.Each
CodexAppServerBackendnow sweeps, on a detached thread when it is built, thehide-ai-codex-home-<pid>-<nanos>directories whose owner pid is gone.A live pid keeps its homes even if the pid was reused; unparsed names, non-directories, symlinks and other users' entries are never touched.
One sweep removes at most 32 and logs
ai.codex_home.swept(removed, bytes, failed, unreadable, capped, first error kind), which hided now writes toLogs/core.jsonl; no screen changes, so no screenshot.Review
ai.attempt/ai.request.finishednow also land incore.jsonl(1 MB rotating); forward only failures if that is too much.hide-ai/src/codex_home.rssweep/pid_alive- failure path that deletes files; check the keep-on-doubt rules.herdr-core/src/ai.rsDiagnosticLogSink- replaces threeNoopLogSinks;diagnostic!onlytry_sends, and no router or backend here runs underMutex<Runtime>(Settings reader worker, Project Memory write thread).hide-ai/src/codex.rsCodexAppServerBackend::new- spawns the sweep thread and never blocks the caller.Evidence
codex_homeunit tests with fixture roots: a dead owner (a reaped child's pid) is removed and theauth.jsonsymlink target survives; a live owner (own pid), five malformed names, a plain file and a top-level symlink are kept; pid 1 (EPERM) is kept; a limit of 2 over 3 homes removes 2 then 1; an unremovable dead home logsfailed=1withfirst_error=permission denied.ai::testsin herdr-core: an event becomes{"kind", "component": "ai", ...}with absent fields omitted.cargo test -p hide-aiall pass (45 unit, 13 claude_cli, 8 codex_app_server, 3 process_ownership);scripts/verify-cargo.sh lintclean;check-no-workstation-identity.sh,check-capability-readers-off-lock.shpass.scripts/verify-cargo.sh test --no-fail-fastpasses every binary excepthide-agent-hookshook_deadline, a regression onmainfrom 23aca6d (not this change;hide-agent-hooksreacheshide-aithroughhide-memory); CI's rust workspace lane passed on the first push.ai.codex_home.sweptline in a running hided'score.jsonl; the sink is covered by the unit test and the shareddiagnostic!path, not a live daemon run.kill -9of a codex owner followed by a restart; Linux behavior (pid namespaces with a shared/tmpwould make a live owner look dead) is untested.More evidence
First code review found no path that deletes a live owner's home or follows a symlink out of
$TMPDIR(remove_dir_allon rustc 1.97.1 walks withO_NOFOLLOW).Fixed from it: the doc omitted the thread-spawn case of
sweep_failed, and wrongly claimed the CI kill test leaves a home (its owner is a stand-in that never creates one).Second review (of the log routing) found the records lacked the
componentkey other core diagnostics carry; fixed.Follow-ups: 32 or more permanently unremovable homes that sort first would block the sweep on every start; integration tests sweep the developer's real
$TMPDIR(harmless, dead owners only); an orphaned app-server can outlive a killed owner for a few seconds, during which its home may be swept; the context-label plugin'sEventLogcould reuse the newSerializeinstead of its own key=value format.AI tooling: mostly AI tools; the keep-on-doubt rules and the before/after counts were checked against this machine's
$TMPDIR.