fix(server): tolerate malformed responses in triplet export - #574
Rio Yu (rioyu123) wants to merge 2 commits into
Conversation
Signed-off-by: Rio Yu <52408936+rioyu123@users.noreply.github.com>
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", []) |
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>
Sylvester Kaczmarek (sylvesterkaczmarek)
left a comment
There was a problem hiding this comment.
These checks are at the right boundary for a public export formatter: JSON-valid provider payloads can still have the wrong nested shapes, and triplet export should degrade individual unrecognized fragments rather than fail the whole query. The mixed legacy-chunk regression is particularly useful because it proves malformed neighbours do not suppress valid token data. Normalizing non-dict server metadata separately also preserves the existing HTTP/error fields. No blocker.
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