Skip to content

POC, testing with the eviction API#1820

Draft
mattzcarey wants to merge 8 commits into
mainfrom
feat/eviction-api-test-poc
Draft

POC, testing with the eviction API#1820
mattzcarey wants to merge 8 commits into
mainfrom
feat/eviction-api-test-poc

Conversation

@mattzcarey

Copy link
Copy Markdown
Contributor

No description provided.

@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 23b545e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR


await evictDurableObject(agent as unknown as DurableObjectStub);

const history = await agent.getHistory();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm if we did an eviction, the stub shouldn't work after that I think? have to confirm with workerd team

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

weird that these tests pass then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why the test passes — the stub is supposed to work after eviction

evictDurableObject(stub)workerdUnsafe.evict(stub)channel->evictForTest() in workerd. The source says it outright:

workerd/src/workerd/api/unsafe.h:118-122

"gracefully evict the Durable Object referred to by stub from its isolate, simulating the runtime tearing it down when it goes idle. Durable storage is left intact, so the DO rebuilds (rerunning its constructor) on its next request."

workerd/src/workerd/io/io-channels.h:267-274

"forcibly evict the target … this destroys the actor instance while durable storage survives, so the next request rebuilds it. … Throws if the target Durable Object is not currently running."

So threepointone's intuition is incorrect (and this is exactly the workerd-team confirmation he asked for). A DurableObjectStub is an ID-addressed routing handle, not a pointer to the live instance. Eviction destroys the in-isolate actor but keeps storage; the next call through the same stub reruns the constructor and rehydrates from SQLite. The stub continuing to work is the production hibernation lifecycle — that's the whole point of the helper.

For contrast, the three sibling APIs differ precisely here:

  • evict() / evictAllDurableObjects() — graceful: storage intact, stub keeps working, hibernates/closes WebSockets.
  • abortAllDurableObjects() — throws an exception into the actor (this is the one that breaks in-flight work).
  • deleteAllDurableObjects() — abort and wipes storage so the DO restarts clean.

One nice corollary: evict() rejects if the DO isn't currently running. In provider.test.ts the agent was just written to (appendMessage), so it's live → the eviction definitely happened, otherwise evict() itself would have thrown and failed the test.

@pkg-pr-new

pkg-pr-new Bot commented Jun 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

create-think

npm i https://pkg.pr.new/create-think@1820

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 23b545e

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.

2 participants