Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(windows): derive the Windows pane-probe budget from the probe worker's deadlines (#1225)

eneskircac01aa5f68d59
diff --git a/CLAUDE.md b/CLAUDE.md
index 3594d6d7d..2f698594b 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -119,10 +119,12 @@ whole envelope in its composer and never submitted it, so the delivery reported
separate Enter moments later sent it. A pane that never shows the envelope gets no Enter at all.
**Both Windows owner reads get a longer budget than the 2 s `PANE_PROBE_TIMEOUT_MS`.** The session
host's `messageOwnerV1` and `NativeWindowsPane.owner()` run the same PowerShell console/CIM probe
-(`readWindowsConsoleOwner`, its own child bounded at 4 s), measured at ~2.4 s on a loaded Windows 11
-machine — so under the 2 s bound every Windows target read `unknown` and refused as
-`targetPaneUnreadable`, permanently, behind an error that invites a retry. `PtyManager.
-paneProbeTimeoutMs` answers `WINDOWS_PANE_PROBE_TIMEOUT_MS` (8 s) for exactly the backends
+(`readWindowsConsoleOwner`), measured at ~2.4 s one-shot on a loaded Windows 11 machine — so under
+the 2 s bound every Windows target read `unknown` and refused as `targetPaneUnreadable`, behind an
+error that invites a retry (#1211). The #1206 probe worker is fast only once WARM and exits after
+60 s idle, so a message sent minutes after the last meets its 6 s first-request deadline plus the 4 s
+one-shot fallback. `PtyManager.paneProbeTimeoutMs` answers `WINDOWS_PANE_PROBE_TIMEOUT_MS` — DERIVED
+from those two deadlines + 1 s (`session-host/windows-probe-budget.ts`; never a literal) — for exactly the backends
`paneOwner` routes to that probe, and both shells forward it as the optional
`AgentMessagingDeps.paneProbeTimeoutMs` through ONE helper, `ptyPaneProbeDeps`, which binds the read
and its budget together (an optional dep that is not forwarded fails silently). SSH and tmux keep 2 s: that bound exists because
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 823f732c8..6c027d736 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -63,8 +63,10 @@ Do not replace that read with a stored `agentId` or the restart heuristic's deep
An interpreter such as `node` is named by its script's package `bin` entry, never as `node`, so
npm-installed CLIs such as Codex are recognized. A session released by park expiry or offscreen
release is still messageable: existence and routing ask the backend, not the attached client.
-Both Windows owner reads (session host and direct ConPTY) shell out to PowerShell and take ~2.4 s, so
-they get their own `WINDOWS_PANE_PROBE_TIMEOUT_MS` through `PtyManager.paneProbeTimeoutMs`; ssh and
+Both Windows owner reads (session host and direct ConPTY) go through a PowerShell probe that takes
+seconds when cold, so they get their own `WINDOWS_PANE_PROBE_TIMEOUT_MS` through
+`PtyManager.paneProbeTimeoutMs`, derived from the probe's own deadlines
+(`session-host/windows-probe-budget.ts`) — change a probe deadline there, not a literal; ssh and
tmux keep the 2 s bound. A shell that wires agent messaging must forward that optional dep.
Never put the submitting Enter in the same write as a message paste: `core/settled-submit.ts`
pastes, waits for the envelope to render, then submits separately, on every backend.
diff --git a/src/core/agents/pane-probe.test.ts b/src/core/agents/pane-probe.test.ts
index dba65549f..5e95e87ec 100644
--- a/src/core/agents/pane-probe.test.ts
+++ b/src/core/agents/pane-probe.test.ts
@@ -68,3 +68,28 @@ describe('probeWithin', () => {
expect(PANE_PROBE_TIMEOUT_MS).toBe(2000)
})
})
+
+describe('WINDOWS_PANE_PROBE_TIMEOUT_MS covers the Windows probe it bounds (#1211)', () => {
+ // A messaging read reaches `readWindowsConsoleOwner`, which asks this process's long-lived probe
+ // worker (#1206) and falls back to a one-shot powershell.exe when the worker cannot answer. The
+ // worker idles out after a minute, so a message sent minutes after the last one meets a COLD
+ // worker: its first-request deadline (PowerShell startup + Add-Type) and, if that lapses, the
+ // one-shot run. An outer budget below that sum discards the answer that was on its way and reads
+ // a healthy pane as `targetPaneUnreadable`.
+ it('is above the cold-worker deadline plus the one-shot fallback', async () => {
+ const { WINDOWS_PANE_PROBE_TIMEOUT_MS } = await import('./pane-probe')
+ const { PROBE_FIRST_REQUEST_TIMEOUT_MS, WINDOWS_ONESHOT_PROBE_TIMEOUT_MS } = await import(
+ '../../session-host/windows-probe-budget'
+ )
+ expect(WINDOWS_PANE_PROBE_TIMEOUT_MS).toBeGreaterThan(
+ PROBE_FIRST_REQUEST_TIMEOUT_MS + WINDOWS_ONESHOT_PROBE_TIMEOUT_MS
+ )
+ })
+
+ it('stays a real bound, above the tmux/ssh one', async () => {
+ // The outer bound only has to outlast the inner ones; it must stay a bound (finite, sane).
+ const { WINDOWS_PANE_PROBE_TIMEOUT_MS, PANE_PROBE_TIMEOUT_MS } = await import('./pane-probe')
+ expect(WINDOWS_PANE_PROBE_TIMEOUT_MS).toBeGreaterThan(PANE_PROBE_TIMEOUT_MS)
+ expect(WINDOWS_PANE_PROBE_TIMEOUT_MS).toBeLessThanOrEqual(15_000)
+ })
+})
diff --git a/src/core/agents/pane-probe.ts b/src/core/agents/pane-probe.ts
index f6c0feebd..20158e28b 100644
--- a/src/core/agents/pane-probe.ts
+++ b/src/core/agents/pane-probe.ts
@@ -1,3 +1,5 @@
+import { PROBE_FIRST_REQUEST_TIMEOUT_MS, WINDOWS_ONESHOT_PROBE_TIMEOUT_MS } from '../../session-host/windows-probe-budget'
+
/**
* A bounded pane probe for `src/core`.
*
@@ -38,16 +40,23 @@ export const PANE_PROBE_TIMEOUT_MS = 2000
/**
* The budget for a pane read on Windows, where there is no tmux and no ssh: both Windows backends
- * read the pane through the same PowerShell console/CIM probe (`readWindowsConsoleOwner`, which
- * bounds its own child at 4 s) — the session host to answer `messageOwnerV1` for a persistent
+ * read the pane through the same PowerShell console/CIM probe (`readWindowsConsoleOwner`) — the session host to answer `messageOwnerV1` for a persistent
* pane, and `NativeWindowsPane.owner()` for a non-persistent one.
*
* MEASURED on Windows 11 (26200), on a loaded machine: `powershell.exe -NoProfile` +
* `Get-CimInstance Win32_Process` costs ~2.4s, of which ~1.4s is PowerShell STARTUP alone. Under
* `PANE_PROBE_TIMEOUT_MS` (2s) that read can never answer, so every Windows pane read `unknown` and
* every agent-to-agent delivery refused as `targetPaneUnreadable` — a permanent failure wearing a
- * transient error's clothes. This budget must stay ABOVE the probe's own 4 s child timeout plus
- * the host IPC hop, or the outer bound fires first and discards an answer that was on its way.
+ * transient error's clothes.
+ *
+ * Since #1206 the probe runs in a long-lived worker per process (session-host/windows-probe-worker.ts)
+ * that is fast once warm, but it exits after 60 s idle — so a message sent minutes after the last
+ * one meets a COLD worker: `PROBE_FIRST_REQUEST_TIMEOUT_MS` (6 s: startup + the one-time Add-Type)
+ * and, if that lapses, the one-shot fallback (`WINDOWS_ONESHOT_PROBE_TIMEOUT_MS`, 4 s). This budget
+ * is DERIVED from those two plus 1 s for the host IPC hop, so the outer bound never fires first and
+ * discards an answer that was on its way (`pane-probe.test.ts` pins the inequality). The
+ * session-host client's own 10 s request deadline can still give up first on a fully lapsed
+ * worker; that is the same `unknown`, reached sooner.
*
* Larger is SAFE here in a way it would not be on the ssh leg, and the difference is the whole
* reason this is a separate constant rather than a bigger `PANE_PROBE_TIMEOUT_MS`:
@@ -60,7 +69,8 @@ export const PANE_PROBE_TIMEOUT_MS = 2000
* this long to say so, twice. Agent-to-agent messaging is not a hot path, and the per-pair rate
* limiter still sits in front of it.
*/
-export const WINDOWS_PANE_PROBE_TIMEOUT_MS = 8000
+export const WINDOWS_PANE_PROBE_TIMEOUT_MS =
+ PROBE_FIRST_REQUEST_TIMEOUT_MS + WINDOWS_ONESHOT_PROBE_TIMEOUT_MS + 1000
/**
* Run `fn`, but never wait longer than `timeoutMs`.
diff --git a/src/session-host/windows-pane-owner.ts b/src/session-host/windows-pane-owner.ts
index e9e2f7553..768cb2399 100644
--- a/src/session-host/windows-pane-owner.ts
+++ b/src/session-host/windows-pane-owner.ts
@@ -5,6 +5,7 @@ import type { PaneOwner } from '../shared/agents/pane-owner-predicate'
import { powershellArgs, powershellExe } from '../core/win32-powershell'
import { windowsConsoleProbeScript } from './windows-probe-script'
import { getWindowsProbeWorker, type WindowsProbeWorker } from './windows-probe-worker'
+import { WINDOWS_ONESHOT_PROBE_TIMEOUT_MS } from './windows-probe-budget'
/** Exact Windows console/process generation, not merely a reused PID or executable name. */
export function sameNativeProcess(before: PaneOwner | undefined, after: PaneOwner | null): boolean {
@@ -198,7 +199,7 @@ function asSnapshot(value: unknown): WindowsConsoleSnapshot | null {
function readOneShot(rootPid: number, generation: string, script: string): Promise<PaneOwner | null> {
return new Promise((resolve) => {
execFile(powershellExe(), powershellArgs(script),
- { timeout: 4000, maxBuffer: 4 * 1024 * 1024, windowsHide: true }, (error, stdout) => {
+ { timeout: WINDOWS_ONESHOT_PROBE_TIMEOUT_MS, maxBuffer: 4 * 1024 * 1024, windowsHide: true }, (error, stdout) => {
if (error) return resolve(null)
try {
const snapshot = asSnapshot(JSON.parse(stdout))
diff --git a/src/session-host/windows-probe-budget.ts b/src/session-host/windows-probe-budget.ts
new file mode 100644
index 000000000..c4fbf0439
--- /dev/null
+++ b/src/session-host/windows-probe-budget.ts
@@ -0,0 +1,11 @@
+// The deadlines of the Windows pane probe, in one dependency-free leaf so the core's outer budget
+// (`WINDOWS_PANE_PROBE_TIMEOUT_MS`, core/agents/pane-probe.ts) can be derived from them without
+// pulling child_process into the agent-messaging module graph.
+
+/** Deadline for the first request after the probe worker spawns: PowerShell startup + the
+ * one-time Add-Type compile (windows-probe-worker.ts). */
+export const PROBE_FIRST_REQUEST_TIMEOUT_MS = 6000
+
+/** Deadline of the one-shot powershell.exe `readWindowsConsoleOwner` falls back to when the worker
+ * cannot answer (windows-pane-owner.ts). */
+export const WINDOWS_ONESHOT_PROBE_TIMEOUT_MS = 4000
diff --git a/src/session-host/windows-probe-worker.ts b/src/session-host/windows-probe-worker.ts
index 789fb56ac..76cee6752 100644
--- a/src/session-host/windows-probe-worker.ts
+++ b/src/session-host/windows-probe-worker.ts
@@ -24,6 +24,7 @@ import { spawn as spawnChild } from 'child_process'
import type { Readable, Writable } from 'stream'
import { powershellArgs, powershellExe } from '../core/win32-powershell'
import { validProbePid, WINDOWS_PROBE_WORKER_SCRIPT } from './windows-probe-script'
+import { PROBE_FIRST_REQUEST_TIMEOUT_MS } from './windows-probe-budget'
export type ProbeRequest = { op: 'owner'; pid: number } | { op: 'table' }
@@ -56,7 +57,7 @@ export interface ProbeWorkerDeps {
}
export const PROBE_REQUEST_TIMEOUT_MS = 1500
-export const PROBE_FIRST_REQUEST_TIMEOUT_MS = 6000
+export { PROBE_FIRST_REQUEST_TIMEOUT_MS }
export const PROBE_IDLE_MS = 60_000
export const PROBE_MAX_FAILURES = 2
export const PROBE_COOLDOWN_MS = 5 * 60_000