This repository was archived by the owner on May 22, 2026. It is now read-only.
Repository navigation
fix: session ID persistence with Cloudflare Workers workaround - #21
Merged
Merged
Conversation
This change fixes session ID persistence issues caused by Cloudflare Workers bug #2240
where state.id.name is not available in Durable Object constructors.
Changes:
- Pass session ID via X-Session-Id header instead of relying on DO ID properties
- Change session ID format from UUID to ISO timestamp-based: web/slack-YYYYMMDDTHHmmssZ-{random}
- Add fail-fast validation after idFromName() calls to catch errors early
- Add /api/session/:id/init endpoint to initialize sessions on creation
- Display full session IDs in session list (not truncated)
- Show first user message in session list for better context
- Add "Fail Fast, Fail Explicitly" design principles to README
- Clean up excessive logging while keeping validation checks
Technical details:
- Workaround for cloudflare/workerd#2240
- Modified ChatSession.fetch() to extract session ID from request header
- Added session ID mismatch validation throughout the stack
- All stub.fetch() calls now include X-Session-Id header
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Split initialization into two phases to improve /history endpoint performance: - initialize(): Lightweight, loads only session and messages from D1 - initializeFilesystem(): Heavy, initializes file system, directories, and git mounts Changes: - /history requests now skip filesystem initialization (3s → ~100ms expected) - /chat and bash commands lazy-load filesystem only when needed - Add performance logging to identify bottlenecks - Filesystem state cached in DO instance, initialized once per DO lifetime Performance improvements: - Session query timing - Messages query timing with count - Directory initialization timing - Mount restoration timing - Total timings for both phases Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move /history endpoint from Durable Object to Worker API layer - Query D1 database directly instead of routing through DO - Remove unused /history endpoint from ChatSession DO - Add Known Issues section to README documenting CF Workers bug #2240 This optimization reduces the /history endpoint latency from ~3s to <100ms by avoiding unnecessary DO initialization and filesystem setup. Related: #22 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
state.id.nameis not available in Durable Object constructorsX-Session-Idheader instead of relying on DO ID propertiesweb-YYYYMMDDTHHmmssZ-{random}orslack-YYYYMMDDTHHmmssZ-{random}Technical Details
This PR implements a workaround for Cloudflare Workers issue #2240 where the
nameproperty on Durable Object IDs is not properly set even when usingidFromName().Key Changes:
ChatSession.fetch()to extract session ID fromX-Session-Idheaderstub.fetch()calls inapi.tsandslack.tsto include the headeridFromName()call with fail-fast error handling/api/session/:id/initendpoint to persist sessions on creationcrypto.randomUUID()to ISO timestamp formatDesign Principles:
Test Plan
🤖 Generated with Claude Code