Repository navigation
Claim a run's simulator before using it and release it when the run ends - #171
Merged
Merged
Conversation
bitomule
force-pushed
the
worktree-t-mav-157-simulator-targeting
branch
from
December 2, 2026 23:50
06dedb9 to
6331ab3
Compare
A run could take a simulator another project's run was using: with nothing named, the booted fallback picked whatever was booted, and `mav open` wrote its lock only after the launch recipe had rebuilt and relaunched the app. `mav stop` released only a simulator pinned in config.yaml, so a run routed by target_command or the booted fallback stayed locked after it ended. - Claim the simulator atomically (flock on a guard file) as soon as it is resolved: `mav run` before its first step, `mav open` before it boots the simulator or runs the launch recipe. - The booted fallback skips simulators another live run holds and refuses with booted_simulator_held when every booted simulator is held. - Release every lock a run took, by run id, when it stops, fails or its lease expires; a failed standalone open gives its claim back. - While a run holds its simulator, its commands (mav ui included) target it instead of re-running target_command, so an expired cache cannot move the run to another simulator or rewrite its target-command.json. Closes #157
- Hold a standalone session's claim with its worker, and hold it with open's own process while open restarts the probe stream, so the lock never names a dead process mid-session (mav open --no-relaunch, mav run --run). - The stale-target retry keeps the run's claim until it has secured another simulator, and restores it when the retry finds nothing better. - While a run holds a target_command simulator, still re-run target_command once per cache TTL as a ping, so a pool's TTL lease keeps being renewed. - Matrix reservations go through the same guarded claim, and every lock write is atomic (temp file + rename).
bitomule
force-pushed
the
worktree-t-mav-157-simulator-targeting
branch
from
December 3, 2026 00:12
6331ab3 to
3f1e4bf
Compare
This was referenced Dec 3, 2026
Merged
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 #157.
Problem
A run could take a simulator another project was using, relaunch its app on it, and leave it locked:
mav openwrote the simulator lock only after the launch recipe had built, installed and relaunched the app. For the whole build, another project's run saw the simulator as free.mav stopreleased only the simulator pinned in.mav/config.yaml. A run routed bytarget_commandor the booted fallback kept its lock after it ended.mav ui tree) re-rantarget_commandonce its 2-minute cache expired. They could then target a different simulator than the run's own, and rewrite the run'starget-command.jsonwith it.Change
Most of the change is in a new file,
internal/mav/simclaim.go; the hooks incli.go,target.goandmatrix.goare small.mav runclaims it before its first step,mav openbefore booting the simulator or running the launch recipe. The read-decide-write happens under anflockon a guard file next to the lock, and lock files are written by temp file and rename, so two runs racing for one free simulator cannot both win.sim_locked(--forcestill overrides).booted_simulator_held, instead of dispatching to simctl'sbooted.mav opengives its claim back.mav openholds the claim itself while it restarts the probe stream, so the lock never names a dead process mid-session (--no-relaunch,mav run --run <id>)..mav/runs/<id>/simulator.json.target_commandis still re-run once per cache TTL as a ping, so a pool's TTL lease (simpool lease) keeps being renewed. A command asking for another device (--device/--ios) routes throughtarget_commandas before.Runs of the same project (same root) still share a simulator: matrix children, a manual
mav opensession alongside amav run, and concurrentmav runs in one checkout. Protection is between projects, which is what the issue reports.Tests
internal/mav/simclaim_test.goadds 15 tests. With the wiring incli.goandtarget.goreverted tomain, 10 of them fail:With the fix, all 15 pass. The other 5 pass on
maintoo:TestDeviceRequestBypassesTheRunsClaimandTestNoRelaunchOpenKeepsTheSessionClaimAliveguard behaviour the change must not break.TestConcurrentClaimsOnOneSimulatorHaveOneWinner,TestClaimLeavesSameProjectHolderInPlaceandTestClaimTakesOverStaleLocktest the new claim code directly.make check(gofmt,go test ./..., build) passes.Docs
The README precedence section gains a "A simulator another run holds is never taken" section and lists
simulator.jsonin the run state. The skill's lock guidance is updated.