server: disable tool calls during compaction requests#591
Open
ober wants to merge 1 commit into
Open
Conversation
When the Responses API input history ends with a "compaction" or "context_compaction" bookkeeping item, the model was still emitting DSML tool calls as part of its summary output. These tool calls were returned as raw text in the response content, causing breakage in clients like opencode that expect structured tool_calls or plain text. Track whether the last input item was a compaction type and disable has_tools in that case, so the model generates a plain text summary without attempting tool invocations. Fixes bogus DSML appearing in compaction/summary responses.
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.
server: disable tool calls during compaction requests
Problem
When opencode (or other Responses API clients) sends a compaction request to summarize a session, the ds4 server was allowing the model to emit DSML tool calls as part of its summary output. These tool calls were returned as raw text in the response content instead of being converted to structured tool_calls, causing breakage in clients that expect either proper JSON tool calls or plain text.
Observed Behavior
During session compaction, the model would output raw DSML like:
This raw DSML text was included in the assistant response content, which:
Root Cause
The Responses API parser (parse_responses_input) correctly identifies "compaction" and "context_compaction" items as bookkeeping entries in the input history. However, this information was not propagated to the request handler, so has_tools remained true even when the request was clearly a compaction/summary operation.
With has_tools = true, the model DSML tool call output was processed by the tool parser. When the parser failed (or the DSML was incomplete), the raw DSML was returned as assistant text content.
Solution
Track whether the last item in the Responses API input history is a compaction type ("compaction" or "context_compaction"), and disable tool calls (has_tools = false) for such requests.
Changes
parse_responses_input: Added a bool *last_was_compaction out-parameter that is set to true when a compaction bookkeeping item is encountered in the input history.
parse_responses_request: Passes the last_was_compaction flag and uses it to disable tools:
Test updates: Updated existing test calls to parse_responses_input to pass NULL for the new parameter.
Impact
Testing
Files Changed