Skip to content

keepAlive: replace schedule rows with ref-counted alarms#1147

Merged
threepointone merged 1 commit into
mainfrom
fix-keep-alive-logs
Mar 22, 2026
Merged

keepAlive: replace schedule rows with ref-counted alarms#1147
threepointone merged 1 commit into
mainfrom
fix-keep-alive-logs

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented Mar 22, 2026

Summary

  • Eliminates observability event noise from keepAlive() — no longer creates schedule rows or emits schedule:create/schedule:execute/schedule:cancel events every 30 seconds. Uses an in-memory ref count that feeds directly into _scheduleNextAlarm().
  • Multiple concurrent keepAlive() callers share a single alarm cycle instead of each creating their own interval schedule row (N fibers → 1 alarm, not N schedule rows).
  • Adds _onAlarmHousekeeping() hook called on every alarm cycle, replacing the old _cf_keepAliveHeartbeat callback. The fiber mixin overrides this for eviction recovery instead of coupling to the scheduling system.
  • Schema v2 migration cleans up orphaned _cf_keepAliveHeartbeat schedule rows from the previous implementation (without this, upgrading users would hit a tight alarm loop from stale rows).
  • Removes @experimental from keepAlive() and keepAliveWhile().

Test plan

  • All 855 existing tests pass (3 consecutive full-suite runs)
  • npm run check passes (lint, typecheck, format, export validation)
  • Updated keep-alive tests verify ref counting, no schedule rows, dispose idempotency, negative-ref guard
  • Updated fiber tests verify keepAlive refs during fiber execution and absence of schedule rows
  • Schema version tests updated for v2
  • Docs updated (docs/scheduling.md, design/think.md)

Made with Cursor


Open with Devin

Replace the schedule-based keepAlive heartbeat with an in-memory reference-counted alarm. keepAlive() now increments/decrements _keepAliveRefs and relies on _scheduleNextAlarm() to set a single Durable Object alarm every 30s while refs > 0; it no longer creates schedule rows or emits schedule observability events. Add _onAlarmHousekeeping() hook (called on each alarm) for extensions (e.g. fiber mixin) to run recovery/housekeeping. Bump internal schema to v2 and migrate by removing orphaned _cf_keepAliveHeartbeat schedule rows. Remove legacy heartbeat cleanup code, unmark keepAlive/keepAliveWhile as experimental, and update docs and tests to reflect the new behavior. A changeset was added to describe the patch.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 22, 2026

🦋 Changeset detected

Latest commit: 8993bee

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

This PR includes changesets to release 1 package
Name Type
agents 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
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 22, 2026

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 8993bee

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@threepointone threepointone merged commit 1f85b06 into main Mar 22, 2026
2 checks passed
@threepointone threepointone deleted the fix-keep-alive-logs branch March 22, 2026 13:48
@github-actions github-actions Bot mentioned this pull request Mar 22, 2026
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