Skip to content

fix(server): normalize Codex Responses tool-call follow-ups - #260

Merged
davide221 merged 1 commit into
Luce-Org:mainfrom
howard0su:qwen
May 23, 2026
Merged

davide221 merged 1 commit into
Luce-Org:mainfrom
howard0su:qwen

Conversation

@howard0su

Copy link
Copy Markdown
Contributor

Codex CLI could miss tool calls or loop on follow-up turns when the native server handled Qwen Responses output too literally. Qwen can emit bare <function=...> XML without an outer <tool_call> wrapper, and Codex sends follow-up function_call / function_call_output items that must be replayed back into the prompt as assistant/tool turns.

Handle bare <function= and <tool_code> openers in the SSE emitter so the native Responses path still converts Qwen tool XML into Responses function_call events. Normalize Responses follow-up items in http_server.cpp by replaying prior function calls as assistant tool-call XML, mapping function_call_output items to tool turns, and preserving the system / developer prompt folding used by Codex requests.

Add regression coverage for both failures: bare-function Responses tool calls in the emitter and the Responses follow-up normalization path in the native server flow. Compile http_server.cpp into test_server_unit so the regression test exercises the production normalization logic directly.

Codex CLI could miss tool calls or loop on follow-up turns when the native
server handled Qwen Responses output too literally. Qwen can emit bare
`<function=...>` XML without an outer `<tool_call>` wrapper, and Codex sends
follow-up `function_call` / `function_call_output` items that must be replayed
back into the prompt as assistant/tool turns.

Handle bare `<function=` and `<tool_code>` openers in the SSE emitter so the
native Responses path still converts Qwen tool XML into Responses
`function_call` events. Normalize Responses follow-up items in
`http_server.cpp` by replaying prior function calls as assistant tool-call XML,
mapping `function_call_output` items to tool turns, and preserving the system /
developer prompt folding used by Codex requests.

Add regression coverage for both failures: bare-function Responses tool calls in
the emitter and the Responses follow-up normalization path in the native server
flow. Compile `http_server.cpp` into `test_server_unit` so the regression test
exercises the production normalization logic directly.

Co-authored-by: Copilot <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="dflash/src/server/http_server.cpp">

<violation number="1" location="dflash/src/server/http_server.cpp:37">
P2: parse_responses_arguments silently swallows JSON parse errors, returning an empty object and losing malformed argument data without any log or error</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

return buf;
}

json parse_responses_arguments(const json & item) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: parse_responses_arguments silently swallows JSON parse errors, returning an empty object and losing malformed argument data without any log or error

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At dflash/src/server/http_server.cpp, line 37:

<comment>parse_responses_arguments silently swallows JSON parse errors, returning an empty object and losing malformed argument data without any log or error</comment>

<file context>
@@ -34,6 +34,125 @@ static std::string generate_id(const char * prefix) {
     return buf;
 }
 
+json parse_responses_arguments(const json & item) {
+    if (!item.contains("arguments")) return json::object();
+    const auto & arguments = item["arguments"];
</file context>

@davide221
davide221 merged commit 3a5acea into Luce-Org:main May 23, 2026
3 checks passed
easel added a commit to easel/lucebox-hub that referenced this pull request May 23, 2026
Pulls in PR Luce-Org#260 (howard0su): fix(server): normalize Codex Responses
tool-call follow-ups, which improves the sse_emitter THINK_OPEN/CLOSE
extraction parser. Also picks up frequency/presence penalty sampling,
test tightening, and gemma4 HIP runtime fixes.

# Conflicts:
#	dflash/src/server/http_server.cpp
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