Skip to content

Sanitize leaked tool-call wire format in assistant text#157

Merged
CJackHwang merged 2 commits intodevfrom
codex/analyze-toolcall-output-formatting-issue
Mar 22, 2026
Merged

Sanitize leaked tool-call wire format in assistant text#157
CJackHwang merged 2 commits intodevfrom
codex/analyze-toolcall-output-formatting-issue

Conversation

@CJackHwang
Copy link
Owner

Motivation

  • Long toolcall conversations can surface intermediate wire-format fragments (tool-call arrays, result blobs, and meta markers) into visible assistant text when relay/client layers mis-handle or reserialize tool events.
  • Once leaked into visible text these fragments can be treated as context and then amplified by subsequent model turns.
  • Add server-side defensive sanitization to remove these artifacts before they contaminate downstream conversation state.

Description

  • Add three regex detectors leakedToolCallArrayPattern, leakedToolResultBlobPattern, and leakedMetaMarkerPattern in internal/adapter/openai/tool_history_sanitize.go and apply them in sanitizeLeakedToolHistory to strip wire-format arrays, <| Tool |>… result blobs, and <| … |> meta markers.
  • Preserve existing cleanup behavior for [TOOL_CALL_HISTORY]/[TOOL_RESULT_HISTORY] blocks and empty JSON fences (emptyJSONFencePattern).
  • Add regression tests in internal/adapter/openai/tool_history_sanitize_test.go that exercise leaked wire-format tool-call + result sequences and standalone meta-marker leaks.

Testing

  • Ran go test ./internal/adapter/openai -run SanitizeLeakedToolHistory -count=1 and the test run completed successfully.
  • The new tests in tool_history_sanitize_test.go passed, confirming the sanitizer removes the targeted leak patterns.

Codex Task

@vercel
Copy link

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ds2api Ready Ready Preview, Comment Mar 22, 2026 2:36pm

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@CJackHwang CJackHwang merged commit 6e8f318 into dev Mar 22, 2026
3 checks passed
@CJackHwang CJackHwang deleted the codex/analyze-toolcall-output-formatting-issue branch March 22, 2026 14:46
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