Skip to content

Fix retrieval and output semantic correctness - #8366

Merged
Git-on-my-level merged 3 commits into
mainfrom
david/zach-retrieval-semantics
Jun 26, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
david/zach-retrieval-semantics

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Supersedes #8290, #8291, #8306, #8310, #8311, #8313, #8319, #8320.

Original issue discovery, reproductions, and candidate fixes by @ZachL111.

This aggregates the retrieval/output semantic correctness fixes into one focused backend PR:

  • adds shared conversation metadata keys/model and uses them for vector metadata production + reranking
  • fixes metadata entity extraction so entities no longer copy topics
  • refactors RAG chunking through a pure build_conversation_context(...) -> str | None path so short conversations are included consistently
  • separates calendar deletion successes from failures before building user-visible output
  • normalizes merge/photo timestamps through a UTC-aware helper and keeps malformed/missing photo dates with a structured warning
  • makes proactive-notification cache setters keyword-only for app_id to prevent passing an App object as the cache key
  • validates daily-summary LLM JSON with a Pydantic payload, falls back only on JSON/model-validation failures, and stops logging raw LLM output
  • safely handles Google contacts with absent names while preserving email extraction

Included Zach PRs

Included/redesigned in this aggregate: #8290, #8291, #8306, #8310, #8311, #8313, #8319, #8320.

Deferred from this aggregate: none.

Tests

  • cd backend && ./scripts/sync-python-deps.sh
  • cd backend && source .venv/bin/activate && pytest tests/unit/test_retrieval_semantics.py tests/unit/test_daily_summary_regenerate.py tests/unit/test_daily_summary_race_condition.py tests/unit/test_conversations_to_string.py
  • cd backend && source .venv/bin/activate && python -m py_compile models/conversation_metadata.py models/calendar_mutation.py models/daily_summary_payload.py utils/conversations/datetime_utils.py utils/conversations/merge_conversations.py utils/retrieval/rag.py utils/llm/chat.py utils/llm/external_integrations.py utils/retrieval/tools/calendar_tools.py database/mem_db.py database/redis_db.py database/vector_db.py tests/unit/test_retrieval_semantics.py
  • cd backend && bash testing/e2e/run.sh — 73 passed, 6 skipped

Also ran python backend/scripts/scan_async_blockers.py from repo root; it exits 0 and reports existing async-blocker findings unrelated to this PR. Running it from backend/ currently fails with Error: backend/routers not found, so root invocation was used.

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

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cb349ca76

ℹ️ 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".

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

5 issues found across 14 files

Confidence score: 3/5

  • In backend/models/daily_summary_payload.py, using list[dict] for LLM output means key typos can pass validation and silently produce empty/default fields, which risks shipping incorrect summaries without obvious failures — add stricter schema validation (typed models/required keys) before merging.
  • backend/tests/unit/test_retrieval_semantics.py introduces regression coverage, but if the test runner script does not include this module, CI can report green while these checks never run and regressions slip through — wire this test into the backend test runner before merging.
  • In backend/utils/llm/external_integrations.py, logging raw exceptions may expose user/LLM content in logs, creating avoidable privacy and compliance risk — replace interpolated exception logging with static or sanitized messages before merge.
  • backend/models/conversation_metadata.py has unused key constants and an unused normalize_metadata_values helper, which adds confusion around the true metadata contract and increases maintenance risk — clean these up now or immediately in a follow-up to keep keys single-sourced.

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

Re-trigger cubic

Comment thread backend/models/daily_summary_payload.py Resolved
Comment thread backend/models/conversation_metadata.py Resolved
Comment thread backend/models/conversation_metadata.py Resolved

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed the unresolved review feedback.

Changes:

  • Added tests/unit/test_retrieval_semantics.py to backend/test.sh so CI's source-of-truth backend runner executes the new regression tests.
  • Replaced raw dict daily-summary section payloads with typed Pydantic item models; malformed keys such as topic_name now fail validation instead of silently defaulting.
  • Sanitized daily-summary parse error logging before emission.
  • Removed unused conversation metadata dead code/constants flagged by Cubic.

Verification:

  • ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run pytest tests/unit/test_retrieval_semantics.py -q → 17 passed
  • python3 -m py_compile models/daily_summary_payload.py models/conversation_metadata.py utils/llm/external_integrations.py → passed

@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

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f94adce83

ℹ️ 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".

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed the validation-error logging finding.

Changes:

  • Added sanitize_validation_error() to log only structural Pydantic error details (type, loc, msg) with include_input=False.
  • Split the daily-summary fallback handler so JSON decode errors still log sanitized decoder details, while schema validation errors no longer stringify the full ValidationError / input_value.
  • Added regression coverage proving private summary text and input_value are absent from the validation log summary while the field path remains available for debugging.

Verification:

  • ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run pytest tests/unit/test_retrieval_semantics.py -q → 18 passed in 0.11s
  • git diff --check → clean

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: f69bce524a

ℹ️ 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".

@Git-on-my-level
Git-on-my-level merged commit 06a5a4e into main Jun 26, 2026
4 checks passed
@Git-on-my-level
Git-on-my-level deleted the david/zach-retrieval-semantics branch June 26, 2026 02:56
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.

2 participants