Skip to content

feat(codemode): add durable execution retries#1769

Draft
mattzcarey wants to merge 1 commit into
cloudflare:mainfrom
mattzcarey:feat/codemode-runtime-transient-retries
Draft

feat(codemode): add durable execution retries#1769
mattzcarey wants to merge 1 commit into
cloudflare:mainfrom
mattzcarey:feat/codemode-runtime-transient-retries

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Add durable retries with safe defaults to the Code Mode runtime and expose framework-neutral execution through runtime.execute({ code }).

This is intended for consumers such as cloudflare-mcp, where a dynamic-worker pass may hit an explicit transient response (for example a 429) or time out after earlier connector calls have already succeeded. Retrying under the same execution ID allows those applied calls to replay from the durable log while only the failure boundary executes again.

What changed

  • Add runtime.execute({ code }), sharing the same durable path as the AI SDK tool adapter.
  • Add a smart default retry policy for RetryableError: three total attempts, honoring retryAfterMs or using bounded exponential backoff (500ms, 1s, up to 10s).
  • Add CodemodeRetryOptions for customizing attempts, retry classification, and delay, plus retry: false to opt out.
  • Add RetryableError, including optional retryAfterMs, as a structured connector retry signal.
  • Preserve structured retry and timeout metadata across connector RPC, the dynamic-worker sandbox, and executor results.
  • Add a durable per-execution attempt fence:
    • late calls from a superseded timed-out pass are inert;
    • late results cannot overwrite the retry's log entry;
    • executions created before this change lazily backfill their attempt row.
  • Keep retry intent host-authoritative when generated code catches the local error marker, and block later effects in that failed pass.
  • Add a retrying pass-end lifecycle status for per-pass cleanup.
  • Document direct execution and retry safety.

Explicit RetryableErrors retry without configuration. Executor timeouts remain non-retryable by default and require application policy because a timed-out write can have an ambiguous remote outcome.

Verification

  • pnpm --filter @cloudflare/codemode test
    • 296 unit tests
    • 43 real durable-runtime tests
    • 33 browser tests
  • pnpm run build
    • 22 projects built successfully
  • pnpm run check
    • package exports valid
    • formatting and lint clean
    • all 108 projects typecheck

The changeset is intentionally patch.

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6bb77f6

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/codemode 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

@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1769

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1769

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1769

create-think

npm i https://pkg.pr.new/create-think@1769

hono-agents

npm i https://pkg.pr.new/hono-agents@1769

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1769

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1769

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1769

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1769

commit: 6bb77f6

@mattzcarey mattzcarey force-pushed the feat/codemode-runtime-transient-retries branch from 7fd3d38 to 6bb77f6 Compare June 16, 2026 21:27
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