Skip to content

fix: parse Memory /Recall response per-item to avoid dropping valid results#89

Open
ryanrishi wants to merge 2 commits into
mainfrom
fix-recall-parsing
Open

fix: parse Memory /Recall response per-item to avoid dropping valid results#89
ryanrishi wants to merge 2 commits into
mainfrom
fix-recall-parsing

Conversation

@ryanrishi

Copy link
Copy Markdown
Member

Summary

MemoryClient.retrieve_memory() parsed the Conversation Memory /Recall response with a single MemoryRetrievalResponse(**data) call wrapped in a broad except that returned an empty response. A single malformed item (unexpected field value or a missing required field on one observation, summary, or communication) raised ValidationError and 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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Release / version bump

Checklist

  • Tests added/updated
  • Documentation updated
  • Tested E2E

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

…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>
Copilot AI review requested due to automatic review settings July 21, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 meta with 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.

Comment thread tests/test_recall_parsing_resilience.py Outdated
Comment thread src/tac/context/memory.py
Comment thread tests/test_recall_parsing_resilience.py Outdated
Comment thread src/tac/context/memory.py
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants