Fix Windows WhatsApp session-store DSN handling for SQLite init and lookup paths#1
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/chz160/openmessage/sessions/4500974b-9ba5-4885-ad0a-fa7bb708545a Co-authored-by: chz160 <3420276+chz160@users.noreply.github.com>
Agent-Logs-Url: https://github.com/chz160/openmessage/sessions/4500974b-9ba5-4885-ad0a-fa7bb708545a Co-authored-by: chz160 <3420276+chz160@users.noreply.github.com>
Agent-Logs-Url: https://github.com/chz160/openmessage/sessions/4500974b-9ba5-4885-ad0a-fa7bb708545a Co-authored-by: chz160 <3420276+chz160@users.noreply.github.com>
Agent-Logs-Url: https://github.com/chz160/openmessage/sessions/4500974b-9ba5-4885-ad0a-fa7bb708545a Co-authored-by: chz160 <3420276+chz160@users.noreply.github.com>
Agent-Logs-Url: https://github.com/chz160/openmessage/sessions/4500974b-9ba5-4885-ad0a-fa7bb708545a Co-authored-by: chz160 <3420276+chz160@users.noreply.github.com>
Agent-Logs-Url: https://github.com/chz160/openmessage/sessions/4500974b-9ba5-4885-ad0a-fa7bb708545a Co-authored-by: chz160 <3420276+chz160@users.noreply.github.com>
Agent-Logs-Url: https://github.com/chz160/openmessage/sessions/4500974b-9ba5-4885-ad0a-fa7bb708545a Co-authored-by: chz160 <3420276+chz160@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix Windows-specific WhatsApp session store initialization failure
Fix Windows WhatsApp session-store DSN handling for SQLite init and lookup paths
May 11, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows failures when opening/migrating the WhatsApp session-store SQLite DB by ensuring file: DSNs are built from Windows-safe, normalized paths, and by reusing that same DSN logic for read-only lookup opens.
Changes:
- Centralized DSN construction via
sessionStoreDSNWithQuery, normalizing Windows paths (\→/and/C:/...prefixing) before buildingfile:URLs. - Added a dedicated read-only DSN helper (
mode=ro+busy_timeout) and updated session-store lookup helpers to use it. - Added tests to validate Windows drive-path normalization and read-only DSN query behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/whatsapplive/client.go | Normalizes Windows paths for SQLite file: DSNs and reuses the same logic for read-only session DB opens. |
| internal/whatsapplive/client_test.go | Adds test coverage for Windows path normalization and read-only DSN query parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Windows WhatsApp bridge startup was failing during session-store migration because SQLite DSNs were built from raw Windows paths via
url.URL, producing malformedfile:URIs (e.g. encoded backslashes) and surfacing asSQL logic error: out of memory (1).This change makes DSN generation Windows-safe and applies the same logic to all WhatsApp session DB open paths.
DSN construction hardening (cross-platform)
internal/whatsapplive/client.go.\→//so DSN becomesfile:///C:/..._pragma=foreign_keys(1)&_pragma=busy_timeout(5000)Read-only helper compatibility
lookupPNFromSessionStorelookupLIDFromSessionStoremode=ro&_pragma=busy_timeout(5000).Focused coverage for Windows path behavior
internal/whatsapplive/client_test.govalidating:C:\...andc:\...)mode=roand expected pragma.Example of the normalized output pattern:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
instantmessaging-pa.googleapis.com/tmp/TestBuiltBinaryAcceptsPairCommand566876082/001/openmessage /tmp/TestBuiltBinaryAcceptsPairCommand566876082/001/openmessage pair -stringintconv l/linux_amd64/vet /tmp/go-build1583251920/b358/vet.cfg rg/toolchain@v0.0.1-go1.25.0.lin-p ux-amd64/src/net/http/httptest/httptest.go ux-amd64/pkg/tool/linux_amd64/vet(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fix the Windows-specific WhatsApp session store initialization failure in repository
chz160/openmessage.Problem
When running
openmessage serveon Windows, the server starts but logs a warning when initializing the WhatsApp bridge:Failed to initialize WhatsApp bridge for status error="open WhatsApp session store: failed to upgrade database: failed to check if foreign keys are enabled: SQL logic error: out of memory (1)"The failure occurs during WhatsApp session store initialization in
internal/whatsapplive/client.go, where the code opens a SQLite-backed whatsmeow session database using a DSN constructed bysessionStoreDSN(path string). The current implementation builds afile:URL usingnet/url.URL:sqlstore.New(context.Background(), "sqlite", sessionStoreDSN(b.sessionPath), waLog.Noop)ininitClientLocked()sessionStoreDSN()currently returns afile:URL with_pragma=foreign_keys(1)&_pragma=busy_timeout(5000)query paramsThe app stores the WhatsApp DB at
filepath.Join(dataDir, "whatsapp-session.db"), wheredataDirdefaults tofilepath.Join(home, ".local", "share", "openmessage")unlessOPENMESSAGES_DATA_DIRis set.Suspected root cause
The current DSN construction likely mishandles Windows file paths when passed to the SQLite driver / whatsmeow sqlstore, causing a misleading SQLite
out of memory (1)logic error during foreign key pragma checks or migration.Relevant code
internal/whatsapplive/client.gointernal/app/app.goGoal
Make WhatsApp session-store initialization work reliably on Windows without regressing Unix/macOS behavior.
Expected approach
internal/whatsapplive/client.go.sessionStoreDSN()and any related callsites as needed so Windows paths are encoded in a way compatible with the SQLite driver used by whatsmeow/sqlstore.foreign_keys(1),busy_timeout(5000)) unless there is a strong reason to change them.lookupPNFromSessionStore/lookupLIDFromSessionStore) remain compatible on Windows as well.Acceptance criteria
openmessage serveno longer emits the WhatsApp session-store initialization warning on Windows for a valid writable data dir.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: When running openmessage serve on windows, the server starts fun however the console is throwing these errors message:
7:01PM WRN Failed to initialize WhatsApp bridge for status error="open WhatsApp session store: failed to upgrade database: failed to check if foreign keys are enabled: SQL logic error: out of memory (1)"
Assistant: That warning likely means the SQLite DB used by the WhatsApp bridge is failing during startup on Windows, and the bridge’s migration/init path is surfacing SQLite’s generic
out of memory (1)error while checkingPRAGMA foreign_keys.I’m going to inspect the repo for the WhatsApp bridge/session-store initialization and where that exact warning is logged.
Assistant: This looks like a WhatsApp session-store initialization failure on Windows, not a failure of the main OpenMessage server.
The server is still starting because
servetreats WhatsApp as optional and only logs a warning if it can’t initialize:And the exact warning you saw comes from the status path here:
The root cause is likely this SQLite-backed WhatsApp session DB open/upgrade step: