The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): tie mux keepalive to persist timeout
Niklas Kietaibl75634d5cc2aa
diff --git a/apps/desktop/electron/ssh-connection.test.ts b/apps/desktop/electron/ssh-connection.test.tsindex 49b7d032142..f0e33cae236 100644--- a/apps/desktop/electron/ssh-connection.test.ts+++ b/apps/desktop/electron/ssh-connection.test.ts@@ -15,6 +15,8 @@ import {buildInteractiveSshArgs,buildMasterArgs,classifySshError,+ CONTROL_FORWARD_KEEPALIVE_MS,+ CONTROL_PERSIST_SECONDS,controlSocketPath,createSshProbeConnection,forwardSpec,@@ -520,22 +522,23 @@ test('mux forward keeps the ControlPersist master alive until the final forwardconst conn = new SshConnection({ host: 'box', user: 'me' },- { spawnFn, controlDir: '/tmp/d', controlKeepaliveMs: 1_000 }+ { spawnFn, controlDir: '/tmp/d' })await conn.forward(5000, 6000)await conn.forward(5001, 6001)- await vi.advanceTimersByTimeAsync(1_000)+ assert.ok(CONTROL_FORWARD_KEEPALIVE_MS < CONTROL_PERSIST_SECONDS * 1_000)+ await vi.advanceTimersByTimeAsync(CONTROL_FORWARD_KEEPALIVE_MS)const checks = () => spawnFn.calls.filter(args => args[0] === '-O' && args[1] === 'check').lengthassert.equal(checks(), 1, 'a tracked forward refreshes the ControlPersist timer')await conn.cancelForward(5000, 6000)- await vi.advanceTimersByTimeAsync(1_000)+ await vi.advanceTimersByTimeAsync(CONTROL_FORWARD_KEEPALIVE_MS)assert.equal(checks(), 2, 'cancelling one of several forwards keeps the refresh active')await conn.cancelForward(5001, 6001)- await vi.advanceTimersByTimeAsync(2_000)+ await vi.advanceTimersByTimeAsync(CONTROL_FORWARD_KEEPALIVE_MS * 2)assert.equal(checks(), 2, 'cancelling the final forward stops the refresh timer')} finally {vi.useRealTimers()diff --git a/apps/desktop/electron/ssh-connection.ts b/apps/desktop/electron/ssh-connection.tsindex 935749ac0e1..f2e3ab364d1 100644--- a/apps/desktop/electron/ssh-connection.ts+++ b/apps/desktop/electron/ssh-connection.ts@@ -58,7 +58,7 @@ const REMOTE_PROBE_TIMEOUT_SECS = 15const DEFAULT_TUNNEL_RESTART_LIMIT = 5const DEFAULT_TUNNEL_RESTART_DELAY_MS = 1_000const CONTROL_PERSIST_SECONDS = 300-const DEFAULT_CONTROL_KEEPALIVE_MS = 60_000+const CONTROL_FORWARD_KEEPALIVE_MS = Math.min(60_000, Math.floor((CONTROL_PERSIST_SECONDS * 1_000) / 2))// eslint-disable-next-line no-control-regex -- deliberately reject control chars in ssh targetsconst _CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/@@ -654,7 +654,6 @@ class SshConnection {_tunnels: Map<string, any>_controlMasters: ControlMasterHolders_forwardedSpecs: Set<string>- _controlKeepaliveMs: number_controlKeepaliveTimer: ReturnType<typeof setInterval> | nullconstructor(cfg, opts: any = {}) {@@ -698,7 +697,6 @@ class SshConnection {this._forwardTimeoutMs = opts.forwardTimeoutMs ?? DEFAULT_FORWARD_TIMEOUT_MSthis._tunnelRestartLimit = opts.tunnelRestartLimit ?? DEFAULT_TUNNEL_RESTART_LIMITthis._tunnelRestartDelayMs = opts.tunnelRestartDelayMs ?? DEFAULT_TUNNEL_RESTART_DELAY_MS- this._controlKeepaliveMs = opts.controlKeepaliveMs ?? DEFAULT_CONTROL_KEEPALIVE_MSthis._controlKeepaliveTimer = nullthis._opened = false}@@ -900,8 +898,10 @@ class SshConnection {}this._controlKeepaliveTimer = setInterval(() => {+ // Remote liveness owns reconnect/teardown. Keep refreshing through a+ // transient failed check rather than turning one timeout into expiry.void this.isAlive()- }, this._controlKeepaliveMs)+ }, CONTROL_FORWARD_KEEPALIVE_MS)this._controlKeepaliveTimer.unref?.()}@@ -1324,6 +1324,7 @@ export {buildInteractiveSshArgs,buildMasterArgs,classifySshError,+ CONTROL_FORWARD_KEEPALIVE_MS,CONTROL_PERSIST_SECONDS,controlSocketPath,createSshProbeConnection,