Skip to content

Parse whole-response tool call arrays - #2689

Merged
webbrain-one merged 2 commits into
mainfrom
agent/parse-whole-response-tool-call-arrays
Aug 6, 2026
Merged

Parse whole-response tool call arrays#2689
webbrain-one merged 2 commits into
mainfrom
agent/parse-whole-response-tool-call-arrays

Conversation

@webbrain-one

Copy link
Copy Markdown
Owner

Summary

  • parse a tool-call batch when the entire trimmed model response is a valid JSON array
  • require every array element to be an allowed call object and reject mixed or disallowed batches atomically
  • handle whole-response arrays before wrapper, XML, bare-object, and call:name{} fallbacks so call-like strings inside rejected arrays cannot be mined
  • keep prose-prefixed, prose-suffixed, labeled, bulleted, and otherwise inline arrays ignored
  • preserve Chrome/Firefox byte parity and the existing fallback output shape

Why

PR #2682 deliberately narrowed bare JSON recovery to objects that stand alone on their line. That safer rule also drops legitimate compact batches such as:

[{"name":"read_page","arguments":{}},{"name":"click","arguments":{"text":"Go"}}]

Parsing only when the complete response is a JSON array recovers that format without reopening arbitrary inline-object scanning. Atomic validation prevents an allowed-looking subset from executing when another element is disallowed, metadata, narration, or a call-like string.

Validation

  • node test/run.js: 1,483 passed; the sole failure is the pre-existing package.json 26.1.2 vs CHANGELOG.md 26.1.0 assertion
  • node test/security/injection-corpus.mjs: 60/60
  • node --check on both parser modules
  • Chrome and Firefox parser SHA-256 values are identical
  • git diff --check

@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webbrain Ready Ready Preview Aug 6, 2026 8:53am

Request Review

@esokullu
esokullu marked this pull request as ready for review August 6, 2026 08:45
@webbrain-one
webbrain-one requested a balanced review from Copilot August 6, 2026 08:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds safe recovery of whole-response JSON tool-call arrays while preserving parser security boundaries and browser parity.

Changes:

  • Parses valid standalone JSON arrays atomically.
  • Rejects mixed, disallowed, and narrated batches.
  • Adds Chrome/Firefox parity and regression coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/chrome/src/agent/tool-call-parser.js Adds atomic array parsing and shared conversion.
src/firefox/src/agent/tool-call-parser.js Mirrors the Chrome parser changes.
test/run.js Covers valid, narrated, mixed, and disallowed arrays.

馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@webbrain-one
webbrain-one merged commit a643949 into main Aug 6, 2026
7 checks passed
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.

3 participants