Skip to content

fix(toolcall): fix deepseek function calling bug and add json repair#92

Merged
CJackHwang merged 5 commits intoCJackHwang:devfrom
valkryhx:main
Mar 17, 2026
Merged

fix(toolcall): fix deepseek function calling bug and add json repair#92
CJackHwang merged 5 commits intoCJackHwang:devfrom
valkryhx:main

Conversation

@valkryhx
Copy link
Contributor

  • Fix: Expand stream sieve keywords to support function.name: and [TOOL_CALL_HISTORY]

  • Fix: Add repairInvalidJSONBackslashes to handle unescaped backslashes in Windows paths

  • Sync: Update JS stream sieve to match Go implementation

  • Test: Add unit tests for backslash repair and deepseek format parsing

  • Tool: Move repair json test tool to tests/repair_json_tool.go

CJackHwang and others added 2 commits March 9, 2026 21:42
Merge pull request CJackHwang#89 from CJackHwang/codex/review-changes-in-pull-request-#88

Support text-kv `function.name`/`function.arguments` fallback and looser name matching
- Fix: Expand stream sieve keywords to support function.name: and [TOOL_CALL_HISTORY]

- Fix: Add repairInvalidJSONBackslashes to handle unescaped backslashes in Windows paths

- Sync: Update JS stream sieve to match Go implementation

- Test: Add unit tests for backslash repair and deepseek format parsing

- Tool: Move repair json test tool to tests/repair_json_tool.go
@vercel
Copy link

vercel bot commented Mar 13, 2026

@valkryhx 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

@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: 7318d1f4a8

ℹ️ 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".

return -1
}
lower := strings.ToLower(s)
keywords := []string{"tool_calls", "function.name:", "[tool_call_history]"}

Choose a reason for hiding this comment

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

P1 Badge Parse newly-detected DeepSeek markers before capturing stream

Adding function.name: and [TOOL_CALL_HISTORY] to the start detector makes the sieve enter capture mode for DeepSeek text-KV outputs, but this capture path is still parsed only via tool_calls JSON in consumeToolCapture. In that scenario ready stays false on each chunk, so streaming content is withheld until flush and no tool call is emitted, which regresses live responses whenever these markers appear.

Useful? React with 👍 / 👎.

if i+1 < len(runes) {
next := runes[i+1]
switch next {
case '"', '\\', '/', 'b', 'f', 'n', 'r', 't':

Choose a reason for hiding this comment

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

P1 Badge Escape backslash-n/t/r sequences in repaired path arguments

The repair routine currently preserves escapes like \n, \t, and \r as valid JSON escapes, which breaks the Windows-path recovery this change introduces: inputs such as {"path":"C:\new\tmp"} still deserialize with newline/tab characters instead of literal backslashes. This silently corrupts tool arguments after json.Unmarshal rather than returning the original raw payload.

Useful? React with 👍 / 👎.

@vercel
Copy link

vercel bot commented Mar 13, 2026

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

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

@CJackHwang
Copy link
Owner

  • Fix: Expand stream sieve keywords to support function.name: and [TOOL_CALL_HISTORY]

  • Fix: Add repairInvalidJSONBackslashes to handle unescaped backslashes in Windows paths

  • Sync: Update JS stream sieve to match Go implementation

  • Test: Add unit tests for backslash repair and deepseek format parsing

  • Tool: Move repair json test tool to tests/repair_json_tool.go

@valkryhx You can look at the review results of codex and see if you can solve it. Thank you.

@CJackHwang CJackHwang self-requested a review March 15, 2026 10:35
- Upgrade missingArrayBracketsPattern regex to support single-level nested {} objects
- This fixes DeepSeek's list hallucination where tool call JSON objects contain nested fields like {"input": {"q": "value"}}
- Add comprehensive test cases covering 2-5 nested objects, mixed nested/primitive fields, and real DeepSeek 8-queen output patterns
- Add RepairLooseJSON function to repair unquoted keys and missing array brackets

Fixes: DeepSeek tool call parsing with nested JSON objects
…ds and safety limits

- Add support for multiple keywords: tool_calls, function.name:, [tool_call_history]
- Add OOM protection with search limits in extractToolCallObjects
- Add max scan length limit in extractJSONObject to prevent OOM on unclosed objects
- Update tool_sieve to handle more tool call patterns
- Add loose JSON repair in parseToolCallPayload for better error recovery

This improves DeepSeek tool call parsing robustness.
- Add targeted test commands to TESTING.md for debugging tool call issues
- Add quick test commands reference in README.md
- Document specific test cases for DeepSeek tool call parsing
@CJackHwang CJackHwang merged commit f16e0b5 into CJackHwang:dev Mar 17, 2026
0 of 5 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