Skip to content

fix(tools): accept zero-argument OpenAI tool calls and reject non-object args - #1612

Open
Agnik47 wants to merge 1 commit into
supermemoryai:mainfrom
Agnik47:fix/openai-zero-arg-tool-calls
Open

fix(tools): accept zero-argument OpenAI tool calls and reject non-object args#1612
Agnik47 wants to merge 1 commit into
supermemoryai:mainfrom
Agnik47:fix/openai-zero-arg-tool-calls

Conversation

@Agnik47

@Agnik47 Agnik47 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • treat arguments: "" as "no arguments" so the three required: [] tools are callable
  • reject non-object JSON at the gate instead of letting it throw out of executeToolCall
  • eight regression tests, six of which fail against main

Why

getProfile, documentList and memoryForget all declare required: [] in memoryToolSchemas, so a model may call them with no arguments. The OpenAI API serialises that as arguments: "", and parseToolArguments (added in #1594, cherry-picking #1488) hands the empty string straight to JSON.parse:

{"success":false,"error":"Invalid JSON arguments for getProfile"}

So those three tools never work in their documented no-argument form — the model gets a hard error back and no call is made.

The same gate also lets non-object JSON through, which is the case #1488 was meant to close. "null" parses cleanly, then rejects in the destructuring parameter of every tool function:

TypeError: Cannot destructure property 'containerTag' of 'object null' as it is null.

executeToolCall has no catch, so that rejection escapes and fails the whole request — exactly the throw the gate exists to contain. "5" and "\"text\"" are quieter but worse: they destructure to undefined and call the API with no container tag.

Change

packages/tools/src/openai/tools.ts — blank arguments parse as {}, and the parsed value must be a non-null, non-array object. Malformed JSON still returns the tool error #1488 introduced.

Validation

…ect args

`getProfile`, `documentList` and `memoryForget` all declare `required: []`,
so a model may legitimately call them with no arguments at all. The OpenAI
API serialises that as `arguments: ""`, and `parseToolArguments` handed the
empty string straight to `JSON.parse`, so every no-argument call came back as

    {"success":false,"error":"Invalid JSON arguments for getProfile"}

Those three tools were unreachable in their documented no-argument form.

The same gate also lets non-object JSON through. `"null"` parses cleanly and
then rejects in the destructuring parameter of every tool function --
`TypeError: Cannot destructure property 'containerTag' of 'object null'` --
which escapes `executeToolCall`, since it has no catch, and fails the whole
request. That is precisely the throw supermemoryai#1488 added this gate to contain. `"5"`
and `"\"text\""` are quieter but worse: they destructure to `undefined` and
call the API with no container tag at all.

Treat blank arguments as `{}`, and require the parsed value to be a non-null,
non-array object. Malformed JSON still returns the tool error supermemoryai#1488 added.

Adds eight regression tests. Six of them fail against the current
implementation -- two on the blank-argument path and four on the non-object
path, one carrying the raw TypeError. The two guard tests, malformed JSON and
an ordinary well-formed call, pass both before and after, so the behaviour
supermemoryai#1488 established is pinned rather than changed.
@Agnik47
Agnik47 force-pushed the fix/openai-zero-arg-tool-calls branch from 9749f03 to 14cfc75 Compare August 28, 2026 16:57
@yesprasad

Copy link
Copy Markdown

DeepGraph consequence review
DeepGraph traced the changed parseToolArguments helper in:
packages/tools/src/openai/tools.ts:555
The change reaches createToolCallExecutor and downstream package and test surfaces, including:

  • packages/tools/src/openai/index.ts
  • packages/tools/src/index.ts
  • packages/tools/test-supermemory.ts
  • packages/tools/test/chatapp/app/api/openai-chat/route.ts
  • packages/tools/test/openai-responses-test.ts

The workspace analysis completed successfully:

  • 11 projects discovered
  • Bun + Turborepo workspace
  • 49 workspace imports resolved
  • 0 unresolved workspace imports
  • Maximum dependency depth: 3

The existing tests already cover empty, whitespace-only, malformed, primitive, array, null, and valid object arguments.
The remaining validation question is whether the intended parser behavior is preserved across every downstream executor and runtime surface identified above—particularly the chat route, Supermemory example, package exports, and response tests.
This is an evidence-based consequence report, not a claim that the implementation is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants