Repository navigation
feat(agents): synchronous Lifecycle job push and cancel - #2420
Closed
mattzcarey wants to merge 1 commit into
Closed
mattzcarey wants to merge 1 commit into
mattzcarey wants to merge 1 commit into
Conversation
jobs.pushSync() and jobs.cancelSync() write the job inside the caller's storage.transactionSync, so it commits or rolls back with the capability's own rows. They skip the re-arm; call jobs.rearm() after the commit. The queue also recreates its table when a rolled-back transaction took the CREATE TABLE with it.
🦋 Changeset detectedLatest commit: 08712c2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Comment on lines
193
to
+205
| The queue is ordered by timestamp, and every queue mutation re-arms the | ||
| physical alarm automatically — there is no explicit rearm call. When the | ||
| physical alarm automatically. The one exception is a job that must commit with | ||
| the capability's own rows. `jobs.pushSync()` and `jobs.cancelSync()` write | ||
| synchronously inside a `storage.transactionSync`, so the job and the rows | ||
| commit or roll back together. They skip the re-arm, so call `jobs.rearm()` | ||
| once the transaction commits: | ||
|
|
||
| ```ts | ||
| this.lifecycle.storage.transactionSync(() => { | ||
| this.#insertRow(id, input); | ||
| this.lifecycle.jobs.pushSync({ id, fn: "step", time: Date.now() }); | ||
| }); | ||
| await this.lifecycle.jobs.rearm(); |
Contributor
There was a problem hiding this comment.
Contributor
|
✅ agents import sizes: no significant changes ( |
mattzcarey
added a commit
to mattzcarey/agents
that referenced
this pull request
Sep 30, 2026
submit() admits into pi once, after the session's wake has a job. The wake's step waits while pi has live tasks in the session and parks when it has none, so it never admits or replays. The copied driver writes its row and job atomically with jobs.pushSync (cloudflare#2420).
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
mattzcarey
added a commit
to mattzcarey/agents
that referenced
this pull request
Sep 30, 2026
submit() admits into pi once, after the session's wake has a job. The wake's step waits while pi has live tasks in the session and parks when it has none, so it never admits or replays. The copied driver writes its row and job atomically with jobs.pushSync (cloudflare#2420).
aron-cf
approved these changes
Sep 30, 2026
Member
Author
|
Not needed: the pi harness example (#2419) now wakes with a plain per-session Lifecycle job, so nothing needs an atomic row-plus-job push. |
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.
Lifecycle capabilities can now push or cancel a job in the same
transactionSyncas their own rows, so the job and the rows commit or roll back together.jobs.pushSync(options)/jobs.cancelSync(id): same semantics aspush/cancel, but synchronous, and they don't re-arm the physical alarm. Callrearm()after the commit.JobQueuerecreatescf_agents_jobswhen a rolled-back transaction also rolled back itsCREATE TABLE(the cached "table exists" flag goes stale otherwise).docs/agents/lifecycle.md.Why: a driver that queues a row and its wake job with the async
pushhas a window where the row exists without a job, or the job without the row. Taken from the driver in #2396. The pi harness example (#2419) is stacked on this.