Repository navigation
fix(backend): keep existing memories when a reprocess extracts nothing - #12525
Merged
Merged
Conversation
The empty-replacement destructive gate is right for deletion callers, but the conversation-extraction entry (finalize and reprocess) reaches it whenever a model pass extracts zero memories over a conversation that already has canonical rows. Reprocess holds no explicit_memory_deletion gate, so those requests died with LegalHoldAuthorityUnavailable — the residual prod 500s after #12410 (3/day on routers/conversations.py reprocess_conversation). Extraction emptiness is model variance, not deletion intent. The boundary now takes intent as an explicit argument (the prescription this failure class already carries): replace_conversation_sourced_memories grows empty_set_intent, the extraction wrapper declares "extraction", and an empty extraction over existing rows keeps them as a successful no-op. Deletion callers keep the default "retraction" semantics, and a caller genuinely holding the gate still falls through so the retraction is recorded. Failure-Class: FC-destructive-gate-keyed-on-proxy-for-intent Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 5/5
backend/tests/unit/test_conversation_replacement_backoff.pycontains a duplicate test with identical setup and assertions, adding maintenance noise without changing behavior; remove the redundanttest_default_intent_still_treats_empty_over_existing_rows_as_a_retractiontest.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/tests/unit/test_conversation_replacement_backoff.py">
<violation number="1" location="backend/tests/unit/test_conversation_replacement_backoff.py:274">
P3: test_default_intent_still_treats_empty_over_existing_rows_as_a_retraction duplicates the existing test_empty_replacement_over_existing_rows_still_demands_the_gate line-for-line (same setup, same LegalHoldAuthorityUnavailable assertion, same surviving-row assertion; only the docstring differs). Since the default intent is already covered by the earlier test, drop the new test (or, if you want the intent-explaining docstring kept, fold it into the existing test) to avoid two identical bodies that must be kept in sync.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| assert db.docs[f"users/{UID}/memory_state/apply_control"]["source_generation"] == 2 | ||
|
|
||
|
|
||
| def test_default_intent_still_treats_empty_over_existing_rows_as_a_retraction(): |
There was a problem hiding this comment.
P3: test_default_intent_still_treats_empty_over_existing_rows_as_a_retraction duplicates the existing test_empty_replacement_over_existing_rows_still_demands_the_gate line-for-line (same setup, same LegalHoldAuthorityUnavailable assertion, same surviving-row assertion; only the docstring differs). Since the default intent is already covered by the earlier test, drop the new test (or, if you want the intent-explaining docstring kept, fold it into the existing test) to avoid two identical bodies that must be kept in sync.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/unit/test_conversation_replacement_backoff.py, line 274:
<comment>test_default_intent_still_treats_empty_over_existing_rows_as_a_retraction duplicates the existing test_empty_replacement_over_existing_rows_still_demands_the_gate line-for-line (same setup, same LegalHoldAuthorityUnavailable assertion, same surviving-row assertion; only the docstring differs). Since the default intent is already covered by the earlier test, drop the new test (or, if you want the intent-explaining docstring kept, fold it into the existing test) to avoid two identical bodies that must be kept in sync.</comment>
<file context>
@@ -232,3 +232,62 @@ def test_empty_replacement_over_existing_rows_still_demands_the_gate(monkeypatch
+ assert db.docs[f"users/{UID}/memory_state/apply_control"]["source_generation"] == 2
+
+
+def test_default_intent_still_treats_empty_over_existing_rows_as_a_retraction():
+ """The extraction shortcut must not relax the deletion callers' contract."""
+
</file context>
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.
What changed and why
Residual production 500s after #12410: conversation reprocess (
routers/conversations.py::reprocess_conversation→process_conversation→replace_conversation_memories) still dies withLegalHoldAuthorityUnavailable: destructive operation gate is not active in this contextwhenever a reprocess extracts zero memories over a conversation that already has canonical rows (~3/day on prodbackend).#12410 fixed the empty-and-no-existing-rows case but deliberately kept an empty replacement over existing rows demanding the
explicit_memory_deletiongate — right for deletion callers, wrong for the extraction entry, which never holds that gate. Extraction emptiness is model variance, not deletion intent.Following the failure class's own prescription ("take intent as an explicit argument"),
replace_conversation_sourced_memoriesgrowsempty_set_intent: the conversation-extraction wrapper declares"extraction", so an empty extraction over existing rows keeps them and resolves as a successful no-op. Deletion callers keep the default"retraction"semantics unchanged, and a caller genuinely holding the gate still falls through so the retraction is recorded.Product invariants affected
How it was verified
backend/.venv/bin/python -m pytest tests/unit/test_conversation_replacement_backoff.py— 8 passed (includes both fix(backend): stop treating an empty extraction as a memory deletion #12410 guards unchanged).backend/.venv/bin/python -m pytest tests/unit/test_ws_j_delete_privacy.py tests/unit/test_conversation_jit_processing.py— passed.gcloud logging readonbased-hardwareshows the traceback entering throughrouters/conversations.py:491 reprocess_conversationon 2026-08-31 and 2026-09-01.Tests
test_extraction_intent_empty_over_existing_rows_is_a_noop_that_keeps_them— the regression: reprocess extracting nothing keeps the rows, never enters the destructive boundary.test_default_intent_still_treats_empty_over_existing_rows_as_a_retraction— the deletion callers' contract is not relaxed.test_unknown_empty_set_intent_is_rejected— intent is a closed enum.Failure class (fixes)
Failure-Class: FC-destructive-gate-keyed-on-proxy-for-intent
Line-count exceptions
Oversized files grew by the minimal intent-argument patch; splitting them is out of scope for this production-regression fix.
Line-Count-Exception: backend/utils/memory/canonical_memory_adapter.py | 3496 -> 3537 | take empty-set intent as an explicit argument at the shared replacement boundary
Line-Count-Exception: backend/utils/memory/memory_service.py | 3939 -> 3949 | declare extraction intent at the conversation-extraction wrapper