Skip to content

fix(cloud-agent-next): retry git rate-limited workspace setup - #5060

Merged
eshurakov merged 2 commits into
mainfrom
polished-brisket
Aug 6, 2026
Merged

eshurakov merged 2 commits into
mainfrom
polished-brisket

Conversation

@eshurakov

@eshurakov eshurakov commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Why

Cold Cloud Agent workspace bootstrap can fail when GitHub throttles clone/ref discovery with HTTP 429 (or equivalent “too many requests” / rate-limit text). Those failures were previously unclassified (workspace_setup_unknown) and only got a single generic pending-message redelivery, so concurrent or bursty clone traffic could fail sessions that would succeed moments later.

What was done

  • Classify wrapper git clone/checkout stderr matching \b429\b, too many requests, or rate limit(ed) as workspace subtype git_rate_limited (after auth patterns so 401/403 still win).
  • Map the subtype through shared failure classification as platform rate_limited, project the safe user message “Repository request was rate limited”, and map code-review terminal reason to existing repository_clone_failed (no new DB enum).
  • Give pending flush a dedicated short backoff budget (15s, 45s — two retries / three total attempts) for WORKSPACE_SETUP_FAILED + git_rate_limited, reusing the full cold bootstrap path instead of adding an inner clone retry loop.
  • Treat git rate-limit as reset-eligible alongside sandbox storage-full (fresh budget on entry from a non-reset-eligible failure; alternating reset-eligible modes still accumulate and exhaust).

High-level architecture

sequenceDiagram
  participant DO as Session DO
  participant Pending as Pending flush
  participant Wrapper as Sandbox wrapper
  participant GitHub as Git remote

  DO->>Pending: Drain queued cold-start message
  Pending->>Wrapper: Prepare workspace (clone/checkout)
  Wrapper->>GitHub: git clone / fetch
  GitHub-->>Wrapper: 429 / rate limited
  Wrapper-->>Pending: WORKSPACE_SETUP_FAILED git_rate_limited
  Note over Pending: Schedule retry at +15s then +45s<br/>(reset-eligible budget)
  Pending->>Wrapper: Retry full cold bootstrap
  alt Throttle cleared
    Wrapper->>GitHub: clone succeeds
    Wrapper-->>DO: Workspace ready
  else Budget exhausted
    Pending-->>DO: Terminal safe failure projection
  end
Loading

Architecture decision

Decision: Detect git rate limits at wrapper classification and retry via the existing pending-flush mechanism with a dedicated short backoff budget, rather than adding an inner retry loop inside cloneRepository.

Context: Pending flush already owns durable redelivery of cold bootstrap, and other transient workspace conditions (e.g. sandbox storage full) already use subtype-specific reset-eligible budgets. Clone 429s are short-lived platform throttling that clear without a new product path.

Rationale: Reusing pending flush keeps retry durability, attempt accounting, and terminalization in one place, mirrors the storage-full pattern, and avoids duplicating bootstrap side effects inside the wrapper.

Alternatives considered:

  • Inner clone retry in the wrapper. Would hide durability from the DO and risk partial workspace state on repeated in-process attempts; not chosen.
  • Treat as generic warm/cold single redelivery. Too little budget for throttling that often needs tens of seconds to clear; not chosen.

Consequences: Sessions survive brief GitHub clone throttling with clearer diagnostics and platform ownership. Detection remains best-effort regex on sanitized process output (no captured production 429 stderr sample in-repo); permanent or long throttles still exhaust after two backed-off retries.

Classify clone/checkout 429 and rate-limit errors as git_rate_limited,
give them a short backed-off pending-message retry budget, and surface
a clear safe failure message instead of failing after one redelivery.
@kilo-code-bot

kilo-code-bot Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of commit 426f381 confirms the previously reported rate-limit classification false positive is fixed: the 429 pattern is now anchored to an HTTP-error context and a regression test covers git progress object counts, with high confidence in the changed scope.

Files Reviewed (2 files)
  • services/cloud-agent-next/wrapper/src/session-bootstrap.ts
  • services/cloud-agent-next/wrapper/src/session-bootstrap.test.ts
Previous Review Summary (commit 9bd24cf)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 9bd24cf)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
services/cloud-agent-next/wrapper/src/session-bootstrap.ts 182 Bare \b429\b in the new rate-limit pattern can match standalone object counts in git --progress stderr (e.g. remote: Enumerating objects: 429, done.), misclassifying a genuine network failure as git_rate_limited since it is evaluated before git_network_failed
Files Reviewed (7 files)
  • apps/web/src/lib/code-reviews/terminal-reason-from-failure.ts
  • packages/worker-utils/src/cloud-agent-failure.ts
  • services/cloud-agent-next/src/session/pending-messages.test.ts
  • services/cloud-agent-next/src/session/pending-messages.ts
  • services/cloud-agent-next/src/session/safe-failure-projection.ts
  • services/cloud-agent-next/wrapper/src/session-bootstrap.test.ts
  • services/cloud-agent-next/wrapper/src/session-bootstrap.ts - 1 issue

The retry-budget logic (reset-eligibility, alternation accumulation, exhaustion), subtype plumbing (wrapper → session-ready error → WrapperError → ExecutionError → pending flush), telemetry classification, safe-message projection, and code-review terminal-reason mapping were all verified end-to-end and are consistent. No memory-leak vectors introduced (constants and classification only; no new timers/listeners/caches).

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 46.9K · Output: 9.9K · Cached: 361.5K

Review guidance: REVIEW.md from base branch main

@eshurakov

Copy link
Copy Markdown
Contributor Author

@kilocode-bot address PR feedback

@kilo-code-bot

kilo-code-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

One or more Cloud Agent sessions failed:

  • Kilo-Org/cloud (agent_b9a8bdd0-b528-4f19-978a-1236e028e9af): Workspace setup failed: termination nonzero exit, exit code 128

Clone/fetch run with --progress, so stderr of a clone that failed for
other reasons can contain standalone object counts (e.g. "remote: Total
429 (delta 12)"). A bare \b429\b matched those and, being evaluated
before git_network_failed, misclassified network failures as
git_rate_limited with the wrong safe message, telemetry, and retry
budget. Anchor the numeric alternative to error/http/status context and
add a regression case.
@eshurakov
eshurakov merged commit e97175d into main Aug 6, 2026
42 checks passed
@eshurakov
eshurakov deleted the polished-brisket branch August 6, 2026 11:25
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