Repository navigation
PR #66 + #67 review fixes + chat/completions tool labels + FPC brace fix - #68
Conversation
…_use, tool_choice none, response.failed Addresses Codex review feedback on PR #66 (now in main) and the open PR #67. 1. Group parallel function_call inputs into one assistant turn (PR #66) When Codex sends multiple function_call items in a single Responses API turn (parallel tool use), AppendAssistantToolCall previously created one TMessage per call. Anthropic rejects request shapes that split a single assistant turn into multiple consecutive assistant messages with tool_use blocks. The helper now appends to the previous message when it is an empty-content assistant with tool_calls, coalescing the parallel turn into one message while still creating a new message after any non-assistant boundary (function_call_output / message). Matching with function_call_output is unaffected since it keys by call_id. 2. Anthropic SSE: accumulate tool_use blocks (PR #67, P1) HandleAnthropicSSE was only tracking text_delta / message_delta / message_start / message_stop. Tool-call-only assistant turns streamed back with no ToolCalls, so the gateway never emitted the function_call output items and Codex couldn't execute the tools. Added handling for the three events that bracket a tool_use block: content_block_start (type=tool_use) -> capture id+name, start buffer content_block_delta (type=input_json_delta) -> append partial_json content_block_stop -> flush accumulated TToolCall to GStreamLast ChatStream now propagates GStreamLast.ToolCalls into Result. Also clears the tool-block state and Finalizes GStreamLast on entry so the previous call's managed fields don't leak refcounts under the subsequent FillChar zero. 3. Anthropic: emit tool_choice {type: "none"} explicitly (PR #67, P2) Anthropic supports {"type":"none"} to forbid tool calls; omitting tool_choice when tools are present still allows the model to call them. BuildRequest now emits the explicit form when ToolChoice = "none" so the client's intent reaches the API. 4. Streaming failures emit response.failed (PR #67, P2) StreamResponsesViaProvider used to emit response.completed with status "completed" and empty output even when the provider raised or returned FinishReason="error" after SSE headers were sent. Streaming clients (openai-python, Codex) treat that as a successful empty response, hiding real errors. Added a ResFailedEvt helper and a Failed flag in StreamResponsesViaProvider. When the ChatStream call raises or the response carries FinishReason="error", capture the error string, suppress the fake-text-chunk fallback, and emit response.failed with the response object's status set to "failed" and an {code:"server_error", message:<err>} error block — matching the non-streaming HandleResponses' error shape. https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 539fb31e1e
ℹ️ 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".
| if (MsgCount > 0) | ||
| and (Msgs[MsgCount - 1].Role = mrAssistant) | ||
| and (Msgs[MsgCount - 1].Content = '') | ||
| and (Length(Msgs[MsgCount - 1].ToolCalls) > 0) then |
There was a problem hiding this comment.
Preserve call/output turn boundaries
When a later Responses input contains another function_call immediately after the previous call's function_call_output, this predicate still appends it to the earlier assistant message because MsgCount was not incremented after the append path. The resulting history puts the new tool_use before the intervening tool_result (assistant tool_use A+B, then tool_result A), so Anthropic rejects or misinterprets normal multi-turn sequences where the model calls a tool, receives its output, and then calls another tool in the next turn. Track that the last processed item was a function_call (or increment a separate boundary) so only truly consecutive function_call items are coalesced.
Useful? React with 👍 / 👎.
Three layered changes on the open PR:
1. Review fixes from PRs #66 + #67 (commit
539fb31)function_callinputs into one assistant turn (PR [reopen #63] Responses Phase 2: tool passthrough so Codex can drive its own tools #66). Anthropic rejects request shapes where parallel tool_use blocks are spread across consecutive assistant messages.AppendAssistantToolCallnow appends to the previous message when it is an empty-content assistant withToolCalls.tool_useblocks (PR [reopen #64] Responses Phase 2+: tool_choice forwarding and real partial streaming #67, P1).HandleAnthropicSSEnow handlescontent_block_start(typetool_use),content_block_delta(typeinput_json_delta), andcontent_block_stop; flushedTToolCalls reachResult.ToolCallsso streaming-mode tool-call-only turns no longer drop the function_call output items.tool_choice: {type:"none"}explicitly (PR [reopen #64] Responses Phase 2+: tool_choice forwarding and real partial streaming #67, P2).response.failed(PR [reopen #64] Responses Phase 2+: tool_choice forwarding and real partial streaming #67, P2). NewResFailedEvthelper +Failedflag inStreamResponsesViaProvider. Swapsresponse.completedforresponse.failedwith{code:"server_error", message:<err>}.2. Friendly tool-activity labels on
/v1/chat/completions(commit9e46fe8)Clients used to see
[tool: fs_read]as the heartbeat — almost no signal. Args (which the server logs fully under--debug) never reached the frontend at all. Closes that gap on both delivery modes with a per-tool label, args+results still gated server-side.New
PasClaw.Tools.Labels.LabelToolCall(Name, ArgsJSON):fs_read{"path":"foo.pas"}Reading foo.pasfs_write{"path":"bar.pas",...}Writing bar.pasfs_list{"path":"src/"}Listing src/fs_grep{"pattern":"X","path":"src","include":"*.pas"}Searching for "X" in src (*.pas)fs_edit_hashline{"patch":"¶foo#..."}Editing fooshell_exec{"command":"go test ./..."}Running: go test ./...skill_<name>Running skill <name>Calling <name>TSSEStreamer.NoteToolCallwraps the label in brackets → visible delta[Reading foo.pas]instead of[tool: fs_read]. Raw args still go to the structured SSE comment + debug log.TToolLabelCollectorhooked ontoLoopCfg.OnToolCall.PrependToolTranscriptsticks one[Label]line per call above the model's content with a blank-line separator.Only the label crosses to the client. Args and results stay in the
--debugserver log.3. FPC brace-comment build fix (commit
9e46fe8)The first two commits' own comments embedded literal
{"type":"..."}fragments inside{ ... }Pascal block comments. FPC closes the comment on the first unbalanced}, leaving the JSON as live code:Switched both to
(* ... *)and dropped the literal braces from the prose. Behaviour and field-emission logic unchanged.Verification
makebuilds clean against FPC 3.2.2 after this PR.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon