Skip to content

fix(core): take a session's burn rate from the account once it runs alone, not its even share - #82

Open
scarletkc wants to merge 1 commit into
mainfrom
fix/use-alone-measured-rate
Open

scarletkc wants to merge 1 commit into
mainfrom
fix/use-alone-measured-rate

Conversation

@scarletkc

Copy link
Copy Markdown
Owner

Summary

Sessions that start between the same two usage readings share the rise of the account rate evenly, and that estimate never changes again. An A100 (11.77 CU/h) and a T4 (1.76 CU/h) that start together are 6.765 each. After the A100 stops, the account rate is the T4's own, and the app already records it every reading as the T4's measured rate for the new-session form. The card and the spend limit still used 6.765.

A session that is the account's only runtime now takes the account rate as its estimate. The reading must meet three conditions:

  • The account rate has moved since a runtime last came or went. Until then it can still hold what a runtime that went burned.
  • The rate has held for two minutes since it last moved. Runtimes that go together can each leave the rate at a time of their own.
  • The listing taken with the reading matched the session to the account's runtime.

If the rate moves again while nothing comes or goes, the measurement is taken back and the value before it is restored. Every other estimate is worked out as before: the measurement sits beside the estimate in RateAttribution and never feeds into it. The other session in the example keeps its even share for as long as both run. A session that never runs alone is not changed.

This is a much smaller alternative to #75 for its first case. #81 split a joint rise by hardware rates and was closed because it could be further from the real rate than main. This change only adds a measurement, so it can be further from the real rate only if the measurement is wrong.

When it can be wrong

The measurement is exact as long as the account rate follows each runtime's start and stop within two minutes. In that case every fall still to come is visible by the time the hold ends. When a runtime's rate takes longer than two minutes to leave the account, the survivor can take the rate of a runtime that is already gone. The estimate is then further from the real rate than main, until the late fall arrives and takes the measurement back. If another runtime joins before that, the wrong value stays.

Nothing in the repository says how long Colab's rate takes. #43 reports that ccu-info keeps the old rate for one or more polls after colab new.

Equal to main: if Colab's runtime count drops a reading after the account rate already fell, the rate never moves within the spell, so nothing is measured.

Checks

  • 9 new tests in usage.rs and 1 in mock.rs. Removing each condition (the rate having moved, the hold, the take-back, the system-time reset, the listing check) fails at least one of them.
  • cargo test -p colab-playground-core --lib (214 tests), cargo clippy -p colab-playground-core --all-targets -- -D warnings and cargo fmt --all -- --check pass locally on Windows. real_backend.rs and the app suite are left to CI. Nothing ran against real Colab.
  • A scratch simulation, not part of the repository, replayed random one-hour traces through observe_at and through main's observe. Each trace had a start or stop about every 5 minutes, readings every 30 s or 5 s, and a reading right after each start and stop the app makes. Rows varied empty accounts against app starts with running sessions, runtimes outside the app or none, and rates that follow late on starts only or on stops too. Every session was compared at every reading:
Delay of the account rate Rows Session-readings further from the real rate than main Without an estimate where main has one
0, 20, 59, 100, 120 s, and random up to 120 s per runtime 96 0 0
150 s, random up to 200 s, 300 s, only on starts 24 0 0
150 s, random up to 200 s, 300 s, on stops too 24 0 to 2,230 per row (of 270,000 to 720,000) 0

No screenshots: the interface does not change.

Decisions

  • The hold is timed with the reading's system time, as spend is. A step back of the system time starts the hold again; a step forward can shorten it.
  • The measurement for the new-session form stays as it was, the latest reading of a session alone, without the hold. It only sets where the form's figure starts, and the next reading corrects it.
  • Measurements are kept in memory, not in the ledger, so after a restart a session is measured again once it runs alone. Old ledger readings were taken without these conditions.
  • AccountUsage::record_success takes verified and sets ownership_verified itself, instead of each backend overwriting it after the call.

…lone, not its even share

Sessions that start between the same two usage readings share the rise of the
account rate evenly, and the estimate never changed again. When all but one of
them stopped, the one left was still shown and charged its share, although the
account rate was then its own and the app already recorded it for the
new-session form.

A session that is the account's only runtime now takes the account rate for its
estimate, once that rate has moved after the last runtime came or went and then
held for two minutes. A rate that moves again with nothing coming or going takes
the measurement back. Every other estimate is worked out as before.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved runtime rate estimates when multiple runtimes overlap, helping preserve stable estimates when one runtime stops.
    • Rate measurements now rely on verified observations where an account is assigned to a single live runtime.

The change adds verified sole-runtime rate measurements after a 120-second stable hold. It updates mock and real usage recording to pass listing verification into rate attribution, and adds tests for measurement behavior and rate estimates.

Changes: Rate attribution

