Skip to content

fix(memory): retain schema fields omitted from updates - #7318

Open
r266-tech wants to merge 2 commits into
volcengine:mainfrom
r266-tech:codex/preserve-omitted-memory-fields
Open

r266-tech wants to merge 2 commits into
volcengine:mainfrom
r266-tech:codex/preserve-omitted-memory-fields

Conversation

@r266-tech

@r266-tech r266-tech commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

A content-only extraction update to an existing typed memory drops schema fields from MEMORY_FIELDS. The merge loop only handles supplied fields, while the old preservation loop excludes every schema field, including omitted ones.

Backfill an old field only when it is absent from both resolved_op.memory_fields and the final metadata. Supplied fields retain their configured merge behavior, and metadata generated during this update, including trace and extraction IDs, keeps its new value. This preserves entity/preference identity for filename and embedding template rendering.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Fixes #7317. The explicit-replacement behavior addressed by #4193 remains covered.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Test update

Changes Made

  • Extend the existing preservation pass to omitted schema fields, with both operation-membership and final-metadata guards.
  • Extend the existing updater/rename contract with an in-place content-only update. Both paths verify serialized identity, version, custom metadata, links and fresh trace/extraction IDs; the rename also verifies explicit replacement.

Testing

  • python -m pytest tests/session/memory/test_memory_updater.py tests/session/memory/test_merge_ops.py tests/session/memory/test_replace_string_edits.py tests/session/memory/test_schema_models.py tests/session/memory/test_streaming_memory_updater.py --no-cov -q: 279 passed, 1 failed. The remaining failure, test_apply_operations_skips_link_updates_for_deleted_uris, is the pre-existing fixture that rejects the deleted-file read required by link migration. Reproduced that failure on the previous PR head 504f8c96 in the same environment; both extended update/rename cases pass there too.
  • Six existing temporary apply_operations/serializer probes pass: entity/preference identity, explicit replacement, immutable fields, falsy values, numeric addition and fresh reads.
  • Eight additional apply_operations/serializer cases pass on both the previous and revised heads with identical serialized output: omission, replacement, supplied None and empty strings, custom-field null/empty values, a real failing merge, and supplied old provenance overridden by the new operation source.
  • Ruff lint, test formatting, changed-source-block formatting and git diff --check pass. mypy --no-incremental --follow-imports=silent openviking/session/memory/memory_updater.py tests/session/memory/test_memory_updater.py reports the same 419 existing diagnostics on both heads; none added.
  • macOS arm64, Python 3.14.10, the same pinned dependency environment used for the original PR. No model calls, HTTP/native storage integration, full repository suite or other OS run.

Checklist

  • My code follows the project coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes

This preserves omitted fields on future updates; it does not reconstruct identity fields already lost from existing cards. Source-file formatting is limited to the changed block to avoid unrelated cleanup.

@heaoxiang-ai

Copy link
Copy Markdown
Collaborator

Could we add key not in resolved_op.memory_fields alongside key not in metadata in the backfill condition? Checking the operation makes the omission rule explicit and prevents backfill from restoring a supplied field if a future merge operation removes its key.

The metadata guard also protects values generated during this update, such as source_extraction_id and last_update_trace_id. I tested _apply_upsert() with mocked storage. Replacing the existing check caused the old trace and extraction IDs to overwrite the new ones. Keeping both checks produced identical serialized output to the current PR for omitted fields, explicit replacements, None, empty strings, and merge failures.

@r266-tech

Copy link
Copy Markdown
Contributor Author

Added key not in resolved_op.memory_fields in d0f5641164c6a19fc5079a78125bea63ed006d37, alongside the existing key not in metadata guard.

The existing update/rename contract now starts with old source_extraction_id and last_update_trace_id values and verifies that the newly generated IDs survive serialization, together with omitted identity fields, explicit replacement and links.

Eight additional cases through apply_operations and the real serializer produce identical output on 504f8c96 and this revision: omitted fields, replacement, supplied None/empty strings, custom-field null/empty values, a failing merge, and old provenance supplied in the operation. The six original built-in-schema probes pass too.

The five focused memory modules return 279 passed, 1 failed. The failure is the same deleted-file-read fixture already documented in the PR, reproduced on 504f8c96 in the same environment. Ruff and formatting checks pass; isolated mypy has the same 419 existing diagnostics and no additions. The PR description has the exact commands and limits.

AI-only verification on macOS arm64 / Python 3.14.10. No model, HTTP/native storage integration, full-suite or other OS run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Bug]: Memory update drops schema fields omitted by the operation (card degrades to {"version": 1})

2 participants