Skip to content

fix: 避免 assistant.content=nil 注入 "null" 导致工具历史混杂#79

Merged
CJackHwang merged 3 commits intodevfrom
codex/analyze-and-optimize-issue-#77
Mar 6, 2026
Merged

fix: 避免 assistant.content=nil 注入 "null" 导致工具历史混杂#79
CJackHwang merged 3 commits intodevfrom
codex/analyze-and-optimize-issue-#77

Conversation

@CJackHwang
Copy link
Owner

Motivation

  • 修复当上一轮 assistant 仅返回 tool_callscontent = null 时,归一化过程把 nil 序列化为字面量 null 并注入到提示词中,导致工具历史块与自然语言混杂,干扰后续工具识别和执行。

Description

  • normalizeOpenAIContentForPrompt 中对 nil 值做了提前返回空字符串处理以避免注入 "null"(修改文件:internal/adapter/openai/message_normalize.go)。
  • 新增回归单元测试 TestNormalizeOpenAIMessagesForPrompt_AssistantNilContentDoesNotInjectNullLiteral 覆盖 assistant.content=nil + tool_calls 场景,确保不会注入 null 字面量且工具历史块仍被保留(修改文件:internal/adapter/openai/message_normalize_test.go)。

Testing

  • 运行了 go test ./internal/adapter/openai ./internal/util,所有测试均通过。

Codex Task

@vercel
Copy link

vercel bot commented Mar 5, 2026

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

Project Deployment Actions Updated (UTC)
ds2api Ready Ready Preview, Comment Mar 6, 2026 1:24pm

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: 0e261ff0a0

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

default:
return marshalToPromptString(v)
}
return prompt.NormalizeContent(v)

Choose a reason for hiding this comment

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

P2 Badge Preserve content fallback when text is empty

Delegating normalizeOpenAIContentForPrompt to prompt.NormalizeContent changes behavior for array content items that include both text and content: the previous implementation only consumed text when it was non-empty, then fell back to content, but NormalizeContent treats an empty text string as present and continues, so non-empty content is dropped. For OpenAI-compatible payloads that send placeholder "text": "" with real text in "content", this now strips message text from the prompt and can alter downstream tool-selection and model behavior.

Useful? React with 👍 / 👎.

@CJackHwang CJackHwang linked an issue Mar 6, 2026 that may be closed by this pull request
@CJackHwang CJackHwang merged commit 75969e7 into dev Mar 6, 2026
3 checks passed
@CJackHwang CJackHwang deleted the codex/analyze-and-optimize-issue-#77 branch March 6, 2026 14:20
CJackHwang added a commit that referenced this pull request Mar 6, 2026
Merge pull request #79 from CJackHwang/codex/analyze-and-optimize-issue-#77

fix: 避免 assistant.content=nil 注入 "null" 导致工具历史混杂
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] 目前工具调用存在一些格式问题导致系统无法识别 [Bug] cc的工具调用不正常

1 participant