Skip to content

fix: reaper meta key for android, evidence-walk cost, atomic writes#47

Merged
ElbertePlinio merged 1 commit into
mainfrom
fix/reaper-meta-atomic-writes
Jul 19, 2026
Merged

fix: reaper meta key for android, evidence-walk cost, atomic writes#47
ElbertePlinio merged 1 commit into
mainfrom
fix/reaper-meta-atomic-writes

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Closes #46.

P0

  • packages/android/src/session.ts: create/destroy now set/clear REAPER_CLEANUP_PENDING_META_KEY using the same protocol as desktop-linux/browser (set on a failed stop so the emulator stays trackable, clear once cleanup is confirmed complete). Added packages/android/test/reaper.test.ts, which forces a destroy failure and proves reapDeadRunningSessions still finds and cleans up the leaked emulator.

P1 — performance & reliability

  • packages/core/src/evidence.ts: appendAction no longer does a full recursive readdir+lstat walk 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-log reads 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

  • Hoisted writeFileAtomic (tmp + rename, mode-preserving, cleans up the tmp file on any failure) from agent-installers/src/atomicFile.ts into packages/core/src/paths.ts (next to ensureDir), exported from core's index. Used 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) — evidence.ts's concurrency-critical claim/lock logic is otherwise untouched.

Validation

  • bun run typecheck (tsc --noEmit) clean across the workspace.
  • Full vitest run (root bun run test equivalent): 78 files, 950 passed / 2 skipped, including packages/core, packages/android, packages/browser, packages/mcp-server.
  • No sudo usage introduced; MCP surfaces untouched w.r.t. privilege.
  • No overlap with Architecture: deepen local runtime seams #44's lifecycle-centralization work — this only fixes the android reaper protocol and hoists a shared write helper.

)

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.
@ElbertePlinio
ElbertePlinio merged commit b23e92c into main Jul 19, 2026
1 check passed
@ElbertePlinio
ElbertePlinio deleted the fix/reaper-meta-atomic-writes branch July 19, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reliability: android reaper meta key, evidence-walk cost, atomic writes

1 participant