Compare commits

...
Author SHA1 Message Date
paseo-bot[bot] e03811554a fix(app): keep agent metadata after reload
The agent directory cache dropped metadata while keeping the cursor. Require metadata in cached snapshots so older rows trigger the existing agent directory refresh.
2026-11-29 02:00:22 +00:00
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
5 changed files with 102 additions and 1 deletions
@@ -7,7 +7,10 @@ import {
} from "@/stores/session-store";
import type { StreamItem } from "@/types/stream";
import { normalizeAgentSnapshot } from "@/utils/agent-snapshots";
import { createPluginWorkspaceSnapshot } from "@/plugins/client-state/snapshots";
import {
createPluginAgentSnapshot,
createPluginWorkspaceSnapshot,
} from "@/plugins/client-state/snapshots";
import { ReplicaCache } from ".";
import type { DirectoryCheckpoint } from "@/runtime/replica-cache";
import type { ReplicaHostRows, ReplicaRow, ReplicaRowChanges, ReplicaRowStore } from "./row-store";
@@ -158,6 +161,7 @@ function agent(id = "agent-1"): Agent {
persistence: null,
title: "Cached agent",
labels: {},
metadata: {},
},
SERVER_ID,
),
@@ -1433,3 +1437,40 @@ it("retains workspace metadata across replica-cache reload and invalidates pre-m
projects: checkpoint.projects,
});
});
it("restores agent metadata for plugins when the directory cache reopens", async () => {
const storage = new MemoryStorage();
const writer = createCache(storage);
const baseline = directory();
const metadata = { "plugin.waiting": { kind: "plan", at: "2026-07-18T08:02:00.000Z" } };
baseline.agents.set("agent-1", { ...agent(), metadata });
commitDirectory(writer, SERVER_ID, baseline);
await writer.flush();
const restored = await createCache(storage).readDirectory(SERVER_ID);
expect(
createPluginAgentSnapshot(restored.agents.get("agent-1")!, "workspace-1").metadata,
).toEqual(metadata);
expect(restored.checkpoint).toEqual(baseline.checkpoint);
});
it("discards the agent cursor when a pre-metadata agent row is restored", async () => {
const storage = new MemoryStorage();
const writer = createCache(storage);
const baseline = directory({
agents: { generation: "g", afterSeq: 12 },
projects: { generation: "g", afterSeq: 4 },
});
commitDirectory(writer, SERVER_ID, baseline);
await writer.flush();
const key = `${SERVER_ID}:agent:agent-1`;
const row = storage.rows.get(key)!;
const legacyPayload = JSON.parse(row.payload) as { snapshot: Record<string, unknown> };
delete legacyPayload.snapshot.metadata;
storage.rows.set(key, { ...row, payload: JSON.stringify(legacyPayload) });
const restored = await createCache(storage).readDirectory(SERVER_ID);
expect(restored.checkpoint).toEqual({ projects: baseline.checkpoint.projects });
expect(restored.agents.size).toBe(0);
});
@@ -257,6 +257,8 @@ const StoredAgentSnapshotSchema = z.strictObject({
lastError: z.string().optional(),
title: z.string().nullable(),
labels: z.record(z.string(), z.string()),
// Require metadata so older rows invalidate the agent cursor and refetch from the daemon.
metadata: z.record(z.string(), z.unknown() as z.ZodType<JsonValue>),
// Optional: clients without background_agents never received a background agent to cache.
background: z.boolean().optional(),
requiresAttention: z.boolean().optional(),
@@ -705,6 +707,7 @@ function serializeAgent(agent: Agent): StoredAgent {
...(agent.lastError ? { lastError: agent.lastError } : {}),
title: agent.title,
labels: agent.labels,
metadata: agent.metadata ?? {},
...(agent.background ? { background: true } : {}),
requiresAttention: agent.requiresAttention ?? false,
backgroundWork: agent.backgroundWork,
@@ -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 }) =>