Skip to content

fix(tools): handle malformed OpenAI tool arguments - #1488

Closed
abhinav7x94 wants to merge 1 commit into
supermemoryai:mainfrom
abhinav7x94:fix/tools-invalid-json-arguments
Closed

fix(tools): handle malformed OpenAI tool arguments#1488
abhinav7x94 wants to merge 1 commit into
supermemoryai:mainfrom
abhinav7x94:fix/tools-invalid-json-arguments

Conversation

@abhinav7x94

Copy link
Copy Markdown
Contributor

What changed

  • return the existing structured error shape when OpenAI tool arguments contain malformed JSON
  • keep one malformed call from rejecting an entire tool-call batch
  • add focused offline regression coverage

Why

OpenAI-compatible models can emit partial or invalid JSON in function arguments. The executor previously parsed outside its result flow, so a SyntaxError escaped and Promise.all discarded sibling results.

Validation

  • bunx vitest run src/openai/tools.test.ts src/tool-operations.test.ts --testTimeout 100000 (16 passed)
  • bun run build
  • bunx biome check packages/tools/src/openai/tools.ts packages/tools/src/openai/tools.test.ts
  • git diff --check

The package-wide TypeScript command remains red on unrelated pre-existing dependency and example errors; it reports no errors in the new test or changed lines.

@MaheshtheDev

Copy link
Copy Markdown
Member

Included in #1594 with your commit and authorship intact, plus a Co-Authored-By trailer in the description so the credit survives the squash merge.

We dropped tools.test.ts. The parseToolArguments change itself is unchanged.

Thanks @abhinav7x94.

graphite-app Bot pushed a commit that referenced this pull request Aug 24, 2026
#1594)

Cherry-picks four contributor PRs for `@supermemory/tools` onto one branch, and bumps the package to 2.2.0.

- #1244 (@rajarshidattapy): `withSupermemory` accepts `options.apiKey` instead of only reading `SUPERMEMORY_API_KEY`, matching the Vercel, Mastra and Voltagent integrations. Unblocks secrets managers, edge runtimes and per-request keys.
- #1574 (@Agnik47): re-exports `PromptTemplate`, `MemoryPromptData` and `WithSupermemoryOptions` from `ai-sdk`. `./vercel` is not a published subpath, so the documented custom-template example did not compile.
- #1488 (@abhinav7x94): malformed tool-call JSON returns an error result instead of throwing out of the request.
- #1507 (@abhinav7x94): VoltAgent `onEnd` awaits the conversation save, which was fire-and-forget and could be dropped when a serverless runtime tore down.

Dropped the `middleware.test.ts` added by #1244. Note that editing `packages/tools/package.json` triggers the npm publish workflow on merge.

Co-Authored-By: rajarshidattapy <138959719+rajarshidattapy@users.noreply.github.com>
Co-Authored-By: Agnik47 <140933190+Agnik47@users.noreply.github.com>
Co-Authored-By: abhinav7x94 <204053250+abhinav7x94@users.noreply.github.com>
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