Skip to content

feat(compression): add /api/compression/replay endpoint (PR-024) - #162

Merged
KooshaPari merged 1 commit into
mainfrom
pr-024-compression-replay-endpoint
Jun 30, 2026
Merged

KooshaPari merged 1 commit into
mainfrom
pr-024-compression-replay-endpoint

Conversation

@KooshaPari

Copy link
Copy Markdown
Owner

Summary

Adds GET /api/compression/replay to surface the recent compression run history alongside the live compression.completed event rendered by open-sse/services/compression/engineBreakdown.ts. Useful for forensic inspection, post-hoc engine comparisons, and tooling that needs a stable snapshot of the last N runs (vs. the ephemeral live stream).

Endpoint

GET /api/compression/replay
  ?provider=<name>      (optional, case-insensitive substring)
  ?model=<name>         (optional, request_id LIKE filter — model is not stored on compression_analytics)
  ?windowMs=<number>    (optional, clamped to [1000, 2592000000] ms, default 86_400_000)
  ?limit=<number>       (optional, clamped to [1, 1000], default 100)

Response shape

{
  "ok": true,
  "filters": { "provider": null, "model": null, "windowMs": 86400000, "limit": 100, "sinceIso": "..." },
  "runs": [
    {
      "requestId": "...", "provider": "openai", "completedAt": "...",
      "originalTokens": 0, "compressedTokens": 0, "compressionRatio": 0,
      "rulesApplied": 0, "engine": "unknown", "engines": [ { "name":"rtk","originalTokens":0,"compressedTokens":0,"compressionRatio":0 } ],
      "raw": { ...compression_analytics row... }
    }
  ]
}

Changes

File Change
src/lib/db/compressionAnalytics.ts +3 helpers: ensureCompressionAnalyticsTables(), getCompressionEngineBreakdownForRequests(), getRecentCompressionAnalyticsRuns()
src/app/api/compression/replay/route.ts New GET handler with parameter validation, clamping, and per-engine breakdown attachment
src/app/api/compression/replay/__tests__/route.test.ts 13 focused tests

Why these helpers

The existing module already exposed getLatestCompressionAnalyticsRun, getCompressionAnalyticsSummary, and getPerEngineAnalytics, but nothing to fetch a window of runs paired with their breakdown rows. The new helpers compose with the existing schema (no new migrations) — compression_analytics (036) + compression_engine_breakdown (037) + indexes (049).

Tests

13/13 passing on the pr-024-compression-replay-endpoint branch (based off v3.8.34):

  • Empty store → 200 + zero runs + default filters
  • Newest-first ordering + full row shape
  • Breakdown row attachment when present
  • Breakdown synthesis when absent (single-run fallback)
  • provider=openai case-insensitive substring filter
  • model=gpt-4o request_id LIKE filter
  • windowMs=60000 → only rows in the last minute
  • windowMs=garbage → falls back to default 24h
  • windowMs=999999999999 → clamps to 30d
  • limit=1 / limit=99999 → clamps to [1,1000]
  • Empty query string treated as unset
  • DB helper honors provider + model + sinceIso together

Run with:

set DISABLE_SQLITE_AUTO_BACKUP=true
node --import tsx --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test src/app/api/compression/replay/__tests__/route.test.ts

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@KooshaPari, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b185c30f-c4fa-41d6-a4f1-7310c7f9ec00

📥 Commits

Reviewing files that changed from the base of the PR and between ffeafdf and 2c8397d.

📒 Files selected for processing (3)
  • src/app/api/compression/replay/__tests__/route.test.ts
  • src/app/api/compression/replay/route.ts
  • src/lib/db/compressionAnalytics.ts

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "review"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr-024-compression-replay-endpoint

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c8397dfdd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if (model) {
if (where) where += " AND request_id LIKE ?";
else where = "WHERE request_id LIKE ?";
params.push(`%${model}%`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use stored model data for model filtering

When model is supplied, this predicate searches request_id, but the production compression writers populate that field with skillRequestId = generateRequestId() rather than a model-prefixed value (see open-sse/handlers/chatCore.ts:917, with writes at :1632 and :1728). As a result, real requests to /api/compression/replay?model=gpt-4o return zero compression runs even when those model runs exist; the endpoint needs a real stored model field or should not apply/advertise this filter.

Useful? React with 👍 / 👎.

@sonarqubecloud

Copy link
Copy Markdown

@KooshaPari
KooshaPari merged commit 48b7be2 into main Jun 30, 2026
70 of 78 checks passed
@KooshaPari
KooshaPari deleted the pr-024-compression-replay-endpoint branch June 30, 2026 09:38
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