Skip to content

fix(ai): recover query matches outside the selected category - #783

Merged
izadoesdev merged 2 commits into
stagingfrom
codex/query-capability-discovery
Sep 14, 2026
Merged

izadoesdev merged 2 commits into
stagingfrom
codex/query-capability-discovery

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 10, 2026

Copy link
Copy Markdown
Member

A category-scoped search can miss an existing analytics builder. For example, retention under Custom Events returns zero results even though identified_profile_retention exists under Profiles. Discovery now returns separately labeled outsideCategory matches after a scoped keyword miss, preserving the scoped count, actual category labels, substring matching and full query contracts.

The final change is limited to the discovery tool and its regression tests: 13 production lines added, six removed. It uses the existing catalog and performs no I/O.

Validation: root lint, all 33 typecheck tasks and the full 27-task test suite pass. The AI package reports 724 passed, 229 skipped, zero failed. Three behavioral checks reproduce failures on the frozen reference and pass here; native contract coverage also verifies selectors, ordering, genuine misses, complete browsing and existing search behavior. Independent read-only review found no actionable regressions.

We ran 48 live attempts across two frozen paired experiments with the same configured openai/gpt-5.6-terra gateway alias, native MCP configuration, tool schemas and synthetic data. The first experiment recovered retention in 4/4 attempts versus 0/4. The second compared catalog compaction against the final simpler fallback:

Second paired experiment Compact version Final fallback
Requested data answers completed 9/10 10/10
Correct retention answers 4/4 4/4
Greeting controls without tools 2/2 2/2
Model steps 44 37
Discovery calls 21 14
Observed input tokens, including cache 519,230 437,594
Median attempt latency 12.08s 10.39s

Compaction repeatedly required three discovery calls for property questions versus one with full contracts. The final version emits more discovery-response bytes but uses 15.7% fewer input tokens in the paired sample. Cache usage differs, so this is not an established monetary saving. The fixed tool-definition payload remains about 50 KB per model step.

Each experiment uses six known synthetic cases with two repetitions, alternating which version runs first and reversing case order for repeat two. SQL/schema/profile alternatives are deliberately unavailable, so the compact version's missing checkout answer does not prove a production regression. All attempts and traces are retained; no failures were selectively replaced. This is a small diagnostic sample, not a production success rate or a live Sazabi comparison.

Scope and integration: rebased onto staging 00704a0f0, with no source overlap or merge dependency on #782 or #751. Both evaluation arms explicitly compose #782's earlier conversation/schema repair at f61250448; only discovery differs within each pair. Final source is identical to the evaluated fallback (SHA-256 d76442b4407b18fe56c2c711fab7d981ae090311ec33d0c5bd4e95dabc6c3a66). No model, main prompt, authorization, storage or deployment changes.

Fresh independent review found no production issue: widening occurs only on scoped keyword misses and preserves the exact global query contracts. Native regression tests pass; final-head CI and configured review are required before staging merge. AI-assisted implementation and evaluation, directed by the maintainer.

@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
databuddy-status Ready Ready Preview Sep 14, 2026 12:24pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
dashboard Skipped Skipped Sep 14, 2026 12:24pm UTC
documentation Skipped Skipped Sep 14, 2026 12:24pm UTC

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: cd1c8a7d-f56e-4a15-9283-002dc6f8da8c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@unkey-deploy

unkey-deploy Bot commented Sep 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Unkey Deploy

Name Status Preview Inspect Updated (UTC)
links (preview) Ready Visit Preview Inspect Sep 14, 2026 12:24pm

@izadoesdev izadoesdev changed the title fix(ai): make query discovery recover across categories fix(ai): recover query matches outside the selected category Sep 10, 2026
@izadoesdev
izadoesdev force-pushed the codex/query-capability-discovery branch from aa24213 to c91c906 Compare September 14, 2026 12:23
@vercel
vercel Bot temporarily deployed to Preview – documentation September 14, 2026 12:24 Inactive
@vercel
vercel Bot temporarily deployed to Preview – dashboard September 14, 2026 12:24 Inactive
@izadoesdev
izadoesdev marked this pull request as ready for review September 14, 2026 12:24
@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai Please review final head c91c906 before staging merge. This is the two-file query discovery fallback: only a scoped keyword miss widens to separately labeled outsideCategory matches, preserving exact query contracts and scoped counts. It is rebased onto staging; fresh lint, all 33 type/build checks, all 27 test tasks and 45 focused native tests pass.

@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extends analytics query discovery so a category-scoped keyword miss retains its empty scoped result while separately exposing matching builders from the full catalog.

  • Computes keyword matches globally before applying the selected category.
  • Adds outsideCategory only for nonblank scoped searches with no in-category match.
  • Preserves each recovered builder’s actual category and complete query contract.
  • Adds regression coverage for unique and broad fallback matches, genuine misses, substring behavior, category browsing, compact unfiltered browsing, and contract completeness.

Confidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, contract, or repository-rule issue remains.

The fallback is limited to scoped nonblank keyword misses, preserves the original scoped count and types, and returns the same ordered full-contract entries produced by an unscoped keyword search. Existing search and browsing paths remain unchanged and are covered by focused regression tests.

Important Files Changed

Filename Overview
packages/ai/src/ai/tools/discover-query-types.ts Adds a narrowly gated, contract-preserving global fallback for category-scoped keyword misses.
packages/ai/src/ai/tools/discover-query-types.test.ts Adds comprehensive regression coverage for fallback results and unchanged discovery contracts.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Discovery request] --> B[Match keyword against full catalog]
  B --> C[Apply selected category]
  C --> D{Scoped nonblank search with zero scoped matches?}
  D -->|No| E[Return normal scoped or global result]
  D -->|Yes| F[Return empty scoped types and count]
  F --> G[Attach full global matches as outsideCategory]
Loading

Reviews (1): Last reviewed commit: "fix(ai): retain full query contracts aft..." | Re-trigger Greptile

@izadoesdev
izadoesdev merged commit 250c391 into staging Sep 14, 2026
21 checks passed
@izadoesdev
izadoesdev deleted the codex/query-capability-discovery branch September 14, 2026 12:31
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