dsh-remote-vs 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,7 +66,7 @@ import {
66
66
  unstageCommand,
67
67
  } from '../../git-ops.ts'
68
68
  import { parseBlamePorcelain, parseFileHistory, type BlameLine, type FileHistoryCommit } from '../blame-model.ts'
69
- import { api, gitTimeoutMs, type RequestOptions } from '../api.ts'
69
+ import { api, gitTimeoutMs, type ExecLane, type RequestOptions } from '../api.ts'
70
70
  import { isRequestAbort } from '../request-gate.ts'
71
71
  import { appendExecOutput, networkBudgetMs, networkCommands, type PushTarget } from '../exec-output.ts'
72
72
  import { timeoutSeconds } from '../../timeouts.ts'
@@ -125,6 +125,23 @@ function failureOf(result: RemoteExecResult, timeoutMs: number): GitOpError {
125
125
  export interface RunOptions {
126
126
  background?: boolean
127
127
  signal?: AbortSignal
128
+ /**
129
+ * Which HOST channel budget this command spends.
130
+ *
131
+ * The default for everything in this file is `'git'` — the git-command budget,
132
+ * where a big tree's `git status` is allowed 300 s and a git command used to
133
+ * park one of the shared exec slots for that whole time. It covers the local
134
+ * writes too (`commit`, `stage`, `discard`, branch verbs): they are git commands
135
+ * with a git timeout, and they must not compete with the monitor and the agent
136
+ * tools for the exec slots either. `'network'` is for the fetch/pull/push family,
137
+ * whose budget is even longer (20 minutes). Omitted means "the default above",
138
+ * and only a command that is NOT a git command may ask for `'exec'` — there is
139
+ * none in this module today.
140
+ *
141
+ * Deliberately NOT part of {@link RequestOptions}: that bag drives the local
142
+ * request gate and the fetch, while this is a body field the host's pool reads.
143
+ */
144
+ lane?: ExecLane
128
145
  }
129
146
 
130
147
  /** Map {@link RunOptions} onto the HTTP layer's {@link RequestOptions}. */
@@ -135,6 +152,20 @@ function requestOptionsOf(options: RunOptions): RequestOptions {
135
152
  }
136
153
  }
137
154
 
155
+ /**
156
+ * The channel lane a command spends.
157
+ *
158
+ * Every command that flows through `run`/`tryRun` is a git command (a read or a
159
+ * local write), so the default is the git-command budget (`'git'`); the network
160
+ * verbs override it with `'network'`. Marking a local write as a network verb
161
+ * would move a fast command onto the two-slot network lane, and leaving it on the
162
+ * exec budget is exactly the bug this budget exists to fix — so the default is the
163
+ * git lane and overrides are explicit at the call site.
164
+ */
165
+ function laneOf(options: RunOptions): ExecLane {
166
+ return options.lane ?? 'git'
167
+ }
168
+
138
169
  /** Run one command, raising a readable error on a non-zero exit. */
139
170
  async function run(
140
171
  alias: string,
@@ -142,7 +173,7 @@ async function run(
142
173
  timeoutMs = normalTimeoutMs(),
143
174
  options: RunOptions = {},
144
175
  ): Promise<RemoteExecResult> {
145
- const result = await api.exec(alias, command, timeoutMs, requestOptionsOf(options))
176
+ const result = await api.exec(alias, command, timeoutMs, requestOptionsOf(options), laneOf(options))
146
177
  if (result.success) return result
147
178
  throw failureOf(result, timeoutMs)
148
179
  }
@@ -155,7 +186,7 @@ async function tryRun(
155
186
  options: RunOptions = {},
156
187
  ): Promise<string> {
157
188
  try {
158
- const result = await api.exec(alias, command, timeoutMs, requestOptionsOf(options))
189
+ const result = await api.exec(alias, command, timeoutMs, requestOptionsOf(options), laneOf(options))
159
190
  return result.success ? result.stdout : ''
160
191
  } catch (error) {
161
192
  // A cancelled command is not "no answer": swallowing it would let the
@@ -207,7 +238,10 @@ export async function probeRepoRoot(
207
238
  // to the listing the user is waiting on.
208
239
  background: true,
209
240
  ...(signal === undefined ? {} : { signal }),
210
- })
241
+ // A repository READ (unlike the verbs that go through `run`, this one calls
242
+ // the API directly, so it has to name its lane): the host's repository-read
243
+ // budget, not the six exec slots the monitor and the agent tools poll on.
244
+ }, 'git')
211
245
  } catch (error) {
212
246
  if (isRequestAbort(error)) throw error
213
247
  // The transport/route failed before any git exit code existed.
@@ -570,13 +604,20 @@ export async function lastCommitMessage(alias: string, root: string): Promise<st
570
604
  return (await tryRun(alias, headMessageCommand(root), 30_000)).trim()
571
605
  }
