Compare commits

...
Author SHA1 Message Date
paseo-bot[bot]andClaude Opus 5.5 b1677e58d8 Start Windows terminals when ConPTY's output worker is slow (#11238)
* fix(terminal): let a Windows terminal start when ConPTY's worker is slow

node-pty starts a worker thread for ConPTY output and waits 5 s for it
to report ready. When the message comes later, it fails the spawn and
the program exits with code -1 before it runs. On a loaded Windows CI
runner this made "delivers MCP key tokens through in-process" find no
terminal at all. Patch the wait to 30 s; a worker that fails still
reports an error at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(terminal): block the event loop from a check-phase callback

The old 5 s ConPTY timer now always runs before the worker's ready
message, so the test fails without the node-pty patch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 00:55:51 +00:00
3 changed files with 57 additions and 0 deletions
@@ -653,6 +653,39 @@ describe("createTerminal", () => {
expect(session.getExitInfo()).toEqual(exitInfo);
});
it.runIf(isPlatform("win32"))(
"starts a ConPTY program when the event loop stalls past five seconds after spawn",
async () => {
// node-pty reports the ConPTY output worker ready by a worker message, and failed the
// spawn with exit code -1 when that message came after 5 s. A loaded runner delays it
// that long; blocking the event loop for 6 s makes the delay certain. Spawning and
// blocking inside a check-phase callback makes the next loop iteration start with the
// timers phase, so the old 5 s timer always runs before the worker message is delivered.
const child = await new Promise<pty.IPty>((resolve) => {
setImmediate(() => {
const spawned = pty.spawn(process.execPath, ["-e", "process.stdout.write('STARTED')"], {
cols: 80,
rows: 24,
cwd: realpathSync(tmpdir()),
});
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 6000);
resolve(spawned);
});
});
let output = "";
child.onData((data) => {
output += data;
});
const exited = new Promise<number>((resolve) => {
child.onExit(({ exitCode }) => resolve(exitCode));
});
expect(await exited).toBe(0);
expect(output).toContain("STARTED");
},
30_000,
);
it("retains the final lines after output far exceeds the recent-output char cap", async () => {
// Emit many small chunks whose total length is well past the 16000-char
// recent-output cap, so the chunk-trimming path runs repeatedly. The final
+16
View File
@@ -0,0 +1,16 @@
diff --git a/node_modules/node-pty/lib/windowsPtyAgent.js b/node_modules/node-pty/lib/windowsPtyAgent.js
index 90ffd8f..d9567b1 100644
--- a/node_modules/node-pty/lib/windowsPtyAgent.js
+++ b/node_modules/node-pty/lib/windowsPtyAgent.js
@@ -21,7 +21,10 @@ var conptyNative;
* has started.
*/
var FLUSH_DATA_INTERVAL = 1000;
-var CONNECTION_TIMEOUT = 5000;
+// Paseo: the output worker is a worker thread that reports ready by message. A busy event loop
+// or a loaded machine can delay that message past 5 s, and the spawn then fails with exit
+// code -1 before the program starts. Wait 30 s instead; a worker that fails still errors at once.
+var CONNECTION_TIMEOUT = 30000;
var defaultWindowsPtyAgentOptions = {
connectionTimeout: CONNECTION_TIMEOUT,
conoutConnectionFactory: function (conoutPipeName, useConptyDll) { return new windowsConoutConnection_1.ConoutConnection(conoutPipeName, useConptyDll); }
+8
View File
@@ -123,6 +123,14 @@ const patchedPackages = [
patchPrefix: "@opencode-ai+sdk+",
cwd: "packages/server",
},
// Windows: wait 30 s instead of 5 s for the ConPTY output worker to report ready. A loaded
// machine delays that message past 5 s, and the program then exits with code -1 before it
// starts. Upstream keeps 5 s through 1.2.0-beta.18; keep while the server uses node-pty.
{
nodeModulesPath: "packages/server/node_modules/node-pty",
patchPrefix: "node-pty+",
cwd: "packages/server",
},
];
const installedPackages = patchedPackages.filter(({ nodeModulesPath }) =>