Skip to content

fix(container-usage): recover missing meter intervals - #4840

Merged
pandemicsyn merged 3 commits into
mainfrom
fix-meter-correctness-drifts
Jul 28, 2026
Merged

fix(container-usage): recover missing meter intervals#4840
pandemicsyn merged 3 commits into
mainfrom
fix-meter-correctness-drifts

Conversation

@pandemicsyn

Copy link
Copy Markdown
Contributor

Summary

  • Recover missing container usage intervals from heartbeat and stop mutations using the repeated immutable billing context and the meter receive time as a conservative boundary.
  • Preserve reconciled stopped_at, last_seen_at, and confirmed usage when a stop arrives late, while retaining the stop metadata and recording zero newly accepted seconds.
  • Keep recovery idempotent and concurrency-safe through PostgreSQL constraints, context fingerprints, and consistent single-open conflict handling. Recovery deliberately bypasses the new-start SKU acceptance gate so existing usage can finish after an SKU is disabled.

Verification

  • No manual runtime verification was performed because this change is confined to transactional PostgreSQL metering behavior and has no interactive path.
  • Additional manual verification details from the author/reviewer.

Visual Changes

N/A

Reviewer Notes

Focus on transaction races around missing-interval insertion, single-open generation conflicts, and the no-over-bill boundary for stops arriving after unconfirmed reconciliation.

Comment thread services/container-usage-meter/src/postgres.ts
@kilo-code-bot

kilo-code-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The previously flagged missing-SKU-validation warning in recoverMissingInterval has been fixed by adding an existence and unit-type check; no new issues were found in the incremental changes.

Files Reviewed (2 files)
  • services/container-usage-meter/src/postgres.ts
  • services/container-usage-meter/test/postgres.test.ts
Previous Review Summary (commit 58df574)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 58df574)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

Missing-interval recovery in postgres.ts creates new billing intervals from a heartbeat/stop without validating the SKU exists or is billable, bypassing the same admission checks applyStartWithDb enforces.

Overview

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

WARNING

File Line Issue
services/container-usage-meter/src/postgres.ts 129 recoverMissingInterval skips SKU existence/acceptance validation, allowing a heartbeat/stop to create a billable interval for a disabled or unknown SKU
Files Reviewed (2 files)
  • services/container-usage-meter/src/postgres.ts - 1 issue
  • services/container-usage-meter/test/postgres.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 26 · Output: 4K · Cached: 476.4K

Review guidance: REVIEW.md from base branch main

@pandemicsyn
pandemicsyn merged commit 590f9b8 into main Jul 28, 2026
15 checks passed
@pandemicsyn
pandemicsyn deleted the fix-meter-correctness-drifts branch July 28, 2026 19:01
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