572
606
 
573
- /** fetch / pull / push / sync. */
607
+ /**
608
+ * fetch / pull / push / sync.
609
+ *
610
+ * Every branch here is a NETWORK verb (`{ lane: 'network' }`): each one can hold a
611
+ * channel for `networkBudgetMs`, so it spends the host's small network budget
612
+ * rather than the repository-read one the rest of this module uses.
613
+ */
574
614
  export async function syncRepo(alias: string, root: string, kind: 'fetch' | 'pull' | 'push' | 'sync'): Promise<string> {
575
- if (kind === 'fetch') return (await run(alias, fetchCommand(root), longTimeoutMs())).stdout
576
- if (kind === 'pull') return (await run(alias, pullCommand(root), longTimeoutMs())).stdout
577
- if (kind === 'push') return (await run(alias, pushCommand(root), longTimeoutMs())).stdout
578
- const pulled = (await run(alias, pullCommand(root), longTimeoutMs())).stdout
579
- const pushed = (await run(alias, pushCommand(root), longTimeoutMs())).stdout
615
+ const network = { lane: 'network' } as const
616
+ if (kind === 'fetch') return (await run(alias, fetchCommand(root), longTimeoutMs(), network)).stdout
617
+ if (kind === 'pull') return (await run(alias, pullCommand(root), longTimeoutMs(), network)).stdout
618
+ if (kind === 'push') return (await run(alias, pushCommand(root), longTimeoutMs(), network)).stdout
619
+ const pulled = (await run(alias, pullCommand(root), longTimeoutMs(), network)).stdout
620
+ const pushed = (await run(alias, pushCommand(root), longTimeoutMs(), network)).stdout
580
621
  return `${pulled}\n${pushed}`.trim()
581
622
  }
582
623
 
@@ -585,7 +626,9 @@ export async function syncRepo(alias: string, root: string, kind: 'fetch' | 'pul
585
626
  * `HEAD:refs/for/<branch>`). Same timeout budget as the other network verbs.
586
627
  */
587
628
  export async function pushWithRefspec(alias: string, root: string, remote: string, refspec: string): Promise<string> {
588
- const out = await run(alias, pushRefspecCommand(root, remote, refspec), longTimeoutMs())
629
+ // A refspec push is the review-upload path (Gerrit): same network verb, same
630
+ // 20-minute budget, so it must not sit in an exec slot either.
631
+ const out = await run(alias, pushRefspecCommand(root, remote, refspec), longTimeoutMs(), { lane: 'network' })
589
632
  return `${out.stdout}\n${out.stderr}`.trim()
590
633
  }
591
634
 
