Repository navigation
fix(memory): require facts in replacement imports - #8131
Conversation
willem-bd
left a comment
There was a problem hiding this comment.
Reviewed against head f580731. Verified the gate and its preservation property at the head tree (PYTHONPATH-pinned imports, not the local checkout):
- Gate placement is pre-mutation, confirmed.
MemoryImportRequestredeclaresfactsas required, and FastAPI body validation runs before the handler — a rejected import never constructs the manager or touches the store. Model-level probes at head: missingfacts-> 422 (missing),facts: null-> 422 (list_type),facts: []-> accepted (the documented explicit clear). - No bypass found. Whitespace-only content passes the schema but is rejected pre-storage by the updater's existing gate (ValueError -> 400, raised before
normalize_memory_dataor any storage read; confirmed present at base bf4aa82), so the router schema and updater validation form working defense in depth. - Replacement semantics: agent-scoped import is a full replace via the
apply_changeschange set (upserts + deletes of ids absent from the backup + summary replacement); the default bucket forcesfactsto[]. Consistent with the 409-on-concurrency path. - Callers verified compatible: the frontend
normalizeMemoryPayloadalready rejects facts-less backups client-side (default"reject"strategy) and always sends an explicitfactsarray on import; the benchmark runner seedsfactsexplicitly; the harnessclient.import_memorybypasses the router but still hits the updater gate. - Tests:
backend/tests/test_memory_router.py— 82 passed at the head tree, including the new parametrized test covering rejection (422 +locpinned), snapshot preservation, and the subsequent explicit clear.ruff format --checkandruff checkclean.
Two non-blocking notes below/in the summary: the PR is missing a CHANGELOG.md Unreleased entry (the Fixed section at head carries entries for prior memory fixes in this family, and this is a user-facing API behavior change — previously accepted backups now return 422), and a one-line OpenAPI description tweak is suggested inline.
| ) | ||
| @require_permission("memory", "write") | ||
| async def import_memory(body: MemoryResponse, request: Request, agent_name: str | None = None) -> MemoryResponse: | ||
| async def import_memory(body: MemoryImportRequest, request: Request, agent_name: str | None = None) -> MemoryResponse: |
There was a problem hiding this comment.
Nit: the route's description (line 575) predates the new contract. Consider mentioning it so OpenAPI/docs consumers see the rule at the endpoint itself, e.g. "Requires an explicit facts array; omitting it returns 422, while an empty array clears the selected bucket." — the README and routers/AGENTS.md now document it, but this string is what OpenAPI codegen surfaces. Optional since the request schema already marks facts required.
There was a problem hiding this comment.
Thanks for the review. In 36ccd82, I updated the endpoint’s OpenAPI description to say that omitting facts returns HTTP 422 and that an explicit empty array clears the selected fact bucket. I also added an Unreleased changelog entry for the behavior change. All 82 memory-router tests passed after the update, and Ruff lint and format checks passed.
willem-bd
left a comment
There was a problem hiding this comment.
Re-reviewed at 36ccd82. Both prior notes are addressed: the OpenAPI description now states the explicit-facts requirement with the 422-vs-empty-clear semantics, and a CHANGELOG Unreleased/Fixed entry documents the behavior change. Gate re-verified intact at the new head — MemoryImportRequest.facts remains schema-required, the delta touches only the decorator string, and the rejection/preservation tests are unchanged. One nit remains on the new changelog lines.
|
|
||
| - **memory:** Importing a backup without a `facts` array now returns HTTP 422 | ||
| and preserves saved memory. An explicit empty array still clears the selected | ||
| fact bucket. ([#8131]) |
There was a problem hiding this comment.
Nit: ([#8131]) has no matching link reference — the definitions at the bottom of the file end at [#8072], so this renders as literal text instead of a link. Please add [#8131]: https://github.com/bytedance/deer-flow/pull/8131 to the reference block, following the sibling entries (e.g. [#7794], [#8072]).
There was a problem hiding this comment.
Added the [#8131] link definition to the changelog’s reference block in 4aa18bc. The Unreleased entry now links to this PR. git diff --check passed.
Resolve the CHANGELOG.md conflict by keeping upstream's bytedance#8131 memory entry and appending the bytedance#7939 agents entry after it. The nine code and test changes are unchanged from the previous head.
Fixes #8130
Why
The memory import endpoint uses the response schema, which defaults a missing
factsfield to an empty array. A backup that omits the field therefore returns 200 and clears the selected bucket.What changed
Require an explicit
factsarray in the import request. Omitting it now returns 422 before any write. An explicit empty array still clears the selected bucket. Export and read responses retain their existing schema.Surface area
POST /api/memory/importfactsare rejectedBug fix verification
backend/tests/test_memory_router.py::test_import_requires_explicit_facts_to_replace_saved_memoryfailed onbf4aa82ffor both the default and named-agent buckets (200 with empty facts), then passed with the fix. The test checks that a rejected import preserves the exported snapshot and that a subsequent explicit empty import clears the selected bucket.Validation
AI assistance
Tool(s) used: OpenAI Codex.
How you used it: Investigated the import boundary, reproduced the behavior, implemented the request schema and tests, and drafted the issue and PR.