Skip to content

fix(client): reject brace-match tool calls with trailing prose - #104

Merged
Patel230 merged 1 commit into
mainfrom
fix/inline-toolcall-false-positives
Aug 3, 2026
Merged

fix(client): reject brace-match tool calls with trailing prose#104
Patel230 merged 1 commit into
mainfrom
fix/inline-toolcall-false-positives

Conversation

@Patel230

@Patel230 Patel230 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Phase 3 medium audit finding (E4): the Tier 3 inline tool-call fallback in client/core/stream.go (parseBraceMatchToolCall) would treat any JSON-shaped {"name": ..., "arguments": {...}} object found anywhere in a response as a tool call to execute — including JSON examples in prose or inside code fences. This is a false-positive execution risk: model output that merely illustrates a tool call would be executed.

Fix

parseBraceMatchToolCall now requires the candidate JSON object to run to the end of the response (ignoring trailing whitespace). If any prose follows the closing }, the text is treated as an example/explanation, not a tool call. The engine-level gates in engine/host_runtime.go and client/aliases.go are unchanged — both delegate to the single real implementation.

Tests

  • TestParseBraceMatch_JSONExampleInProseNotExecuted — example followed by prose ⇒ no call
  • TestParseBraceMatch_FencedJSONExampleNotExecuted — JSON in code fences ⇒ no call
  • TestParseBraceMatch_TrailingWhitespaceStillParsed — trailing whitespace (common in generation) still yields a call

Verified: go test ./client/... ./engine/ all green.

@Patel230
Patel230 merged commit 026bfdd into main Aug 3, 2026
16 checks passed
@Patel230
Patel230 deleted the fix/inline-toolcall-false-positives branch August 3, 2026 00:30
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.

1 participant