Skip to content

feat(submit): remove all per-day token/cost size caps - #691

Merged
junhoyeo merged 1 commit into
mainfrom
feat/remove-submission-size-caps
Jun 8, 2026
Merged

feat(submit): remove all per-day token/cost size caps#691
junhoyeo merged 1 commit into
mainfrom
feat/remove-submission-size-caps

Conversation

@junhoyeo

@junhoyeo junhoyeo commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Closes #684

@xsyetopz, @ramarivera, and @handsupmin all hit the daily-token / daily-cost / cost-per-million sanity caps with legitimate Codex usage (the kind of cache-heavy submission patterns that trip 10B tokens or $10k/day without anything being wrong). The fix per @junhoyeo's reply on the issue is to remove the restrictions.

What this drops

All four size constants and the checks that reference them:

Constant Was Where it fired
MAX_DAILY_TOKENS 10B / day summary, day-level, per-client
MAX_DAILY_COST $10k / day summary, day-level, per-client, plus maxCostInSingleDay
MAX_COST_PER_MILLION_TOKENS $10k / M summary, day, per-client (the "implausibly cheap" sanity cap)
WARN_DAILY_TOKENS 5B / day structured console.warn band

What stays

These are arithmetic consistency, not size limits — they catch corrupted/inconsistent submissions, not large ones:

  • Day token breakdown sums to day total (TOKEN_RELATIVE_TOLERANCE)
  • Client tokens/cost sum to day totals (COST_RELATIVE_TOLERANCE, COST_ABSOLUTE_TOLERANCE)
  • Tokenless-cost detection (cost > 0 with tokens === 0) — still rejects the data-corruption case where someone submits a cost figure without any token data
  • Cursor legacy tokenless carve-out

Test diff

  • accepts internally consistent high-volume one-day token totals (kept, cap-boundary comment removed)
  • accepts trillion-token internally consistent payloads (no size cap) (new — confirms a 1T-token submit validates)
  • rejects one-day fabricated token totals above the submission cap (deleted — no cap to enforce)
  • rejects submitted cost that is implausible for the reported tokens (deleted — no cost-per-million sanity cap)
  • rejects submitted cost without corresponding tokens (kept — tokenless-cost branch is still gated)

bunx tsc --noEmit exit 0. Full submit test suite passes locally.

Test plan

  • Frontend Vitest green on CI
  • After merge: ask @xsyetopz, @ramarivera, @handsupmin to retry bunx tokscale submit against the new deploy
  • Monitor /api/submit server logs for unexpected payload shapes now that the upper bound is gone (the arithmetic-consistency checks should still catch anything corrupted)

Summary by cubic

Removes all per-day token and cost caps in submission validation to unblock legitimate high-volume usage (e.g., Codex with deep cache). Addresses #684 while keeping arithmetic consistency and tokenless-cost checks.

  • New Features
    • Dropped MAX_DAILY_TOKENS, MAX_DAILY_COST, MAX_COST_PER_MILLION_TOKENS, and WARN_DAILY_TOKENS with their checks.
    • Kept day/client sum consistency and tokenless-cost detection; preserved Cursor legacy carve-out.
    • Tests updated: added 1T-token acceptance; removed cap-based failures.

Written for commit b687d13. Summary will update on new commits.

Review in cubic

Legitimate power users with deep cache reuse routinely report >10B tokens
or >$10k cost per day from a single client (notably Codex). The size caps
were rejecting these submissions outright, blocking real usage.

Closes #684.

Removed:
- MAX_DAILY_TOKENS (10B per day) — daily, summary, and per-client checks
- MAX_DAILY_COST ($10k per day) — daily, summary, per-client, and
  maxCostInSingleDay checks
- MAX_COST_PER_MILLION_TOKENS ($10k/M) — summary, day, and per-client
  cost-per-million sanity caps
- WARN_DAILY_TOKENS soft-warn band (5B) and its console.warn

Kept (these are arithmetic consistency, not size limits):
- Day token breakdown sums to day total (TOKEN_RELATIVE_TOLERANCE)
- Client tokens/cost sum to day totals
- Tokenless-cost detection (cost > 0 with tokens === 0) — still rejects
  the data-corruption case where someone submits a cost figure without
  any token data
- Cursor legacy carve-out

Tests:
- 'accepts internally consistent high-volume one-day token totals' kept
  (now just a smoke test, the cap-boundary comment removed)
- 'accepts trillion-token internally consistent payloads (no size cap)'
  new — confirms a 1T-token submit now validates
- 'rejects one-day fabricated token totals above the submission cap'
  removed (no cap left to enforce)
- 'rejects submitted cost that is implausible for the reported tokens'
  removed (no cost-per-million sanity cap)
- 'rejects submitted cost without corresponding tokens' kept (tokenless-
  cost remains)

Confidence: high
Scope-risk: moderate
Rejected: keep MAX_DAILY_COST at $10k | the user community explicitly
  hit this wall with legitimate Codex usage (see #684 thread)
Directive: If we re-introduce any size cap in the future, gate it on
  an env var so we can roll it back per-deploy without a code change
Not-tested: real Codex submission >10B tokens in production
@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tokscale Ready Ready Preview, Comment Jun 8, 2026 10:11am

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

if (day.totals.cost > 0 && day.totals.tokens === 0) {

P2 Badge Keep cost validation within persisted decimal range

After this daily cost cap is removed, a day with cost >= 1000000 still passes validation as long as it has tokens, but /api/submit later writes each day as dayTotals.cost.toFixed(4) into daily_breakdown.cost, which is declared as decimal("cost", { precision: 10, scale: 4 }) in packages/frontend/src/lib/db/schema.ts and cannot store seven digits before the decimal. In that high-cost-day scenario, validation returns success and the request fails during insert/update with a database numeric overflow instead of a controlled 400 or a migrated wider column.

ℹ️ 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".

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@junhoyeo
junhoyeo merged commit 59b8043 into main Jun 8, 2026
7 checks passed
@junhoyeo
junhoyeo deleted the feat/remove-submission-size-caps branch June 8, 2026 10:44
junhoyeo added a commit that referenced this pull request Jun 8, 2026
…rflow (#692)

fix(db): widen total_cost and daily cost columns

submissions.total_cost was decimal(12, 4) — max ~$100M lifetime.
daily_breakdown.cost was decimal(10, 4) — max ~$1M per day.

#691 removed the application-layer cost cap ($10k/day), so a single
day above ~$1M now overflows the column and Postgres raises
numeric_value_out_of_range, rolling back the entire submit
transaction with no user-friendly error.

Widened:
- submissions.total_cost   decimal(12, 4) -> decimal(18, 4) (~$100T)
- daily_breakdown.cost     decimal(10, 4) -> decimal(14, 4) (~$10M / day)

These ceilings are far above any plausible single-user usage for the
lifetime of this product. ALTER COLUMN TYPE rewrites the table; at
this dataset size (~1k submissions, ~100k daily_breakdown rows) the
rewrite is sub-second.

Migration 0014_widen_cost_columns.sql was hand-written because
drizzle-kit generate runs interactively against the existing diff
and cannot complete in CI/non-TTY contexts. The corresponding
_journal.json entry uses Date.now() = 1780915651573 (UTC 2026-06-08)
so the monotonic ordering invariant holds (later than 0013's
1780172800000). This is the second hand-rolled timestamp; the prior
one (0010/0011) was the one that caused the 2026-06-08 incident, so
flagging the precedent explicitly.

Confidence: high
Scope-risk: moderate
Constraint: Migration must be applied with manual db:migrate against
  prod after merge (Vercel does not auto-migrate)
Rejected: Add app-level overflow validation matching the column
  ceilings | re-introduces the 'reject legitimate submissions'
  problem #691 was specifically meant to remove
Rejected: drizzle-kit generate to avoid the hand-roll | interactive
  prompt about provider_breakdown/model_breakdown column renames
  blocks non-TTY generation
Directive: Next time a migration is needed, prefer drizzle-kit
  generate over hand-rolled SQL; only fall back to hand-rolled if
  the generator gets confused by historic renames as it did here
Not-tested: Postgres-side numeric_value_out_of_range under real
  submit traffic above the old ceilings
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.

Could not submit via Codex CLI (says too many at once)

1 participant