Skip to content

fix(insights): bind verification to exact measurements - #731

Merged
izadoesdev merged 4 commits into
stagingfrom
codex/insights-verification-check
Sep 6, 2026
Merged

fix(insights): bind verification to exact measurements#731
izadoesdev merged 4 commits into
stagingfrom
codex/insights-verification-check

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 6, 2026

Copy link
Copy Markdown
Member

Repair follow-ups could claim recovery from an incomplete window, undersampled read, or changed population. This change saves optional goal/funnel verification conditions, binds them to the expected definition, and computes the verdict from an exact native analytics response. The model cannot supply the stored verdict or override its summary.

Existing single-goal/funnel analytics now return their actual measured dates and measured definition. Cache keys include that identity; clipped historic windows and changed filters remain inconclusive. One analytics read can also inspect the definition, removing the separate list lookup for ordinary verification. Failed/inconclusive case closure no longer receives a recovered marker. Native SDK callbacks prevent finishing alongside unseen reads, including when a read already has its own output/input hooks. Resolved website identity comes from the measured metadata, so valid domain aliases work.

Multi-source evidence citations preserve both periods/cohorts in one concise comparison. Scheduled/reply persistence uses one projection and removes duplicate update mappings. There is no new table, agent, replay conversation, or investigation lifecycle.

Scope: one verification/measurement-boundary slice against staging. No dependencies. File overlap with open PR #680 in goals.ts: this PR changes single getAnalytics and its output; #680 owns bulkAnalytics. That bulk path is untouched here.

Fresh evaluation: same 24 synthetic scenarios × 2 per revision through the real model gateway. Turns 108→95; reads 80→64; summed durations 442.6s→386.8s; rejected finishes 12→2. Five false recovery claims in the baseline check scenarios became zero; all 12 candidate machine verdicts and corresponding copy matched the measured condition. Two baseline small-sample cases also lost/misclassified the 300-entrant requirement. The baseline is not penalized merely for lacking the new stored field. Fourteen subsequent confirmations, a final 25-case sweep, three corrected native-funnel repeats and boundary tests cover later review fixes. All 336 exploratory/comparison runs and 738 observable steps were retained and reviewed locally. The first native fixture returned the current period for both period queries; it was corrected, retained and excluded from final native-funnel findings.

Limits: synthetic tool latency is not production latency. Input tokens increased 10%, and four published briefs exceeded 60 words on both sides. Initial goal investigations still mishandle contradictory measurements, and free-text recovery conditions remain weak. Runtime is net +310 lines for the new verification boundary; persistence is 38 lines smaller. This does not establish overall product quality or price fit.

Review dispositions: configured-target fixture evidence is retained at the prior action's original evidence index; current follow-up context is not substituted. Targets absent from all cited evidence remain invalid. Domain-alias and mixed read/finish findings are fixed with boundary tests. SPEC now folds impact into summary while counting legacy impact toward the brief budget. The population-drift fixture allows a new inspected filter repair rather than treating every action as a repeated route edit.

Validation: root lint; all 33 type/build tasks; all 27 test tasks including 337 insights tests; four RPC actual-window/population/cache tests; 38 local PostgreSQL/Redis integration tests. MCP JSON-schema serialization is covered by the existing full test suite. No customer data or notifications were used in evals.

Final review: the agent's production get_goal_analytics input (packages/ai/src/ai/tools/goals.ts) accepts only goalId, websiteId and the date range; its executor forwards exactly those fields. Request-level filters on the public RPC therefore cannot enter an agent repair snapshot through this tool. Existing verification guards still reject extra query filters. The callback now uses the native SDK contract, and the eval reuses insightMeasurementSchema, removing 11 duplicate lines.

Funnel review fixes: native measurements retain step names and stored conditions for repair validation; saved verification uses only evaluated population fields. Regression cases cover native-only repair, a native read after list, lost-condition rejection, published verification and cosmetic rename stability. Filter fields/operators reuse the existing edit constraints. Uninspected checks produce the existing actionable validation message. The goal RPC mock uses the actual goal signature and asserts the fourth argument.

The passed-domain boundary test is retained: native SDK toolResults carry parsed input even when a mock executor ignores it. The verifier previously compared that input directly and rejected the domain alias. This tests the verification boundary, not the unchanged domain resolver.

Final live findings: all six check verdicts/copy remain correct. All three native-funnel repeats preserved conditions and created an 82% check with a 200-entrant minimum in two turns, but none passed the complete usefulness rubric: one unnecessarily renamed a step, two exceeded the brief budget. The final sweep also reproduced the stale-zero story despite fetching 164 current visits, omitted Direct in the source comparison, and had three overlong briefs. These are documented remaining limitations, not reported as quality passes.

The final P3 suggestion to add a condition-only cache-key test is not a new runtime defect. The key already serializes the complete measurement and existing tests assert full condition retention plus invalidation on changed definitions. Native repair tests separately reject lost stored conditions. No condition-specific cache branch exists; another assertion of JSON serialization would duplicate that coverage. Conditions remain excluded from the recovery population comparison because current analytics does not evaluate them.

@vercel

vercel Bot commented Sep 6, 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 6, 2026 1:32pm UTC
databuddy-status Ready Ready Preview Sep 6, 2026 1:32pm UTC
documentation Ready Ready Preview Sep 6, 2026 1:32pm UTC

@coderabbitai

coderabbitai Bot commented Sep 6, 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: Team

Run ID: 9e45dcc6-8731-4968-bb49-93da81a7f901

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.

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

All reported issues were addressed across 9 files

Architecture diagram
sequenceDiagram
    participant Agent as Insights Agent
    participant Prompt as Agent Prompt
    participant Verifier as Verification Checker
    participant Analytics as Analytics Tools (get_funnel_analytics)
    participant DB as Insights DB (analyticsInsights)
    participant Reply as Reply/Scheduled Flow
    participant Eval as Eval Runner

    Note over Agent,Verifier: Repair with Structured Verification

    Agent->>Prompt: Define repair with next.check
    Prompt-->>Agent: Goal/funnel check: metric, dates, min entrants, threshold
    Agent->>Verifier: CHANGED: Submit verification check
    Verifier->>Analytics: Read exact definition with UTC dates
    Analytics-->>Verifier: Measured count, entrants, conversion rate

    alt Measurement matches saved check
        Verifier->>Verifier: CHANGED: Compute verdict (passed/failed/inconclusive)
        Verifier-->>Agent: Code-generated summary (not model prose)
    else Legacy no structured check
        Agent->>Agent: Use prose condition (no invented check)
    end

    Note over Agent,DB: Persistence with Shared Projection

    Agent->>DB: CHANGED: Persist outcome + verification status
    DB-->>Reply: CHANGED: Single caseValues projection
    Reply->>Reply: CHANGED: Reuse same projection (no duplicate update)
    alt Verification passed
        Reply->>DB: Label "recovered" only if passed
    else Failed or inconclusive
        Reply->>DB: Keep "resolved/open" (not recovered)
    end

    Note over Agent,Eval: Eval with Source Snapshots

    Eval->>Eval: NEW: Copy agent.ts, insights.ts, quality.ts to output dir
    Eval->>Agent: Run verification scenarios (passed/failed/small-sample/unfinished-window)
    Agent-->>Eval: Outcome with verification status matching scenario
    Eval->>Eval: Validate code verdict vs expected, not model summary

    Note over Agent,DB: Multi-Source Evidence
    Agent->>Prompt: CHANGED: Evidence refs may be array of sources
    Prompt-->>Agent: Include all contributing periods/populations/mechanisms
    Agent->>Agent: Validate every cited source in combined claim
Loading

Shadow auto-approve: would not auto-approve because issues were found.

Re-trigger cubic

