fix(engine,ui): strip pseudo tool-call text before it reaches the user #52

Merged
salmaelsoly merged 2 commits from development_strip_pseudo_tool_call_text into development 2026-05-25 13:08:35 +00:00
Member

Summary

Implements a three-layer defense against models that emit [TOOL_CALL]{tool => ..., args => {}}[/TOOL_CALL] pseudo-syntax (e.g. minimax-m2.7 via OpenRouter) instead of using the provider tool-call protocol.

Closes #24

Changes

  • tool_call_recovery.rs: Added strip_bracket_tool_calls (extracts [TOOL_CALL]...[/TOOL_CALL] blocks) and normalize_arrow_syntax (converts {tool => "name", args => {...}} arrow syntax to canonical JSON). Includes 6 unit tests.
  • tool_call_recovery_module.rs: Extended lift_recovered_tool_calls to handle bracket syntax at the top of the function — promotes to a real tool call if the tool name is registered, otherwise sanitizes content before it reaches the user.
  • session.rs: Added tracing::warn! to strip_fake_tool_call_envelopes when it fires (final-reply fallback, now observable). Added unit test for the bracket-only case.
  • store.ts: Added stripBracketToolCalls helper wired into flushStreamBuffer (streaming defense) and the turn:end SSE handler (final display defense).

Test Results

1664 tests passed. 9 pre-existing environment failures (no /bin/sh, python3, bubblewrap in sandbox) — unrelated to these changes.

## Summary Implements a three-layer defense against models that emit `[TOOL_CALL]{tool => ..., args => {}}[/TOOL_CALL]` pseudo-syntax (e.g. minimax-m2.7 via OpenRouter) instead of using the provider tool-call protocol. ## Related Issue Closes https://forge.ourworld.tf/lhumina_code/hero_shrimp/issues/24 ## Changes - **`tool_call_recovery.rs`**: Added `strip_bracket_tool_calls` (extracts `[TOOL_CALL]...[/TOOL_CALL]` blocks) and `normalize_arrow_syntax` (converts `{tool => "name", args => {...}}` arrow syntax to canonical JSON). Includes 6 unit tests. - **`tool_call_recovery_module.rs`**: Extended `lift_recovered_tool_calls` to handle bracket syntax at the top of the function — promotes to a real tool call if the tool name is registered, otherwise sanitizes content before it reaches the user. - **`session.rs`**: Added `tracing::warn!` to `strip_fake_tool_call_envelopes` when it fires (final-reply fallback, now observable). Added unit test for the bracket-only case. - **`store.ts`**: Added `stripBracketToolCalls` helper wired into `flushStreamBuffer` (streaming defense) and the `turn:end` SSE handler (final display defense). ## Test Results 1664 tests passed. 9 pre-existing environment failures (no `/bin/sh`, `python3`, `bubblewrap` in sandbox) — unrelated to these changes.
fix(engine,ui): strip pseudo tool-call text before it reaches the user
Some checks failed
Verify / verify (push) Failing after 11s
Verify / verify (pull_request) Failing after 8s
1b473f53a4
fix: handle potential errors when fetching and parsing JSON responses
Some checks failed
Verify / verify (push) Failing after 8s
Verify / verify (pull_request) Failing after 11s
da9bec939b
salmaelsoly merged commit abe0db2563 into development 2026-05-25 13:08:35 +00:00
salmaelsoly deleted branch development_strip_pseudo_tool_call_text 2026-05-25 13:08:40 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_shrimp!52
No description provided.