Repository navigation
fix(openaicompletions): recover leaked DSML tool calls safely - #4851
Merged
Merged
Conversation
- Added a new `dsmlFilter` to manage and extract DSML tool calls from streamed content, ensuring that native tool-call syntax does not disrupt user-facing responses. - Introduced `extractDSMLToolCalls` function to parse DSML calls and return structured data while preserving malformed markup visibility. - Enhanced the `parseResponse` and `processStream` methods to integrate DSML handling, updating finish reasons accordingly. - Created unit tests for DSML extraction and filtering to validate functionality and ensure robustness against various input scenarios. (cherry picked from commit 4294bcc3aefbe4cbf1c8ec81d148e2bc5d0efdd5)
lyingbug
marked this pull request as ready for review
October 28, 2026 15:19
8 tasks done
7 of 11 tasks
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.
Description
Some OpenAI-compatible endpoints return a DSML
function_callsblock incontentwithfinish_reason=stop. The agent then displays protocol markup and stops instead of invoking tools. Recover complete trailing DSML blocks in both streaming and non-streaming completions, using the tools enabled by the current request.tool_callswhen both representations are present, avoiding duplicate execution.float64.Recovery is conservative: ambiguous or partially parsed content remains text. No configuration or public API changes.
Type of Change
Related Issue
Related to #2798, which addresses leaked DSML with rejection and retry.
Testing
ChatandChatStreamusing local HTTP/SSE fixtures.go test ./internal/models/... ./internal/agent/...go vetandgo testover all 148 CI application packages, excluding/docreader/as inapp.yml.go build -o <temporary-directory>/server ./cmd/server.golangci-lint run --new-from-rev=github_public/main ./...— 0 issues.git diff --check github_public/main...HEADChecklist
Screenshots / Recordings
Not applicable; backend-only change.