Skip to content

Comments

feat: Add session id in heuristic abuse#398

Open
alex-alecu wants to merge 4 commits intomainfrom
feat/heuristic-abuse-add-session
Open

feat: Add session id in heuristic abuse#398
alex-alecu wants to merge 4 commits intomainfrom
feat/heuristic-abuse-add-session

Conversation

@alex-alecu
Copy link
Contributor

Easily find what session has possibility of abuse /admin/users/..../heuristic-abuse

@alex-alecu alex-alecu requested a review from eshurakov February 20, 2026 10:30
@alex-alecu alex-alecu self-assigned this Feb 20, 2026
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 20, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

This PR adds a session_id field (sourced from the X-KiloCode-TaskId header) to the usage tracking pipeline. The implementation is thorough and consistent:

  • Schema & Migration: session_id column added to microdollar_usage_metadata table and microdollar_usage_view with a proper Drizzle migration.
  • Type safety: session_id added to both MicrodollarUsageContext and UsageMetaData types, flowing correctly through extractUsageContextInfo.
  • Input sanitization: Uses extractHeaderAndLimitLength (truncates to 500 chars) — consistent with how machine_id and editor_name are handled.
  • SQL insert alignment: Column and value positions match correctly in the raw SQL insert.
  • All callsites updated: openrouter route, FIM route, consume-credits dev route, admin insert-usage-record route, and test helpers all include session_id.
  • Tests: New test case verifies session_id storage, existing test updated to assert null default.
Files Reviewed (11 files)
  • src/db/schema.ts
  • src/db/migrations/0021_orange_maggott.sql
  • src/db/migrations/meta/0021_snapshot.json
  • src/db/migrations/meta/_journal.json
  • src/lib/processUsage.ts
  • src/lib/processUsage.test.ts
  • src/app/api/openrouter/[...path]/route.ts
  • src/app/api/fim/completions/route.ts
  • src/app/api/dev/consume-credits/route.ts
  • src/app/admin/api/users/[id]/dev/insert-usage-record/route.ts
  • src/app/admin/components/UserAdmin/UserAdminHeuristicAbuse.tsx
  • src/scripts/usage/benchmark-insert-usage.ts
  • src/tests/helpers/microdollar-usage.helper.ts

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