Skip to content

fix(desktop-backend): don't fail a chat turn on a guessed web-search requirement - #9692

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/retrieval-policy-heuristic-503
Jul 14, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/retrieval-policy-heuristic-503

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

The bug

is_fresh_public_lookup() (retrieval_policy.rs) marks a turn as requires public web whenever the last user message contains any of "right now" / "currently" / "today" / "this week" and any of a generic subject list ("schedule", "match", "game", "news", "release", "market", …) — raw str::contains substring matching over the entire message, at any length.

That guess is then treated as a hard requirement: in chat_completions.rs, a route that cannot run Anthropic's server-side web_search (every claude-haiku route, or any route when the OMI_DESKTOP_WEB_SEARCH_DISABLED kill switch is set) returns 503 web_search_unavailable instead of answering, and translate_request_inner hard-errors on the same condition.

The two combine into a deterministic break:

  • Calendar import extracts nothing. CalendarReaderService's synthesis prompt is machine-written, runs on the haiku synthesis model (ModelQoS.Claude.synthesis), and contains both Today's date: <iso> and work schedule. Every import 503s on both attempts and silently drops all memories/tasks/profile. GmailReaderService, AppleNotesReaderService and the haiku agent-pill calls have the same shape.
  • Ordinary sonnet chat turns get hijacked. "review the marketing copy I wrote today" matches (market inside marketing) → the forced-search instruction is prepended, and that instruction explicitly tells the model not to use the user's private context.

Introduced by ef8104a (07-13), which added the generic qualifier+subject heuristic on top of the pre-existing haiku 503 guard.

Root cause: a heuristic was given the authority of an explicit user instruction.

The fix

  • A guessed requirement never fails a turn. Freshness / AnaphoricLookup on a route without web search now degrades: answer from model knowledge, no injected tool, no forced-search instruction, and record a chat_retrieval / capability_mismatch / degraded fallback (per the AGENTS.md fallback contract). Only an explicit "search the web" (ExplicitWeb / Mixed) still fails closed — RetrievalPolicy::web_requirement_is_explicit().
  • The generic heuristic stops matching by accident. Word-boundary matching (so market no longer fires inside marketing) and a 240-char cap, so machine-generated service prompts stay out of it. The fixed phrases ("latest news", "current weather", …) still apply at any length.

