fix: reaper meta key for android, evidence-walk cost, atomic writes#47
Merged
Conversation
) P0: - Android session create/destroy now sets/clears REAPER_CLEANUP_PENDING_META_KEY using the same protocol as desktop-linux and browser: set it when a stop fails so a leaked emulator stays reaper-trackable, clear it once cleanup is confirmed complete. Added a test proving a leaked android session is picked up and reaped by reapDeadRunningSessions. P1 performance/reliability: - appendAction no longer does a full recursive readdir+lstat walk of the run directory on every evidence action. The artifact byte total is cached per run directory and only rescanned when a cheap entry-name snapshot (readdir only, filtered the same way the walk is) shows the counted tree actually changed; the journal's own live size is read off the already-open handle instead of being folded into the walk, so uncounted control-file churn (the journal lock, the truncation sentinel) never forces a rescan. Orphaned artifacts written directly to disk are still caught, matching prior behavior. - MCP run-log resource reads now cap the amount pulled into memory, mirroring the screenshot guard: an oversized log is read via tail semantics (last N bytes off an open handle) instead of loading the whole file before redacting secrets from it. - The browser supervisor child-shim's stderr buffer is now bounded to the last 64KB when no newline arrives, instead of growing without limit. P1 simplify: - Hoisted writeFileAtomic (tmp + rename + mode-preserving, cleans up the tmp file on any failure) from agent-installers/atomicFile.ts into core (packages/core/src/paths.ts, exported from index.ts). Used it in core/session.ts writeSession, run.ts writeManifest, config.ts writeConfigFile (all three previously leaked the tmp file on rename failure), agent-installers' own call sites, and the two already-safe evidence.ts call sites (active-pointer publish, truncation-sentinel commit) without touching evidence.ts's concurrency-critical claim/lock code paths otherwise. Validated with bun/vitest test runs and tsc --noEmit across every touched package.
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.
Closes #46.
P0
packages/android/src/session.ts: create/destroy now set/clearREAPER_CLEANUP_PENDING_META_KEYusing the same protocol asdesktop-linux/browser(set on a failed stop so the emulator stays trackable, clear once cleanup is confirmed complete). Addedpackages/android/test/reaper.test.ts, which forces a destroy failure and provesreapDeadRunningSessionsstill finds and cleans up the leaked emulator.P1 — performance & reliability
packages/core/src/evidence.ts:appendActionno longer does a full recursivereaddir+lstatwalk of the run directory on every action. The artifact byte total is cached per run dir and only rescanned when a cheap entry-name snapshot shows the counted tree actually changed (filtered the same way the walk is, so journal-lock/truncation-sentinel churn never forces a rescan). The journal's own live size comes off the already-open handle. Orphaned on-disk artifacts (never referenced by any journaled action) are still caught, matching prior behavior — covered by a new cache/perf test plus the existing cumulative-bytes tests, all passing.packages/mcp-server/src/resources.ts:run-logreads now cap memory use like the screenshot guard at:528— an oversized log is read via tail semantics (last ~1MB off an open handle) instead of loading the whole file before redacting secrets.packages/browser/src/supervisor.ts: the child-shim's stderr buffer is now bounded to the last 64KB when no newline arrives, instead of growing unbounded.P1 — simplify
writeFileAtomic(tmp + rename, mode-preserving, cleans up the tmp file on any failure) fromagent-installers/src/atomicFile.tsintopackages/core/src/paths.ts(next toensureDir), exported from core's index. Used incore/session.tswriteSession,run.tswriteManifest,config.tswriteConfigFile(all three previously leaked the tmp file on rename failure), agent-installers' own call sites, and the two already-safeevidence.tscall sites (active-pointer publish, truncation-sentinel commit) — evidence.ts's concurrency-critical claim/lock logic is otherwise untouched.Validation
bun run typecheck(tsc --noEmit) clean across the workspace.vitest run(rootbun run testequivalent): 78 files, 950 passed / 2 skipped, includingpackages/core,packages/android,packages/browser,packages/mcp-server.sudousage introduced; MCP surfaces untouched w.r.t. privilege.