Skip to content

Fix/fail closed remote mode - #4

Draft
santiagocasas wants to merge 2 commits into
snez:masterfrom
santiagocasas:fix/fail-closed-remote-mode
Draft

santiagocasas wants to merge 2 commits into
snez:masterfrom
santiagocasas:fix/fail-closed-remote-mode

Conversation

@santiagocasas

Copy link
Copy Markdown

Important

This PR depends on #1 and should not be merged until that PR has been merged.

While PR #1 is still open, this PR's diff also includes its commits. I will rebase this branch onto master after PR #1 is merged.

Fixes issue #2.

What this changes

This is a follow-up to #1 and is intended to address #2.

Remote mode used to depend only on in-memory session state. If that state disappeared, or
if the SSH control connection died, a Bash command could fall through and run locally.
That is a risky failure mode because the user asked to work on another machine.

This PR makes remote mode fail closed:

  • remote state is recorded as connecting, connected, or unavailable;
  • the selected host and state are persisted by OpenCode session ID;
  • the matching SSH control socket is checked before every Bash command;
  • a command is replaced with a clear local error when the connection is unavailable;
  • native local file tools remain disabled while remote intent is active;
  • restarting OpenCode no longer silently forgets that the session was remote; and
  • saying local explicitly clears the persisted state and closes the control connection.

It also reuses an already authenticated control socket. Automatic connection attempts use
SSH batch mode, so OpenCode does not get stuck waiting for a password or TOTP prompt it
cannot display. If interactive authentication is needed, the tool returns the exact
control-socket command to run in a normal terminal.

The remote system prompt now also makes it clear that OpenCode's platform and working
directory metadata describe the local machine, not the connected host.

Checks

  • Ran git diff --cached --check.
  • Reviewed connected, unavailable, resumed-session, and explicit-disconnect paths in the
    hook logic.
  • This repository does not currently have an automated test suite, so this still needs
    runtime testing against a real OpenCode session.

AI assistance

The code and this PR description were generated with help from GPT-5.6-Sol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant