Skip to content

[Bug]: orca environment rm does not stop the connection — the running app keeps reconnecting to the removed environment until restart #20995

Description

@GodCC6

Operating system

macOS

Orca version

1.4.204 (both machines)

Details

Short summary

Correction (see comment): the GUI trash button is not affected — runtimeEnvironments:remove does tear the transport down. This is orca environment rm only, because the CLI is a separate process that rewrites the store file and never reaches the running app. Root cause and a suggested fix are in that comment.

orca environment rm — and the trash button in Settings → Remote Orca Servers — orca environment rm removes the environment from orca-environments.json, but the running client keeps the live WebSocket to that endpoint and re-establishes it when the connection drops. The removal only takes effect after the client app restarts. Meanwhile orca environment list reads the persisted file, so the removed server is invisible while it is still connected; the only way to see the discrepancy is lsof/netstat on port 6768.

What happened

Two machines, A and B, each running Orca as both client and server. A had two saved environments pointing at B's runtime over two different network paths (a Tailscale address and a WireGuard overlay address). I removed the overlay one on A.

  1. T+0 — orca environment rm --environment <name> returned ok: true with the removed record. orca environment list on A then showed only the Tailscale environment.
  2. T+6min — A still had an established outbound connection to ws://<overlay-ip>:6768, source port P1.
  3. T+10min — B's Orca was restarted for an unrelated reason, forcing both sides to re-establish.
  4. After that, A's connection to the removed endpoint came back with a new source port P2, numerically adjacent to the source port of the surviving Tailscale connection — i.e. both were opened in the same batch. A new source port means a new connection: the removed environment actively reconnected ~10 minutes after it was deleted from disk.

Control

B's Orca main process started after I had removed the mirror-image environment on B's side. B therefore booted with only one environment in memory, and it opened zero connections over the overlay path. Same build, same topology; the only difference is whether the environment was in memory when it was removed.

The endpoint is not on disk any more

I grepped the whole ~/Library/Application Support/orca tree for the overlay address. The only configuration-shaped hit is profiles/local-default/orca-data.json → .sshTargets[N].host, which belongs to the SSH-targets feature — not a WebSocket endpoint, not port 6768. orca-environments.json contains only the surviving endpoint. So ws://<overlay-ip>:6768 exists nowhere on disk, and the connection can only come from in-process state.

