fix: parse Memory /Recall response per-item to avoid dropping valid results#89
Open
ryanrishi wants to merge 2 commits into
Open
fix: parse Memory /Recall response per-item to avoid dropping valid results#89ryanrishi wants to merge 2 commits into
ryanrishi wants to merge 2 commits into
Conversation
…esults Validate observations, summaries, and communications independently when parsing the Conversation Memory /Recall response. Previously the whole response was validated in a single MemoryRetrievalResponse(**data) call, so a single malformed item raised ValidationError and collapsed the entire response to empty, silently discarding all valid results. Invalid items are now dropped and logged via the existing logger while valid items are returned. The existing behavior of returning an empty response when the API request itself fails is preserved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Improves MemoryClient.retrieve_memory() robustness by parsing the /Recall response per-item so that a single malformed entry doesn’t discard otherwise valid recall results.
Changes:
- Add per-item Pydantic validation for observations, summaries, communications (dropping + logging invalid entries).
- Add parsing for
metawith graceful fallback when invalid. - Add pytest coverage to ensure malformed items don’t collapse the full response.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/tac/context/memory.py |
Switch recall parsing to per-item validation and add helpers to drop/log invalid items instead of failing the whole response. |
tests/test_recall_parsing_resilience.py |
Add async tests verifying invalid items are dropped while valid observations/summaries/communications still return. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Guard _parse_items against non-list values: log a single warning with the item type and received type, then return an empty list instead of iterating a non-list and emitting per-key warnings. - Add a test covering invalid meta falling back to defaults while valid items still parse. - Make the httpx.AsyncClient mock explicitly emulate an async context manager (__aenter__/__aexit__ as AsyncMock) for reliable awaitability. - Tighten the test helper return annotation to MemoryRetrievalResponse. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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
MemoryClient.retrieve_memory()parsed the Conversation Memory /Recall response with a singleMemoryRetrievalResponse(**data)call wrapped in a broadexceptthat returned an empty response. A single malformed item (unexpected field value or a missing required field on one observation, summary, or communication) raisedValidationErrorand collapsed the entire response to empty, silently discarding all valid results.This change validates observations, summaries, and communications independently. Invalid items are dropped and logged via the existing structlog logger while the valid items are returned. The existing behavior of returning an empty response when the API request itself fails is preserved.
Type of Change
Checklist
SDK Parity
This is the Python SDK. This is the Python parity fix for the TypeScript change in twilio/twilio-agent-connect-typescript PR #79.
🤖 Generated with Claude Code