fix(server): tolerate malformed responses in triplet export - #574
Open
Rio Yu (rioyu123) wants to merge 2 commits into
Open
fix(server): tolerate malformed responses in triplet export#574Rio Yu (rioyu123) wants to merge 2 commits into
Rio Yu (rioyu123) wants to merge 2 commits into
Conversation
Signed-off-by: Rio Yu <52408936+rioyu123@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens triplet event export against malformed provider response shapes.
Changes:
- Validates choices, legacy chunks, token lists, and server metadata.
- Adds endpoint coverage for malformed and mixed response fragments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
agentlightning/server/routes/events.py |
Adds defensive shape checks during triplet conversion. |
tests/server/test_endpoints.py |
Tests malformed response handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| response_token_ids = choices[0].get("token_ids", []) | ||
| response_log_probs = _extract_choice_log_probs(choices[0]) | ||
| prompt_token_ids = choice.get("prompt_token_ids", []) | ||
| response_token_ids = choice.get("token_ids", []) |
Contributor
Author
There was a problem hiding this comment.
Fixed in 58c0a4d. Non-list token_ids from non-streaming choices now normalize to an empty list, matching the legacy path. Added a parameterized public endpoint case; the full suite passes (78 passed, 3 skipped), with Ruff and Pyright clean.
Signed-off-by: Rio Yu <52408936+rioyu123@users.noreply.github.com>
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.
Summary
model_requestevents can contain JSON-valid provider responses whose nested choices, legacy chunks, or server metadata are not objects. The triplet formatter currently calls.get()on those values, failing the entire publicformat=tripletquery.This change adds narrow shape checks around choices, legacy chunks, token ID lists, and server metadata. Unrecognized fragments are skipped, while valid legacy fragments, HTTP status fields, provider errors, and model/version metadata keep their existing behavior.
Testing