Repository navigation
fix(server): device_close with shutdown after a plain close turns the device off - #48437
juliusmarminge wants to merge 2 commits into
Conversation
…e device on (#48424) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… device off A close without shutdown retires the thread's session, so a later close with shutdown matched nothing and reported success while the device stayed booted and kept its Simlock lease. Close now shuts down the booted device it names when the thread has no session left, and fails when another thread still has that device open. The MCP device_close tool finds the device's host the same way. Fixes #48424 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — A shutdown request now turns off a named device even after its session was already closed. Existing host-disambiguation checks and a guard against shutting down another thread’s device limit the exposure. You can add or adjust custom eligibility rules. Learn more. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
The automated pipeline stopped on this pull request and will not merge it: the fix is written and reviewed, but proving it needs something no worker has:
It stays open for a person to finish or close. |
If an agent closed a device without shutting it down and then called
device_closeagain withshutdown: true, the call reported success but did nothing. The device stayed booted and kept its Simlock lease until the lease expired. Now that second close turns the device off. If another thread still has the device open, the call returns an error.DeviceService.close: whenshutdownis set, adeviceIdis named and the thread has no session left for it, the service shuts down that device if it is booted on the host. If another thread still has a session on the device, it fails withDeviceHostUnavailableErrorand does not turn it off.device_close: when the thread has no session for the device, the handler finds the device's host from the device list withlocateDevice, so a Simlock or SSH device is shut down on its own host and not looked up on the local one.Fixes #48424
Reproduction on main
Commit: origin/main 9ba2879. Real server:
T3CODE_DEV_SEED=0 node apps/server/src/bin.ts --base-dir <fresh dir> --port <free> --no-browser, driven over its WebSocket RPC with a scratch script (sign-in as in scripts/scenarios/t3.ts rpcClient). Steps: (1) server.updateSettings with simlockDeviceHostsEnabled: true and one Simlock host (the real shared gateway, maxLeases: 1, maxLeaseMinutes: 30); device.configure {enabled: true}. (2) device.open a Pixel 9 (android) on that host for thread A: it returned a session and the device showed booted: true. (3) device.close {threadId A, deviceId, shutdown: false}: success, the session was removed and the device was still booted (this part is intended). (4) device.close {threadId A, deviceId, shutdown: true}: success with no error, but the device was still booted: true and no lease release reached Simlock. (5) device.open of another Android device for thread B failed with DeviceHostUnavailableError "Pool is limited to 1 device at once. Close one in the Device panel first." Cleanup: device.shutdown (the Device panel's power-off) released the lease (booted list empty), then the server was stopped. The MCP device_close handler is a thin wrapper over the same DeviceService.close, so the agent tool behaves the same way. A failing unit test in DeviceService.test.ts (open → close(shutdown:false) → close(shutdown:true) → expects a /shutdown request and booted:false) fails on main: no /shutdown request is sent.Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/device/DeviceService.test.ts -t "close with shutdown follows"without the fix: 1 failed (repro confirmed)vp test run src/device/DeviceService.test.ts src/mcp/McpDeviceToolkit.test.ts(apps/server) with the fix: 110 passedvp test run src/device/DeviceService.test.ts -t closeafter adding the error-path test: 20 passedvp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (3 files, 98 tests) all passNot in this change
device_closehandler still returns{}whenshutdown: truenames a device that is not booted on any host; it reports no 'already off' state.closewithshutdown: trueand nodeviceId(close every device for the thread) still does nothing when the thread has no sessions; without a device id there is nothing safe to shut down.Who did the work
Run by the t3code factory in T3 Code.