Skip to content

fix: fail closed on unhealthy prewrite search - #3

Open
VailElla wants to merge 2 commits into
mcncarl:mainfrom
VailElla:agent/fix-prewrite-reconciliation
Open

fix: fail closed on unhealthy prewrite search#3
VailElla wants to merge 2 commits into
mcncarl:mainfrom
VailElla:agent/fix-prewrite-reconciliation

Conversation

@VailElla

@VailElla VailElla commented Jul 11, 2026

Copy link
Copy Markdown

Summary

  • expose per-backend search health and return a non-zero status when the primary SQLite backend is unavailable
  • bound long prewrite descriptions before search while retaining the full input for safety and similarity checks
  • fail closed in prewrite and postwrite reconciliation instead of treating search failures as an empty result set
  • improve long-description matching with reverse coverage and normalized title detection
  • require sufficiently specific candidates before title or reverse-coverage shortcuts can force an update

Root cause

The closeout wrapper treated search-process failures as an empty candidate list. That made an unhealthy primary index indistinguishable from a legitimate no-match result, so prewrite could recommend ADD. Long descriptions also diluted one-way lexical coverage enough to miss an existing memory even when its title was present.

The matching shortcuts need their own guard: a short generic title or a candidate with only a few tokens can otherwise achieve high reverse coverage from an incidental mention. This revision limits those shortcuts while preserving specific English and Chinese title matches.

Impact

Prewrite now returns status=error and recommendation_unavailable_reason=reconcile_search_unhealthy when SQLite search is unavailable. Postwrite reconciliation records a blocking finding for the same condition. Ordinary failures from the optional vector backend remain non-blocking warnings when SQLite is healthy.

The branch is rebased onto 3cc6b43 and includes the updated postwrite test contract introduced on current main.

Safety and privacy

  • the change contains only public scripts, documentation, and synthetic tests
  • no real memory vault content, local configuration, database, logs, model data, credentials, or personal absolute paths are included
  • both commits use the GitHub noreply author and committer address
  • the full diff passed private-path, credential, private-key, forbidden-artifact, and whitespace scans

Validation

  • /usr/bin/python3 -m unittest discover -s tests -p 'test_*.py' — 38 tests passed
  • Python 3.14 targeted reconciliation and search tests — 13 tests passed
  • isolated CLI test with a missing SQLite index — exits 2 with no write recommendation
  • isolated CLI test with a healthy template index — returns UPDATE for the existing workflow
  • /usr/bin/python3 -m compileall -q scripts tests
  • /usr/bin/python3 scripts/agent_memory_check.py --skip-state-db
  • git diff --check upstream/main

@VailElla
VailElla force-pushed the agent/fix-prewrite-reconciliation branch from e04e6e3 to 51f3163 Compare July 12, 2026 13:07
@VailElla
VailElla marked this pull request as ready for review July 12, 2026 13:07
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