Skip to content

feat(corch-14): built-in account quota source - #550

Merged
finedesignz merged 2 commits into
mainfrom
phase-corch-14-builtin-quota
Nov 17, 2026
Merged

finedesignz merged 2 commits into
mainfrom
phase-corch-14-builtin-quota

Conversation

@finedesignz

Copy link
Copy Markdown
Owner

CORCH-14: built-in account quota source

The orchestrator now reads per-account Claude usage itself. No separate usage app, release or quota:publish key is needed for the cutover.

What changed

  • Supervisor (supervisor/src/usage/slot-quota-poll.ts, wired in hub-client.ts): a slot supervisor (REMO_ACCOUNT_SLOT set and holding its account token) polls on auth_ok and every REMO_SLOT_QUOTA_INTERVAL_MS (default 300000, floor 60000). It sends a minimal max_tokens: 1 /v1/messages call and reads anthropic-ratelimit-unified-{5h,7d}-{utilization,reset}. The long-lived slot token gets 403 from /api/oauth/usage (no user:profile scope), so the headers are the only source. The token is only the Authorization header: never logged, returned or framed; the body is never read. Desktop supervisors never run it.
  • Wire: new /ws/agent frame slot_quota_report (percentages 0..100, ISO resets, fetched_at).
  • Hub (hub/src/corch/slot-quota.ts, handler in ws/agent.ts): accepted only when the reporting connection registered that exact account_slot; a reading dated more than 120s ahead is dropped. Upserts corch_quota_accounts (account_id = slot, source = 'live') through the existing quotaStore.upsertSnapshot, then the same queue push and dispatch evaluation as the HTTP ingest. Stored with the CORCH flag OFF too.
  • POST/GET /api/quota/snapshot, scopes and quota-eligibility.ts are unchanged. No schema change.
  • Docs: docs/corch.md (new section), docs/corch-linux-slots.md, docs/corch-enable-runbook.md (item 1 is now OPTIONAL), CLAUDE.md.

Tests (run locally, all pass)

  • supervisor/test/slot-quota-poll.test.ts (header parsing boundaries, gating, token never in results)
  • supervisor/test/corch-slot.test.ts (slot sends one slot_quota_report on connect, non-slot sends none, no frame carries a secret)
  • hub/test/corch-slot-quota.test.ts (schema, own-slot only, future-dated, eligibility with unchanged rules)
  • hub/test/corch-no-token-guard.test.ts, corch-quota-eligibility.test.ts, corch-quota-ingest.test.ts, supervisor/test/corch-slot-image.test.ts still pass
  • tsc --noEmit: no new errors in hub or supervisor versus main

Not proven here

  • The live path (a real slot container reporting to the production hub) is exercised in the cutover, runbook item 8.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T17:48:29.857470Z 943923e PR opened
ℹ️ 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 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

Here are some automated review suggestions for this pull request.

Reviewed commit: 943923ea2a

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

Comment thread supervisor/src/usage/slot-quota-poll.ts Outdated
} catch (err: any) {
return { ok: false, reason: `network_error: ${err?.name ?? 'error'}` }
}
if (!res.ok) return { ok: false, reason: `http_${res.status}` }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve valid quota headers on rate-limited responses

When the probe receives HTTP 429 with valid unified utilization headers, this return discards the reading before parseUnifiedHeaders runs. Rate limiting is precisely when the hub needs the exhausted-account reading: pollAndSendSlotQuota sends no report on failure, so evaluateAccounts can continue treating the previous below-ceiling snapshot as eligible until its 10-minute TTL expires, allowing new work to target an exhausted account. Anthropic documents 429 as a rate-limit response. Accept valid quota headers from 429 responses while continuing to reject responses without usable windows; an injected 429 with 100% utilization currently reproduces the dropped report.

Useful? React with 👍 / 👎.

finedesignz and others added 2 commits November 17, 2026 18:59
…t their own usage)

The orchestrator no longer depends on a separate usage app. A slot supervisor
(REMO_ACCOUNT_SLOT + its account token) polls its own account by reading the
unified rate-limit headers of a minimal /v1/messages call and sends a
slot_quota_report frame. The hub stores it in corch_quota_accounts through the
existing store function, only for the connection's own registered slot.

- supervisor: usage/slot-quota-poll.ts, wired into HubClient on auth_ok
- hub: slot_quota_report schema, corch/slot-quota.ts, supervisor handler
- POST /api/quota/snapshot unchanged and now optional (runbook item 1)
- eligibility rules unchanged

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…terval ceiling; 429 readings

Live probe (2026-11-17) returned 200 with the 7d headers and no 5h headers, so
requiring both would have left such an account with no reading. A null 5h is
sent instead (unknown, never 0; the hub caps it at one run). Also from the
phase verifier: clamp the interval below the hub staleness TTL, accept a 429
that carries the windows, cancel the unread body, fix the CLAUDE.md docs map.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zero-exposure-app
zero-exposure-app Bot force-pushed the phase-corch-14-builtin-quota branch from 8fcd52b to c7d6877 Compare November 17, 2026 18:59
@zero-exposure-app

Copy link
Copy Markdown
Contributor

Zero Exposure did not auto-merge this PR.

Blocking reason: auto-merge blocked: not eligible -- diff classifier: hub/src/corch/slot-quota.ts: potential flag/safety change: identifier-shape heuristic matched "enabled" added with a truthy value and no removed counterpart to pair against; semantic effect unverified; requires review: enabled: true,; diff classifier: hub/test/corch-slot-quota.test.ts: potential flag/safety change: identifier-shape heuristic matched "enabled" added with a truthy value and no removed counterpart to pair against; semantic effect unverified; requires review: source: 'live', enabled: true, blocked: false,; diff classifier: supervisor/src/usage/slot-quota-poll.ts: cron/cadence literal or identifier changed (an outbound-send-rate change): /** The hub treats a reading as stale 10 min after it was received, so the cadence must stay well inside that. */; diff classifier: supervisor/test/slot-quota-poll.test.ts: potential flag/safety change: identifier-shape heuristic matched "ignored" added with a truthy value and no removed counterpart to pair against; semantic effect unverified; requires review: return new Response('{"ignored":true}', { status: 200, headers: FULL })

Reviewed commit: c7d6877. A human needs to resolve this (or merge the PR manually). This comment is updated in place when the reason changes; it is not re-posted per retry.

@finedesignz
finedesignz merged commit b87d3fd into main Nov 17, 2026
6 checks 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.

1 participant