Skip to content

fix(platform-cloudflare): awaitProgress re-issues after a transient reset - #63

Merged
systemfsoftware-bot merged 3 commits into
mainfrom
fix-progress-wait-eviction-hang
Nov 26, 2026
Merged

systemfsoftware-bot merged 3 commits into
mainfrom
fix-progress-wait-eviction-hang

Conversation

@systemfsoftware-bot

@systemfsoftware-bot systemfsoftware-bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What happened

test/progress-wait.test.ts > #94 Cloudflare durable progress wait > reconnects after eviction, reconstructs the wait, and rechecks durable authority timed out at 20000ms on main at 1ea54e8. The step that never resolved was the test's own subscription latch; the client's wait had already ended.

Cause

  • packages/platform-cloudflare/src/CloudflareThreadClient.ts:888-899 (before this change): the retry re-issued only when the rejection was flagged retryable === true && overloaded !== true, and did not handle an answer that cannot be decoded.
  • packages/platform-cloudflare/test/progress-wait.test.ts:164 (before this change): after the abort the test awaited the reconstructed-waiter latch, which waits for awaitProgressSubscribedAfter on the new incarnation.

state.abort() rejects an in-flight RPC and the platform does not replay it on the fresh incarnation (measured: remote=true and durableObjectReset=true on 200/200 plain RPC probes and 160/160 through the client path). Not every rejection carries those flags: a bare remote rejection, an overload-flagged rejection, and an answer cut off mid-write (undecodable) each arrive at the client in a different shape. The old predicate re-issued only the flagged shape, so in the others the client wait ended at once and no subscription ever reached the new incarnation. With no subscription to bind, the latch never resolved and the test ran to its cap.

Proof

  • A workerd-free probe with a fake namespace and a spy on the RPC: with the old predicate each of the three unflagged shapes called awaitProgress exactly once and failed (no re-issue); only the reset-flagged rejection re-issued and then succeeded.
  • End to end, with one bare post-abort rejection injected by the test object: old code gave a failed client wait and a latch that never bound; fixed code bound the latch on incarnation 2 and the wait completed.
  • In 30 unmodified iterations, 1 showed a client wait failing about 32ms after the abort while the latch timed out at 5s, the same shape as the CI failure. The exact wire error of the CI run is not in its log, so the mechanism was proved by injection rather than captured from CI.

Change

  • Waiting for progress observes durable state, so a transport failure that observed nothing may re-issue within the same attempt budget: a ThreadClientError from a bare remote rejection of a reset, and a HostProtocolError from an answer that cannot be decoded, now re-issue. An overload-flagged rejection stays terminal, because the runtime marks that shape as not worth retrying (a retry adds load to an object that cannot keep up), and typed host failures (ThreadStoreError, ThreadNotMaterialized, OperationDenied) stay terminal. The attempt budget, the schedule and every timeout are unchanged; no retry or sleep was added.
  • The eviction test races the reconstructed-waiter latch against the client wait's join, so a client wait that ends early surfaces its own typed error instead of parking until the cap. The 20s timeout, the assertions and the object-side endpoint are unchanged.
  • Changeset: patch for @systemfsoftware/agent-platform-cloudflare.
  • Corrects docs/solutions/test-failures/cross-object-test-work-outlives-the-workerd-environment.md, which said an in-flight wait survives a reset and is replayed on the fresh incarnation; the measurement shows the reset rejects it and workerd does not replay it, so the client must re-issue.

Verification

cd packages/platform-cloudflare
nice -n 19 ionice -c 3 ../../node_modules/.bin/vitest run test/progress-wait.test.ts --project workerd

exit 0, 3/3 tests; 12 consecutive runs of that file alone before the review fix, and 10 after it, all exit 0.

Package typecheck rc=0; repo lint: 0 warnings, 0 errors, rc=0; dprint check on the changed files rc=0.

…eset

A Durable Object reset reaches the waiting client as a plain remote
rejection, an overload-flagged rejection, or an answer that cannot be
decoded, not only as a rejection flagged as a reset. The wait observes
durable state, so every such transport failure leaves the attempt with
nothing observed and the same attempt budget can re-issue it; typed host
failures stay terminal. Without this, the client wait ended on the reset
and no subscription reached the fresh incarnation, so a caller awaiting
progress never saw it reconnect.

The eviction test now races the reconstructed-waiter latch against the
client wait's join, so a client wait that ends early surfaces its own
error instead of parking until the test cap. Timeout, assertions and
the attempt budget are unchanged.
…erminal

The wait re-issued every transport failure, including one the runtime
flagged as overloaded. That shape is marked as not worth retrying
because a retry adds load to an object that cannot keep up, so it stays
terminal; the bare remote rejection of a reset and an answer that cannot
be decoded still re-issue.
…-issues it

The solution doc said an in-flight awaitProgress call survives state.abort()
and is replayed on the fresh incarnation, so the client's retry never runs.
Measured otherwise: the reset rejects the call with remote and
durableObjectReset set, and workerd does not replay it, which is why the
client re-issues and why a test that waits for the fresh incarnation's
subscription stalls when that re-issue does not happen.
@systemfsoftware-bot
systemfsoftware-bot merged commit 8dc0647 into main Nov 26, 2026
13 of 14 checks passed
@systemfsoftware-bot

Copy link
Copy Markdown
Contributor Author

Known residual, recorded at merge: awaitProgress re-issues within the existing 5-attempt budget, about 310 ms of backoff in total (10, 20, 40, 80 and 160 ms). If a Durable Object reset takes longer than that to come back, the wait still fails. That's not a hang: the error reaches the caller. Sizing this budget against measured reset-recovery times is follow-up work.

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