Skip to content

fix(backend): key the all-ungrounded memory guard on candidates seen, not container truthiness (#11685) - #11702

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/issue-11685-canonical-extractor-empty-guard
Aug 16, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/issue-11685-canonical-extractor-empty-guard

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

Backend Unit Tests has been red on main since 5af7e53 (PR #11688, the fix for #11685).
tests/unit/test_process_conversation_usage_context.py::test_app_summary_results_reach_the_database
fails with ValueError: canonical memory extraction returned evidence without a unique source binding.

Three consecutive main pushes are red (5af7e53, 43b30d6, 13de450); every other lane on
13de450 is green, so this single file is the whole red.

Root cause

PR #11688 stopped one ungrounded L1 candidate from aborting the entire canonical extraction run,
and kept a guard for the genuinely untrustworthy case — every candidate failed grounding — because
replace_conversation_memories is called unconditionally and an empty replacement would retract the
source's existing memories.

That guard was gated on extracted_candidates and not capture_candidates: the truthiness of
whatever extract_canonical_l1_memory_candidates returned. Truthiness is not a count. Any truthy
object that yields nothing when iterated reads as "candidates existed and all of them failed
grounding", so the guard fires on a conversation that simply produced no candidates and aborts its
finalization. test_app_summary_results_reach_the_database stubs the extractor with a bare
MagicMock — truthy, iterates empty — and trips exactly that.

Fix

Count the candidates the loop actually yielded and gate the raise on that count. Behaviour for a real
list is unchanged (a non-empty list yields non-zero); the guard now states what it means, and the
dropped-candidate warning reports the counted total instead of len() on the same container.

Tested

cd backend
: > /tmp/f.txt
echo tests/unit/test_process_conversation_usage_context.py >> /tmp/f.txt
echo tests/unit/test_memory_replace_policy.py >> /tmp/f.txt
BACKEND_UNIT_TEST_FILE_LIST=/tmp/f.txt bash test.sh
  • before: test_process_conversation_usage_context.py → 1 failed, 29 passed (reproduces CI exactly)
  • after: 30 passed; test_memory_replace_policy.py 16 passed
  • verified at 5af7e53fd7^ that the same file was 30 passed, confirming fix(backend): drop only the ungrounded memory candidate, not the whole run (#11685) #11688 is the breaking commit
  • new regression test test_canonical_capture_accepts_an_extractor_that_yields_no_candidates calls
    _extract_memories_canonical through the real seam; reverting only the process_conversation.py
    hunk makes it fail, so it does catch this
  • make preflight green

Line-Count-Exception: backend/utils/conversations/process_conversation.py | 1806 -> 1810 | one loop counter plus the comment explaining why the guard counts observed candidates instead of reading the container's truthiness

Failure-Class: none

🤖 automated by hourly watchdog — tested and merged

Review in cubic

… not container truthiness

PR #11688 added a guard that raises when every extracted L1 candidate fails
evidence grounding, so the run cannot submit an empty replacement that would
retract the source's existing memories. It gated that raise on
`extracted_candidates and not capture_candidates` — the truthiness of whatever
extract_canonical_l1_memory_candidates returned.

Truthiness is not a count. Any truthy object that yields nothing when iterated
reads as "candidates existed and all of them failed grounding", so the guard
fires on a conversation that simply produced no candidates and aborts
conversation finalization for it. That is exactly what broke Backend Unit Tests
on main from 5af7e53 onward: test_app_summary_results_reach_the_database
stubs the extractor with a bare MagicMock, which is truthy and iterates empty.

Count the candidates the loop actually yielded and gate on that. Behaviour for
a real list is unchanged; the guard now states what it means.

Verification:
  cd backend
  : > /tmp/f.txt
  echo tests/unit/test_process_conversation_usage_context.py >> /tmp/f.txt
  echo tests/unit/test_memory_replace_policy.py >> /tmp/f.txt
  BACKEND_UNIT_TEST_FILE_LIST=/tmp/f.txt bash test.sh
    -> 30 passed (usage_context, was 1 failed/29 passed), 16 passed (replace_policy)
Reverting only the process_conversation.py hunk fails the new test
(test_canonical_capture_accepts_an_extractor_that_yields_no_candidates),
so the regression test does catch this.

Failure-Class: none

@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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@kodjima33
kodjima33 merged commit d9f20cc into main Aug 16, 2026
43 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-11685-canonical-extractor-empty-guard branch August 16, 2026 18:39
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