Skip to content

fix(apple-runner): keep runner trees another session may read through a cache rebuild - #4916

Merged
thymikee merged 10 commits into
mainfrom
fix/runner-cache-live-readers-4886
Nov 23, 2026
Merged

thymikee merged 10 commits into
mainfrom
fix/runner-cache-live-readers-4886

Conversation

@thymikee

@thymikee thymikee commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Invariant: while a launch holds a managed runner tree, no clean, rebuild, trim or eviction removes it. Fixes #4886.

  • Each build lands in a fresh Build/Products-<id> directory; the cache metadata points at the current tree.
  • A start records a pending hold on the tree it resolves, under the cache key lock and inside its runner lease lock. The hold is released when that lock exits, after the runner lease is published or the start fails. A dead owner's hold protects nothing.
  • Every deletion path reads live trees from published leases plus pending holds. A symlinked managed key is unlinked, never walked.
  • fix(apple-runner): rebuild the shared runner cache only when a retry also fails #4880's retry rules do not change. No new flag.

Before / after

Two sessions on one keyed cache-<key> (runner-cache-live-readers.test.ts):

  • Base: a rebuild reuses the reader's tree path, and a second rebuild replaces the first rebuild's bytes. Both tests fail.
  • Head: both pass. So do tests for a hold past ten minutes, a dead owner, leases, symlinked keys and eviction.

Validation

At 3a4a2169: apple-runner passes (three load flakes passed on rerun); lint, typecheck, check:command-docs, fallow audit pass. With the hold made a no-op, four tests fail.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.53 MB 6.53 MB +1.8 kB
Package (unpacked) 6.53 MB 6.53 MB +1.8 kB
Package (download) 1.99 MB 1.99 MB +688 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.0 ms 20.6 ms +0.6 ms
CLI --help 44.7 ms 40.2 ms -4.5 ms

@thymikee

Copy link
Copy Markdown
Member Author

Live check: a rebuild while another session is mid-launch

Source cdd9133e (same runtime code as 54bd9f30, which only moves a constant). Worktree CLI node bin/agent-device.mjs with one contained cache AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH=.tmp/runner-4886-live/cache and two daemons with separate --state-dirs.

  • A: iPhone Air (1B89356B…), session live-a, ran open com.apple.Preferences then snapshot -i.
  • B: iPad (A16) (A14201BD…), session live-b, daemon started with AGENT_DEVICE_IOS_CLEAN_DERIVED=1. B started as soon as A's first tree was published, so B's clean and rebuild ran while A was launching from that tree.

iPhone 17 Pro was claimed by a live session from another worktree, so the iPad stood in for it.

