Skip to content

fix(insights): validate tool-supplied retention comparisons - #780

Merged
izadoesdev merged 2 commits into
stagingfrom
codex/retention-validity
Sep 10, 2026
Merged

fix(insights): validate tool-supplied retention comparisons#780
izadoesdev merged 2 commits into
stagingfrom
codex/retention-validity

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 10, 2026

Copy link
Copy Markdown
Member

A report-use investigation can query retention as supporting evidence without a saved retention snapshot. Previously, numeric grounding could accept a published comparison from fewer than 50 eligible profiles or incomplete follow-up. The retention detector and scheduled rechecks already enforced those limits; the missing check was on tool-supplied evidence.

Published native retention evidence now selects two exact get_data results with {retention: true}. Code validates and renders the overall populations, cohort dates, identity basis, event selectors, horizon, timezone and observation cutoff. An earlier conflicting read of the same population remains binding. A complete overall aggregate remains usable when daily display rows are trimmed, and unrelated uncited retention data does not suppress an independently supported finding. Unsupported structured comparisons resolve privately with code-rendered eligible/incomplete profile counts and no asserted retention rate. Private grounded counts no longer trigger public-copy restrictions. If public prose repeats measured numbers, feedback names the exact field to rewrite and preserves the valid evidence references.

Scope: the insights agent's publication boundary and synthetic regression tests. No schema, dashboard or query-executor changes. Validation runs inside the existing finish call; actual model corrections are measured separately. No dependencies. Known overlap: draft #751 also edits the agent and SPEC; this slice starts from staging and does not depend on it.

Validation: 683 insights tests passed (six live-only skipped), all 28 publication tests passed, and root lint and all 33 package typechecks pass. Native-tool argument validation is exercised with synthetic query outputs. Independent review passes; Greptile reviewed final head aee85ea and reports 5/5 with no outstanding findings. All review threads are resolved.

Fresh paired qualification ran 16 unscripted agent invocations (four synthetic cases, two repetitions, both heads) through the native get_data executor with only database execution replaced. The old head published all four undersized/incomplete comparisons; this head published none. Both heads preserved both mature 50-profile comparisons and both independent report-use findings. All attempts completed. Candidate median latency was 17.9s versus 15.5s; total model turns were 30 versus 28, with five versus one rejected finishes. This is a publication-quality improvement, not a latency reduction.

Earlier attempts remain recorded: the first 16-run batch is excluded from retention conclusions because its replay mishandled native date precedence. A corrected intermediate comparison exposed one lost valid result and unnecessary private corrections, which prompted the final fix. Its inconsistent companion event counts were corrected for both arms before the final fresh comparison. Tests do not establish SQL execution, production data quality or customer value.

AI-assisted implementation and review using Codex.

@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
dashboard Ready Ready Preview Sep 10, 2026 7:19am UTC
databuddy-status Ready Ready Preview Sep 10, 2026 7:19am UTC
documentation Ready Ready Preview Sep 10, 2026 7:19am 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: 3fe267ed-9915-47fd-b72e-9265104c8526

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.

@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai review this exact head: 21710635314274b9a40f7751387e797bacbd566f.

Please check retention publication without a saved snapshot: exact native get_data references; complete overall populations with at least 50 eligible profiles each; event/namespace/horizon/date/timezone/cutoff binding; sticky earlier conflicts; and preservation of independent findings and complete overall aggregates when daily rows are trimmed. The detector already enforces sample and maturity thresholds; this PR closes the supporting-tool-evidence route.

The native-agent regression reproduces the previous head incorrectly publishing 16/20 → 4/20 and verifies rejection on this head. Root lint, 33 package typechecks, all 27 pre-push test tasks and 25 targeted publication tests pass. Fresh model behavior evaluation remains in progress. Please provide an explicit verdict on this commit rather than treating a skipped review check as approval.

@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR strengthens the Insights publication boundary for tool-supplied retention comparisons.

  • Requires two exact native retention results with matching scope, cohort duration, event selectors, timezone, horizon, and observation cutoff.
  • Prevents publication when cohorts are undersized, incomplete, inconsistent, overlapping, or contradicted by an earlier equivalent read.
  • Preserves valid overall aggregates when daily rows are truncated and allows unrelated evidence to support independent findings.
  • Adds synthetic regression coverage for valid, invalid, private-resolution, and conflicting-read scenarios.

Confidence Score: 5/5

The PR appears safe to merge with no outstanding findings.

No changes were made after the previous review, no new actionable issues were identified, and the sole previous finding was resolved after Greptile explicitly withdrew it as an appropriate untrusted-input validation boundary.

Important Files Changed

Filename Overview
apps/insights/src/agent.ts Adds strict validation and code rendering for tool-supplied retention evidence, including cohort eligibility and conflicting-read safeguards.
apps/insights/src/retention-publication.test.ts Adds comprehensive synthetic coverage for valid publication, private resolution, malformed metadata, truncation, citation requirements, and conflicting reads.
SPEC.md Documents the publication contract and correction behavior for retention evidence queried during investigations.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Model cites two get_data results] --> B[Validate exact references and retention schema]
    B --> C{Scopes and cohort metadata match?}
    C -- No --> D[Reject finish for correction]
    C -- Yes --> E{Both cohorts complete and eligible?}
    E -- No, private outcome --> F[Render eligible and incomplete counts without a rate]
    E -- No, public outcome --> D
    E -- Yes --> G{Earlier equivalent read conflicts?}
    G -- Yes --> D
    G -- No --> H[Render code-grounded retention comparison]
    H --> I[Publish qualitative finding]
Loading

Reviews (3): Last reviewed commit: "fix(insights): avoid redundant retention..." | Re-trigger Greptile

Comment thread apps/insights/src/agent.ts Outdated
@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 10, 2026 7:18am

@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai review the final pushed head aee85ea57ba976a220f5754c60b6598a56350eeb.

Fresh provider runs exposed unnecessary corrections on a private limitation and one lost valid result after generic numeric-copy feedback. This update lets private undersized/incomplete structured comparisons record validated eligibility counts without a retention-rate claim. Public minimum populations, maturity, scope and sticky-conflict checks remain intact. Private authoring counts still undergo ordinary numeric grounding. Public numeric feedback now quotes the exact field to correct while preserving valid evidence/references.

Root lint, 33 package typechecks, 683 insights tests (six live-only skipped), and 28 publication boundary tests pass. Independent review checked the private fallback and public protections. Please provide an explicit verdict on this exact head; the prior untrusted-input unknown finding was withdrawn with the repository-specific guidance and remains resolved.

@izadoesdev
izadoesdev marked this pull request as ready for review September 10, 2026 07:37
@izadoesdev
izadoesdev merged commit f080a3d into staging Sep 10, 2026
20 checks passed
@izadoesdev
izadoesdev deleted the codex/retention-validity branch September 10, 2026 07:43
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