@@ -613,6 +656,10 @@ export async function streamNetworkVerb(
613
656
  let result: RemoteExecResult | undefined
614
657
  for (const command of networkCommands(root, kind, push)) {
615
658
  result = await api.execStream(alias, command, timeoutMs, {
659
+ // A network verb for the HOST as well: its channel comes from the small
660
+ // network budget, so a push that hangs for its whole 20-minute budget
661
+ // cannot starve status refreshes / the monitor / the agent tools.
662
+ lane: 'network',
616
663
  ...(handlers.signal === undefined ? {} : { signal: handlers.signal }),
617
664
  onData: (stream, text) => {
618
665
  output = appendExecOutput(output, text)
@@ -642,7 +689,11 @@ export async function branchOp(
642
689
  case 'delete': return (await run(alias, deleteBranchCommand(root, op.name, op.force), 60_000)).stdout
643
690
  case 'rename': return (await run(alias, renameBranchCommand(root, op.from, op.to), 60_000)).stdout
644
691
  case 'merge': return (await run(alias, mergeCommand(root, op.ref), longTimeoutMs())).stdout
645
- case 'publish': return (await run(alias, publishBranchCommand(root, op.name, op.remote), longTimeoutMs())).stdout
692
+ // `publish` is `git push --set-upstream`: a network verb, so it spends the
693
+ // network budget instead of an exec slot (the other branch verbs are local).
694
+ case 'publish': {
695
+ return (await run(alias, publishBranchCommand(root, op.name, op.remote), longTimeoutMs(), { lane: 'network' })).stdout
696
+ }
646
697
  default: return ''
647
698
  }
648
699
  }
@@ -5271,6 +5271,12 @@ body[data-ds-dark-theme] .rvs-doctor {
5271
5271
  flex: 0 1 auto;
5272
5272
  }
5273
5273
 
5274
+ /* Same rule for the connection-pool section: whichever collapsible section is
5275
+ open gets the room, the metric cards keep their natural height. */
5276
+ .rvs-monitor-body:has(.rvs-pool.expanded) .rvs-monitor-content {
5277
+ flex: 0 1 auto;
5278
+ }
5279
+
5274
5280
  /* The rail title and the scope picker both wanted flex:1; the title yields so
5275
5281
  the picker keeps enough width for its own label at 230px. */
5276
5282
  .rvs-monitor-header .rvs-title {
@@ -6486,6 +6492,176 @@ body[data-ds-dark-theme] .rvs-doctor {
6486
6492
  }
6487
6493
  }
6488
6494
 
6495
+ /* === SSH connection-pool section (monitor page) =========================== */
6496
+
6497
+ /* Collapsed it is a single header row under the process section; expanded it
6498
+ takes the leftover height (basis:0, so the list scrolls instead of pushing
6499
+ the metric cards off the pane). Same shape as `.rvs-proc`. */
6500
+ .rvs-pool {
6501
+ flex: 0 0 auto;
6502
+ border-top: 1px solid var(--rvs-editor-chrome-border, var(--rvs-border));
6503
+ background: var(--rvs-layer3);
6504
+ }
6505
+
6506
+ .rvs-pool.expanded {
6507
+ display: flex;
6508
+ flex: 1 1 0;
6509
+ flex-direction: column;
6510
+ min-height: 120px;
6511
+ }
6512
+
6513
+ .rvs-pool-head {
6514
+ display: flex;
6515
+ align-items: center;
6516
+ gap: 4px;
6517
+ padding: 4px 8px;
6518
+ min-height: 26px;
6519
+ }
6520
+
6521
+ .rvs-pool-toggle {
6522
+ display: inline-flex;
6523
+ align-items: center;
6524
+ justify-content: center;
6525
+ width: 18px;
6526
+ height: 18px;
6527
+ padding: 0;
6528
+ border: 0;
6529
+ background: transparent;
6530
+ color: var(--rvs-fg2);
6531
+ cursor: pointer;
6532
+ }
6533
+
6534
+ .rvs-pool-title {
6535
+ flex: 0 0 auto;
6536
+ font-weight: 600;
6537
+ font-size: 11px;
6538
+ }
6539
+
6540
+ /* 台/条/排队 counts: tabular-nums keeps the header from twitching when a
6541
+ channel count changes on its own poll. */
6542
+ .rvs-pool-summary {
6543
+ flex: 1 1 auto;
6544
+ min-width: 0;
6545
+ overflow: hidden;
6546
+ text-overflow: ellipsis;
6547
+ white-space: nowrap;
6548
+ color: var(--rvs-fg3);
6549
+ font-size: 10px;
6550
+ font-variant-numeric: tabular-nums;
6551
+ }
6552
+
6553
+ .rvs-pool-collapsed {
6554
+ padding: 0 8px 5px;
6555
+ color: var(--rvs-fg3);
6556
+ font-size: 10px;
6557
+ }
6558
+
6559
+ /* The one-line degrade/loading/empty copy. Muted on purpose: "this Host does
6560
+ not report pool statistics" is information, not a failure of the link the
6561
+ metric cards above are already reporting on. */
6562
+ .rvs-pool-note {
6563
+ display: flex;
6564
+ align-items: center;
6565
+ gap: 4px;
6566
+ padding: 0 8px 5px;
6567
+ color: var(--rvs-fg3);
6568
+ font-size: 10px;
6569
+ }
6570
+
6571
+ /* A real request failure is the exception: it keeps the readable server text
6572
+ but colours it, because something IS wrong. */
6573
+ .rvs-pool-note.error {
6574
+ color: var(--rvs-danger-text);
6575
+ }
6576
+
6577
+ .rvs-pool-list {
6578
+ flex: 1 1 auto;
6579
+ min-height: 0;
6580
+ overflow: auto;
6581
+ scrollbar-width: thin;
6582
+ }
6583
+
6584
+ .rvs-pool-host {
6585
+ padding: 4px 8px 6px;
6586
+ border-bottom: 1px solid var(--rvs-border);
6587
+ }
6588
+
6589
+ .rvs-pool-host:last-child {
6590
+ border-bottom: 0;
6591
+ }
6592
+
6593
+ .rvs-pool-host-head {
6594
+ display: flex;
6595
+ align-items: center;
6596
+ gap: 6px;
6597
+ }
6598
+
6599
+ .rvs-pool-host-alias {
6600
+ flex: 1 1 auto;
6601
+ min-width: 0;
6602
+ overflow: hidden;
6603
+ text-overflow: ellipsis;
6604
+ white-space: nowrap;
6605
+ font-weight: 600;
6606
+ font-size: 11px;
6607
+ }
6608
+
6609
+ /* "排队 N" badge: the same signal the ordering uses, so the first row is the
6610
+ one with a queue and it is obvious WHY it is first. */
6611
+ .rvs-pool-queue {
6612
+ flex: none;
6613
+ padding: 0 4px;
6614
+ border: 1px solid var(--rvs-danger-text);
6615
+ border-radius: 3px;
6616
+ color: var(--rvs-danger-text);
6617
+ font-size: 9px;
6618
+ font-variant-numeric: tabular-nums;
6619
+ }
6620
+
6621
+ /* Name | state column, with the egress line spanning the second column under
6622
+ the shared lane it belongs to. */
6623
+ .rvs-pool-lane {
6624
+ display: grid;
6625
+ grid-template-columns: 56px minmax(0, 1fr);
6626
+ column-gap: 6px;
6627
+ align-items: baseline;
6628
+ font-size: 10px;
6629
+ }
6630
+
6631
+ .rvs-pool-lane-name {
6632
+ color: var(--rvs-fg3);
6633
+ }
6634
+
6635
+ .rvs-pool-lane-state {
6636
+ color: var(--rvs-fg2);
6637
+ font-variant-numeric: tabular-nums;
6638
+ }
6639
+
6640
+ /* A dialled lane is the fact the user came for; an idle one stays dim. */
6641
+ .rvs-pool-lane-state.open {
6642
+ color: var(--rvs-fg);
6643
+ }
6644
+
6645
+ /* Both the shared connection's route and the "files fell back to it" marker sit
6646
+ under the lane they belong to, in the second grid column. */
6647
+ .rvs-pool-egress,
6648
+ .rvs-pool-fallback {
6649
+ grid-column: 2;
6650
+ overflow: hidden;
6651
+ text-overflow: ellipsis;
6652
+ white-space: nowrap;
6653
+ color: var(--rvs-fg3);
6654
+ }
6655
+
6656
+ .rvs-pool-slots {
6657
+ display: flex;
6658
+ flex-wrap: wrap;
6659
+ gap: 0 10px;
6660
+ color: var(--rvs-fg3);
6661
+ font-size: 10px;
6662
+ font-variant-numeric: tabular-nums;
6663
+ }
6664
+
6489
6665
  /* ------------------------------------------------------ Ctrl+P quick open */
6490
6666
 
6491
6667
  .rvs-qo-mask {
@@ -10,6 +10,7 @@ import { SshRpcPeer, SSH_PROTOCOL_VERSION } from '@deepseek-ai/dsh-ssh/protocol'
10
10
  import { helloSchema } from '@deepseek-ai/dsh-ssh/schemas'
11
11
  import { z } from 'zod'
12
12
  import type { RemoteHostEntry } from '../protocol.ts'
13
+ import type { RoutedDial } from '../pool.ts'
13
14
  import { InFlightGate } from './in-flight-gate.ts'
14
15
 
15
16
  export interface RpcDialOpts {
@@ -21,6 +22,26 @@ export interface RpcDialOpts {
21
22
  /** Remote default workspace for the hello handshake. */
22
23
  workspace: string
23
24
  leaseMs?: number
25
+ /**
26
+ * The HOST's routed transport for this alias (proxy tunnel / jump-host channel),
27
+ * optional so a caller without a pool still dials directly.
28
+ *
29
+ * Without it this transport is a BARE direct connection: a host reachable only
30
+ * through a proxy or jump host would answer exec/SFTP (the pool honours the
31
+ * route) and fail every file/Git fast path — the "some features work, some do
32
+ * not" report. The pool supplies it via `openRoutedSocket`; the returned
33
+ * `release` is called here (once) on failure, close, reconnect and dispose.
34
+ */
35
+ openSocket?: () => Promise<RoutedDial>
36
+ /**
37
+ * The ssh2 client factory.
38
+ *
39
+ * A seam, not a preference — the same one `RemotePool.makeClient` has: the only
40
+ * way a self-check can observe what this transport hands ssh2 (`{sock}` with no
41
+ * `host`/`port` for a routed dial, the reverse for a direct one) without a real
42
+ * server. Production never overrides it.
43
+ */
44
+ makeClient?: () => Client
24
45
  }
25
46
 
26
47
  export interface RpcHello {
@@ -174,6 +195,17 @@ export class RpcConnection {
174
195
  * grow host memory.
175
196
  */
176
197
  private stderrTail = ''
198
+ /**
199
+ * Teardown of the ROUTED transport this attempt rides (proxy socket / jump-host
200
+ * tunnel), or undefined for a direct dial.
201
+ *
202
+ * It lives on the instance because the release has to outlive the handshake: the
203
+ * tunnel must stay open exactly as long as the SSH connection rides it, so the
204
+ * call belongs in `teardownTransport` (dispose, reconnect, failed open) rather
205
+ * than in the dial promise. The pool's release is idempotent, so calling it from
206
+ * a failure path AND from the teardown is safe.
207
+ */
208
+ private releaseRoute: (() => void) | undefined
177
209
  /** Per-connection in-flight cap; see MAX_IN_FLIGHT. */
178
210
  private readonly gate = new InFlightGate(MAX_IN_FLIGHT)
179
211
 
@@ -189,6 +221,18 @@ export class RpcConnection {
189
221
  return this.stderrTail.trim()
190
222
  }
191
223
 
224
+ /**
225
+ * How many helper calls are in flight right now.
226
+ *
227
+ * Read-only diagnostics for the monitor: the helper caps itself at its own
228
+ * gate, so a saturated helper shows up as a number here instead of looking
229
+ * like an idle connection. It is NOT a queue — a call waits inside the gate
230
+ * before it counts, so this number never exceeds the gate's ceiling.
231
+ */
232
+ get inFlight(): number {
233
+ return this.gate.inFlight
234
+ }
235
+
192
236
  get ready(): Promise<RpcHello> {
193
237
  if (this.readyPromise === undefined) this.readyPromise = this.open()
194
238
  return this.readyPromise
@@ -327,10 +371,17 @@ export class RpcConnection {
327
371
  this.channel = undefined
328
372
  this.conn = undefined
329
373
  this.stderrTail = ''
374
+ // LAST: give the tunnel back after the connection riding it is closed (for a
375
+ // jump host this closes the channel and releases the hold; for a proxy it
376
+ // destroys the socket). Idempotent on the pool side, so a failure path that
377
+ // already released is fine.
378
+ const release = this.releaseRoute
379
+ this.releaseRoute = undefined
380
+ release?.()
330
381
  }
331
382
 
332
383
  private async open(): Promise<RpcHello> {
333
- const conn = new Client()
384
+ const conn = this.opts.makeClient?.() ?? new Client()
334
385
  this.conn = conn
335
386
  try {
336
387
  const hello = await this.dialAndHello(conn)
@@ -362,6 +413,19 @@ export class RpcConnection {
362
413
  // teardown is about a link nobody owns any more; the callbacks below compare
363
414
  // against the live value before touching `dead`/`stderrTail`.
364
415
  const generation = this.generation
416
+ /**
417
+ * The route the HOST resolves for this alias — a proxy tunnel socket or a
418
+ * jump-host channel — or nothing for a direct connection. It is acquired
419
+ * BEFORE the handshake so a route failure surfaces as itself (`proxy auth
420
+ * failed: …` / `jump host "x" failed: …`) instead of as a mysterious
421
+ * connection timeout.
422
+ *
423
+ * The release is stashed for `teardownTransport`, which runs on every way this
424
+ * attempt can end (ready-then-lost, failed open, reconnect, dispose). If the
425
+ * acquisition itself throws there is nothing to release.
426
+ */
427
+ const routed = this.opts.openSocket === undefined ? undefined : await this.opts.openSocket()
428
+ if (routed !== undefined) this.releaseRoute = routed.release
365
429
  await new Promise<void>((resolve, reject) => {
366
430
  let settled = false
367
431
  conn.on('ready', () => {
@@ -390,10 +454,15 @@ export class RpcConnection {
390
454
  if (generation === this.generation) this.invalidate(new Error('ssh connection closed'))
391
455
  })
392
456
  try {
457
+ // `{ sock }` and NOT `host`/`port`: a routed transport is the socket ssh2
458
+ // must ride, and passing both would let ssh2 pick between dialing the
459
+ // target itself and riding the tunnel (the same rule `pool.dial` follows).
460
+ const transport = routed?.sock === undefined
461
+ ? { host: entry.host, port: entry.port }
462
+ : { sock: routed.sock }
393
463
  if (entry.auth.kind === 'key') {
394
464
  conn.connect({
395
- host: entry.host,
396
- port: entry.port,
465
+ ...transport,
397
466
  username: entry.user,
398
467
  privateKey: readFileSync(entry.auth.keyPath as string),
399
468
  passphrase: entry.auth.passphrase,
@@ -403,8 +472,7 @@ export class RpcConnection {
403
472
  })
404
473
  } else {
405
474
  conn.connect({
406
- host: entry.host,
407
- port: entry.port,
475
+ ...transport,
408
476
  username: entry.user,
409
477
  password: entry.auth.password,
410
478
  readyTimeout: CONNECT_READY_TIMEOUT_MS,
package/src/p2/worlds.ts CHANGED
@@ -82,6 +82,17 @@ const DIAL_IMMEDIATE_RETRIES = 2
82
82
 
83
83
  export class RemoteWorlds {
84
84
  private readonly rpcs = new Map<string, Promise<RpcConnection>>()
85
+ /**
86
+ * Aliases whose helper connection is still being dialed.
87
+ *
88
+ * `rpcs` holds the PROMISE, so a caller that awaits it waits for the whole
89
+ * dial (up to `CONNECT_READY_TIMEOUT_MS`, 45 s through a proxy or a jump host).
90
+ * The monitor polls `helperLane` every few seconds and must never inherit that
91
+ * wait — the route is read-only and would report the previous sample for the
92
+ * whole dial, or hold the client's single-flight guard. A name in this set is
93
+ * therefore "cannot say yet", which the client already renders as no row.
94
+ */
95
+ private readonly dialingRpc = new Map<string, Promise<RpcConnection>>()
85
96
  private readonly fsViews = new Map<string, Promise<FsView>>()
86
97
  private readonly fsReady = new Map<string, FsView>()
87
98
  private readonly procs = new Map<string, SshProcRuntime>()
@@ -471,6 +482,30 @@ export class RemoteWorlds {
471
482
  }
472
483
  }
473
484
 
485
+ /**
486
+ * The helper connection of one alias, for the monitor's fifth lane.
487
+ *
488
+ * The helper dials its OWN SSH connection (see `RpcConnection`), so the pool
489
+ * cannot report it — this is the only place that knows. Read-only by
490
+ * contract: it awaits a record that already exists and never starts a dial, a
491
+ * deploy or a reconnect, because the monitor polls this every few seconds and
492
+ * a diagnostic must not be able to bring a helper up (or keep a dead one
493
+ * alive). `undefined` means "cannot say": no record, a record still dialing, or
494
+ * a record the router is about to replace — the client then omits the row
495
+ * rather than claiming the helper is closed.
496
+ */
497
+ async helperLane(alias: string): Promise<{ open: boolean; channels: number; held: number } | undefined> {
498
+ // A record that is still dialing is not an answer: awaiting it would make the
499
+ // monitor wait out the handshake (45 s worst case) for a read-only poll.
500
+ if (this.dialingRpc.has(alias)) return undefined
501
+ const pending = this.rpcs.get(alias)
502
+ if (pending === undefined) return undefined
503
+ const conn = await pending.catch(() => undefined)
504
+ if (conn === undefined || !conn.alive) return undefined
505
+ // One channel is the whole helper transport (exec + JSON-RPC frames).
506
+ return { open: true, channels: 1, held: conn.inFlight }
507
+ }
508
+
474
509
  /** Drop one host's RPC + fs view + proc runtime (call after host update/delete). */
475
510
  async dropHost(alias: string): Promise<void> {
476
511
  this.fsReady.delete(alias)
@@ -635,11 +670,18 @@ export class RemoteWorlds {
635
670
  if (pending === undefined) {
636
671
  pending = this.createRpc(alias)
637
672
  this.rpcs.set(alias, pending)
673
+ this.dialingRpc.set(alias, pending)
638
674
  void pending.then(
639
675
  () => {
676
+ // Identity guard: a host edit (`dropHost`) can start a SECOND dial while
677
+ // this one settles, and an unconditional delete would clear the new
678
+ // dial's mark — `helperLane` would then wait out that dial and the
679
+ // monitor would freeze for it, the exact thing this set prevents.
680
+ if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias)
640
681
  this.dialFailures.delete(alias)
641
682
  },
642
683
  (error: unknown) => {
684
+ if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias)
643
685
  if (this.rpcs.get(alias) === pending) this.rpcs.delete(alias)
644
686
  this.noteDialFailure(alias, error)
645
687
  },
@@ -803,6 +845,12 @@ export class RemoteWorlds {
803
845
  helperHash: helper.sha256,
804
846
  workspace: home,
805
847
  leaseMs: 60000,
848
+ // The helper dials its OWN ssh2 client, so it must be handed the route the
849
+ // pool would take (proxy tunnel / jump-host channel): without it a host
850
+ // reachable only through a hop answers exec and SFTP but fails every
851
+ // file/Git path that rides the helper. The pool owns the decision and the
852
+ // error layering; this transport releases the transport when it tears down.
853
+ openSocket: () => this.deps.pool.openRoutedSocket(alias),
806
854
  })
807
855
  try {
808
856
  await conn.ready