Skip to content

fix(agent-core-v2): align rate-limit retries with v1#1598

Merged
kermanx merged 2 commits into
mainfrom
xtr/align-v2-rate-limit-retries
Jul 13, 2026
Merged

fix(agent-core-v2): align rate-limit retries with v1#1598
kermanx merged 2 commits into
mainfrom
xtr/align-v2-rate-limit-retries

Conversation

@kermanx

@kermanx kermanx commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This is a focused fix for reproducible rate-limit handling drift between agent-core-v2 and the legacy engine.

Problem

agent-core-v2 retained the retry policy that predated the v1 fault-tolerance hardening: it used a shorter backoff, discarded provider Retry-After metadata, and classified fewer transient provider failures as retryable. A rate-limited child retry also emitted subagent.spawned again, while the web projector allowed the child error frame to reach the main session. Together, a recoverable child-agent 429 could appear in the UI as a session error and produce duplicate lifecycle events.

What changed

  • Align the v2 exponential backoff, transient-error classification, and server-directed retry delay handling with v1.
  • Preserve Retry-After through the OpenAI and Anthropic provider boundaries and classify embedded OpenAI Responses status_code=429 failures.
  • Avoid re-emitting subagent.spawned when a child turn is retried.
  • Keep subagent error frames out of the main web transcript while preserving main-agent errors.
  • Add contract tests for provider conversion, retry timing, swarm lifecycle events, and web projection.

Validation

  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/stepRetry/stepRetry.test.ts test/app/llmProtocol/errors.test.ts test/app/llmProtocol/providers/provider-errors.test.ts test/session/swarm/sessionSwarm.test.ts --maxWorkers=4 — 135 tests passed.
  • pnpm --filter @moonshot-ai/kimi-web exec vitest run test/agent-event-projector.test.ts — 18 tests passed.
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck
  • pnpm --filter @moonshot-ai/kimi-web typecheck
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain
  • git diff --check
  • Read-only internal-identifier audit of the complete diff.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. No user documentation update is needed for this recovery-path bug fix.

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 122e923

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kermanx kermanx marked this pull request as ready for review July 13, 2026 09:46
@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@122e923
npx https://pkg.pr.new/@moonshot-ai/kimi-code@122e923

commit: 122e923

@kermanx kermanx merged commit 4feca6b into main Jul 13, 2026
12 checks passed
@kermanx kermanx deleted the xtr/align-v2-rate-limit-retries branch July 13, 2026 09:50

@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: 122e923adb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if (error instanceof APIStatusError) {
return [408, 409, 429, 500, 502, 503, 504, 529].includes(error.statusCode);
}
return error instanceof ChatProviderError;

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 Exclude deterministic provider validation errors from retry

When the Anthropic adapter rejects a malformed/unsupported data-URL image before sending any request, it throws a base ChatProviderError from imageUrlPartToAnthropic; this new catch-all now marks that deterministic validation failure as retryable, so stepRetry sleeps and re-enqueues the same step until maxRetriesPerStep instead of surfacing the bad input immediately. This is especially noticeable with higher retry configs and also emits misleading retry events; add the same kind of narrow exclusion for known deterministic ChatProviderErrors rather than retrying every base provider error.

Useful? React with 👍 / 👎.

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