Repository navigation
feat(cloudflare): run each conversation as one Agents SDK state machine - #736
Closed
mattzcarey wants to merge 2 commits into
Closed
mattzcarey wants to merge 2 commits into
mattzcarey wants to merge 2 commits into
Conversation
Replace the hand-rolled Cloudflare execution layer — the zero-delay drain plus 30s heartbeat on schedule(), the in-isolate supervisor chain, detached runFiber attempt fibers with onFiberRecovered, and live deadline enforcement with a force-settle grace — with two Agents SDK Task definitions declared on the generated class: - flue:drive@v1: one bounded reconcile pass (materialize, finalize, recover interrupted rows, claim runnable heads) that starts an attempt run per claim and completes; every former arm-the-drain boundary now ensures this run and joins it when live. - flue:attempt@v1: one submission processed to settlement in the handler body, with the flue abort controller linked to step.signal and the submission's durability timeout as the run deadline. The SDK owns the claim backstop, the replay after an interruption (the body reconciles from evidence first), and settling over a signal-deaf attempt. The submission ledger, canonical stream, admission paths, and recovery classification are unchanged. Requires the agents release that carries cloudflare/agents#2274 (step.signal, run deadline, onError context).
The Cloudflare coordinator's drive and per-submission attempt runs become one durable state machine per conversation, flue:conversation@v1, at a fixed address. Its idle phase parks on the run's mailbox — holding no alarm — until admission or an abort sends it a wake, then claims the next runnable head from the submission ledger; its turn phase processes that submission to settlement and returns to idle, where the next head is claimed in the same invocation. The ledger stays the record of what was accepted and how it settled; the machine is its executor. Interruption is a replayed turn: a turn re-dispatched without the in-isolate claim memory reconciles the running row from the canonical stream, the same way the attempt run did. A hung turn trips the SDK's transition watchdog, whose cancel transition abandons the attempt and returns the machine to idle. Live turns heartbeat the watchdog until the submission's own timeout, which aborts their work from inside. Aborts are honoured in-isolate at once and durably through the mailbox.
|
Thanks for the contribution! We're closing this PR and moving the conversation to the discussion: #737 We've moved to a model where bugs and feature proposals are discussed in issues/discussions before code review, so the community can help prioritize and shape the work. Your branch is linked from the new thread so the implementation isn't lost — please join us there to continue the conversation. — astrobot 🤖 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continues discussion #709 and supersedes #700: the Cloudflare coordinator now runs each conversation as one durable state machine on the Agents SDK engine, instead of a drive run plus one attempt run per submission.
Depends on the unreleased Agents SDK engine in cloudflare/agents#2301 (which is stacked on #2274). Draft until an
agentsrelease carries it; locally it was built against that branch through a workspacelink:override that is not committed.What changes
flue:conversation@v1, at a fixed address. Itsidlephase parks on the run's mailbox — holding no alarm — until admission or an abort sends it a wake, then claims the next runnable head from the submission ledger. Itsturnphase processes that submission to settlement and returns toidle, where the next queued head is claimed in the same invocation. The submission ledger stays the record of what was accepted and how it settled (it is shared with the Node target); the machine is its executor.reconcileInterruptedSubmission, same classification.onCancel, which aborts and orphans the attempt's controller (so a zombie's appends are refused) and returns the machine toidle, where the ledger settles the submission through the timeout classification. Live turns heartbeat the watchdog until the submission's own timeout, which aborts their work from inside.taskDefinitions; the coordinator losesensureDrive,ensureAttemptRun,hasLiveAttemptRunand the per-attempt run ids (~600 lines net).Verified
pnpm check:types(109 tasks), the runtime and vite builds, and the runtime unit tests pass. Live onexamples/cloudflareagainst the engine build: a prompt settlescompleted; two prompts queued back-to-back settle with the second joined at the turn boundary; an abort mid-response settlesabortedand a follow-up prompt completes; killing the dev server mid-response and restarting it replays the turn, which continues from the durable partial stream and settlescompleted. The machine's row parkswaitingon its mailbox with no wake job while the conversation is quiet.Docs: the "Durable agent execution" section of the Cloudflare target guide and "Cloudflare recovery" in the durability guide describe the new model.