fix(mcp): coerce engram timestamps before slicing in memories/recall handlers (#190) - #191
Closed
servathadi wants to merge 1 commit into
Closed
servathadi wants to merge 1 commit into
servathadi wants to merge 1 commit into
Conversation
…#190) Mirror's direct-DB path returns native datetime objects; the HTTP-fallback path returns JSON strings. Three formatting sites in the memories, recall, and squad_recall handlers all did e.get('timestamp'/'ts', '?')[:10] which crashes with 'datetime.datetime' object is not subscriptable on the direct-DB code path. Extract _fmt_engram_ts(value) -> str helper that calls .isoformat() when the value supports it, otherwise str(), then slices to 10 chars. Apply it at all three call sites (original lines 4736, 4780, 4833). Add tests/mcp/test_engram_ts_coercion.py: 8 unit tests for the helper + 2 handler-level integration tests (memories and recall) with fake _mirror_db returning datetime-typed rows. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
Collaborator
Author
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
Fixes #190 —
'datetime.datetime' object is not subscriptablecrash in the MCP memories handler.Root cause: Mirror's direct-DB path (
_mirror_db.recent_engrams()/search_engrams()) returns nativedatetime.datetimeobjects in thetimestampandtscolumns. The HTTP-fallback path returns JSON strings, which masked the bug. Three formatting sites all dide.get('timestamp', '?')[:10]— valid for strings, fatal for datetime objects.Fix: Extract
_fmt_engram_ts(value: object) -> strhelper (line 601 ofsos_mcp_sse.py) that calls.isoformat()[:10]when the value has that method, otherwise falls back tostr(value)[:10]. Applied at all three call sites.Sites fixed (original line numbers before the helper insertion):
recallhandler (tsfield frommirror_match_engrams_v2)squad_recallhandler (timestampfield)memorieshandler (timestampfield fromrecent_engrams)Tests added:
tests/mcp/test_engram_ts_coercion.py_fmt_engram_tscovering datetime, date, string, sentinel, int, tz-awarememorieshandler with fake_mirror_dbreturning datetime rowsrecallhandler with fake_mirror_dbreturning datetime rowsNo service restart needed — fix takes effect only after controlled bridge restart coordinated by Kasra-core. Do NOT merge or deploy without that gate.
Test plan
python3 -m pytest tests/mcp/test_engram_ts_coercion.py -v— 10/10 passtests/mcp/test_mcp_tool_rbac.py— 5/5 pass (no regression)🤖 Generated with Claude Code