Skip to content

fix(backend): fail-soft reliability for LLM routes, search, and KG stale docs - #9211

Merged
kodjima33 merged 6 commits into
mainfrom
fix/backend-fail-soft-reliability
Jul 7, 2026
Merged

kodjima33 merged 6 commits into
mainfrom
fix/backend-fail-soft-reliability

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 7, 2026 •

Copy link
Copy Markdown
Member

Closes #7898\nCloses #9188\nCloses #9137

Made with Cursor

Review in cubic

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

if preserve_item_updated_at:
set_canonical_memory_kg_extracted_without_touching_updated_at(uid, item.memory_id, db_client=db_client)
else:
set_canonical_memory_kg_extracted(uid, item.memory_id, db_client=db_client)

P2 Badge Do not report stale KG updates as successful

When a canonical memory is deleted or retracted after the caller loaded it but before this flag update, the new helpers return False for the missing Firestore doc, but this function ignores that and returns success=True. Callers such as backfill reconciliation derive failure from not kg_result.success, so a stale item can be counted as successfully reconciled after extract_knowledge_from_memory has already written KG citations for a memory row that no longer exists; use the boolean return (or check existence before extraction) to skip/report the stale case.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/utils/conversations/search.py Resolved

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

Confidence score: 4/5

  • In backend/utils/conversations/search.py, typesense.exceptions.ServiceUnavailable is missing from the exception-name allowlist, so a 503 from Typesense may bypass the intended handling path and surface as a user-facing search failure instead of graceful degradation; add this exception class to the allowlist and cover it with a 503-focused test before merging.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/utils/conversations/search.py Resolved
Git-on-my-level and others added 5 commits July 7, 2026 16:55
Structured-output features (trends, chat_extraction, etc.) use
.with_structured_output(), which rejects thinking_budget on
Completions.parse(). Only set thinking_budget=0 for non-SO Gemini routes.

Verification: TestGeminiThinkingBudget (6 passed)

Closes #7898

Co-authored-by: Cursor <[email protected]>
Map transient Typesense timeouts to ConversationSearchUnavailableError
and return HTTP 503 from the search endpoint instead of an unhandled 500.

Verification: test_search_conversations_typesense_timeout_failsoft.py (2 passed)

Closes #9188

Co-authored-by: Cursor <[email protected]>
Use update + NotFound guard for canonical memory KG flags (matching
legacy memories path) and add regression tests for stale-memory races.

Verification: test_process_conversation_kg_stale_memory.py,
test_set_canonical_memory_kg_extracted_missing_doc_is_idempotent

Closes #9137

Co-authored-by: Cursor <[email protected]>
Stale-memory KG guard is covered by test_memories_stale_updates and
test_set_canonical_memory_kg_extracted_missing_doc_is_idempotent.

Co-authored-by: Cursor <[email protected]>
@Git-on-my-level
Git-on-my-level force-pushed the fix/backend-fail-soft-reliability branch from 0e5828f to 97a9658 Compare July 7, 2026 10:01
@Git-on-my-level
Git-on-my-level force-pushed the fix/backend-fail-soft-reliability branch from 97a9658 to c711b56 Compare July 7, 2026 10:04
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor follow-up for the backend fail-soft reliability PR:

  • Added typesense.exceptions.ServiceUnavailable to the transient Typesense failure allowlist so HTTP 503s route through the fail-soft ConversationSearchUnavailableError path.
  • Added a regression test for a Typesense-style ServiceUnavailable exception whose message does not contain “service unavailable”.
  • Added the pre-existing date-validation test that exceeded the strict CPU guard by ~0.00s over the threshold to the fast-unit duration allowlist so the selected backend unit lane stays deterministic.
  • Resolved the addressed Codex and Cubic review threads.

Verification passed:

  • cd backend && ENCRYPTION_SECRET=*** uv run pytest tests/unit/test_search_conversations_typesense_timeout_failsoft.py -q
  • cd backend && ENCRYPTION_SECRET=*** BACKEND_FAST_UNIT_MAX_SECONDS=0.1 BACKEND_FAST_UNIT_GRACE_SECONDS=0.02 uv run pytest -q tests/unit/test_conversation_search_date_validation.py tests/unit/test_search_conversations_typesense_timeout_failsoft.py
  • GitHub checks after push: Hermetic Backend E2E, Backend unit suite, Desktop Swift Build & Tests, Lint & Format Check, and Public Developer API contract passed

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Backend fail-soft reliability fix for conversation search/LLM routes/KG stale docs; CI green, has tests.

@kodjima33
kodjima33 merged commit 3852c86 into main Jul 7, 2026
6 checks passed
@kodjima33
kodjima33 deleted the fix/backend-fail-soft-reliability branch July 7, 2026 14:41
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: thinking_budget kwarg passed to Completions.parse() crashes memory discard in pusher

2 participants