Skip to content

fix(cm): stop desktop crashing at startup when migrating existing chat history - #101

Merged
trmosala merged 1 commit into
devfrom
fix/v2-migration-node-hash
Nov 8, 2026
Merged

trmosala merged 1 commit into
devfrom
fix/v2-migration-node-hash

Conversation

@trmosala

@trmosala trmosala commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Issue for this PR

Fixes #102

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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-v2 already runs it under Electron's Node by redirecting #v1-migration and shimming bun:sqlite, but the migration also calls new Bun.CryptoHasher("sha256") when it has to invent IDs, which only some histories need. This adds a module load hook that swaps that one call for node:crypto's createHash inside the migration module only, so nothing else sees a fake Bun global. 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?

  • Reproduced the crash with CM_BRAND=1 bun run dev:desktop on 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-v2 tests pass (8, including the new guard); cm-v2 typecheck is clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Created with Claude Opus 5.5 in Claude Code.

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>
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@trmosala
trmosala merged commit 128843f into dev Nov 8, 2026
8 of 13 checks passed
@trmosala
trmosala deleted the fix/v2-migration-node-hash branch November 8, 2026 12:07
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.

Desktop crashes at startup: V1 history migration fails with "Bun is not defined"

1 participant