Skip to content

Stop mav open --no-relaunch stacking a log stream per call - #119

Merged
bitomule merged 2 commits into
mainfrom
fix/open-log-stream-leak
Sep 21, 2026
Merged

bitomule merged 2 commits into
mainfrom
fix/open-log-stream-leak

Conversation

@bitomule

Copy link
Copy Markdown
Owner

The probe-logs log stream is supposed to outlive open — it captures for the whole run and is reaped by mav stop or the run worker. That is not the bug. The bug is that one path started a new one without stopping the old.

Plain mav open is fine: it records the run it supersedes and stops it on the way in, so exactly one stream is ever alive.

mav open --no-relaunch was not. It has no bound run and reuses the current one, so nothing supersedes it — and the stopProbeLogs call that would have killed the previous stream was wrapped in if hasBoundRun, contradicting the comment directly above it ("This applies regardless of --no-relaunch ... must always be stopped first"). Every invocation left another live process behind, reaped only when the lease was released.

Ablation

TestRepeatedOpenLeavesOneLogStreamAlive runs four mav open --no-relaunch against a hermetic fake xcrun (the existing writeFakeXcrun shim, where log stream execs a real sleep), and counts the recorded probe-logs PIDs that answer kill -0.

Fix reverted (git stash of cli.go only, test unchanged):

after open 1: [1230]
after open 2: [1230 14314]
after open 3: [1230 14314 27618]
after open 4: [1230 14314 27618 41407]
--- FAIL: after 4 opens, 4 log streams are alive

Fix re-applied:

after open 1: [72864]
after open 2: [91284]
after open 3: [10674]
after open 4: [28613]
--- PASS

Plain mav open was measured the same way and stays at 1 on both sides — no regression there.

The change

The hasBoundRun guard is gone. On a fresh run nothing is recorded yet, so the call is a no-op there.

The test owns its own simulator UDID rather than the shared "SIM": the sim lock is a global file keyed by UDID, so sharing it makes a second open fail with sim_locked for reasons that have nothing to do with log streams.

go build ./... and go test ./... -count=1 green.

https://claude.ai/code/session_018Qmew9oEQ6frPLSrE8XUm5

The probe-logs `log stream` is meant to outlive `open`: it captures for
the whole run and is reaped by `mav stop` or the run worker. Plain `mav
open` holds to that -- it records the run it supersedes and stops it on
the way in, so exactly one stream is ever alive.

`--no-relaunch` did not. It has no bound run and REUSES the current one,
so nothing superseded the old stream, and the stopProbeLogs call that
would have killed it was guarded by hasBoundRun -- against what its own
comment already said ("this applies regardless of --no-relaunch ... must
always be stopped first"). Every invocation left another live process,
reaped only when the lease was released.

Measured, four `mav open --no-relaunch` in a row, counting live recorded
probe-logs PIDs:

  before  1, 2, 3, 4
  after   1, 1, 1, 1

Plain `mav open` measured the same way stays at 1 on both sides.

The guard is gone; on a fresh run there is nothing recorded, so the call
is a no-op there. The test owns its own simulator UDID because the sim
lock is a global file keyed by UDID and the shared "SIM" makes a second
open fail with sim_locked for reasons that have nothing to do with logs.

Claude-Session: https://claude.ai/code/session_018Qmew9oEQ6frPLSrE8XUm5
goto_tree_cache_test.go belongs to work in flight in another branch and
has nothing to do with the log-stream leak. It reached the previous
commit through a stale staged entry, not deliberately. Removed from the
branch only; the file on disk is untouched.

Claude-Session: https://claude.ai/code/session_018Qmew9oEQ6frPLSrE8XUm5
@bitomule
bitomule merged commit ad6c66e into main Sep 21, 2026
1 check passed
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.

1 participant