diff --git a/.changeset/await-progress-reconnect.md b/.changeset/await-progress-reconnect.md new file mode 100644 index 00000000..afd5ba9c --- /dev/null +++ b/.changeset/await-progress-reconnect.md @@ -0,0 +1,5 @@ +--- +"@systemfsoftware/agent-platform-cloudflare": patch +--- + +`CloudflareThreadClient.awaitProgress` now re-issues its wait when a reset reaches it as a bare remote rejection or as an answer that cannot be decoded, so a wait for durable progress survives a Durable Object reset instead of ending with the reset's error. diff --git a/docs/solutions/test-failures/cross-object-test-work-outlives-the-workerd-environment.md b/docs/solutions/test-failures/cross-object-test-work-outlives-the-workerd-environment.md index 0f9e8d5e..050c1301 100644 --- a/docs/solutions/test-failures/cross-object-test-work-outlives-the-workerd-environment.md +++ b/docs/solutions/test-failures/cross-object-test-work-outlives-the-workerd-environment.md @@ -31,10 +31,11 @@ it runs, and the budget is the suite's configured `testTimeout`, not the machine 135 sequential SQLite operations plus a cold reconstruction, so 10 s was below what the work needs when the CPUs are shared. -Measured with a probe: an in-flight `awaitProgress` RPC is not rejected by `state.abort()`. Workerd -re-runs the request on the fresh incarnation, the fresh incarnation reports the waiter, and the -client promise resolves when progress arrives. The client's retry classification therefore never -runs for an eviction. +Measured with a probe: `state.abort()` rejects an in-flight `awaitProgress` RPC with an error +carrying `remote` and `durableObjectReset` (200/200 on a plain RPC, 160/160 through the client), and +workerd does not replay the request on the fresh incarnation. The client therefore has to re-issue +it, and a test that waits for the fresh incarnation to report a subscription stalls for its whole cap +whenever that re-issue does not happen. ## What does not work @@ -48,8 +49,11 @@ runs for an eviction. ## What works -- Count subscriptions monotonically per incarnation, so a replay is observed whether or not it is - still parked, and latch on the count rather than on a gauge. +- Re-issue the wait from the client after a reset-shaped transport failure (a bare remote rejection + or an answer that cannot be decoded), and keep an overload-flagged rejection and a typed host + failure terminal. +- Count subscriptions monotonically per incarnation, so a re-issued request is observed whether or + not it is still parked, and latch on the count rather than on a gauge. - Fork client work through a harness that tracks every fiber, and interrupt and await them after each test instead of at the end of the file. - After each test, disarm the eviction failpoints it armed and delete the persisted alarm of every diff --git a/packages/platform-cloudflare/src/CloudflareThreadClient.ts b/packages/platform-cloudflare/src/CloudflareThreadClient.ts index edf9ce61..8f005e91 100644 --- a/packages/platform-cloudflare/src/CloudflareThreadClient.ts +++ b/packages/platform-cloudflare/src/CloudflareThreadClient.ts @@ -875,21 +875,26 @@ export class CloudflareThreadClient extends Context.Service< ), ) + const reissue = ( + error: ThreadClientError | HostProtocolError, + retry: number, + ): Effect.Effect => + retry < 5 + ? Effect.sleep(Duration.millis(10 * 2 ** retry)).pipe( + Effect.andThen(attempt(retry + 1)), + ) + : Effect.fail(error) + const attempt = (retry: number): Effect.Effect => call(threadId, 'awaitProgress', encoded).pipe( Effect.flatMap( expect(threadId, 'awaitProgress', ProgressObserved, ClientObserveHostFailure), ), Effect.asVoid, - Effect.catchTag( - 'ThreadClientError', - (error) => - error.retryable === true && error.overloaded !== true && retry < 5 - ? Effect.sleep(Duration.millis(10 * 2 ** retry)).pipe( - Effect.andThen(attempt(retry + 1)), - ) - : Effect.fail(error), - ), + Effect.catchTags({ + ThreadClientError: (error) => error.overloaded === true ? Effect.fail(error) : reissue(error, retry), + HostProtocolError: (error) => reissue(error, retry), + }), ) yield* attempt(0).pipe(Effect.onInterrupt(() => cancelProgress(threadId, waiterId))) diff --git a/packages/platform-cloudflare/test/progress-wait.test.ts b/packages/platform-cloudflare/test/progress-wait.test.ts index cfdf20f8..67dcf215 100644 --- a/packages/platform-cloudflare/test/progress-wait.test.ts +++ b/packages/platform-cloudflare/test/progress-wait.test.ts @@ -161,10 +161,13 @@ describe('#94 Cloudflare durable progress wait', () => { state.abort('#94 forced wait eviction') }).catch(() => undefined) - const reconstructedIncarnation = await awaitReconstructedProgressWaiter( - thread, - priorIncarnation, - 1, + const surfaceClientWaitFailure = Fiber.join(waiting).pipe(Effect.flatMap(() => Effect.never)) + + const reconstructedIncarnation = await Effect.runPromise( + Effect.raceFirst( + Effect.promise(() => awaitReconstructedProgressWaiter(thread, priorIncarnation, 1)), + surfaceClientWaitFailure, + ), ) expect(reconstructedIncarnation).not.toBe(priorIncarnation)