fix: strip orphaned fc_ IDs from function_calls when reasoning is pruned from context#12113
Open
octo-patch wants to merge 2 commits intocontinuedev:mainfrom
Conversation
added 2 commits
April 11, 2026 11:40
…le prompt files in edit mode (fixes continuedev#12087) The selector `selectSlashCommandComboBoxInputs` was returning the slash command source as `source`, but `ContinueInputBox` filters slash commands in edit mode by checking `cmd.slashCommandSource`. This property name mismatch caused all slash commands (including prompt files) to be filtered out in edit mode, since `cmd.slashCommandSource` was always `undefined`. Rename `source` to `slashCommandSource` in the selector return value to match the `ComboBoxItem` type definition and the edit-mode filter logic.
…ion (fixes continuedev#12056) When compileChatMessages prunes a thinking message due to context overflow, the associated assistant message still carries fc_* IDs that reference the now-absent reasoning item (rs_*). The OpenAI Responses API then rejects the request with a 400 error: "Item 'fc_...' of type 'function_call' was provided without its required 'reasoning' item: 'rs_...'" Fix: add a second pass in sanitizeResponsesInput that scans backward from each function_call with a fc_* ID to find whether a kept reasoning item exists in the same turn block. If no reasoning is found, the fc_ ID is stripped from the function_call so the API does not look for the missing reasoning item. Also adds test cases covering the pruned-reasoning scenario.
Contributor
|
I have read the CLA Document and I hereby sign the CLA octo-patch seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12056
Problem
When
compileChatMessagesprunes athinkingmessage from the conversation history due to context window overflow, the associated assistant message still carriesfc_*IDs in its metadata (referencing the now-absentrs_*reasoning item).The OpenAI Responses API then rejects the next request with a 400 error:
This affects GPT-5, o3, and other reasoning models that use the Responses API when the conversation history grows long enough to trigger context compaction.
Root Cause
sanitizeResponsesInputalready handles the case where areasoningitem exists in the input but lacksencrypted_content— it removes the reasoning and stripsfc_*IDs from subsequentfunction_callitems.However, it did not handle the case where the reasoning item was never added to the input at all (because
compileChatMessagesremoved thethinkingmessage before the messages reachedtoResponsesInput). In this case, thefunction_callitems still had theirfc_*IDs, causing the API rejection.Solution
Added a second pass in
sanitizeResponsesInputthat scans backward from eachfunction_callwith afc_*ID to find whether a kept reasoning item exists in the same turn block. If no reasoning is found (either it was removed in the first pass or was never in the input), thefc_*ID is stripped from thefunction_callso the API does not look for the missing reasoning item.The backward scan correctly:
function_callitems in the same block (parallel tool calls)Testing
Added test cases covering:
function_callwith orphanedfc_*IDfunction_calls with orphanedfc_*IDsfc_*IDs (with preceding reasoning) are preservedSummary by cubic
Prevents Responses API 400s by stripping orphaned
fc_*IDs after context compaction, and fixes slash command filtering in edit mode by returningslashCommandSource.Bug Fixes
sanitizeResponsesInputto removefc_*IDs fromfunction_callitems when no kept reasoning appears earlier in the same turn; the backward scan skips parallel calls and removed items, and stops at turn boundaries.sourcetoslashCommandSourceinselectSlashCommandComboBoxInputsso prompt files show up in edit mode.Tests
fc_*IDs and a sanity check preserving valid IDs.Written for commit 4daceca. Summary will update on new commits.