Skip to content

feat(usage): track native compaction requests - #6283

Open
okbexx wants to merge 2 commits into
Wei-Shaw:mainfrom
okbexx:feat/usage-compaction-kind
Open

feat(usage): track native compaction requests#6283
okbexx wants to merge 2 commits into
Wei-Shaw:mainfrom
okbexx:feat/usage-compaction-kind

Conversation

@okbexx

@okbexx okbexx commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Problem

Native Remote Compaction V2 uses the normal POST /v1/responses route, so usage logs currently preserve only the transport shape (stream / WebSocket) and lose the semantic fact that a request was a remote compaction. Operators cannot identify or filter confirmed compaction rows without unsafe inference.

Approach

  • add a dedicated usage_logs.native_compaction_v2 boolean instead of overloading request_type
  • capture the existing protocol-positive marker before asynchronous usage recording
  • preserve the existing transport dimensions (request_type, stream, openai_ws_mode)
  • propagate the flag through single/batch/best-effort inserts, reads, DTOs, filters, query caches, trend/model/group/breakdown queries, and raw-query fallback selection
  • expose a positive-only Compaction filter and an additional badge in both admin and user usage views
  • keep cyber policy precedence: a blocked compaction request remains request_type=cyber while retaining the semantic flag

Safety and compatibility

  • classification remains limited to /v1/responses + stream=true + input[].type=compaction_trigger
  • no request body, compaction content, credentials, or authorization data is persisted
  • historical rows are not backfilled or claimed as protocol-confirmed compactions
  • Channel Monitor V2 continues counting successful compactions because transport request types are unchanged
  • migration defaults the new non-null column to false; running it twice is idempotent

Verification

  • Go 1.27 targeted packages:
    • ./internal/repository
    • ./internal/handler
    • ./internal/handler/admin
    • ./internal/handler/dto
  • Go 1.27 focused service regressions:
    • marker persistence
    • stream/compaction orthogonality
    • cyber request-type precedence
  • PostgreSQL 17 disposable migration validation:
    • default false
    • explicit true
    • NOT NULL
    • idempotent re-run
  • frontend:
    • npm run typecheck
    • 4 focused Vitest specs for filters, table badges, and admin/user query propagation
    • ESLint on all 14 changed frontend source/test files
  • git diff --check

All Docker-based validation used --rm containers with bounded temporary caches; no persistent Go cache volume was created.

@okbexx
okbexx force-pushed the feat/usage-compaction-kind branch from 60194c9 to 3481357 Compare August 28, 2026 15:09
@okbexx
okbexx force-pushed the feat/usage-compaction-kind branch from 3481357 to 1a61eb7 Compare August 28, 2026 15:32
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