fix(tools): accept zero-argument OpenAI tool calls and reject non-object args - #1612
Open
Agnik47 wants to merge 1 commit into
Open
fix(tools): accept zero-argument OpenAI tool calls and reject non-object args#1612Agnik47 wants to merge 1 commit into
Agnik47 wants to merge 1 commit into
Conversation
…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
force-pushed
the
fix/openai-zero-arg-tool-calls
branch
from
August 28, 2026 16:57
9749f03 to
14cfc75
Compare
|
DeepGraph consequence review
The workspace analysis completed successfully:
The existing tests already cover empty, whitespace-only, malformed, primitive, array, null, and valid object arguments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
arguments: ""as "no arguments" so the threerequired: []tools are callableexecuteToolCallmainWhy
getProfile,documentListandmemoryForgetall declarerequired: []inmemoryToolSchemas, so a model may call them with no arguments. The OpenAI API serialises that asarguments: "", andparseToolArguments(added in #1594, cherry-picking #1488) hands the empty string straight toJSON.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:executeToolCallhas nocatch, 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 toundefinedand 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
vitest run src/inpackages/tools— 42 passed;src/tools.test.tsstill fails on a missingSUPERMEMORY_API_KEY, which is pre-existing onmainand unrelatedopenai/tools.tsto themainversion and re-ran: 6 of the 8 new tests fail, one with the rawTypeErrorabove. The two guard tests — malformed JSON, and an ordinary well-formed call — pass both before and after, so fix(tools): handle malformed OpenAI tool arguments #1488's behaviour is pinned rather than changedtsc --noEmitonpackages/tools: identical to themainbaseline (the three pre-existingopenai/tools.tserrors at 329/336/369 remain, tracked in@supermemory/toolsfailscheck-types: 31 errors intest/, including an import of a file that no longer exists #1545; no new ones)biome checkclean onopenai/tools.ts