18:34:07 A open start                       Build=[]
18:34:26 A builds                           Build=[Intermediates.noindex Products-15a61b11]
18:34:46 B start (A's tree published)       current=Products-15a61b11
18:34:49 B clean: metadata + scratch go     Build=[Products-15a61b11]          <- A's tree kept
18:34:55 B rebuild (fresh dir)              Build=[… Products-15a61b11 Products-c0d9ccfa]
18:35:06 A runner launches                  -xctestrun <cache>/Build/Products-15a61b11/AgentDeviceRunner.env.session-1B89356B….xctestrun
18:35:07 A first snapshot exit 0            Snapshot: 19 visible nodes
18:35:55 B runner launches                  -xctestrun <cache>/Build/Products-14ef67f3/AgentDeviceRunner.env.session-A14201BD….xctestrun
18:38:03 A snapshot                         Snapshot: 64 visible nodes
18:38:04 B snapshot                         Snapshot: 104 visible nodes

AGENT_DEVICE_IOS_CLEAN_DERIVED cleans before every start in B's daemon, so B rebuilt twice (c0d9ccfa, then 14ef67f3). Each clean kept the trees resolved within the grace window.

Directory listing after the run:

./.agent-device-runner-cache.json                      metadata names: Products-14ef67f3
./Build/Products-14ef67f3/AgentDeviceRunner_AgentDeviceRunnerUITests_iphonesimulator27.1-arm64.xctestrun
./Build/Products-14ef67f3/AgentDeviceRunner.env.session-A14201BD-….xctestrun   (B)
./Build/Products-15a61b11/AgentDeviceRunner_AgentDeviceRunnerUITests_iphonesimulator27.1-arm64.xctestrun
./Build/Products-15a61b11/AgentDeviceRunner.env.session-1B89356B-….xctestrun   (A)
./Build/Products-c0d9ccfa/AgentDeviceRunner_AgentDeviceRunnerUITests_iphonesimulator27.1-arm64.xctestrun

On base, B's clean would have deleted Build/Products and rebuilt it in place while A's xcodebuild test-without-building was reading it.

Disk cost. A replaced tree stays until a clean or trim runs after its one-day window, unless a live lease still names it. One trimmed Products tree measured 8.5–8.6 MB (du -sh), so each rebuild costs at most about 9 MB for a day. Keyed caches drop expired trees at the next build's trim. Override paths drop them at the next clean.

Cleanup: both sessions closed, both daemons stopped, device status shows no claims, the cache directory is removed, and both simulators are shut down.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 54bd9f3. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

Correction to the live-check comment's disk-cost note. Since 1c75467, a replaced tree with no live lease stays for at most 3 minutes after its last resolution (4 × RUNNER_STARTUP_TIMEOUT_MS), not a day. It is removed at the next clean or post-build trim. One trimmed tree is still about 9 MB. The live run's behavior is unchanged: all three trees in that run were resolved inside the window.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 1c75467. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 1c75467 is ready to merge. Not blocking, and fine to take or leave: the launch-grace doc in runner-cache-trim.ts says the lease is written once the runner answers, but the code writes it right after spawn; the lease match in runner-cache-trim.ts uses the directory of the session xctestrun, which with --ios-xctest-env-dir is the env dir and not the products tree, so a runner past the 180 s window could lose its tree to another session's clean or trim; and fs.utimesSync with explicit times in runner-cache.ts needs directory ownership and would throw an untyped error on a group-writable cache owned by another user.

The earlier thread on unbounded retention of rebuilt trees is fixed at this commit, since the window is now 180 s plus the lease: #4916 (comment). It can be resolved.

CI is still running. Smoke Tests (ios) and (macos) cover the changed route (runner build, clean, reuse, launch) and must finish green. Coverage and Prose fail on command-doc-generated-blocks.test.ts, which main also fails at the merge base 4075dd1; this PR does not touch that generated block, so the failure looks unrelated and should clear after #4915 lands and this branch is rebased.

Not verified here: the apple-runner suite and mutation checks were not run, the live run was at cdd9133 and not at this commit (the later change only narrows retention), and it is unconfirmed whether --ios-xctest-env-dir launches at all or whether shared non-owned cache directories are supported.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 21, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. Taking the three notes in order:

  1. Lease timing doc: fixed in 75fea74. The lease is written right after xcodebuild is spawned, so the window only has to cover resolution to spawn. The caveat about explicit startup timeouts no longer applies, since the readiness wait comes after the lease.
  2. --ios-xctest-env-dir: no change. The session .xctestrun copied into an env dir keeps its __TESTROOT__-relative product paths, which then resolve against the env dir. A managed cache tree therefore cannot launch through an env dir. The flag goes with an external .xctestrun, and the cache marks those external and never cleans them (external_bad_artifact preserve path).
  3. utimes on a tree another user owns: fixed in 9eee72c. EPERM (or any errno other than ENOENT) now logs a warning and still reuses the tree. ENOENT takes the rebuild path. Both have regressions.

The earlier retention thread is resolved. Local checks at 75fea74: the apple-runner suite passes. One readiness-preflight case is flaky on this host (load average about 100); it also failed 1 in 3 runs on 1c75467. Lint, typecheck and fallow audit are clean.

@thymikee
thymikee force-pushed the fix/runner-cache-live-readers-4886 branch from 75fea74 to ab6e209 Compare November 21, 2026 18:21
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on ab6e209. The verdict and the full list are in the summary comment.

@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 21, 2026
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The earlier review at 1c75467 found no problems, and the root-level xctestrun handling is now fixed at e5b09e6: runner-cache-trim.ts:86-90 implements it with a test, so #4916 (comment) can be resolved. One defect remains.

When the final managed cache key is a directory symlink, a forced clean reaches the trim call at https://github.com/callstack/agent-device/blob/e5b09e6/packages/apple-runner/src/runner-cache.ts#L257, because assertSafeDerivedCleanup returns immediately with no override (lines 326-332). trimDirectory then opens that path with readdir and removes unkept entries through the symlink (runner-cache-trim.ts:145-156). The base calls rmSync on the key path itself, which unlinks the symlink and leaves the target intact. A rebuild can now delete files in the directory the key points to, including files outside the cache. The rule: the final managed key must be checked with lstat before it is walked, and a symlink at that entry must be unlinked so the rebuild creates a real key directory, as the base does. Please add a test with a symlinked key that holds a file outside the cache.

Could runner-cache and the existing runner-lease owner hold a reservation from resolution under the cache lock until lease publication or cancellation, so the filesystem trim consumes the protected paths without depending on a transport readiness timeout that starts after spawn?

Not verified here: tests were not run, and the runner cache clean and trim layouts were compared against main by reading only. Body rules shows as cancelled and one other check is still running. Neither exercises runner code and no failure output exists. Nothing else is known to block merge, so after the symlink fix the remaining step is for both checks to finish.

@thymikee
thymikee force-pushed the fix/runner-cache-live-readers-4886 branch from e5b09e6 to 5eb1381 Compare November 22, 2026 06:05
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. The symlinked-key defect is fixed in 5eb1381, which is rebased on d6767e0.

Symlinked key. cleanRunnerDerivedArtifacts now lstats the key before walking it. A cache key that is a symlink gets unlinked (rmSync without recursive), never walked, as main does, and the rebuild then creates a real key directory. A missing or dangling entry is handled by the same lstat; the old existsSync followed the link. The post-build trim already refused symlinked keys through its realpath check.
New test in runner-cache-live-readers.test.ts: the managed key is replaced by a symlink to a directory outside the cache that holds keep.txt. After an indictment and a forced rebuild, keep.txt is intact, the outside directory holds only keep.txt, and the key is a real directory. It fails on e5b09e6.

Reservation from resolution to lease publication. I looked at this, and it would not be smaller, so I kept the window. A reservation needs:

  • a record written under the cache lock;
  • release on every exit between resolution and the lease (prepare-env failure, port allocation, spawn failure, request cancellation);
  • liveness for a crashed reader (pid and start time, as leases already do), so a dead record cannot pin a tree forever;
  • the trim reading the records.

That is a second lease kind with its own lifecycle. The window reuses the tree's mtime and adds no state.

The window also does not depend on the readiness timeout. launchLocalRunner returns once xcodebuild is spawned, and writeRunnerLease runs right after, before any readiness wait (runner-session.ts). So the window covers only resolution, the session .xctestrun write, port allocation and spawn, which takes seconds. 4 × RUNNER_STARTUP_TIMEOUT_MS (180 s) is just a generous bound on that gap. The session .xctestrun written into the tree in that gap also moves its mtime. If the gap ever grows past the window, the trim doc names the constant to revisit.

Local checks at 5eb1381: apple-runner 991/991, check:command-docs, lint, typecheck and fallow audit all pass.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Two of the earlier findings are fixed at 5eb1381, but one defect remains in the cache eviction path. CI is green, with 23 checks and none failing, and no conflicts are known. Tests were not run here, and the new test is judged only by reading the code. Only the last commit was reviewed line by line, since the rest is unchanged by the rebase.

A session can resolve a tree in key A before it writes its lease. Another session then indicts A, and the cleanup keeps the stamped tree but removes its cache metadata (runner-cache-retention.ts#L106). If a different key then builds successfully in the same platform folder, key eviction runs (runner-artifact.ts#L526-L536). With AGENT_DEVICE_IOS_RUNNER_CACHE_KEEP=1, A is at once eligible. The recheck under the lock treats the missing metadata as last used at epoch zero and finds no lease (runner-cache-retention.ts#L88-L93). It then deletes A even inside the launch grace period. The pending session loses its resolved .xctestrun and products before it can start the runner. The rule to satisfy: whole-key eviction must skip any key whose tree the forced-cleanup liveness check reports as live. Please add a test where a freshly resolved tree survives eviction after indictment removes its metadata and before its lease is written.

Could runner-cache-retention.ts own the resolved-tree stamp and the pre-lease retention rule for both whole-key eviction and directory cleanup, with runner-cache-trim.ts applying the resulting keep set? The key-retention code already owns the age and lease decision, and the transport readiness timeout measures a later phase.

The three open inline threads on duplicate products trees, the stamp on a missing products directory, and the root-level .xctestrun tree no longer apply at this head, so they can be resolved: #4916 (comment), #4916 (comment), #4916 (comment).

Once the eviction path is fixed and CI is green again, the PR is ready for maintainer review.

@thymikee
thymikee force-pushed the fix/runner-cache-live-readers-4886 branch from 5eb1381 to d2ef8f1 Compare November 22, 2026 09:05
@thymikee

Copy link
Copy Markdown
Member Author

Fixed in d2ef8f1. Whole-key eviction now skips a key that holds a live tree: runner-cache-retention.ts#L116. The check runs under the key lock, after the lease check. It uses the rule the clean and the trim use, listLiveRunnerTrees: a live lease, or resolved within the launch window.

Regression: retention test L374 runs with KEEP=1 on a key whose metadata is gone and whose tree was resolved a minute ago with no lease. That key survives. The closest negative, the same key resolved a day ago, is still evicted. The test fails on 5eb1381.

On ownership: I kept the rule in runner-cache-trim.ts, and retention imports it. Moving it into retention would bring back the import cycle Fallow rejected earlier: retention imports the cache lock from runner-cache.ts, and runner-cache.ts's clean needs the rule. It is still one rule and one owner, applied by cleanup, trim and eviction.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The three findings from the earlier review at 5eb1381 (#4916 (comment)) are resolved, and the new early-return guard on the eviction path looks correct at d2ef8f1. Two problems remain, one in code and one in the stated guarantee.

A managed key that is a symlink to a directory with a matching manifest still loses its reader. Session A resolves and stamps its .xctestrun through the symlink, then releases the key lock. Before A publishes its lease, session B forces a rebuild under the same key lock. The forced clean unlinks the symlink at https://github.com/callstack/agent-device/blob/d2ef8f1/packages/apple-runner/src/runner-cache.ts#L252 without checking liveness, and B builds under a different Products directory. A then fails when it reads the old path in prepareXctestrunWithEnv. The rule should be: no code path may return a launch path through a managed key symlink. Please normalize a symlink at the managed key entry under the key lock before reuse or build can return a path through it. Unlink the entry and build in a real key directory, leaving the target untouched.

The guarantee that every automatic cleanup of a managed key keeps the path a session just resolved does not hold for forced clean. Eviction takes the key lock and checks lease and tree first (runner-cache-retention.ts:100), but forced clean bypasses that check at runner-cache.ts:251-253. The new symlink test at runner-cache-live-readers.test.ts:188-204 removes the tree before installing the link, so no reader of a certified tree through the link is exercised. Please make the guarantee true for this route, or narrow the claim, and add a test where the reader holds a certified tree through the link when the forced rebuild runs.

Could runner-cache.ts own both publishing and checking the pre-lease tree protection, with clean, trim and eviction consuming that policy and runner-lease.ts supplying only published readers? Today the policy sits in the transport module, which exists for a post-spawn readiness timeout, while it protects work before spawn.

Not verified here: the tests were not run, and the conclusions come from reading the source. The live two-daemon run in the PR body predates this change. No new live run is needed for the eviction guard alone, but the symlink route above needs a test that reaches the forced rebuild while a reader holds the link.

The only check that did not pass is Body rules, which was cancelled. It lints the PR body and does not touch apple-runner code, and the other 22 checks pass. Please re-run it. No conflicts are known. After the symlink fix and a passing Body rules run, the PR is ready for maintainer review.

@thymikee
thymikee force-pushed the fix/runner-cache-live-readers-4886 branch from d2ef8f1 to e47a2f2 Compare November 22, 2026 10:08
@thymikee

Copy link
Copy Markdown
Member Author

Fixed in e47a2f2, which is rebased on d1ace81.

Symlinked key. Under the key lock, before reuse or build returns a path, a managed key that is a symlink is unlinked and its target left alone (runner-artifact.ts#L599). The key is then built as a real directory. The forced clean uses the same helper, unlinkSymlinkedManagedRunnerKey (L260). An AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH override is never unlinked.
Test L207: the key is a symlink to a certified tree with a matching manifest. A plain start returns a path under a real key directory, and the target's files are unchanged. It fails on d2ef8f1.

Guarantee. The PR promises that automatic cleanup (rebuild after an indictment, post-build trim, key eviction) never removes a tree a live session resolved. AGENT_DEVICE_IOS_CLEAN_DERIVED is an explicit user action: it replaces the key's metadata and scratch, and a symlinked key becomes a real directory. The body now says so.

Ownership. Unchanged. The previous round asked for retention.ts and this one for runner-cache.ts. Both moves bring back the cycle Fallow rejected. Today there is one rule (listLiveRunnerTrees) with one owner.

Local checks: apple-runner 993/993 (readiness-preflight flakes under host load and passed on rerun), check:command-docs, lint, typecheck and fallow audit.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The earlier findings from d2ef8f1 are fixed at e47a2f2, and one defect remains in the new live-reader check. Tests were not run here, and the two-daemon live run in the PR body predates both fixes.

A session can still lose its runner tree during a rebuild. runner-cache-trim.ts:74 treats a tree as live when its mtime is under 180,000 ms old or a published lease points at it. Session A resolves a managed artifact and releases the key lock before it prepares its per-session plist (runner-artifact.ts:513-530, runner-session.ts:288-320). A publishes its lease only after spawn (runner-session.ts:328-388). The plutil conversion has no timeout (runner-artifact-env.ts:145-162), and the start budget is ten minutes (runner-start-budget.ts:35). If the conversion stalls for three minutes, the tree stops changing. Session B on a second device with the same key can then start the forced rebuild. listLiveRunnerTrees does not list A, and cleanRunnerDerivedArtifacts deletes the tree. A then loses its runner products mid-launch, and it can fail to publish its overlay or reach xcodebuild without them. The cleanup promise in configuration.md:153 also fails here. The rule the code must satisfy: while a launch holds a managed tree, no deletion path may remove it. Record the launch's pending reference to the exact tree under the key lock. Keep it until the published runner lease takes over, the start fails, or the owner is proven dead. Every cache deletion path should read live trees through that one query.

Could runner-lease.ts own this pending reference as part of the existing launch lease lifecycle, with runner-cache-trim.ts reading it next to published leases? The directory mtime only approximates a live reader, and its window does not bound plist preparation.

The only check that does not pass is Body rules, which was cancelled. It lints the PR body and does not exercise packages/apple-runner or the docs, so it looks unrelated. The other 23 checks pass. No review threads are open. Before merge, the cancelled Body rules check needs a re-run. Not verified here: a live run that stalls the plist conversion while a second session rebuilds.

thymikee and others added 2 commits November 22, 2026 21:28
… a cache rebuild

Each runner build lands in a fresh products directory, and a clean or the
post-build trim keeps every tree resolved within the reader grace window or
named by a live runner lease. An indicted or forced rebuild no longer deletes
files a concurrent session is launching from (#4886).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Breaks the runner-cache -> runner-cache-trim import cycle: the trim module
owns the live-tree rule, and runner-cache-retention reads the window from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thymikee and others added 8 commits November 22, 2026 21:28
A live runner lease already keeps a tree a running runner uses, so the
resolution stamp only has to cover the launch before the lease exists.
Replaced trees now outlive their last resolution by four runner startup
timeouts instead of a day, so a rebuild loop no longer piles up copies.
Key eviction keeps its own one-day rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tamp

A tree that vanished between certification and the resolution stamp now
takes the no-usable-cache path (typed tree_missing decision) instead of
failing the start with ENOENT. A tree the user cannot stamp, such as one
another user owns, is still reused: the session's own .xctestrun written
into it moves its mtime anyway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A build's products directory sits under Build/, so an .xctestrun at the
cache root (a legacy or foreign layout) is no tree: a clean removes it as
main did, and it no longer turns the post-build trim into a no-op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…king it

A forced clean of a managed key that is a directory symlink walked and
removed the files it points at. Like main's rmSync, the clean now unlinks
the symlink, so the rebuild creates a real key directory and nothing
outside the cache is touched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…still read

An indictment removes a key's metadata but keeps a tree a launch resolved
and has not leased yet. Whole-key eviction then saw the key as idle since
epoch and deleted it inside the launch window. Eviction now applies the
same live-tree rule as the clean and the trim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he key

Under the key lock, before reuse or build returns a path, a managed key
that is a symlink is unlinked (its target untouched) and the key is built
as a real directory. The forced clean shares the same unlink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…over

The mtime window did not bound plist preparation. A start now records a
pending hold on the exact tree it resolves, under the cache key lock and
inside its runner lease lock; the hold is released when that lock exits,
after the runner lease is published or the start failed, and lapses with
a dead owner. Every deletion path reads live trees from published leases
plus pending holds. The resolution stamp and the time window are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the fix/runner-cache-live-readers-4886 branch from e47a2f2 to 3a4a216 Compare November 22, 2026 20:45
@thymikee

Copy link
Copy Markdown
Member Author

Fixed in 3a4a216, rebased on a4f2dca. The mtime window and the resolution stamp are gone.

  • Hold: a start records a pending hold on the exact tree it resolves. It is written under the cache key lock, inside the device's runner lease lock (runner-artifact.ts#L643 → runner-lease.ts#L602).
  • Release: withRunnerLeaseLock releases the hold when the lock exits (runner-lease.ts#L221). By then the start has published its runner lease or failed, so the failure path needs no separate release. runner-session.ts is unchanged. A cache prewarm holds no lease lock and records nothing.
  • Dead owner: a hold whose owner is proven dead (pid plus start time) protects nothing, and its record is removed (runner-lease.ts#L651).
  • One query: listActiveRunnerLeaseArtifacts returns published leases plus live holds (L641). listLiveRunnerTrees (clean, indictment rebuild, trim) and eviction both read it. The eviction gate I added earlier is superseded, so retention is back to main apart from one doc line.

Tests:

  • L84: a hold survives 10 minutes on a fake clock with the tree's mtime an hour old, while a second device force-rebuilds the key. Once the lock is released, the tree goes.
  • L109: a dead owner's hold does not keep the tree.
  • With holdRunnerTreeForLaunch made a no-op, four hold tests fail.

Docs: configuration.md#L153.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 3a4a216

Since the review of e47a2f2: 1 new · 0 still open · 0 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/apple-runner/src/runner-cache-trim.ts:51 🆕 A lease's cacheKey is ignored by listLiveRunnerTrees, so a rebuild deletes a running runner's tree

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (a4f2dcad0eae).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 3a4a216. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

The earlier finding from the review of e47a2f2 is fixed at 3a4a216, and no new problems were found. The runner tree a second session may read is now kept through a cache rebuild, because the hold is taken on the managed tree before plist preparation. CI is green, with all 23 checks passing, and no conflicts are known. Nothing else must happen before merge.

The resolved thread on the env-dir .xctestrun (#4916 (comment)) does not apply: the file keeps product paths relative to the env dir, and the launch hold already names the managed tree.

Not verified here: tests were not run, and the regression test was judged by reading runner-cache-live-readers.test.ts. Not verified here: the __TESTROOT__ form of a managed .xctestrun against a real cache key. Not verified here: a live run that stalls plist preparation while a second session rebuilds. The hold is lock-scoped state, so the unit route through ensureXctestrunArtifact and withRunnerLeaseLock covers it.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 22, 2026
@thymikee
thymikee merged commit 2953284 into main Nov 23, 2026
23 checks passed
@thymikee
thymikee deleted the fix/runner-cache-live-readers-4886 branch November 23, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apple-runner: a cache rebuild must not delete a runner artifact other sessions are reading

1 participant