Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Recognize and emit executable tool_calls in mixed prose streams; normalize roles and loosen tool-name matching#74

Merged
CJackHwang merged 1 commit intodevfrom
codex/fix-toolcall-whitelist-issue
Mar 2, 2026
Merged

Recognize and emit executable tool_calls in mixed prose streams; normalize roles and loosen tool-name matching#74
CJackHwang merged 1 commit intodevfrom
codex/fix-toolcall-whitelist-issue

Conversation

@CJackHwang
Copy link
Owner

Motivation

  • Treat tool JSON embedded in non-code-block prose as executable tool calls (instead of always preserving as plain text) to support mixed-content streaming tool handoff.
  • Preserve fenced code blocks as examples and do not execute tool snippets inside them.
  • Allow more flexible tool-name matching (qualified names and punctuation variants) so canonical tool names resolve more robustly.
  • Map a developer role to system in prompt normalization to keep role semantics consistent.

Description

  • Updated streaming sieve logic in internal/adapter/openai/tool_sieve_core.go to emit pending tool_calls events for mixed prose and to preserve surrounding prefix/suffix text properly.
  • Relaxed consumeToolCapture constraints so non-whitespace wrapping no longer forces tool JSON to be treated only as plain text when it should be parsed as tool calls.
  • Added fuzzy tool-name resolution in internal/util/toolcalls_parse.go with resolveAllowedToolName and a loose punctuation-stripping pattern to accept qualified or punctuation-variant names (e.g. mcp.search_web, read-file) and canonicalize them.
  • Introduced normalizeOpenAIRoleForPrompt in internal/adapter/openai/message_normalize.go and applied it in responses_input_items.go and message normalization to convert developer to system.
  • Adjusted and added unit tests across the repo: OpenAI handler stream/toolcall tests and responses tests, Gemini adapter tests, toolcalls parser tests, and message normalization tests to reflect the new behavior.
  • Documentation updates in API.md, README.en.md, and TESTING.md clarifying that tool JSON in non-code-block contexts can be recognized even when mixed with prose and that fenced code block examples are exempt.

Testing

  • Ran go test ./... -count=1 including updated packages; unit test suite passed.
  • Executed modified/added Go tests in internal/adapter/openai, internal/adapter/gemini, and internal/util (e.g. toolcalls parsing and message normalization tests) and they succeeded.
  • Confirmed streaming behavior checks by exercising updated SSE parsing tests (responses and chat stream tests), which passed under the new expectations.

Codex Task

@vercel
Copy link

vercel bot commented Mar 2, 2026

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

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

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@CJackHwang CJackHwang merged commit a10e03e into dev Mar 2, 2026
3 checks passed
@CJackHwang CJackHwang deleted the codex/fix-toolcall-whitelist-issue branch March 2, 2026 16:40
@CJackHwang CJackHwang linked an issue Mar 2, 2026 that may be closed by this pull request
CJackHwang added a commit that referenced this pull request Mar 2, 2026
Merge pull request #74 from CJackHwang/codex/fix-toolcall-whitelist-issue

Recognize and emit executable tool_calls in mixed prose streams; normalize roles and loosen tool-name matching
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.

[Bug] cc的工具调用不正常

1 participant