usage: GET /api/v1/usage/wall returns latest near-wall audit row (U1)#43
Merged
Merged
Conversation
New endpoint reads the most recent near_quota_wall row written by the
worker's QuotaWallNudgeWorker, scoped to the caller's team and bounded
to the last 24h. Returns the metadata fields (tier/axis/service/current/
limit/percent_used/at) flattened into the response when a row exists,
or {ok:true, near_wall:false} when absent or stale.
Tier gate: team-tier callers always get near_wall=false without an
audit query — team tier has no walls so the scan is meaningless.
Query uses the existing idx_audit_team_at index (team_id + created_at
DESC from migration 012), which is the exact access pattern. No new
index needed.
Routed under the /api/v1 auth group so a valid session JWT is required
and team scope comes from the JWT claims.
…dge-api-fresh # Conflicts: # internal/router/router.go
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.
Summary
Track U1 — API surface for the dashboard's upgrade banner.
GET /api/v1/usage/wall(api/internal/handlers/usage_wall.go). Returns the most recentnear_quota_wallaudit row written by the worker's QuotaWallNudgeWorker, scoped to the caller's team and bounded to the last 24h.{ok:true, near_wall:false}when no row is present (or the row is stale){ok:true, near_wall:true, tier, axis, service, current, limit, percent_used, at}when a row existsIndex reuse
Query reads
audit_logfiltered by(team_id, kind, created_at >= cutoff)and is covered byidx_audit_team_at (team_id, created_at DESC)from migration 012. No new index needed.Tier gate
team-tier callers always getnear_wall:falsewithout an audit query — team tier has no walls so the scan is meaningless. Saves a DB hit for the most-active paid tier.Auth
Routed under the
/api/v1group, soRequireAuthis enforced and team scope comes from the JWT claims (noteam_idin the path).Test plan
usage_wall_test.gocover the latest-row, no-row, and team-tier short-circuit pathsinternal/handlerssuite green (ok instant.dev/internal/handlers 21.7s)internal/plansand one transient failure ininternal/middlewareare unrelated to U1 (verified withgit stash)🤖 Generated with Claude Code