Layer / File(s) Summary
Sole-runtime measurement and attribution
crates/core/src/usage.rs
RateAttribution tracks verified sole-runtime readings and prefers stored measurements over rate-delta estimates. Tests cover hold timing, verification, rate movement, and clock rollback.
Usage recording callers
crates/core/src/mock.rs, crates/core/src/real.rs
Mock and real usage recording pass listing verification to AccountUsage::record_success. A mock test checks estimated rates after runtime start and stop events.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant UsageCaller
  participant AccountUsage
  participant RateAttribution
  UsageCaller->>AccountUsage: record_success with listing verification
  AccountUsage->>RateAttribution: observe_at with timestamp and verification
  RateAttribution-->>AccountUsage: measured or estimated session rates
Loading

Possibly related PRs

  • scarletkc/colab-playground#73: Both changes use the sole-session measurement path; this PR adds a hold for account-rate attribution, while PR #73 covers stored readings shown in the New session form.
Merge Risk: Minimal · up to bb3f6

The change lets a session that is the account's only runtime use the measured account rate once it has held for two minutes. It leaves other estimates unchanged and keeps measurements in memory only. No concrete merge-blocking issue was found, and the delayed-drop inaccuracy the author notes is a disclosed limitation.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a session that runs alone takes the account's burn rate instead of its even share. The changeset adds RateAttribution.observe_at, a measured per-session rate, and the …
Description check Passed The description covers the change in detail. It explains the problem with even-share estimates, the three conditions for a measurement, the take-back rule, the known failure cases, the test and simula…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a session that runs alone takes the account's burn rate instead of its even share. The changeset adds RateAttribution.observe_at, a measured per-session rate, and the record_success verified argument, all matching the title. The title is specific and concise, and it uses the conventional fix(core) prefix.

Full details: Description check

Explanation

The description covers the change in detail. It explains the problem with even-share estimates, the three conditions for a measurement, the take-back rule, the known failure cases, the test and simulation results, and the design decisions. It matches the raw summary and objectives.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: acd2d9e8-2bb2-4a2d-8e58-20ac9df95a35
Commits

Reviewing files that changed from the base of the PR and between 7f2ac42 and bb3f618.

Files selected for processing: 3

  • crates/core/src/mock.rs
  • crates/core/src/real.rs
  • crates/core/src/usage.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Recent review details

Context from checks skipped due to timeout: 3

  • GitHub Check: Linux (fmt, clippy, test)
  • GitHub Check: windows-latest (check, tests)
  • GitHub Check: macos-latest (check, tests)
Additional context used

Learnings: 2

Learning: 2026-11-23T12:15:49.651Z

Learnt from: CR
Repo: scarletkc/colab-playground PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-11-23T12:15:49.651Z
Learning: Source excerpt:
# Agent notes for Colab Playground

## Rules every change follows

- [Docs and comments](docs/DEVELOPMENT.md#docs-and-comments): the code wins over a description, no
  doc describes how the code works, comments say why.

Applied to files:

  • crates/core/src/usage.rs
Learning: 2026-11-23T12:15:52.235Z

Learnt from: CR
Repo: scarletkc/colab-playground PR: 0
File: docs/DEVELOPMENT.md:0-0
Timestamp: 2026-11-23T12:15:52.235Z
Learning: Applicability reference:
AGENTS.md: # Agent notes for Colab Playground
## Rules every change follows
- [Docs and comments](docs/DEVELOPMENT.md#docs-and-comments): the code wins over a description, no

AGENTS.md: # Agent notes for Colab Playground
## Landing a change
- Pull request against `main`, squash-merged; its title is a conventional commit and becomes the
  changelog line: [Landing a change](docs/DEVELOPMENT.md#landing-a-change). The types are the

AGENTS.md: # Agent notes for Colab Playground
## Landing a change
- Review bot comments are leads, not verdicts, and only a problem that can really happen gets
  fixed: [Automated review comments](docs/DEVELOPMENT.md#automated-review-comments).

Source excerpt:
# Developing Colab Playground

## Docs and comments

- **No doc describes how the code works.** A walk through modules, types, argv or screens is out
  of date as soon as the code changes. Docs hold only what cannot be read from the code: how to
  use and build the app, the cont...

Applied to files:

  • crates/core/src/usage.rs
Additional comments: 1

crates/core/src/usage.rs: 1

344-344: Functional Correctness

The reviewer's claim that a rollback causes early acceptance is not supported by the stated contract. The hold is timed with system time, and the rate held for 120 system-time seconds from t600 to t720. A backward step cannot shorten the real hold. The proposed restart rule would be a separate, stricter design choice. It does not follow from the PR's required behavior, and it does not address forward clock steps.

@scarletkc

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T21:14:01.405204Z bb3f618 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: bb3f618442

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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