Skip to content

Commit aa8fdc8

Browse files
ochafikclaude
andcommitted
Fix null toolOutput being sent as text 'null'
Check for both null and undefined before delivering tool-result notification. Previously null passed through and was stringified. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent eb17954 commit aa8fdc8

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/openai/transport.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ describe("OpenAITransport", () => {
431431

432432
test("converts null _meta to undefined in tool result", async () => {
433433
// Simulate null being set (e.g., from JSON parsing where null is valid)
434-
(mockOpenAI as unknown as { toolResponseMetadata: null }).toolResponseMetadata = null;
434+
(
435+
mockOpenAI as unknown as { toolResponseMetadata: null }
436+
).toolResponseMetadata = null;
435437

436438
const transport = new OpenAITransport();
437439
const messages: unknown[] = [];
@@ -452,6 +454,28 @@ describe("OpenAITransport", () => {
452454
expect(toolResultNotification?.params?._meta).toBeUndefined();
453455
});
454456

457+
test("does not deliver tool-result when toolOutput is null", async () => {
458+
// Simulate null being set (e.g., from JSON parsing)
459+
(mockOpenAI as unknown as { toolOutput: null }).toolOutput = null;
460+
461+
const transport = new OpenAITransport();
462+
const messages: unknown[] = [];
463+
transport.onmessage = (msg) => {
464+
messages.push(msg);
465+
};
466+
467+
transport.deliverInitialState();
468+
469+
await new Promise((resolve) => setTimeout(resolve, 0));
470+
471+
const toolResultNotification = messages.find(
472+
(m: unknown) =>
473+
(m as { method?: string }).method === "ui/notifications/tool-result",
474+
);
475+
// Should NOT deliver tool-result when toolOutput is null
476+
expect(toolResultNotification).toBeUndefined();
477+
});
478+
455479
test("does not deliver notifications when data is missing", async () => {
456480
delete mockOpenAI.toolInput;
457481
delete mockOpenAI.toolOutput;

src/openai/transport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ export class OpenAITransport implements Transport {
495495
});
496496
}
497497

498-
// Deliver tool output if available
499-
if (this.openai.toolOutput !== undefined) {
498+
// Deliver tool output if available (check for both null and undefined)
499+
if (this.openai.toolOutput != null) {
500500
queueMicrotask(() => {
501501
this.onmessage?.({
502502
jsonrpc: "2.0",

0 commit comments

Comments
 (0)