Note for anyone reproducing this: other files in that tree matched the address as well — terminal-history/*/checkpoint.json, ai-vault/session-parse-cache.json, agent-hooks/last-status.json. Those are recorded terminal scrollback of my own commands, not configuration. Judge a hit by its path inside the JSON, not by the file name.

How can we reproduce it?

  1. Pair client A to server B's runtime twice, over two addresses that are both reachable. You now have two environments whose runtimeId is identical.
  2. On B: lsof -nP -iTCP:6768 shows connections arriving over both paths.
  3. On A: orca environment rm --environment <the second one>. Confirm orca environment list no longer lists it.
  4. lsof again on B: the connection over the removed path is still established.
  5. Force a reconnect (restart B's Orca, or drop the link). The removed environment comes back with a new source port.
  6. Restart A's Orca: only now is it actually gone.

Anything else that might help

Why this is worth fixing beyond tidiness:

  • orca environment list is the supported way to see what is saved, and it disagrees with what is connected. There is no in-app way to notice the difference.
  • Someone who removes a server to stop it reaching their machine will reasonably believe it stopped.
  • It compounds the duplicate-workspace behaviour: after removing the redundant environment nothing visibly changes until a restart, which invites people to keep removing things looking for an effect.

Suggested fix: when an environment is removed, close its transport and drop it from the in-memory reconnect set, so environment list and the live connection agree.

No endpoint credentials or pairing material are included in this report.

Activity

  1. added
    os:macos
    on Sep 16, 2026
  2. GodCC6 commented on Sep 16, 2026

    @GodCC6
    Author

    Correction to my own report, and a much sharper root cause after reading the source.

    What I got wrong: I wrote that this also affects "the trash button in Settings → Remote Orca Servers". That is not true, and I had not tested it. The IPC handler runtimeEnvironments:remove in src/main/ipc/runtime-environment-connectivity-handlers.ts does tear the transport down — it calls invalidateTransport(removed.id) and closeLegacySelectorTransport(...) right after removeEnvironment(...). The GUI path is fine. Sorry for the noise.

    What the bug actually is: orca environment rm is CLI-local and never reaches the running app.

    ENVIRONMENT_HANDLERS['environment rm'] in src/cli/handlers/environment.ts does exactly one thing:

    const removed = redactRuntimeEnvironment(removeEnvironment(getDefaultUserDataPath(), selector))

    and removeEnvironment in src/shared/runtime-environment-store.ts is a pure store rewrite — read the file, filter out the entry, write it back. The CLI is a separate process, so nothing in the running desktop app is notified.

    Meanwhile the app keeps the connection in a module-level map in src/main/ipc/runtime-environment-request-connections.ts:

    • sharedControlConnections is keyed by environmentId, and each entry is a RemoteRuntimeSharedControlConnection constructed with the PairingOffer captured when it was created.
    • Its reconnect loop consults only isManuallyDisconnected() and isCapabilityPaused(). It never re-reads the environment store, so "this environment no longer exists" is not something the connection can find out.

    That is exactly what I measured from the outside: the removed environment kept its socket and re-established it with a fresh source port after the peer restarted, while a client process that booted after the removal opened nothing on that path (it never built the connection in the first place).

    Suggested fix, reusing what is already there. The connection already has two "should I stay down?" predicates injected at construction. A third one of the same shape — "is this environment still present in the store?" — would let the reconnect path stop on its own, without a file watcher and without a new CLI→app channel. It only needs to be consulted on the reconnect path, which is backoff-scheduled and not hot.

    I am working on a PR for this and will link it here.

  3. changed the title [-][Bug]: Removing a saved remote server does not close or stop its connection — the client keeps reconnecting until restart[/-] [+][Bug]: `orca environment rm` does not stop the connection — the running app keeps reconnecting to the removed environment until restart[/+] on Sep 16, 2026
  4. GodCC6 commented on Sep 16, 2026

    @GodCC6
    Author

    PR is up: #21048

    It takes the second option from the analysis above — the app closes the socket itself rather than only declining to reconnect — because the reported symptom is the connection that is still open right now, and a disconnect might not come for hours.

    The mechanism turned out to need no new machinery: every open shared-control socket already runs a 10s liveness heartbeat, which is the only level-triggered hook such a socket has. It now checks whether the environment is still in the store and, when it is gone, hands teardown to the same invalidateRuntimeEnvironmentTransport that runtimeEnvironments:remove already uses, so the CLI and GUI removal paths converge. The reconnect scheduler gained a matching guard for the case where a disconnect beats the tick.

    Measured on macOS: the socket closes 10030 ms after the store is rewritten — one liveness interval.

    The same end-to-end test fails on main for the right reason, which is what makes the fix a fix rather than a green test:

    × drops the live socket the desktop app was holding and never reconnects
      Timed out waiting for the removed environment to lose its socket (open=1)
    

    That run boots a real Electron main process and rewrites the store from a separate process, which is what orca environment rm is.

    Two things I deliberately left out of the PR, mentioned here so they are not lost:

    • For a removed environment, RuntimeHostStatusOwner.complete() calls markEnvironmentUsed, which throws and skips settleWaiters(), leaving any refresh() waiter hanging until its own timeout. Happy to open a separate issue if that is useful.
    • orca environment rm still diverges from the GUI path in other ways — it does not clear capability evidence or the manual-disconnect mark, does not retire browser partition storage, and has no equivalent of the GUI's refusal to remove the active server. Also separate.
  5. AmethystLiang commented on Sep 17, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

  6. AmethystLiang commented on Sep 17, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

  7. added
    bug
    orca-remote-server
    on Sep 19, 2026
  8. added theissue type on Sep 19, 2026
  9. added 3 commits that reference this issue on Dec 1, 2026
    8108994
    3ce66f7
    caf9428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugorca-remote-serveros:macos

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions