Skip to content

fix(gcp): a regional quota refusal rules out only its bucket - #2737

Merged
simple-agent-manager[bot] merged 4 commits into
mainfrom
sam/gcp-quota-bucket-descent
Nov 14, 2026
Merged

simple-agent-manager[bot] merged 4 commits into
mainfrom
sam/gcp-quota-bucket-descent

Conversation

@simple-agent-manager

@simple-agent-manager simple-agent-manager Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A GCP quota refusal now rules out only the quota bucket it names (metric + region), and the TaskRunner keeps trying the rest of Google Cloud — smaller types of that family, other families, other regions — before it falls back to the next provider. Slice 2 of SAM task 01M7D36PKX3YHK4CTW8T1F4YV4 ("make SAM actually use GCP first"); idea 01M77QAMDKN1FSSFKMYJK63X22.

Problem. handleProvisioningAttemptFailure (step 2) treated any quota_exceeded as "this source refused" and jumped to the next provider tier. Production placement explanations (tasks cron-1a732cc1…35bf, 01M758A6F8BHWA5VHBB6N6KDYW, 01M79S0WNAMWY7H5C8MDBNRNWH) show attempt 1 (gcp europe-west1-b t2d-standard-8) refused with Quota 'T2D_CPUS' exceeded. Limit: 24.0 in region europe-west1., attempts 2-8 not attempted, then Hetzner. 14 Hetzner VMs followed such a refusal while europe-west4 T2D (0/24), E2_CPUS (0/72) and smaller T2D types were unused. Separately, the 8-offerings-per-tier cut was filled by t2d alone under pack, so no other family was even in the plan.

Change.

  • classifyGcpQuotaBucket() / gcpQuotaBucketCovers() (packages/providers/src/gcp-quota-buckets.ts): parse metric + region from GCP's message; <SERIES>_CPUS rules out the same family in the region needing ≥ the refused vCPUs; generic CPUS only the refused family; SSD_TOTAL_GB disks ≥ the refused disk; other regional metrics the region. A quota naming no region (CPUS_ALL_REGIONS) returns null → old behaviour (next tier).
  • The Hetzner core-quota descent is generalised, not duplicated: node-provisioning-core-quota.ts → node-provisioning-quota-descent.ts, QuotaRejection = hetzner-cores | gcp-bucket. Step 1 of the failure handler descends whenever an un-ruled-out offering remains in the tier; otherwise step 2 moves tiers as before.
  • selectAcrossQuotaBuckets() (node-provisioning-exhaustion.ts): the per-tier cap is dealt round-robin across region+series buckets, distinct sizes before zone repeats, ranked order kept. A single-bucket source (every non-GCP provider) keeps exactly its best-ranked N as before.
  • Reasons name the bucket (rule 74): refused attempt "GCP quota T2D_CPUS in europe-west1 is used up for this offering; trying smaller types of this family, other families and other regions before another provider. Provider error: …"; skipped "Skipped: needs 8 vCPU, and GCP quota T2D_CPUS in europe-west1 already rejected a 8-vCPU offering"; when nothing is left "…is used up, and no other offering from this source remains".

Consumers of the touched predicates (rule 67): failure-handler steps 1-4, the step loop's skip check, buildProvisioningExhaustionPlan (one caller), classifyVmProviderCapacityError (Hetzner-only, unchanged, comment only), isProviderCreateRejectedBeforeVmIdentity (Hetzner-only, reviewed, intentionally not extended: a GCP quota refusal leaves the node row in error and discardProviderRejectedNode deletes it, the same path main took once per task for the tier fallback).

Latency (rule 81): one refused create per attempt, at most operations.provisioningAttemptsPerProviderTier (8) per tier. GCP reports a quota refusal on the insert operation within seconds; the hard bound is 8 × (insert + poll ≤ operationPollTimeoutMs, 5 min). Typical: tens of seconds, instead of a new VM on another provider.

Cooldown: considered, not built. Each concurrent task may pay up to the per-tier cap of refusals; a region-and-metric TTL cooldown would trim that but needs shared state whose TTL must track how fast quota frees as nodes are deleted. Not worth it at current volume (the 2026-11-12 burst was 7 tasks).

Validation

Staging Verification (REQUIRED for all code changes — merge-blocking)

  • Staging deployment green — run 43620525214 (head c0629d5)
  • Live app verified — authenticated staging API (token login) for pool edit, task submit, workspace/node delete
  • Existing workflows confirmed working — task submit, provisioning, workspace create/delete, node delete, pool edit
  • New feature/fix verified on staging — see evidence
  • Infrastructure verification completed — real GCP VMs provisioned and deleted (no cloud-init/VM-agent change)
  • Mobile and desktop verification notes added for UI changes (N/A: no UI changes)

Staging Verification Evidence (2026-11-14, staging at c0629d5, run 43620525214)

Smoke-user pool temporarily set to fallback-chain with only t2d-standard-16 enabled in europe-west1-b,
europe-west1-c and europe-west4-a (reverted afterwards). Staging T2D_CPUS quota is 24 per region.

  • Node 01M7DHWJCNVTFFTXG2BZZJF2TP (t2d-standard-16, europe-west1-b) took 16 of europe-west1's 24 T2D vCPUs.
  • Task 01M7DJ4D5P4429DX8Q8XZ8TFNC (exclusive, provider gcp, ≥9 vCPU) placement record:
    1. europe-west1-b t2d-standard-16 — capacity-exhausted: "GCP quota T2D_CPUS in europe-west1 is used up for
      this offering; trying smaller types of this family, other families and other regions before another
      provider. Provider error: GCP operation failed: QUOTA_EXCEEDED: Quota 'T2D_CPUS' exceeded. Limit: 24.0 in
      region europe-west1."
    2. europe-west1-c t2d-standard-16 — not-attempted: "Skipped: needs 16 vCPU, and GCP quota T2D_CPUS in
      europe-west1 already rejected a 16-vCPU offering"
    3. europe-west4-a t2d-standard-16 — succeeded (node 01M7DJ5CG7MJSXPTNCPVMNSRGG).
  • Real provisionNode + D1 path: no node row left behind for the refused europe-west1 attempt (only the two
    real nodes existed), which answers the validator's MEDIUM about repeated descents.
  • Side finding (pre-existing, filed as idea 01M7DJ7TJA6CAWHX3VEBTXCZZN): an exclusive task took another task's
    freshly provisioned node, and the provisioner failed after 3 placement refusals instead of re-provisioning.
  • Cleanup: tasks terminal, workspaces deleted, node 01M7DHWJCNVTFFTXG2BZZJF2TP deleted, node 01M7DJ5CG7MJSXPTNCPVMNSRGG
    in destroying with its GCP instance already gone (read-only aggregated/instances check), pool reverted to
    queue (revision 78).

UI Compliance Checklist (Required for UI changes)

N/A: no UI changes.

End-to-End Verification

  • Data flow traced with code path citations
  • Capability test exercises the complete happy path across system boundaries (real handleNodeProvisioning with errors from the real GcpProvider.createVM producer; real GCP + D1 on staging)
  • Assumptions verified against code
  • Gaps documented

Data Flow Trace

GcpProvider.createVM → withGcpErrorCategory (quota_exceeded) → provisionNode → handleNodeProvisioning (node-provisioning-step.ts) → handleProvisioningAttemptFailure → quotaRejectionFor → classifyGcpQuotaBucket → recordQuotaExclusions / nextEligibleAttemptIndex → step loop skip via quotaExclusionReason → next attempt; plan built by buildProvisioningExhaustionPlan → selectAcrossQuotaBuckets.

Untested Gaps

N/A: full flow covered by automated tests and the staging run above.

Post-Mortem (Required for bug fix PRs)

What broke

A GCP regional quota refusal sent work straight to Hetzner while other GCP regions, families and smaller types had quota.

Root cause

handleProvisioningAttemptFailure treated quota_exceeded as "the whole source refused" (step 2), and the per-tier cap kept the 8 best-ranked offerings, all of one family under pack.

Class of bug

An error category scoped wider than the condition it names (rule 72/74): a region-and-metric quota read as a provider-wide refusal.

Why it wasn't caught

The Hetzner core-quota descent existed, but GCP's regional quota was never mapped to a scope; tests asserted the old "skip the rest of GCP" behaviour.

Process fix included in this PR

The quota descent is now one mechanism for both providers (node-provisioning-quota-descent.ts) with per-bucket reasons in the placement record, so a future quota shape is a classifier addition, not a new path. Docs: compute-pools guide.

Post-mortem file

tasks/archive/2026-11-14-gcp-quota-bucket-descent.md

Specialist Review Evidence

  • All local reviewers completed and findings addressed before merge
  • If any reviewer did NOT complete: needs-human-review label added and merge deferred to human (N/A)
Reviewer Status Outcome
cloudflare-specialist ADDRESSED 0 CRITICAL/HIGH. MEDIUM: an exhausted GCP quota was labelled "no available capacity" → names the quota now (1f9c3f5/c0629d5dd). LOW: synchronous-403 producer test added; metric/SSD/zone notes documented
task-completion-validator ADDRESSED WARN, 0 CRITICAL/HIGH. MEDIUM zone duplicates consumed capped slots → distinct sizes first + 3-bucket test; MEDIUM real provisionNode/D1 path → proven on staging (no leaked node rows); LOWs (6th consumer, two-source control, latency bound, cooldown rationale, doc sentence) fixed

CodeRabbit Review Evidence

  • CodeRabbit requested after local review, staging if applicable, and CI gates passed
  • Waited about 15 minutes, or up to about 45 minutes in total while a review CodeRabbit had started was still in progress
  • Either CodeRabbit reviewed and no CodeRabbit feedback is unresolved, or it did not review and the observed outcome is recorded below

CodeRabbit Notes

Requested 18:10:42Z via the coderabbit-review label (workflow run 43625133835, success). CodeRabbit replied "Review limit reached" / "Review rate limited" (free OSS quota). No review arrived, so per rule 25 it is skipped and the PR merges on its remaining gates.

Exceptions (If any)

  • Scope: none
  • Rationale: n/a
  • Expiration: n/a

Agent Preflight (Required)

  • Preflight completed before code changes

Classification

  • external-api-change
  • cross-component-change
  • business-logic-change
  • public-surface-change
  • docs-sync-change
  • security-sensitive-change
  • ui-change
  • infra-change

External References

  • Official documentation: Compute Engine quotas (https://cloud.google.com/compute/resource-usage) for regional metrics such as T2D_CPUS, CPUS and SSD_TOTAL_GB; the exact refusal wording was read from production placement records (Quota 'T2D_CPUS' exceeded. Limit: 24.0 in region europe-west1.) and staging regional quotas via regions.get (read-only).

Codebase Impact Analysis

packages/providers (gcp-quota-buckets, index), apps/api task-runner provisioning (quota-descent, failure, exhaustion, step), apps/api/src/services/vm-admission-provider-capacity.ts (comment), docs apps/www/src/content/docs/docs/guides/compute-pools.md.

Documentation & Specs

apps/www/src/content/docs/docs/guides/compute-pools.md updated; task file tasks/archive/2026-11-14-gcp-quota-bucket-descent.md.

Constitution & Risk Check

Principle XI: the per-tier cap stays the existing admin setting operations.provisioningAttemptsPerProviderTier; no new hardcoded limits. Risks: ambiguous creates (503/timeout) still fail fast (controls unchanged); Hetzner descent unchanged; worst-case latency bounded by the cap.

🤖 Generated with Claude Code

raphaeltm and others added 4 commits November 14, 2026 17:44
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ask file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t in the per-tier cap

Review findings on slice 2: a GCP quota refusal with nothing left to try
was recorded as 'no available capacity', and zone duplicates of one
size could take every capped slot of a bucket so the smaller type that
still fits was dropped. Tests: synchronous 403 producer, two-source
scoping control, zone-duplicate cap, exhausted-bucket reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 84d77aa and a46f684.

Files selected for processing: 12

  • apps/api/src/durable-objects/task-runner/node-provisioning-core-quota.ts
  • apps/api/src/durable-objects/task-runner/node-provisioning-exhaustion.ts
  • apps/api/src/durable-objects/task-runner/node-provisioning-failure.ts
  • apps/api/src/durable-objects/task-runner/node-provisioning-quota-descent.ts
  • apps/api/src/durable-objects/task-runner/node-provisioning-step.ts
  • apps/api/src/services/vm-admission-provider-capacity.ts
  • apps/api/tests/unit/durable-objects/task-runner-provider-tiers.test.ts
  • apps/www/src/content/docs/docs/guides/compute-pools.md
  • packages/providers/src/gcp-quota-buckets.ts
  • packages/providers/src/index.ts
  • packages/providers/tests/unit/gcp-quota-buckets.test.ts
  • tasks/archive/2026-11-14-gcp-quota-bucket-descent.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

Copy link
Copy Markdown

@simple-agent-manager simple-agent-manager Bot added the coderabbit-review Trigger CodeRabbit review for opt-in PRs label Nov 14, 2026
@raphaeltm

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@simple-agent-manager
simple-agent-manager Bot merged commit 7bd2bcb into main Nov 14, 2026
32 checks passed
@simple-agent-manager
simple-agent-manager Bot deleted the sam/gcp-quota-bucket-descent branch November 14, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coderabbit-review Trigger CodeRabbit review for opt-in PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant