Hold MCP connections only while work runs (fix DO hibernation / free-tier burn) - #13
Merged
Conversation
A Durable Object holding live MCP client connections never hibernates:
it stays resident — and billed — around the clock even with zero
traffic, while an identical object without connections sleeps at once.
Measured on production: ~109,000 active seconds/day from a few hundred
requests, tripping the free tier's 13,000 GB-s daily cap every day
(each object ~7h/day); a controlled experiment showed 0s active for an
idle object whose connection had been removed vs 170–900s+ for ones
that kept it.
Connections are now opened just before a turn (setup(..., {connect}) —
called by the client before send/retry) or on demand for direct tool
calls, released when the turn ends (onChatResponse/onChatError, and
after callAppTool), and swept on every wake (onStart) to clear leftovers
restored from a previous isolate. A Google connection mid-consent is
kept, since its OAuth state rides on the connection row. My apps shows
"on" for engine apps (no live-connection claim) and "connected" for
Google once tokens exist.
Claude-Session: https://claude.ai/code/session_01MKLJUWk6biNAKXupHTTWn5
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.
Live MCP client connections prevent Durable Object hibernation — objects stayed resident ~7h/day each with near-zero traffic, exhausting the free tier's 13,000 GB-s daily cap every day (verified by per-object analytics and a controlled experiment: removed connection → 0s active). Connections now open right before a turn or tool call, release when it ends, and are swept on wake.
https://claude.ai/code/session_01MKLJUWk6biNAKXupHTTWn5