Skip to content

PR #66 + #67 review fixes + chat/completions tool labels + FPC brace fix - #68

Merged
FMXExpress merged 1 commit into
mainfrom
claude/pr66-67-review-fixes
May 29, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/pr66-67-review-fixes

Conversation

@FMXExpress

@FMXExpress FMXExpress commented May 29, 2026 •

Copy link
Copy Markdown
Owner

Three layered changes on the open PR:

1. Review fixes from PRs #66 + #67 (commit 539fb31)

2. Friendly tool-activity labels on /v1/chat/completions (commit 9e46fe8)

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):

Tool Label
fs_read {"path":"foo.pas"} Reading foo.pas
fs_write {"path":"bar.pas",...} Writing bar.pas
fs_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 foo
shell_exec {"command":"go test ./..."} Running: go test ./...
skill_<name> Running skill <name>
(other) Calling <name>
Delivery Surface
Streaming TSSEStreamer.NoteToolCall wraps 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.
Non-streaming New TToolLabelCollector hooked onto LoopCfg.OnToolCall. PrependToolTranscript sticks 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 --debug server 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:

PasClaw.Providers.Anthropic.pas(199,52) Fatal: Syntax error, ")" expected but "identifier DECIDES" found
PasClaw.Gateway.Server.pas(2287,53) Fatal: illegal character "'}'" ($7D)

Switched both to (* ... *) and dropped the literal braces from the prose. Behaviour and field-emission logic unchanged.

Verification

make builds clean against FPC 3.2.2 after this PR.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon

…_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
@FMXExpress
FMXExpress merged commit 4fb0071 into main May 29, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 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".

Comment on lines +1911 to +1914
if (MsgCount > 0)
and (Msgs[MsgCount - 1].Role = mrAssistant)
and (Msgs[MsgCount - 1].Content = '')
and (Length(Msgs[MsgCount - 1].ToolCalls) > 0) then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@FMXExpress FMXExpress changed the title PR #66 + #67 review fixes: parallel calls, Anthropic SSE tool_use, response.failed PR #66 + #67 review fixes + chat/completions tool labels + FPC brace fix May 29, 2026
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