Repository navigation
fix(cm): stop desktop crashing at startup when migrating existing chat history - #101
Merged
Merged
Conversation
The desktop sidecar runs the published Bun-only V1 migration under Electron's Node, where its synthetic-ID hashing called Bun.CryptoHasher and threw "Bun is not defined" for real histories, killing the sidecar before the window could load. Swap that one call to node:crypto inside the migration module only, and guard that it stays the sole Bun API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Fixes #102
Type of change
What does this PR do?
Since #100, CookieMonster desktop dies on first launch for anyone with existing chat history: the sidecar exits with
V1 history migration failed: Bun is not defined.The published 2.2.5 V1 migration is Bun-only.
cm-v2already runs it under Electron's Node by redirecting#v1-migrationand shimmingbun:sqlite, but the migration also callsnew Bun.CryptoHasher("sha256")when it has to invent IDs, which only some histories need. This adds a moduleloadhook that swaps that one call fornode:crypto'screateHashinside the migration module only, so nothing else sees a fakeBunglobal. Both produce the same SHA-256 hex, so the generated IDs are unchanged. A new test fails if a future 2.2.x migration needs any other Bun API.How did you verify your code works?
CM_BRAND=1 bun run dev:desktopon a real dev profile (backed up first). With the fix the migration completes, all 47 sessions and their message history appear, and the original database is untouched.cm-v2tests pass (8, including the new guard);cm-v2typecheck is clean.Screenshots / recordings
Not a UI change.
Checklist
Created with Claude Opus 5.5 in Claude Code.