fix: name remote sessions after the workspace - #1037
Merged
janicduplessis merged 5 commits intoSep 24, 2026
Merged
Conversation
Every worktree of a repository resolves the same project label, so remote runs from two worktrees both named their agent-device session, tenant and run `stim-<label>` and their EAS session the same. agent-device keeps one local connection per session name, so the second worktree's connect took over the first's connection. resolveRemoteContext now suffixes the label with a random UUID, stored as remoteLabel in the workspace state so later runs reuse it. A workspace that already records a remote session keeps the plain label until that session ends, because the remote agent-device session stays bound to the name it was opened under. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Open
6 tasks
Resolve the node:fs import in device-remote.ts: main moved JSON reads to readJsonObject and dropped readFileSync; this branch adds randomUUID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Description
Remote sessions were named from
projectShortcut, which is the app directory's basename, so every worktree of a monorepo app got the same name (stim-tlon-mobile) for both the EAS session (ownedSessionName) and the agent-device session and profile (sessionNameFor).agent-device stores remote connection state per session name (
~/.agent-device/remote-connections/<session>.json). With two worktrees on--remote easor--remote proxyat once, the second one'sconnect --forcerewrites the connection the first is using. That part is inferred from agent-device's layout. What was observed on stock 1.8.0 is every worktree's session and connection file namedstim-tlon-mobile.Solution
resolveRemoteContextnow derives the name from the workspace root instead of taking a label from the caller:ownedDeviceLabel(root), the same worktree-plus-app label local simulators and AVDs use, followed byworkspaceId(root), the 16-hex path hash local simulators fall back to when their name is taken. For example,stim-tlon-wt2-tlon-mobile-<hash>. The name shows which worktree owns a session in the EAS dashboard, is the same on every run, and needs no stored state. The hash is always added, because unlike local simulators there is no cheap way to check whether a remote name is already in use, and two worktrees or repos can share a folder name.Trade-off: a remote session opened by an older Stim under the plain
stim-<label>name is not carried over. Runstim stopbefore upgrading.--remote eas: after an upgrade mid-session,stim stopstill ends the old EAS session by its recorded id.--remote proxy: the first run after an upgrade rewrites the profile under the new name, so neither its pre-connectclosenorstim stopreleases an agent-device session left under the old name. That session has to be closed by hand under its old name, and until then the daemon may report the device as in use. This comes from reading the code and was not reproduced against a real daemon.Test plan
pnpm test packages/stim-cli/src/__tests__/device-remote.test.ts -t "names its own": two workspaces whose app directories are both namedapp(a/app,b/app) get different agent-device session and EAS names, of the formstim-app-<16 hex>.main:format:check,lint,build,typecheck,knip,pnpm test(154 files, 4710 passed, 18 skipped),test:runtime.[a-z0-9-]) and are shorter, but have not been run against EAS again.--remote proxyagainst a real daemon (unit tests only), and Android.A note for anyone reproducing the two-worktree run: an EAS agent-device lease went inactive after roughly a minute without a command. The next command then allocated a new lease that the session refused (
Lease does not match session owner), and the session was unusable from then on. That also happens with one worktree and is unrelated to this change.