Skip to content

fix(openai): strip leaked tool result markers#483

Merged
CJackHwang merged 1 commit into
CJackHwang:devfrom
NgoQuocViet2001:ai/tool-result-leak-sanitize
May 10, 2026
Merged

fix(openai): strip leaked tool result markers#483
CJackHwang merged 1 commit into
CJackHwang:devfrom
NgoQuocViet2001:ai/tool-result-leak-sanitize

Conversation

@NgoQuocViet2001
Copy link
Copy Markdown
Contributor

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

Fixes #456.

Some leaked DeepSeek tool-result control sections can reach visible OpenAI-compatible output as <|Tool|>...<|end_of_toolresults|>, especially with fullwidth delimiters. The existing sanitizer removed standalone <|Tool|> markers and one JSON-object shape with tool_call_id, but it could leave the payload behind when the whole tool-result section was present.

This change keeps the visible-output sanitizer defensive by:

Duplicate check: reviewed current open PRs (#437, #407, #405) and recent merged sanitizer/tool-call work, especially #476. #476 covers adjacent leakage cases but not the Assistant_END_OF_TOOL_CALLS marker or full <|Tool|>...<|end_of_toolresults|> section shape.

📝 补充信息 | Additional Information

Validation run locally with portable Go 1.26.0:

  • gofmt -w internal/httpapi/openai/shared/leaked_output_sanitize.go internal/httpapi/openai/leaked_output_sanitize_test.go
  • go test ./internal/httpapi/openai -run 'TestSanitizeLeakedOutput' -count=1
  • go test ./internal/httpapi/openai/... -count=1
  • git diff --check
  • ./tests/scripts/check-refactor-line-gate.sh
  • ./tests/scripts/run-unit-all.sh
  • npm run build --prefix webui
  • ./scripts/lint.sh in an LF validation clone with golangci-lint v2.11.4: 0 issues

Note: on the normal Windows CRLF checkout, ./scripts/lint.sh reports repo-wide CRLF/LF formatting diffs in untouched Go files. The same patch passes the repo lint script in an LF clone.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

@NgoQuocViet2001 is attempting to deploy a commit to the cjack's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c9127a032

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/httpapi/openai/shared/leaked_output_sanitize.go
@NgoQuocViet2001 NgoQuocViet2001 force-pushed the ai/tool-result-leak-sanitize branch from 2c9127a to 3e935c0 Compare May 10, 2026 15:05
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

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

Project Deployment Actions Updated (UTC)
ds2api Ready Ready Preview, Comment May 10, 2026 3:31pm

@CJackHwang CJackHwang merged commit 92b3093 into CJackHwang:dev May 10, 2026
8 checks passed
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.

2 participants