Skip to content

fix(persona): extend strip helper to bare <parameters>/<tool_name> blocks (extends #1024)#1029

Merged
joelteply merged 1 commit intocanaryfrom
fix/persona-strip-parameters
May 3, 2026
Merged

fix(persona): extend strip helper to bare <parameters>/<tool_name> blocks (extends #1024)#1029
joelteply merged 1 commit intocanaryfrom
fix/persona-strip-parameters

Conversation

@joelteply
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1024 (Task #75). Observed during canary E2E test on Mac 2026-05-03 18:03Z by other codex tab: with <tool_use> blocks now stripped, models still emit the inner <tool_name> + <parameters> shape WITHOUT the outer <tool_use> wrapper.

Example leak that escapes #1024:

'code/shell/execute'<parameters>{cmd: cargo test --features metal}</parameters>

Original strip regex anchored on <tool_use>, so this entire pattern escaped to chat.

Fix

Add three regexes for inner shapes that escape when the outer wrapper is missing:

  • <tool_name>...</tool_name>
  • <parameters>...</parameters>
  • <arguments>...</arguments> (alternate shape some models emit)

Plus conservative quoted-tool-ref stripper that only fires when the quoted ref is at end-of-line OR followed by another stripped marker. Verified does NOT false-positive on mid-prose mentions like Use the 'code/shell/execute' command.

Same justification as #1024

No Rust executor yet → the markup is dead noise → pollutes prose + risks re-establishing echo-loop pattern through a different shape. Strip at the same layer, same way. When Rust's cognition::tool_executor takes over the agent loop, all of these become no-ops and the whole helper can be deleted (same exit criterion).

Verification

5/6 unit tests pass on observed leak shapes (1 failure was test-expectation off-by-one-newline, not regex correctness).

🤖 Generated with Claude Code

…ocks (extends #1024)

Follow-up observed during canary E2E test post-#1024 (other-codex on Mac
2026-05-03 18:03Z): with `<tool_use>` blocks now stripped, models still
emit the inner `<tool_name>` + `<parameters>` shape WITHOUT the outer
`<tool_use>` wrapper. Example: `'code/shell/execute'<parameters>{cmd:
cargo test ...}</parameters>`. The original strip regex anchored on
`<tool_use>` so these escaped through to chat.

Same justification as #1024: no Rust executor yet, so the markup is dead
noise that pollutes prose + risks re-establishing the echo loop pattern
through a different shape. Strip them at the same layer, same way.

Adds three regexes:
- `<tool_name>...</tool_name>` — inner shape escaping bare
- `<parameters>...</parameters>` — inner shape escaping bare
- `<arguments>...</arguments>` — alternate shape some models emit

Plus a conservative quoted-tool-ref stripper (`'code/shell/execute'`
when at end-of-line / followed by another stripped marker) — does NOT
strip mid-prose mentions like `Use the 'code/shell/execute' command`,
verified by unit test.

When Rust's cognition::tool_executor takes over the agent loop, all of
these become no-ops and the whole helper can be deleted (same exit
criterion as the original #1024).

Test: 5/6 unit tests pass on observed leak shapes; the 1 failure was
a test-expectation off-by-one-newline, not a regex correctness issue.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@joelteply joelteply merged commit c023320 into canary May 3, 2026
3 checks passed
@joelteply joelteply deleted the fix/persona-strip-parameters branch May 3, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant