Skip to content

Commit 3c70cfb

Browse files
committed
fix(code-mode): serialize shared catalog aliases
1 parent 574b3de commit 3c70cfb

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎src/agents/code-mode-controller-source.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,16 @@ export const CODE_MODE_CONTROLLER_SOURCE = String.raw`
255255
const proto = Object.getPrototypeOf(value);
256256
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) return value;
257257
seen.add(value);
258-
if (Array.isArray(value)) return value.map((entry) => serializeCatalogHandles(entry, seen));
259-
const plain = {};
260-
for (const [key, entry] of Object.entries(value)) {
261-
plain[key] = serializeCatalogHandles(entry, seen);
258+
try {
259+
if (Array.isArray(value)) return value.map((entry) => serializeCatalogHandles(entry, seen));
260+
const plain = {};
261+
for (const [key, entry] of Object.entries(value)) {
262+
plain[key] = serializeCatalogHandles(entry, seen);
263+
}
264+
return plain;
265+
} finally {
266+
seen.delete(value);
262267
}
263-
return plain;
264268
}
265269
const catalog = Object.freeze({
266270
search: async (query, options) => {

‎src/agents/code-mode.guest.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,19 @@ describe("Code Mode guest execution", () => {
165165
waitTool: expectDefined(codeModeTools[1], "codeModeTools[1] test invariant"),
166166
code: `
167167
const batches = await Promise.all([catalog.search("noop"), catalog.search("noop")]);
168-
return { batches, byKey: { tool: batches[0][0] } };
168+
const shared = { tool: batches[0][0] };
169+
return { batches, byKey: shared, aliases: { first: shared, second: shared } };
169170
`,
170171
});
171172

172173
const handle = { callableName: "fake_noop", toolName: "fake_noop", description: "Noop" };
173174
expect(details).toMatchObject({
174175
status: "completed",
175-
value: { batches: [[handle], [handle]], byKey: { tool: handle } },
176+
value: {
177+
batches: [[handle], [handle]],
178+
byKey: { tool: handle },
179+
aliases: { first: { tool: handle }, second: { tool: handle } },
180+
},
176181
});
177182
expect(JSON.stringify(details.value)).not.toContain("null");
178183
});

‎src/node-host/mcp.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function startManagerWithTools(listed: ReadonlyArray<{ serverName: string;
7373

7474
function itWithFrozenClock(name: string, run: () => Promise<void>): void {
7575
it(name, async () => {
76-
// Size and pagination proofs must not spend the separately tested catalog deadline.
76+
// Non-timeout catalog proofs must not spend the separately tested catalog deadline.
7777
useFrozenTime(1_000);
7878
try {
7979
await run();
@@ -115,7 +115,7 @@ describe("node host MCP manager", () => {
115115
await manager.close();
116116
});
117117

118-
it("terminates streamable HTTP sessions on failed startup and manager close", async () => {
118+
itWithFrozenClock("terminates HTTP sessions on failed startup and manager close", async () => {
119119
const events = new Map<string, string[]>();
120120
const transports = new Map(
121121
["failed", "healthy"].map((serverName) => {

0 commit comments

Comments
 (0)