Skip to content

fix(agent): frame all external tool text safely - #2

Draft
Bonchaloo wants to merge 2 commits into
mainfrom
fix/untrusted-tool-result-framing
Draft

Bonchaloo wants to merge 2 commits into
mainfrom
fix/untrusted-tool-result-framing

Conversation

@Bonchaloo

@Bonchaloo Bonchaloo commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Issue

make_tool_result_message treated external text beginning with <untrusted_tool_result as if Hermes had already framed it. A fetched result could therefore bypass the provenance warning. An embedded closing tag could also end the frame early, and results shorter than 32 characters had no frame. The external x_search tool was absent from the high-risk classifier.

Change

  • Frame every nonempty string from web, browser, MCP, and X search tools.
  • Escape reserved frame delimiters supplied by the source.
  • Frame text parts of multimodal tool results while preserving image parts and list shape.

Verification

  • Synthetic offline canaries reproduced all three framing gaps on base 929dd9c0d776186d1e8bf268cccfdb31e0398365; patched readback had one opening and one closing delimiter plus the provenance warning.
  • scripts/run_tests.sh tests/agent/test_tool_dispatch_helpers.py -q: 32 passed.
  • Follow-up after CI: pytest tests/run_agent/test_tool_call_guardrail_runtime.py tests/agent/test_tool_dispatch_helpers.py -q: 41 passed in an isolated Python 3.13 interpreter with read-only Python 3.12 site-packages for missing gateway dependencies. The prior test expected raw JSON in the model-facing web_search message; it now asserts the untrusted frame and verifies that progress and completion callbacks still receive raw JSON. Source inspection found no production parser requiring raw JSON in that model-facing message; trajectory export safely stores framed content as text.
  • Ruff and git diff --check: passed.

No model compliance, real command execution, live provider response, or deployed installation was tested. Draft for security review; please do not merge until reviewed.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🔎 Lint report: fix/untrusted-tool-result-framing vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 12433 on HEAD, 12430 on base (🆕 +3)

🆕 New issues (3):

Rule Count
unresolved-attribute 3
First entries
run_agent.py:3069: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
tests/run_agent/test_tool_call_guardrail_runtime.py:197: [unresolved-attribute] unresolved-attribute: Unresolved attribute `tool_complete_callback` on type `AIAgent`

✅ Fixed issues (1):

Rule Count
invalid-assignment 1
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`

Unchanged: 6742 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

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