Skip to content

Comments

feat: Display model + tokens in PR code reviews summary#407

Open
alex-alecu wants to merge 6 commits intomainfrom
feat/add-model-tokens-to-pr-review-summary
Open

feat: Display model + tokens in PR code reviews summary#407
alex-alecu wants to merge 6 commits intomainfrom
feat/add-model-tokens-to-pr-review-summary

Conversation

@alex-alecu
Copy link
Contributor

We cannot include the total tokens in the first summary because we would exclude the tokens used to generate the token itself. Instead we manually add the footer after the summary is posted.

@alex-alecu alex-alecu requested a review from RSO February 20, 2026 15:24
@alex-alecu alex-alecu self-assigned this Feb 20, 2026
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 20, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/app/api/internal/code-review-usage/[reviewId]/route.ts 69 updateCodeReviewStatus overwrites started_at timestamp when called with current status 'running' — the auto-set logic re-stamps started_at because updates.startedAt is undefined
cloudflare-code-review-infra/src/code-review-orchestrator.ts 103 Truthiness checks if (storedState.totalTokensIn) fail for value 0 — currently benign since defaults are 0, but fragile; prefer != null checks
Files Reviewed (13 files)
  • cloudflare-code-review-infra/src/code-review-orchestrator.ts - 1 issue
  • cloudflare-code-review-infra/src/types.ts - 0 issues
  • src/app/api/internal/code-review-status/[reviewId]/route.ts - 0 issues
  • src/app/api/internal/code-review-usage/[reviewId]/route.ts - 1 issue
  • src/db/migrations/0021_add_usage_tracking_to_code_reviews.sql - 0 issues
  • src/db/migrations/meta/0021_snapshot.json - 0 issues (generated)
  • src/db/migrations/meta/_journal.json - 0 issues (generated)
  • src/db/schema.ts - 0 issues
  • src/lib/code-reviews/db/code-reviews.ts - 0 issues
  • src/lib/code-reviews/summary/usage-footer.test.ts - 0 issues
  • src/lib/code-reviews/summary/usage-footer.ts - 0 issues
  • src/lib/integrations/platforms/github/adapter.ts - 0 issues
  • src/lib/integrations/platforms/gitlab/adapter.ts - 0 issues

Fix these issues in Kilo Cloud

…usage data

Use 3 retries with 200/400/800ms delays instead of a single 2-second
sleep. Reduces average latency when data is already present and provides
more attempts when it isn't.
Cover buildUsageFooter and appendUsageFooter including first-time
append, footer replacement with exact and variant whitespace, empty
body, unrelated horizontal rules, and multi-slash model slugs.
Sync model/token/cost accumulators to this.state on every LLM API
event so they are written to durable storage by the existing event
batch save. Restore them in loadState() so accumulation resumes
correctly after a DO restart.
// We pass the current status (no status change) to just update the usage fields.
const status = CodeReviewStatusSchema.parse(review.status);

await updateCodeReviewStatus(reviewId, status, {
Copy link
Contributor

Choose a reason for hiding this comment

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

[WARNING]: updateCodeReviewStatus will overwrite started_at timestamp

When this endpoint is called while the review is in 'running' status, updateCodeReviewStatus auto-sets started_at = new Date() (in code-reviews.ts line 129) because updates.startedAt is undefined. This silently overwrites the original started_at with the current time, making the review appear to have started much later than it actually did.

Consider either:

  • Passing startedAt: review.started_at ? new Date(review.started_at) : undefined to preserve the existing value, or
  • Adding a dedicated updateCodeReviewUsage() function that only updates usage fields without touching status/timestamps.


// Restore usage accumulators from persisted state so they survive DO eviction
if (storedState.model) this.model = storedState.model;
if (storedState.totalTokensIn) this.totalTokensIn = storedState.totalTokensIn;
Copy link
Contributor

Choose a reason for hiding this comment

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

[WARNING]: Truthiness check fails for 0 — fragile restore logic

if (storedState.totalTokensIn) evaluates to false when the value is 0. Currently benign because the class fields default to 0, but this is fragile: if defaults change or if the intent is to explicitly restore a persisted 0, this silently skips the assignment.

Prefer explicit nullish checks:

Suggested change
if (storedState.totalTokensIn) this.totalTokensIn = storedState.totalTokensIn;
if (storedState.totalTokensIn != null) this.totalTokensIn = storedState.totalTokensIn;

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