Skip to content

fix(desktop): harden WPP tool-call parsing - #72

Closed
trmosala wants to merge 1 commit into
devfrom
harden-tool-parsing
Closed

trmosala wants to merge 1 commit into
devfrom
harden-tool-parsing

Conversation

@trmosala

Copy link
Copy Markdown
Owner

Related issue (optional)

None. Follows the bridge review findings H1–H4.

Companion PR: https://github.com/trmosala/CM-WPP-Bits/pull/1 ports the same fix to the extracted bridge package. That keeps the fix when the CookieMonster split removes packages/desktop/src/main/wpp-bridge/ from this repo.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Hardens toolCallNormalizer.mjs, which turns WPP model text into tool calls:

  • Ordinary JSON in an answer, such as a package.json with a name field, no longer runs as a tool call. Only XML function_calls markup and JSON typed tool_call count. A JSON call must also name a tool from the request.
  • Calls inside code fences, whether backtick or tilde and whether closed or not, are treated as examples, as are calls in inline code. They never run.
  • String parameters keep their exact bytes. Values are typed by the request's tool schemas, close tags inside a value no longer cut it short, CDATA is taken verbatim, and valid JSON escapes are no longer rewritten.
  • Every call in a batch is kept. A truncated XML batch fails with o1_code_incomplete_tool_call instead of running only its first part.
  • A malformed fallback candidate no longer hides a later valid one, and JSON history keeps call ids.

Behaviour change: a reply that consists only of a fenced call no longer runs. The WPP agent prompt already forbids fencing calls. If such a reply is also missing the completion marker, the bridge still sends one continuation turn. Proxy logs omit payloads by default, so I couldn't measure how often agents fence calls.

The XML reminder gains two rules, one about fences and one about CDATA, so the pinned Opus envelope hash changes. I checked that those two lines are the only difference. The WPP agent prompt doesn't need reinstalling.

This PR doesn't change authentication, browser grants, permissions, logging, dependencies or release workflows.

How did you verify your code works?

  • bun test src/main/wpp-bridge/ from packages/desktop: 518 pass, 0 fail, including 18 new normalizer tests.
  • bun typecheck from packages/desktop: pass.
  • oxlint packages/desktop/src/main/wpp-bridge/proxy: 0 errors. The 2 warnings are in code this PR doesn't touch.
  • Not run: a live WPP or Electron session.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Only the two transport shapes now become tool calls: XML function_calls
markup and JSON objects typed tool_call. Code fences and inline code hold
examples and never run, and a JSON call must name a tool in the request.

String parameters keep their exact bytes. Values are typed by the
request's tool schemas, close tags inside a value no longer truncate it,
CDATA is taken verbatim, entities decode once across all of Unicode, and
valid JSON escapes are no longer rewritten.

Batches keep every call. Distinct JSON calls are no longer dropped, a
truncated XML batch fails as o1_code_incomplete_tool_call instead of
running its prefix, repeated ids get fresh ones, and a malformed fallback
candidate no longer hides a later valid one. JSON history keeps call ids.

The XML reminder gains two rules about fences and CDATA, so the pinned
Opus envelope hash is updated.
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant