Skip to content

fix(memory): enforce authoritative revision integrity - #1303

Open
knqiufan wants to merge 1 commit into
oceanbase:masterfrom
knqiufan:fix/issue-1297-memory-integrity
Open

fix(memory): enforce authoritative revision integrity#1303
knqiufan wants to merge 1 commit into
oceanbase:masterfrom
knqiufan:fix/issue-1297-memory-integrity

Conversation

@knqiufan

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Closes #1297.

Rationale for this change

MemoryUnitOfWork.commit() is the final persistence trust boundary, but it previously accepted incomplete or internally inconsistent revisions. A malformed direct SPI writer could persist illegal predecessor links or body/hash mismatches, and search could then return text that authoritative entry reads rejected.

What changes are included in this PR?

  • Validate the stored base and the complete base-to-revision transition inside the commit transaction.
  • Require the manifest, changes, new entry versions, direct predecessors, and active projections to agree exactly.
  • Recompute entry hashes and validate declared/manifest hashes, canonical searchable text, and configured embedding bindings before any write.
  • Revalidate entries(), expand(), projection reads, and every FTS/vector candidate against the exact authoritative revision, manifest, entry row, and current head projection.
  • Add regression coverage for nonexistent, cross-entry, cross-Memory, and skipped predecessors; missing/extra/duplicate rows; hash and projection corruption; rollback behavior; and read/search/expand agreement.

Are there any user-facing changes?

Malformed commits made through the public Memory backend SPI now fail with MemoryBackendConfigurationError instead of becoming durable state. Valid service workflows and the documented no-vector degradation remain unchanged. There are no API or persisted-format migrations.

How was this change tested?

  • .venv/Scripts/prek.exe run -a
  • .venv/Scripts/ty.exe check
  • .venv/Scripts/python.exe -m pytest tests/builtin/artifacts/memory tests/builtin/persistence/test_memory.py tests/builtin/persistence/test_memory_integrity.py tests/e2e/test_memory_search_concurrency.py tests/e2e/test_builtin_runtime.py -q (39 passed, 5 skipped)
  • Manual issue reproducer: both the fake predecessor and body/hash mismatch are rejected before persistence.
  • Full Windows run: 612 passed, 14 skipped; 8 unrelated platform failures remain in pre-existing symlink/POSIX-mode, python3 command, encoding, and path-separator assertions.

AI usage statement

OpenAI Codex (GPT-5) was used to inspect the issue and codebase, implement the fix, design regression tests, and review the final change.

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.

bug: Memory commit accepts malformed revisions and search can return text that entries() rejects

1 participant