Repository navigation
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const entryScope = yield* Scope.make("sequential"); | ||
| const agentForwarderProcess = | ||
| input.resolvedTarget.forwardAgent === true | ||
| ? yield* runWithSshAuth({ |
There was a problem hiding this comment.
🟠 High src/tunnel.ts:1506
Password-authenticated hosts cannot use agent forwarding: when the SSH child exits with Permission denied before emitting AGENT_FORWARD_READY_MARKER, startSshAgentForwarder returns the generic readiness error without stderr, so isSshAuthFailure cannot detect the authentication failure and runWithSshAuth never prompts for a password. Make the readiness wait observe the child’s stderr/exit failure and propagate an authentication error that isSshAuthFailure can recognize.
🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/ssh/src/tunnel.ts around line 1506:
Password-authenticated hosts cannot use agent forwarding: when the SSH child exits with `Permission denied` before emitting `AGENT_FORWARD_READY_MARKER`, `startSshAgentForwarder` returns the generic readiness error without stderr, so `isSshAuthFailure` cannot detect the authentication failure and `runWithSshAuth` never prompts for a password. Make the readiness wait observe the child’s stderr/exit failure and propagate an authentication error that `isSshAuthFailure` can recognize.
Evidence trail:
Reviewed commit cb58d9b0: packages/ssh/src/tunnel.ts:1068-1094, 1506-1515; packages/ssh/src/auth.ts:207-217. Git commands: `git show cb58d9b0 -- packages/ssh/src/tunnel.ts`; `git grep -n -C 5 'startSshAgentForwarder\|isSshAuthFailure\|runWithSshAuth' cb58d9b0 -- packages/ssh/src`
| if [ "$FORWARD_AGENT" = "1" ] && [ "$REMOTE_MANAGED" = "managed" ] && [ -n "$REMOTE_PID" ]; then | ||
| kill "$REMOTE_PID" 2>/dev/null || true | ||
| wait_for_pid_exit "$REMOTE_PID" | ||
| REMOTE_PID="" | ||
| REMOTE_PORT="" | ||
| REMOTE_MANAGED="" | ||
| fi | ||
| if [ -z "$REMOTE_PORT" ]; then | ||
| REMOTE_PORT="$(pick_port)" || true | ||
| if [ -z "$REMOTE_PORT" ]; then | ||
| printf 'Failed to find an available port on the remote host. Ensure node is available on PATH.\\n' >&2 | ||
| exit 1 | ||
| fi | ||
| nohup env T3CODE_NO_BROWSER=1 "$RUNNER_FILE" serve --host 127.0.0.1 --port "$REMOTE_PORT" --base-dir "$DEFAULT_SERVER_HOME" >>"$LOG_FILE" 2>&1 < /dev/null & | ||
| if [ "$FORWARD_AGENT" = "1" ]; then | ||
| FORWARDED_SSH_AUTH_SOCK="$(cat "$AGENT_SOCKET_FILE" 2>/dev/null || true)" | ||
| if [ -z "$FORWARDED_SSH_AUTH_SOCK" ] || [ ! -S "$FORWARDED_SSH_AUTH_SOCK" ]; then | ||
| printf 'SSH agent forwarding was requested, but its remote socket is unavailable.\n' >&2 | ||
| exit 1 | ||
| fi | ||
| SSH_AUTH_SOCK="$FORWARDED_SSH_AUTH_SOCK" nohup env T3CODE_NO_BROWSER=1 "$RUNNER_FILE" serve --host 127.0.0.1 --port "$REMOTE_PORT" --base-dir "$DEFAULT_SERVER_HOME" >>"$LOG_FILE" 2>&1 < /dev/null & |
There was a problem hiding this comment.
🟠 High src/tunnel.ts:622
When FORWARD_AGENT=1 and the existing server is managed, this block stops the working server before validating AGENT_SOCKET_FILE; if the socket is unavailable, the script exits and leaves T3 stopped. Validate the forwarded socket before killing REMOTE_PID so this failure preserves the existing server.
+if [ "$FORWARD_AGENT" = "1" ]; then
+ FORWARDED_SSH_AUTH_SOCK="$(cat "$AGENT_SOCKET_FILE" 2>/dev/null || true)"
+ if [ -z "$FORWARDED_SSH_AUTH_SOCK" ] || [ ! -S "$FORWARDED_SSH_AUTH_SOCK" ]; then
+ printf 'SSH agent forwarding was requested, but its remote socket is unavailable.\n' >&2
+ exit 1
+ fi
+fi
if [ "$FORWARD_AGENT" = "1" ] && [ "$REMOTE_MANAGED" = "managed" ] && [ -n "$REMOTE_PID" ]; then
kill "$REMOTE_PID" 2>/dev/null || true
wait_for_pid_exit "$REMOTE_PID"
@@
if [ "$FORWARD_AGENT" = "1" ]; then
- FORWARDED_SSH_AUTH_SOCK="$(cat "$AGENT_SOCKET_FILE" 2>/dev/null || true)"
- if [ -z "$FORWARDED_SSH_AUTH_SOCK" ] || [ ! -S "$FORWARDED_SSH_AUTH_SOCK" ]; then
- printf 'SSH agent forwarding was requested, but its remote socket is unavailable.\n' >&2
- exit 1
- fi
SSH_AUTH_SOCK="$FORWARDED_SSH_AUTH_SOCK" nohup env T3CODE_NO_BROWSER=1 "$RUNNER_FILE" serve --host 127.0.0.1 --port "$REMOTE_PORT" --base-dir "$DEFAULT_SERVER_HOME" >>"$LOG_FILE" 2>&1 < /dev/null &🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/ssh/src/tunnel.ts around lines 622-641:
When `FORWARD_AGENT=1` and the existing server is managed, this block stops the working server before validating `AGENT_SOCKET_FILE`; if the socket is unavailable, the script exits and leaves T3 stopped. Validate the forwarded socket before killing `REMOTE_PID` so this failure preserves the existing server.
Evidence trail:
packages/ssh/src/tunnel.ts:560-616, 622-640, commit cb58d9b0. The reuse path preserves a ready managed server, then the forwarding-specific block kills it before socket validation; socket failure exits afterward.
There was a problem hiding this comment.
🟠 High
t3code/packages/ssh/src/tunnel.ts
Line 78 in cb58d9b
remoteStateKey is identical for forwarded and non-forwarded connections, so their launch scripts share the same remote state and one connection can kill or stop the server used by the other. Include forwardAgent in the state key, for example by hashing targetConnectionKey(target).
🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/ssh/src/tunnel.ts around line 78:
`remoteStateKey` is identical for forwarded and non-forwarded connections, so their launch scripts share the same remote state and one connection can kill or stop the server used by the other. Include `forwardAgent` in the state key, for example by hashing `targetConnectionKey(target)`.
Evidence trail:
Reviewed commit cb58d9b0: packages/ssh/src/command.ts:72-83; packages/ssh/src/tunnel.ts:488-663, 747-760, 1493-1543, 1757-1839. Verify with `git show cb58d9b0 -- packages/ssh/src/command.ts packages/ssh/src/tunnel.ts` and `git grep -n 'remoteStateKey\|targetConnectionKey' cb58d9b0 -- packages/ssh/src`.
| fi | ||
| rm -f "$SOCKET_NEXT" | ||
| } | ||
| trap cleanup_forwarded_socket EXIT HUP INT TERM |
There was a problem hiding this comment.
🟡 Medium src/tunnel.ts:481
The HUP, INT, and TERM traps clean up SOCKET_FILE but do not terminate the script, so the remote forwarder resumes its unconditional while loop after disconnect and leaves a shell/sleep process behind. Repeated desktop reconnects can accumulate these processes and consume the user's process or session quota; exit from the signal handler after cleanup while retaining the EXIT cleanup trap.
-trap cleanup_forwarded_socket EXIT HUP INT TERM
+trap cleanup_forwarded_socket EXIT
+trap 'cleanup_forwarded_socket; exit 0' HUP INT TERM🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/ssh/src/tunnel.ts around line 481:
The `HUP`, `INT`, and `TERM` traps clean up `SOCKET_FILE` but do not terminate the script, so the remote forwarder resumes its unconditional `while` loop after disconnect and leaves a shell/`sleep` process behind. Repeated desktop reconnects can accumulate these processes and consume the user's process or session quota; exit from the signal handler after cleanup while retaining the `EXIT` cleanup trap.
Evidence trail:
Repository commit cb58d9b: `packages/ssh/src/tunnel.ts:461-485` (forwarder traps and loop); `packages/ssh/src/tunnel.ts:1000-1100` (forwarder process launch); `packages/ssh/src/tunnel.ts:1342-1358` and `1616-1655` (scope/process cleanup). POSIX trap specification: https://pubs.opengroup.org/onlinepubs/009604399/utilities/trap.html. POSIX shell signal and loop semantics: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
| exitCode: Number(exitCode), | ||
| }).pipe( | ||
| Effect.andThen( | ||
| tunnelEntry.process.kill({ |
There was a problem hiding this comment.
🟡 Medium src/tunnel.ts:1601
When the agent-forwarding process exits after the tunnel is established, the observer only kills tunnelEntry.process; the managed remote T3 process and its pid/port/managed state are left running with an invalid forwarded socket. This leaves an orphaned remote server until a later ensure or disconnect cleans it up. Close entryScope here so its finalizers also stop the remote server and remove its state.
🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/ssh/src/tunnel.ts around line 1601:
When the agent-forwarding process exits after the tunnel is established, the observer only kills `tunnelEntry.process`; the managed remote T3 process and its `pid`/`port`/`managed` state are left running with an invalid forwarded socket. This leaves an orphaned remote server until a later ensure or disconnect cleans it up. Close `entryScope` here so its finalizers also stop the remote server and remove its state.
Evidence trail:
Commit cb58d9b; packages/ssh/src/tunnel.ts:1503-1534, 1592-1610, 1616-1663, 1687-1707, 461-662, 678-695; git show cb58d9b -- packages/ssh/src/tunnel.ts
| const [savedBackendSshHost, setSavedBackendSshHost] = useState(""); | ||
| const [savedBackendSshUsername, setSavedBackendSshUsername] = useState(""); | ||
| const [savedBackendSshPort, setSavedBackendSshPort] = useState(""); | ||
| const [savedBackendSshForwardAgent, setSavedBackendSshForwardAgent] = useState(false); |
There was a problem hiding this comment.
🟠 High settings/ConnectionsSettings.tsx:1831
Closing the Add Environment dialog leaves savedBackendSshForwardAgent set, so reopening it for another SSH host silently forwards the local agent to that host. Because the remote host can use the forwarded agent, reset this state when the SSH form is cancelled or closed, or scope it to the pending connection.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/settings/ConnectionsSettings.tsx around line 1831:
Closing the Add Environment dialog leaves `savedBackendSshForwardAgent` set, so reopening it for another SSH host silently forwards the local agent to that host. Because the remote host can use the forwarded agent, reset this state when the SSH form is cancelled or closed, or scope it to the pending connection.
Evidence trail:
Short commit: cb58d9b
apps/web/src/components/settings/ConnectionsSettings.tsx:1824-1832, 2147-2180, 2479-2530, 2574-2578, 3413-3420
packages/ssh/src/tunnel.ts:1503-1543
packages/ssh/src/command.ts:104-114
| REMOTE_PORT="" | ||
| REMOTE_MANAGED="" | ||
| fi | ||
| if [ "$FORWARD_AGENT" = "1" ] && [ "$REMOTE_MANAGED" = "managed" ] && [ -n "$REMOTE_PID" ]; then |
There was a problem hiding this comment.
🟠 High src/tunnel.ts:622
Enabling agent forwarding can kill an unrelated process when the managed server's PID has been reused: this path validates only kill -0 and readiness on the recorded port, then sends kill to REMOTE_PID. Verify that the PID still belongs to the recorded T3 server (for example, by checking its command/owner) before terminating it.
🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/ssh/src/tunnel.ts around line 622:
Enabling agent forwarding can kill an unrelated process when the managed server's PID has been reused: this path validates only `kill -0` and readiness on the recorded port, then sends `kill` to `REMOTE_PID`. Verify that the PID still belongs to the recorded T3 server (for example, by checking its command/owner) before terminating it.
Evidence trail:
cb58d9b packages/ssh/src/tunnel.ts:279-305, 488-648, 726-738, 1535-1542; cb58d9b apps/server/src/server.ts:495-524; cb58d9b packages/ssh/src/command.ts:76-82. Verification commands: git show cb58d9b -- packages/ssh/src/tunnel.ts; git show cb58d9b -- apps/server/src/server.ts; git show cb58d9b -- packages/ssh/src/command.ts
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds a substantial SSH agent-forwarding capability that introduces a retained credential channel and changes remote server/process lifecycle, persistence, IPC, and UI behavior. Unresolved findings also identify risks in authentication handling, server termination, state isolation, cleanup, and accidental forwarding to another host. Not approved because:
Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more. |
|
Note This comment is posted by Julius' dot The forwarding lifetime bug is accepted in #11872, including the need for a retained agent owner. This PR changes the SSH environment form, but its UI evidence contains only the after screenshot with the new toggle. The before state is described in text. Closing under the verification requirement for before and after screenshots. Please attach the missing before screenshot and request reconsideration. I corrected this explanation to recognize the maintainer direction in #11872. |
Desktop-managed SSH launch sessions are short-lived, so an agent socket enabled only through
ForwardAgent yesdisappears before provider commands can use it. This is especially visible with the 1Password SSH agent: Git authentication and SSH commit signing fail in the managed remote environment even though ordinary SSH works.Add an explicit Forward SSH agent option for desktop-managed SSH environments. When enabled, the desktop keeps a dedicated
ssh -Achannel alive, validates the remote agent socket, and starts its managed T3 server with thatSSH_AUTH_SOCK. Connections without the option explicitly usessh -a, keeping forwarding opt-in even when the host's SSH config enables it.Testing
@t3tools/ssh,@t3tools/contracts,@t3tools/web, and@t3tools/desktopsh -nUI
Before: the SSH environment form had no agent-forwarding control.
After: the form exposes an opt-in Forward SSH agent toggle, including guidance for 1Password users.
Built with GPT-5.6 Sol through the Codex harness.