Skip to content

Comments

feat: Add session id in heuristic abuse#398

Merged
alex-alecu merged 7 commits intomainfrom
feat/heuristic-abuse-add-session
Feb 24, 2026
Merged

feat: Add session id in heuristic abuse#398
alex-alecu merged 7 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 cleanly adds session_id (sourced from the X-KiloCode-TaskId header) to the microdollar usage tracking pipeline. The implementation is thorough and consistent:

  • Schema & Migration: New session_id text column on microdollar_usage_metadata, view updated to expose it.
  • Header extraction: Both OpenRouter and FIM routes now use extractHeaderAndLimitLength (500-char truncation) — the OpenRouter route previously used raw request.headers.get(), so this is a security improvement.
  • Pipeline plumbing: MicrodollarUsageContextextractUsageContextInfoUsageMetaData → SQL INSERT all correctly thread session_id through.
  • All creation sites updated: OpenRouter route, FIM route, dev consume-credits, admin insert-usage-record, benchmark script, and all test helpers include session_id.
  • Tests: Good coverage — verifies both null and non-null session_id storage.
  • Admin UI: Column added (hidden by default) for session display.
  • No GDPR concern: session_id is a task identifier, not PII.
Files Reviewed (11 files)
  • src/app/admin/api/users/[id]/dev/insert-usage-record/route.ts
  • src/app/admin/components/UserAdmin/UserAdminHeuristicAbuse.tsx
  • src/app/api/dev/consume-credits/route.ts
  • src/app/api/fim/completions/route.ts
  • src/app/api/openrouter/[...path]/route.ts
  • src/db/migrations/0024_real_ikaris.sql
  • src/db/migrations/meta/0024_snapshot.json
  • src/db/migrations/meta/_journal.json
  • src/db/schema.ts
  • src/lib/processUsage.ts
  • src/lib/processUsage.test.ts
  • src/scripts/usage/benchmark-insert-usage.ts
  • src/tests/helpers/microdollar-usage.helper.ts

meta.has_tools,
meta.machine_id,
feat.feature,
meta.session_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need an index on it do we?

@alex-alecu alex-alecu merged commit b84d41f into main Feb 24, 2026
12 checks passed
@alex-alecu alex-alecu deleted the feat/heuristic-abuse-add-session branch February 24, 2026 08:09
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