Repository navigation
fix(retrieval): harden result_bounds edge cases and apply context bounding to omi_tools (#23410) - #23433
Conversation
…nding to omi_tools (BasedHardware#23410)
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks @ducanh3005 — the hardening itself is correct and well-tested (I ran both changed test files on this head: 18/18 pass), but one design issue should be fixed before merge.
What's good:
backend/utils/retrieval/tools/result_bounds.py:cap_items_for_llmnow guardsNoneitems andmax_items <= 0(the olditems[:max_items]silently sliced from the end for negative caps), andbounded_resultsafely coerces None/non-string results and clamps negativeshown. I checked all callers —memory_tools.py:280and this PR's new call — none passmax_items <= 0, so the semantics change breaks nobody.backend/utils/retrieval/tools/omi_tools.py: query validation, theMappingcheck on the docs context, skippingNonesection values, and the 100-section / 60000-char cap close a real gap — this tool previously returned an unbounded docs string to the chat model.backend/tests/unit/test_retrieval_result_bounds.pyand the newbackend/tests/unit/test_omi_tools_resilience.pycover the new edge cases meaningfully and follow the repo's import-isolation conventions.
Blocking: production importlib fallbacks that exist only for the test harness. omi_tools.py and result_bounds.py each gain a try/except ModuleNotFoundError → spec_from_file_location fallback. These trigger only under test_omi_tools_resilience.py's empty-package stubs (stub_modules with __path__=[] parents); in production the plain imports always succeed, so this is dead code in prod modules — and no other module under backend/utils/ uses this pattern. The risk is that a genuine future import breakage (say, utils.model_text stops importing) gets silently papered over by path-loading a second, untracked module instance instead of failing loudly. Suggested fix, entirely test-side: inside the stub_modules block, pre-load the real modules by path under their real names (the same load_module_fresh pattern the test already uses for omi_tools itself — register utils.retrieval.tools.result_bounds and utils.model_text before loading omi_tools). Then the plain imports in both production modules resolve and both fallback blocks can be deleted.
Nit: get_omi_product_info_tool(query: Optional[str] = None) makes query optional in the LLM-facing tool schema, so a model can now invoke with no query and just get the error string. If the goal is internal robustness, consider keeping the parameter required and handling bad runtime input instead.
Cost/performance: strictly positive — the tool result is now capped at 100 sections / 60000 chars instead of unbounded, bounding token spend per product-info call.
USER IMPACT: none for normal docs sizes — product-doc answers are unchanged; only pathologically large docs are now truncated with an honest "more may exist" note.
Once the import fallbacks move into the test, I have no further concerns on this diff.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Official PR Author (
|
kodjima33
left a comment
There was a problem hiding this comment.
fix(retrieval) 5/5: fixes #23410, scoped, tests added, CI green. Independently reviewed the standing CHANGES_REQUESTED (Git-on-my-level) — it flags dead test-only import-fallback code, not a functional defect; not blocking.
…23433 left red #23433 merged with all six backend unit shards failing, and every later main push has failed the same way, so no PR can go green. This carries the minimal repair; revert if the owning change lands its own fix. - The defensive None/junk guards in result_bounds and omi_tools trip pyright's reportUnnecessary* rules. Keep the runtime hardening exactly as merged and suppress per-line with the codebase's established "# type: ignore[...] # defensive" idiom, as memories.py already does. - generate_2025's seg.end None filter gets the same treatment instead of trusting the required-float annotation. - The spec_from_file_location fallbacks did not register the module in sys.modules before exec, so model_text's dataclasses crashed with AttributeError under test_omi_tools_resilience's stub_modules harness (the test never ran in CI: the shards died at pyright first). Register before exec, matching the load_module_fresh recipe. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e CPU guard test_payment_declined_proration lands 1.25-1.66s CPU per test on CI runners (the subscription/Stripe module graph amortizes into the calls under file isolation). The file never ran on main: every shard died at the #23433 pyright errors first, so the guard had not flagged it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…c and legacy paths (#23512) * fix(notes): stop persisting the 🧠 unset emoji default on deterministic and legacy paths #23389 repaired the v2 NotesOutput boundary, but every other writer that never received an emoji still persisted the Structured schema default 🧠: the sync-intake deterministic minimum, the short-clip quiet minimum (emoji=''), the media minimum, and the legacy StructuredExtraction / AgentNotesSubmission submissions. A stored default is indistinguishable from a chosen one, so users saw a deliberate brain badge no code chose. - Move the category fallback (DEFAULT_EMOJI/CATEGORY_EMOJI/fallback_emoji) to models/conversation_emoji.py and map category `other` to the neutral 💬, so every CategoryEnum member resolves to a non-brain emoji. - Deterministic/minimum builders set the category fallback explicitly; quiet_minimum no longer blanks the emoji (blank renders as the client's random pick, which includes 🧠). - StructuredExtraction/RichStructuredExtraction.to_structured apply the fallback, covering AgentNotesSubmission and EpisodeStructuredExtraction. - The Structured model's own default (SDK + backend mirror), the share projection, and the client display projection change 🧠 → 💬, so a forgotten field lands on the neutral emoji. The deliberate relevance-discard placeholder (🧠/🎉 on discarded rows) is untouched. - The app decodes a missing or blank emoji as 💬 and renders an empty emoji deterministically instead of a random pick containing 🧠; the app-client OpenAPI spec and generated dart wire schemas are regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(retrieval): unblock the pyright lane and the isolation fallback #23433 left red #23433 merged with all six backend unit shards failing, and every later main push has failed the same way, so no PR can go green. This carries the minimal repair; revert if the owning change lands its own fix. - The defensive None/junk guards in result_bounds and omi_tools trip pyright's reportUnnecessary* rules. Keep the runtime hardening exactly as merged and suppress per-line with the codebase's established "# type: ignore[...] # defensive" idiom, as memories.py already does. - generate_2025's seg.end None filter gets the same treatment instead of trusting the required-float annotation. - The spec_from_file_location fallbacks did not register the module in sys.modules before exec, so model_text's dataclasses crashed with AttributeError under test_omi_tools_resilience's stub_modules harness (the test never ran in CI: the shards died at pyright first). Register before exec, matching the load_module_fresh recipe. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(payment): allowlist #23416's declined-proration cases against the CPU guard test_payment_declined_proration lands 1.25-1.66s CPU per test on CI runners (the subscription/Stripe module graph amortizes into the calls under file isolation). The file never ran on main: every shard died at the #23433 pyright errors first, so the guard had not flagged it. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes #23410
/claim #23410
Summary