Skip to content

cli: keep tool results contiguous and ordered around mid-conversation system messages - #437

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/normalize-messages-system-around-tool-results
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/normalize-messages-system-around-tool-results

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 3, 2026

Copy link
Copy Markdown

Summary

Fixes message normalization in cli/lib/common.js (normalizeMessages) when a mid-conversation system / developer message appears between an assistant tool-call turn and its tool results, or between two tool results:

  1. Previously, a system message buffered in pending after an assistant turn was flushed as { role: "user", aside: true } before the incoming tool result, and a system message between two tool results emitted { role: "user", aside: true } immediately after the first tool result. Both broke tool-result adjacency to the preceding assistant call turn and prevented the call-ID reorder pass from aligning out-of-order tool results with assistant.calls.
  2. normalizeMessages now keeps mid-conversation system notes buffered across contiguous tool results and flushes them as a single { role: "user", aside: true } once the tool-result run finishes (or merges them into a following user message), while skipping empty mid-conversation system strings so they do not emit blank turns.
  3. Added a regression test in cli/test/openai_test.mjs covering mid-conversation system messages before and between out-of-order tool results (verified failing before the fix and passing after).

Verification

  • node --check cli/lib/common.js cli/test/openai_test.mjs -> clean
  • node --test cli/test/*_test.mjs -> 174 pass, 0 fail, 0 skipped
  • npm run test:packages -> 213 pass, 0 fail, 6 skipped
  • npm run test:runtime -> 6/6 runtime checks passed (172 frames)

@Pybsama
Pybsama requested a review from Nehanth as a code owner December 3, 2026 23:31
@vercel

vercel Bot commented Dec 3, 2026

Copy link
Copy Markdown

@Pybsama is attempting to deploy a commit to the nehanth's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant