Fix alarm() to call super for init#1050
Merged
threepointone merged 2 commits intomainfrom Mar 2, 2026
Merged
Conversation
…ialization The Agent class defined alarm as a public readonly arrow function property, which completely shadowed PartyServer's alarm() prototype method. This meant #ensureInitialized() was never called when a Durable Object woke via alarm (e.g. from scheduleEvery), causing this.name to throw and onStart to never run. Converted alarm from an arrow function property to a regular async method that calls super.alarm() before processing scheduled tasks. Also added an onAlarm() no-op override to suppress PartyServer's default warning log. Added TestAlarmInitAgent and tests verifying this.name is accessible and onStart is called during alarm-triggered scheduled callback execution.
Co-authored-by: threepointone <threepointone@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 77eadbe The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
threepointone
approved these changes
Mar 2, 2026
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.
All done. Here's a summary of the changes:
Fix: Agent
alarm()override bypasses PartyServer initializationRoot cause
The
Agentclass definedalarmas apublic readonlyarrow function property (packages/agents/src/index.ts:2432), which completely shadowed PartyServer'salarm()prototype method. When a Durable Object woke via alarm (e.g. fromscheduleEvery), PartyServer's#ensureInitialized()was never called, so:this.namewould throw ("Attempting to read .name before it was set")onStart()was never calledFix (3 changes in
packages/agents/src/index.ts)Converted
alarmfrom an arrow function property to a regularasync alarm()method — this allows proper prototype-chain method override instead of instance-level shadowing.Added
await super.alarm()as the first line of the newalarm()method — this calls PartyServer's#ensureInitialized(), which hydratesthis.namefrom durable storage and callsonStart()if needed.Added
onAlarm(): void {}no-op override — PartyServer'ssuper.alarm()callsthis.onAlarm()after initialization, and the default implementation logs a warning. The no-op suppresses this.Tests added
TestAlarmInitAgent— a test agent withonStart()tracking and anameCheckCallbackthat readsthis.nameduring alarm executionalarms.test.ts:this.nameis accessible during scheduled callback (captures the agent name correctly)onStartis called before executing scheduled callbacksVerification
npm run check: sherif, export checks, formatting, linting, typecheck across all 46 projects)Closes #1048
github run