-
fix(recall): pass Pydantic models with kwargs and required source literal (#2785)
发布于
2026-05-06 03:57:04 +00:00 Summary
Two bugs in `cognee/api/v1/recall/recall.py` made every `POST
/api/v1/recall` call return HTTP 409 whenever the request scope
included `trace` or `graph_context`. The recall endpoint catches
`Exception` broadly and returns `409: An error occurred during
recall.`, so the actual root cause was silent in client logs.Bug 1 — `_search_trace` passes a Pydantic model positionally (line
```python
results.append(ResponseAgentTraceEntry(entry)) # entry is a
SessionAgentTraceEntry
```Pydantic v2 `BaseModel.init` rejects positional args:
```
TypeError: BaseModel.init() takes 1 positional argument but 2 were
given
```Fix mirrors the working pattern from `_search_session` (line 209):
```python
results.append(ResponseAgentTraceEntry(**entry.model_dump(),
source="trace"))
```Bug 2 — `_fetch_graph_context` omits the required `source`
literal (line 312)
```python
return [ResponseGraphContextEntry(content=snapshot)]
````ResponseGraphContextEntry` declares `source:
Literal["graph_context"]` as a required field. Once Bug 1 is fixed
and execution reaches this runner, this would be the next 409.Reproduction
```python
import requests
requests.post("http://localhost:8000/api/v1/recall", json={
"query": "anything",
"session_id": "",
"scope": ["session", "trace", "graph_context"],
}).status_code409 before, 200 after
```
End-user symptom
The Claude Code memory plugin hits this endpoint on every
`UserPromptSubmit`. With these two bugs, the `🔍 cognee recall`
status header always reported `0 / 0 / 0` regardless of what was in
session memory — recall was effectively dead for that integration.Test plan
- Verified locally against `cognee.serve()` on a session with
stored QA + trace entries:
`scope=["session","trace","graph_context"]` returns 200 with
content from all three buckets. - Verified `scope=["graph"]` (existing path) still returns 200
with `GRAPH_COMPLETION` results. - Add unit coverage for `_search_trace` and
`_fetch_graph_context` constructing valid `ResponseAgentTraceEntry`
/ `ResponseGraphContextEntry` from realistic inputs.
Summary by CodeRabbit
-
New Features
-
Recall and search results now include a visible "source" field
indicating whether data comes from trace entries or graph context. -
Chores
- Project version updated to 1.0.8.
下载附件
- Verified locally against `cognee.serve()` on a session with