Verification

  • cargo test — 360 passed, including 4 new regression tests: the real calendar synthesis prompt and "review the marketing copy I wrote today" stay on auto; a guessed-freshness turn on haiku and with web search disabled translates with no tools and no policy instruction instead of erroring; explicit vs guessed web requirement.
  • The tests catch the bug: reverting only the source fix (keeping the tests) fails 3 of them — leaves_a_service_synthesis_prompt_on_auto, does_not_match_generic_lookup_terms_inside_longer_words, test_translate_request_guessed_freshness_answers_without_web_search. (The 4th covers the new accessor, which doesn't exist pre-fix.)
  • cargo clippy -- -D warnings (the exact CI command) clean; rustfmt applied.
  • Not exercised against a live backend. Coverage is at the Rust behavior level — the tests call the production retrieval_policy() / translate_request_inner() with the literal prompt text from CalendarReaderService.swift, but I did not run a real Calendar import through a deployed desktop-backend. UNVERIFIED at that layer.

Not merged

Prod desktop-backend was last promoted 2026-07-12 01:16; the offending commit landed 07-13 16:54, so this is live on main/dev (and the beta lane), not on prod — the watchdog's auto-merge gate requires live prod impact. Landing this before the next desktop_promote_prod run keeps it from ever reaching prod users.

🤖 automated by hourly watchdog; opened for review, not merged.

Review in cubic

…requirement

is_fresh_public_lookup() classifies a turn as "requires public web" whenever the
last user message contains any of "right now"/"currently"/"today"/"this week"
AND any of a generic subject list ("schedule", "match", "game", "news",
"market", …), matched as raw substrings over the whole message. That guess then
becomes a terminal error: a route that cannot run Anthropic's server-side
web_search (every claude-haiku route, or any route when the kill switch is set)
returns 503 web_search_unavailable instead of answering.

The two combine into a deterministic break. CalendarReaderService's synthesis
prompt is machine-written, runs on the haiku synthesis model, and contains both
"Today's date: <iso>" and "work schedule" — so every Calendar import 503s on
both attempts and silently extracts nothing. GmailReaderService,
AppleNotesReaderService and the haiku agent-pill calls share the shape. On
sonnet, an innocuous "review the marketing copy I wrote today" ("market" inside
"marketing") gets the forced-search instruction prepended, which explicitly bans
the user's private context from the answer.

Root cause: a heuristic was given the authority of an explicit user instruction.

- A guessed requirement (freshness/anaphoric) now degrades on a route without
  web search: answer from model knowledge, no injected tool, no forced-search
  instruction, and record a `chat_retrieval` capability_mismatch fallback.
  Only an explicit "search the web" still fails closed.
- The generic qualifier+subject heuristic matches on word boundaries and is
  capped to short conversational turns, so machine-generated prompts and
  ordinary words can't trip it.

Regression tests: the calendar synthesis prompt and "marketing copy … today"
stay on auto; a guessed freshness turn on haiku (and with web search disabled)
translates with no tools and no policy instruction instead of erroring.

Verified: cargo test 360 passed; cargo clippy -- -D warnings (the CI command)
clean; rustfmt applied. 3 of the 4 new tests fail on the pre-fix source (the 4th covers a new accessor).
@kodjima33
kodjima33 merged commit a2a8016 into main Jul 14, 2026
23 of 29 checks passed
@kodjima33
kodjima33 deleted the watchdog/retrieval-policy-heuristic-503 branch July 14, 2026 14:36
Git-on-my-level added a commit that referenced this pull request Jul 15, 2026
## Summary
- Add a diff-scoped 1,500-line ratchet for Python, Swift, and Rust
product sources.
- Seed the committed snapshot with the 47 currently oversized files and
provide a downward-only updater for splits.
- Fold `RealtimeHubController.swift`'s overlapping size guard into the
shared ratchet; its extracted-type ownership guard remains.

## Root cause and durable guard
Oversized product files repeatedly concentrate collisions and costly
navigation (#9838; notably #9836 and #9384/#9638/#9692). The new shared
boundary freezes further growth, rejects smaller files that cross the
threshold, and makes any exceptional raise exact-count,
source-diff-bound, and one-line-justified.

## Verification
- `python3
.github/scripts/test_check_product_file_line_count_ratchet.py`
- `python3 desktop/macos/scripts/check-hub-controller-ratchet.py
--self-test`
- `make preflight` (rerun after applying the internal-only
`no-changelog-needed` label)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9851?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
@undivisible undivisible added the AI label Aug 10, 2026
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…#9851)

## Summary
- Add a diff-scoped 1,500-line ratchet for Python, Swift, and Rust
product sources.
- Seed the committed snapshot with the 47 currently oversized files and
provide a downward-only updater for splits.
- Fold `RealtimeHubController.swift`'s overlapping size guard into the
shared ratchet; its extracted-type ownership guard remains.

## Root cause and durable guard
Oversized product files repeatedly concentrate collisions and costly
navigation (BasedHardware#9838; notably BasedHardware#9836 and BasedHardware#9384/BasedHardware#9638/BasedHardware#9692). The new shared
boundary freezes further growth, rejects smaller files that cross the
threshold, and makes any exceptional raise exact-count,
source-diff-bound, and one-line-justified.

## Verification
- `python3
.github/scripts/test_check_product_file_line_count_ratchet.py`
- `python3 desktop/macos/scripts/check-hub-controller-ratchet.py
--self-test`
- `make preflight` (rerun after applying the internal-only
`no-changelog-needed` label)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9851?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants