Skip to content

fix(insights): validate saved definitions and retire obsolete investigations - #776

Merged
izadoesdev merged 6 commits into
stagingfrom
codex/measurement-review-followup
Sep 9, 2026
Merged

fix(insights): validate saved definitions and retire obsolete investigations#776
izadoesdev merged 6 commits into
stagingfrom
codex/measurement-review-followup

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 9, 2026

Copy link
Copy Markdown
Member

Business-context saves could preserve invalid website bindings when callers omitted measurement plans. Editing or removing an activation/return definition also left its old investigation permanently due.

Validate the effective plans inside the existing save transaction. During discovery, retire an obsolete due case only after locking and verifying the current organization, website, explicit saved definitions, and exact latest observation. Record it as stale with a quiet history entry that explicitly says recovery was not measured. Preserve unknown, failed, insufficient, and future measurements; a label-only rename remains measurable. The retirement marker blocks older and equal-snapshot writes from reopening the case on both persistence paths, while later measured work for a restored definition can reopen it.

Also apply the existing measurement-card typography utilities and document a merge gate requiring completed final-head reviews and resolved feedback. Addresses all three review comments on #775. No schema or model/prompt changes. AI-assisted maintainer contribution.

Validation: root lint and all 33 workspace typecheck tasks passed; 41 service integration tests and 29 persisted lifecycle tests passed against isolated synthetic PostgreSQL and real local Redis cache invalidation; 59 related insights unit/source tests passed. Four stale-binding cases, six definition-retirement cases, and four equal-snapshot writes were reproduced failing before their fixes. Independent review cleared the final patch, including concurrent retirement, parallel detector reads, and later definition restoration.

Scope: measurement definition saves, lifecycle, and the associated review feedback. Rebased onto current staging after #777; no unmerged dependency.

Integration tests exercise real local Redis invalidation and close both PostgreSQL and Redis during teardown. Root watch/coverage and package unit commands select integration suites externally; native watch/coverage selector checks verify a unit-test control runs while this database suite is excluded.

@vercel

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

@coderabbitai

coderabbitai Bot commented Sep 9, 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: d233ebf9-2d92-469b-a8e7-01f4db453204

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
izadoesdev force-pushed the codex/measurement-review-followup branch from 9c5524e to 2d0754f Compare September 9, 2026 11:50
@izadoesdev izadoesdev changed the title fix(insights): complete saved measurement lifecycle review fixes fix(insights): validate saved definitions and retire obsolete investigations Sep 9, 2026
@izadoesdev
izadoesdev marked this pull request as ready for review September 9, 2026 11:50
@unkey-deploy

unkey-deploy Bot commented Sep 9, 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 9, 2026 12:12pm

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR validates effective measurement-plan bindings during saves and retires obsolete retention investigations only after transactional ownership, definition, and observation checks.

  • Prevents omitted plans from preserving invalid website bindings.
  • Resolves obsolete investigations as stale while preserving unavailable, failed, future, and label-only remeasurements.
  • Prevents older or equal-snapshot writes from reopening retired cases while allowing later measured work after restoration.
  • Adds persisted lifecycle and measurement-plan integration coverage.
  • Excludes integration suites from root watch and coverage commands and closes both PostgreSQL and Redis during teardown.
  • Applies measurement-card typography utilities and documents the final-head review gate.

Confidence Score: 5/5

The final head appears safe to merge, with all previous findings resolved and no remaining actionable defects identified.

The Redis teardown now closes and clears the real cache client, root watch and coverage commands consistently exclude integration suites, and the two earlier rule violations remain fixed. The retirement path verifies the canonical saved definition and exact latest observation under transaction locks before resolving a case, while persistence fences protect the stale transition from older and equal-snapshot writes.

Important Files Changed

Filename Overview
packages/services/src/organization-business-context.ts Validates the effective persisted measurement plans inside the existing save transaction, including inherited plans when callers omit the field.
apps/insights/src/persistence.ts Adds transactionally guarded retirement of obsolete retention observations and fences stale concurrent persistence.
apps/insights/src/generation.ts Integrates obsolete-case retirement into production discovery without retiring unmeasurable or shadow-mode cases.
apps/insights/src/retention-retirement.integration.test.ts Covers retirement, concurrency, tenant isolation, transient failures, stale writes, restoration, and complete database/cache teardown.
package.json Consistently excludes integration suites from root watch and coverage commands using the repository’s established Bun test filter.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Load due retention observation] --> B[Attempt remeasurement]
    B -->|Measured| C[Continue with measured signal]
    B -->|Not measured in production| D[Lock organization and website]
    D --> E{Saved definition still matches?}
    E -->|Yes or unavailable| F[Keep investigation due]
    E -->|No| G[Lock matching open investigation]
    G --> H{Exact observation is still latest?}
    H -->|No| F
    H -->|Yes| I[Resolve investigation as stale]
    I --> J[Append quiet non-published history]
    J --> K[Invalidate insight and agent caches]
Loading

Reviews (3): Last reviewed commit: "test(insights): close test resources and..." | Re-trigger Greptile

Comment thread apps/insights/src/retention-retirement.integration.test.ts Outdated
Comment thread apps/insights/src/retention-retirement.integration.test.ts Outdated
@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai Please re-review the current final head 16a72e77e5de1b9a4860fba1979345e1ae7559a1. Both findings from the previous review are fixed: the Redis namespace import/spies are removed, real synthetic Redis invalidation is exercised, and the suite now uses an ordinary active describe with selection handled by the existing package test command. All 29 persisted tests, root lint, all 33 typecheck tasks, and a dedicated test-file typecheck pass. Please verify the fixes and report any remaining findings before merge.

Comment thread apps/insights/src/retention-retirement.integration.test.ts
Comment thread apps/insights/src/retention-retirement.integration.test.ts
@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai Please re-review final head 66d1ed7e536547da5e1586f0c2afe870c21a4f8b before merge. Both new findings are fixed: teardown awaits both PostgreSQL and Redis shutdown, and root watch/coverage commands now consistently exclude integration suites outside the test source. All 29 persisted PostgreSQL/Redis regressions pass; native coverage/watch selector smokes pass with a real unit-test control and no service environment. Root lint, 33 typecheck tasks, dedicated test-file types, and independent review are clear. Please report any remaining actionable findings on this head.

@izadoesdev
izadoesdev merged commit a981ac5 into staging Sep 9, 2026
22 checks passed
@izadoesdev
izadoesdev deleted the codex/measurement-review-followup branch September 9, 2026 12:16
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