Skip to content

Add analytics outlier flag for unusually expensive paid queries#112

Merged
emrekayat merged 1 commit into
emrekayat:mainfrom
Seunfunmi-319509:feat/analytics-price-outlier-flag
Jun 30, 2026
Merged

Add analytics outlier flag for unusually expensive paid queries#112
emrekayat merged 1 commit into
emrekayat:mainfrom
Seunfunmi-319509:feat/analytics-price-outlier-flag

Conversation

@Seunfunmi-319509

@Seunfunmi-319509 Seunfunmi-319509 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a priceOutlier flag to analytics usage rows when a paid query price exceeds the expected configured provider price by more than 10%. This helps investor and SCF demos make budget safety and provider selection quality obvious.

Changes

  • packages/shared/src/types.ts: Added priceOutlier?: boolean and priceOutlierReason?: string fields to UsageEvent
  • apps/api/src/lib/persistence.ts: Implemented computePriceOutlier() that compares priceUsd against the configured provider price (10% threshold) and flags outliers during buildUsageEvent
  • apps/api/src/lib/storage/serialization.ts: Updated usageEventToRow and rowToUsageEvent to serialize/deserialize the new fields
  • apps/api/src/lib/storage/sqlite/migrations.ts: Added migration v4 with price_outlier INTEGER and price_outlier_reason TEXT columns
  • apps/api/src/lib/storage/sqlite/repository.ts: Updated INSERT_USAGE query to include the new columns
  • apps/api/src/lib/persistence.test.ts: Added tests verifying normal prices are NOT flagged and expensive prices ARE flagged
  • apps/web/src/types.ts: Updated AnalyticsResponse recentUsage type to include priceOutlier and priceOutlierReason
  • apps/web/src/pages/ControlDeckPage.tsx: Added compact warning badge (AlertTriangle icon + "Price outlier" text) on outlier rows in the execution feed
  • apps/web/src/styles.css: Added .price-outlier-warning CSS styles

Acceptance Criteria

  • Analytics rows can include priceOutlier: true and a safe reason string
  • Normal configured prices do not show a warning
  • Dashboard shows a compact warning on outlier rows
  • Tests cover normal and outlier records
  • No payment execution behavior changes

Closes #159

…queries

When a paid query price exceeds the configured provider price by more
than 10%, mark it as a priceOutlier in the usage event with a safe
reason string explaining the discrepancy.

Changes:
- Add priceOutlier and priceOutlierReason fields to UsageEvent type
- Implement computePriceOutlier detection in buildUsageEvent
- Add SQLite migration v4 for the new columns
- Update serialization layer (usageEventToRow / rowToUsageEvent)
- Update INSERT_USAGE query in SQLite repository
- Show compact warning icon on outlier rows in the dashboard
- Add tests for normal and outlier price scenarios

Closes emrekayat#78
@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

@Seunfunmi-319509 is attempting to deploy a commit to the emrekayat's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@Seunfunmi-319509 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@emrekayat emrekayat merged commit 5b294d9 into emrekayat:main Jun 30, 2026
1 check failed
Micheal-Blessed pushed a commit to Micheal-Blessed/Query402 that referenced this pull request Jun 30, 2026
…queries (emrekayat#112)

When a paid query price exceeds the configured provider price by more
than 10%, mark it as a priceOutlier in the usage event with a safe
reason string explaining the discrepancy.

Changes:
- Add priceOutlier and priceOutlierReason fields to UsageEvent type
- Implement computePriceOutlier detection in buildUsageEvent
- Add SQLite migration v4 for the new columns
- Update serialization layer (usageEventToRow / rowToUsageEvent)
- Update INSERT_USAGE query in SQLite repository
- Show compact warning icon on outlier rows in the dashboard
- Add tests for normal and outlier price scenarios

Closes emrekayat#78
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.

2 participants