Skip to content

feat(insights): charge $1 per completed investigation - #786

Merged
izadoesdev merged 23 commits into
stagingfrom
codex/fixed-investigation-pricing
Sep 12, 2026
Merged

feat(insights): charge $1 per completed investigation#786
izadoesdev merged 23 commits into
stagingfrom
codex/fixed-investigation-pricing

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 12, 2026

Copy link
Copy Markdown
Member

Investigations cost $1 per completed result, replacing token-based credits for customers with the new investigation entitlement. A scan may investigate multiple selected signals. Supported no-action answers remain readable and billable; failed, incomplete and inconclusive work releases its reserved unit.

  • Add Autumn investigation_runs and a $1 prepaid investigations_topup SKU, whole-unit checkout validation, separate balance/purchase UI, and matching plan, pricing, documentation and notification copy.
  • Reserve one durable unit before fresh analysis and persist settlement intent with the readable result. Retries reuse the operation and provider lock; uncertain provider responses stay pending for recovery.
  • Include saved-evidence clarifications, trusted repair/definition-change verification and native saved-check continuations. Explicit new analysis persists the accepted $1 price with the queued operation and requires fixed-unit entitlement; reservations must match its immutable quote. Included checks continue through an earlier paid candidate's reservation failure.
  • Retain only typed, allowlisted native measurement fields for clarifications; omit raw profiles, sessions, source files, search queries and arbitrary properties with explicit limitations. Use Luna for native investigations and preparation. Completion and arithmetic checks preserve actual measurement scope, reject incomplete evidence and handle claims that cite several source types.

Existing attached legacy plans and credit balances retain their terms. Chat still uses credits. New active plan versions add zero investigation units; purchasing investigations or switching to a new plan version adopts fixed pricing. An exhausted investigation balance never falls back to old credits.

Validation: full lint/policy checks, all 33 typecheck tasks and all 27 repository test tasks passed. The complete Insights integration script passed on disposable PostgreSQL 17/Redis, including durable reservations, settlement outages, retries, readable no-action results, incomplete releases, mixed paid/included portfolios and anchored clarifications. The complete Insights lifecycle suite passed 72 service tests, and the real API/RPC handler suite passed 23 tests; checkout boundary coverage passed 56 tests. Live Luna tests completed 6 investigation scenarios, 12 clarification replies and 6 targeted follow-up regressions using synthetic data; raw traces were manually reviewed and defects found were fixed with regressions. SDK billing tests use a controlled HTTP transport, not live provider receipts. A supplemental direct API typecheck has 132 existing transitive diagnostics; the final typing cleanup adds none compared with f228f26.

Rollout: canonical PostgreSQL db:push includes the new ledger and nullable evidence/reply fields, including accepted price; schema application and a second no-op were verified. The Autumn catalog changes are included in this PR. No live catalog push or customer migration was performed; catalog synchronization must preserve existing attached plan versions. This PR targets staging only.

Scope: native Insights pricing and its included reply behavior. No dependency on an unmerged PR. Known overlaps: #751 touches business context/resume, #782 touches shared agent execution, and #784 includes the Luna cost registry; its general conversation default remains separate.

@vercel

vercel Bot commented Sep 12, 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 12, 2026 12:16pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
dashboard Skipped Skipped Sep 12, 2026 12:16pm UTC
documentation Skipped Skipped Sep 12, 2026 12:16pm UTC

@coderabbitai

coderabbitai Bot commented Sep 12, 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: b9ea8fc6-d3c6-445d-b84f-b766438f42ba

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 12, 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 12, 2026 12:15pm

@greptile-apps

greptile-apps Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces fixed-price investigation billing while preserving legacy credit behavior. It adds durable reservation and settlement state, immutable accepted-price handling, typed saved-evidence projections, included clarification and verification paths, purchase validation, and corresponding dashboard, catalog, documentation, schema, and test updates.

  • Charges one investigation_runs unit only after a complete readable result is persisted.
  • Releases reservations for failed, incomplete, or inconclusive work and retains uncertain settlements for reconciliation.
  • Persists explicit-analysis pricing and reuses durable operation identities across retries.
  • Separates fixed-price investigation balances and purchases from legacy agent credits.
  • Restricts clarification evidence to validated, allowlisted measurement fields.
  • Updates customer-facing pricing, billing controls, notifications, and documentation.

Confidence Score: 5/5

The final head appears safe to merge, with no accepted new issue or outstanding previous finding.

All previous root findings are resolved, fixed, or explicitly withdrawn after clarification. The final test-seam adjustment uses the same Autumn singleton as the RPC implementation and restores its spy and environment state; no concrete regression caused by the post-review changes remains.

Important Files Changed

Filename Overview
apps/insights/src/investigation-billing.ts Implements durable fixed-unit reservation, confirmation, release, and reconciliation behavior.
apps/insights/src/generation.ts Integrates investigation billing with candidate execution and completed-result persistence.
apps/insights/src/resume.ts Separates paid fresh analysis from included clarification and verification continuations.
apps/insights/src/evidence-snapshot.ts Projects untrusted tool results into typed, allowlisted evidence suitable for durable clarification.
packages/rpc/src/routers/insights.ts Validates explicit analysis consent and durably records the accepted fixed price.
packages/db/src/drizzle/schema/investigation-billing.ts Adds durable investigation operation, reservation, and settlement records.
apps/api/src/integration/insights-handlers.test.ts Uses the production Autumn singleton seam while preserving test isolation and handler coverage.
apps/dashboard/autumn.config.ts Defines the investigation entitlement and prepaid fixed-price top-up catalog configuration.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Explicit investigation request] --> B[Validate entitlement and accepted price]
  B --> C[Persist operation and reserve one unit]
  C --> D[Run investigation]
  D --> E{Complete readable result?}
  E -->|Yes| F[Persist observation and settlement intent]
  F --> G[Confirm reserved unit]
  E -->|No| H[Release reserved unit]
  F --> I[Included clarification or repair verification]
  I --> J[Reuse saved evidence without another charge]
Loading

Reviews (4): Last reviewed commit: "test(api): use a billing spy compatible ..." | Re-trigger Greptile

Comment thread apps/insights/src/evidence-snapshot.ts Outdated
Comment thread packages/rpc/src/routers/insights.ts
@izadoesdev

Copy link
Copy Markdown
Member Author

The outside-diff retry suggestion is intentionally declined because the product contract distinguishes billable completion from publication and terminal processing. An incomplete necessary question can remain visible while its unit is released. Repeating identical missing evidence immediately does not complete the answer.

84db054f3 adds a regression proving release without charge, no additional work on same-run replay, and successful re-investigation in a later manual run. Existing scheduled eligibility is preserved. The two inline findings are addressed in the linked commits above; final CI and reviewer completion remain required before merge.

@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai Please review the latest head f228f26, including the fixes and documented disposition above.

Comment thread apps/api/src/billing/investigation-purchase.ts
Comment thread apps/api/src/integration/insights-handlers.test.ts
@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai Please review final head 37dde5f. Both typing/import findings are addressed in the linked commits and resolved threads; all local checks and targeted tests passed.

Comment thread apps/insights/src/evidence-snapshot.ts
Comment thread apps/insights/src/resume-clarification.test.ts
@izadoesdev

Copy link
Copy Markdown
Member Author

@greptileai Please review final head 69d5231, including the documented dispositions above. The CI-only test mock incompatibility is fixed; the handler suite passes all 23 tests under both the exact Bun CI command and Vitest.

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