Skip to content

Ignore tool_call payloads inside fenced code blocks and chat envelopes; stream-aware code-fence tracking#149

Merged
CJackHwang merged 7 commits intodevfrom
codex/fix-tool-miscall-during-complex-json-test
Mar 22, 2026
Merged

Ignore tool_call payloads inside fenced code blocks and chat envelopes; stream-aware code-fence tracking#149
CJackHwang merged 7 commits intodevfrom
codex/fix-tool-miscall-during-complex-json-test

Conversation

@CJackHwang
Copy link
Owner

Motivation

  • Prevent accidental parsing/execution of tool_calls that appear only inside fenced code examples or inside chat transcript envelopes.
  • Improve streaming detection of fenced code blocks so tool detection does not misfire when backticks are split across chunks.
  • Support more robust detection for nested/qualified markup tool syntax and extend the context tail window for streaming state.

Description

  • Add heuristics to skip tool-call parsing when the only occurrences are inside fenced code blocks by implementing stripFencedCodeBlocks / shouldSkipToolCallParsingForCodeFenceExample in both JS and Go parsers.
  • Detect and ignore chat-transcript-style envelopes that contain a tool_calls field using isLikelyChatMessageEnvelope / isLikelyChatMessageEnvelope in both languages.
  • Make sieve code stream-aware of fenced code state by increasing TOOL_SIEVE_CONTEXT_TAIL_LIMIT from 256 to 4096 and adding incremental fence tracking (codeFenceStack, codeFencePendingTicks, codeFenceLineStart), plus insideCodeFenceWithState, updateCodeFenceState, and related simulation helpers.
  • Update parsing flow to consult the stream-aware fence state in findToolSegmentStart and consumeToolCapture, and add markup-syntax checks to avoid false positives.
  • Mirror the JS changes in Go utility functions (toolcalls_candidates.go, toolcalls_parse.go) and add unit tests and expected fixtures updates to cover ignoring fenced JSON blocks, chat envelope cases, chunk-split fences, nested fences, and legacy behavior adjustments.

Testing

  • Updated and ran unit tests for the Go package (go test ./...) and Node tests (npm test / test suite used in repository), including new tests for fenced JSON ignoring, transcript envelope ignoring, chunk-split fence handling, and nested fences, and all tests passed.
  • Updated compatibility fixtures (tests/compat/expected) to reflect the new behavior for fenced examples and validated against the test expectations.
  • Existing parsing and sieve tests were exercised and confirmed to still detect legitimate tool_calls outside of ignored contexts.

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 8:37am

Copy link

@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: b108a7915a

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ol-call-parsing

Do not promote fenced code examples to tool calls and centralize tool-keyword detection
@CJackHwang CJackHwang merged commit b0a09df into dev Mar 22, 2026
3 checks passed
@CJackHwang CJackHwang deleted the codex/fix-tool-miscall-during-complex-json-test branch March 22, 2026 08:50
CJackHwang added a commit that referenced this pull request Mar 22, 2026
Merge pull request #149 from CJackHwang/codex/fix-tool-miscall-during-complex-json-test

Ignore tool_call payloads inside fenced code blocks and chat envelopes; stream-aware code-fence tracking
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