Skip to content

usage: carry the claim's template and size on claim events - #409

Merged
CMGS merged 2 commits into
mainfrom
usage-claim-template-size
Nov 2, 2026
Merged

CMGS merged 2 commits into
mainfrom
usage-claim-template-size

Conversation

@tonicmuroq

@tonicmuroq tonicmuroq commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Claim events now carry template and size from the claim's pool key, in the journal line and as two new columns of sandboxd_usage.

A consumer that prices compute by sandbox shape (e.g. 4c8g vs 8c16g, or by the platform the template implies) can only get the shape from the claim record today, and that record is gone after release. key is a hash, so it can't be mapped back. With the shape on the claim event, the usage stream alone is enough to price a sandbox.

  • usage.Event: template, size (omitted when empty; only claim events set them)
  • sandboxd_usage: template, size text columns, NOT NULL DEFAULT ''
  • docs: journal fields in sandboxd-api.md, DDL in deploy.md

Upgrade note: sandboxd_usage is only created when missing, so a table made by a pre-release build of #407 needs the columns added by hand before this runs. Until then landing fails and GET /v1/usage answers 503. The journal itself is unaffected and catches up after the ALTER, for lines still in usage.jsonl and its .1 backup:

ALTER TABLE sandboxd_usage
    ADD COLUMN IF NOT EXISTS template text NOT NULL DEFAULT '',
    ADD COLUMN IF NOT EXISTS size     text NOT NULL DEFAULT '';

A consumer pricing compute by sandbox shape could only read the shape from
the claim record, which is gone after release, and `key` is a one-way hash.
Claim events now carry `template` and `size` from the claim's pool key, in
the journal line and as two new `sandboxd_usage` columns.

Tested: the tenant claim test and the PG round-trip test fail with the
implementation reverted (empty template/size) and pass with it; sandboxd
go test ./... and go-lint pass; PG tests run against postgres:16.
@tonicmuroq
tonicmuroq force-pushed the usage-claim-template-size branch from 8b63ad3 to 496ee4b Compare November 2, 2026 02:52
…lines

Renaming either JSON tag passed every test, so the documented journal and API keys could break silently. The /v1/usage example now shows both fields, and the docs state that claim lines from v0.1.20 or earlier lack them.
@CMGS
CMGS merged commit 493552b into main Nov 2, 2026
1 check passed
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