POC, testing with the eviction API#1820
Conversation
…on history rehydration
…tAllDurableObjects
|
|
|
||
| await evictDurableObject(agent as unknown as DurableObjectStub); | ||
|
|
||
| const history = await agent.getHistory(); |
There was a problem hiding this comment.
hmm if we did an eviction, the stub shouldn't work after that I think? have to confirm with workerd team
There was a problem hiding this comment.
weird that these tests pass then
There was a problem hiding this comment.
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
stubfrom 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.
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
No description provided.