obs(quotas): measure overshoot cancelled by the enforcement sweep - #1136
Open
kyle-compute wants to merge 1 commit into
Open
obs(quotas): measure overshoot cancelled by the enforcement sweep#1136kyle-compute wants to merge 1 commit into
kyle-compute wants to merge 1 commit into
Conversation
Lock-free admission (#1118) deliberately lets two concurrent submissions both observe headroom and both get admitted; the enforcement sweep then cancels the overage. Whether that overshoot happens in practice, and what it costs, has been invisible. Emit one metric=quota.overshoot_cancelled INFO line per enforcement action from the rows the sweep already loaded (no new queries, no behavior change): queued-vs-running split of the cancelled set, min/median/max seconds since each trial's created_at, and the reserved USD basis mirroring _sum_inflight_reserved_usd. A cancelled trial still QUEUED seconds after creation is the overshoot signature; this makes it legible without any further analysis, so the atomic-reservation decision can be data-driven. Claude-Session: https://claude.ai/code/session_01MzJSdrHKEqJrJHU7RRJ758
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Oddish previewCommit:
Vercel deployment URL: https://oddish-auqqagn4j.oddish.app Plan:
This comment is updated by the PR Preview workflow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Why
#1118 removed the blocking advisory lock from trial admission on purpose: the old lock starved workers during over-quota storms. The tradeoff is that admission now checks headroom with no lock, so two concurrent submissions can both observe headroom and both get admitted — briefly overshooting the cap — and the enforcement sweep (
cancel_trials_if_quota_reached) claws the overage back afterward.Whether that overshoot actually happens, how often, and what it costs is currently invisible. Before anyone builds an atomic reservation system (~150-300 LOC), this adds the metric that makes that decision data-driven.
What
One
INFOline per enforcement action, emitted insidecancel_trials_if_quota_reachedjust before the cancellation mutation loop (it reads each trial's pre-cancellation status), computed entirely from the trial rows the sweep already loaded — no new queries, no schema change, no behavior change:trials— size of the cancelled setqueued/running— pre-cancellation status split:queuedcounts PENDING+QUEUED (never started running — the pure overshoot admissions),runningcounts RUNNING+RETRYING (crossed the cap mid-flight)age_min_s/age_median_s/age_max_s— seconds between each cancelled trial'screated_atand now. A cancelled trial that is still QUEUED seconds after creation is the overshoot signature: low ages with a highqueuedcount mean admissions raced past the cap; high ages withrunningmean spend legitimately crossed the limit mid-flight.reserved_usd— per-trialmax(cost_usd or 0, pending_trial_reservation_usd), the exact reservation basis_sum_inflight_reserved_usduses, so the line reads as "how many reserved dollars the sweep released".Format follows the existing
metric=<dotted.name> key=valueconvention (quota.lock_busy,quota.trials_cancelled,quota.would_block) with lazy%slogging. INFO level: this fires rarely and is the whole point of the change (the siblingquota.trials_cancelledWARNING remains the alerting line; this one carries the analysis fields).Tests
test_overshoot_metric_reports_statuses_ages_and_reserved(new, DB-free): three in-memory trials with known statuses/ages/costs; asserts the exact emitted line, including the median and the reserved-USD floor.test_org_quota_cancels_every_users_active_trials(extended, DB-backed): asserts the sweep emits the line withtrials=4 queued=2 running=2for the org-scope cancellation it already exercises.Ran locally against a throwaway Postgres with the oddish alembic schema (plus the backend-owned
quotas/org_quotas/quota_bumpstables):tests/test_quota_enforcement.py,tests/test_quota_admission.py,tests/test_quota_lock_try_acquire.py,tests/test_quota_unattributed_retry.py,tests/test_quotas_usage.py,tests/test_quota_config_defaults.py— all pass.ruff check,ruff format,black, andmypyare clean on the changed files.Note on cost: per-trial reserved cost IS derivable from the loaded rows (
cost_usd+ the settings reservation floor), soreserved_usdis included rather than skipped.https://claude.ai/code/session_01MzJSdrHKEqJrJHU7RRJ758
Note
Low Risk
Observability-only: one INFO log line before existing cancellation logic; no schema, queries, or enforcement behavior changes.
Overview
Adds
metric=quota.overshoot_cancelledINFO logging when the quota enforcement sweep is about to cancel trials, so lock-free admission overshoot can be measured without changing cancellation behavior.Each line is emitted from
cancel_trials_if_quota_reachedimmediately before the mutation loop, using only the trial rows already loaded: cancelled set size, queued vs running (pre-status), age_min/median/max sincecreated_at, andreserved_usdaligned with inflight reservation (max(cost_usd, pending_trial_reservation_usd)).Tests cover the exact log format via a DB-free helper test and assert the metric appears during the existing org-scope cancellation integration test.
Reviewed by Cursor Bugbot for commit 0629076. Bugbot is set up for automated code reviews on this repo. Configure here.