Skip to content

fix(backend): keep existing memories when a reprocess extracts nothing - #12525

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/reprocess-empty-extraction-noop
Sep 1, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/reprocess-empty-extraction-noop

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

What changed and why

Residual production 500s after #12410: conversation reprocess (routers/conversations.py::reprocess_conversation → process_conversation → replace_conversation_memories) still dies with LegalHoldAuthorityUnavailable: destructive operation gate is not active in this context whenever a reprocess extracts zero memories over a conversation that already has canonical rows (~3/day on prod backend).

#12410 fixed the empty-and-no-existing-rows case but deliberately kept an empty replacement over existing rows demanding the explicit_memory_deletion gate — 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_memories grows empty_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

  • INV-MEM-1
  • INV-MEM-2
  • INV-MEM-3
  • INV-MEM-4
  • INV-MEM-5
  • INV-MEM-6

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.
  • Prod log evidence: gcloud logging read on based-hardware shows the traceback entering through routers/conversations.py:491 reprocess_conversation on 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

Review in cubic

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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Confidence score: 5/5

  • backend/tests/unit/test_conversation_replacement_backoff.py contains a duplicate test with identical setup and assertions, adding maintenance noise without changing behavior; remove the redundant test_default_intent_still_treats_empty_over_existing_rows_as_a_retraction test.
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():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@Git-on-my-level
Git-on-my-level merged commit bcac6fc into main Sep 1, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/reprocess-empty-extraction-noop branch September 1, 2026 07:46
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.

1 participant