Comment thread apps/insights/src/evals/quality.ts
Comment thread apps/insights/src/agent.ts Outdated
Comment thread apps/insights/src/agent.ts
Comment thread apps/insights/src/agent.ts
Comment thread SPEC.md Outdated
Comment thread SPEC.md
@unkey-deploy

unkey-deploy Bot commented Sep 6, 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 6, 2026 1:31pm

@greptile-apps

greptile-apps Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces structured goal and funnel recovery checks and binds verdicts to exact analytics metadata rather than model-authored claims.

  • Adds canonical measurement identity to single-goal and funnel analytics responses and cache keys.
  • Persists verification conditions, measured verdicts, and corrected case-resolution metadata.
  • Supports multi-source evidence references and prevents finishing alongside unseen reads.
  • Adds boundary, persistence, analytics-contract, and evaluation coverage.
  • The goal path still needs to distinguish temporary analytics filters from the persisted definition used for later verification.

Confidence Score: 4/5

The PR is not yet safe to merge because goal repairs inspected with temporary filters can never satisfy their subsequently generated verification read, and an explicit repository typing requirement remains violated.

The verification flow stores request-level goal filters as part of the expected persisted definition but omits them from the later exact read, forcing valid recoveries to remain inconclusive; the newly introduced unknown types also must be replaced to satisfy the repository rule.

Files Needing Attention: apps/insights/src/agent.ts, apps/insights/src/evals/quality.ts

Important Files Changed

Filename Overview
apps/insights/src/agent.ts Adds measurement-bound verification, generated verdict summaries, combined evidence citations, and mixed read/finish protection; temporary goal filters can contaminate the persisted expected definition.
packages/shared/src/insights.ts Defines canonical measurement metadata, structured verification checks, persisted verdicts, and multi-source evidence-reference contracts.
packages/rpc/src/routers/goals.ts Returns effective goal measurement metadata and keys cached analytics by its full identity, including request-level filters.
packages/rpc/src/routers/funnels.ts Returns canonical funnel measurement metadata and binds cached results to the effective definition and period.
apps/insights/src/persistence.ts Consolidates case persistence into one projection and marks only passed verification closures as recovered.
apps/insights/src/resume.ts Reuses the consolidated case projection when committing reply-driven investigation outcomes.

Sequence Diagram

sequenceDiagram
    participant Agent
    participant Analytics
    participant Store
    participant Resume

    Agent->>Analytics: Inspect goal/funnel definition and measurements
    Analytics-->>Agent: Counts plus canonical measurement metadata
    Agent->>Store: Save action and structured verification check
    Resume->>Store: Load latest pending check
    Resume->>Analytics: Read exact definition and UTC window
    Analytics-->>Resume: Counts, actual dates, and measured population
    Resume->>Resume: Validate identity, completeness, sample, and threshold
    Resume->>Store: Persist passed, failed, or inconclusive verdict
Loading

Reviews (1): Last reviewed commit: "fix(insights): verify actual populations..." | Re-trigger Greptile

Comment thread apps/insights/src/agent.ts
Comment thread apps/insights/src/agent.ts Outdated

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

All reported issues were addressed across 10 files (changes from recent commits).

Shadow auto-approve: would not auto-approve because issues were found.

Re-trigger cubic

Comment thread apps/insights/src/agent.ts
Comment thread packages/shared/src/insights.ts Outdated
Comment thread apps/insights/src/agent.ts Outdated
Comment thread apps/insights/src/investigation-flow.test.ts
Comment thread packages/rpc/src/routers/analytics-measurement.test.ts

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

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would not auto-approve. Auto-approval blocked by 5 unresolved issues from previous reviews.

Re-trigger cubic

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

All reported issues were addressed across 5 files (changes from recent commits).

Shadow auto-approve: would not auto-approve because issues were found.
Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/rpc/src/routers/analytics-measurement.test.ts
@izadoesdev
izadoesdev merged commit f8e3622 into staging Sep 6, 2026
20 checks passed
@izadoesdev
izadoesdev deleted the codex/insights-verification-check branch September 6, 2026 13:55
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