Messages: grant the Messages folder so recent messages in the write-ahead log are visible - #198
Merged
Merged
Conversation
patp
force-pushed
the
messages-folder-access
branch
from
September 1, 2026 21:59
7a2afbb to
e8355c3
Compare
Owner
The service asked for chat.db alone. Messages keeps that database in WAL mode: every new message is committed to chat.db-wal first and only reaches chat.db when SQLite checkpoints the log, every few MB of writes. With a grant on the single file the log was unreadable, so Madrid opened the database with immutable=1 and messages_fetch could not see anything newer than the last checkpoint, often hours behind, then everything at once. The file picker now asks for ~/Library/Messages (directories only, constrained to a folder named Messages) and the bookmark covers the folder, which lets SQLite read chat.db together with its -wal and -shm companions (Madrid's Database.AccessMode.live). The security scope now stays open until the fetch is done, since SQLite opens the log lazily. A bookmark stored by an earlier version (chat.db alone) keeps working in immutable mode; the first fetch of a launch offers to re-select the folder, and declining is remembered for that launch. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0187kUP2mjhwMfJkwRbP5DG7
patp
force-pushed
the
messages-folder-access
branch
from
September 4, 2026 02:05
e8355c3 to
5ce2cbc
Compare
patp
marked this pull request as ready for review
September 4, 2026 02:05
Contributor
Author
|
Same here: rebased onto |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Cancellation handling and warning-state synchronization must be fixed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates Messages access to include SQLite WAL files so recent messages remain visible.
Changes:
- Requests read-only access to the Messages folder.
- Keeps security scope active during reads and supports legacy grants.
- Documents WAL behavior and migration.
Required fixes:
- Preserve legacy grants when the upgrade folder picker is cancelled.
- Synchronize the shared one-time warning flag to prevent concurrent races.
File summaries
| File | Description |
|---|---|
README.md |
Documents folder access and WAL visibility. |
App/Services/Messages.swift |
Adds folder grants, live database access, and legacy fallback handling. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+52
to
+53
| if !warnedAboutFileGrant { | ||
| warnedAboutFileGrant = true |
| } | ||
|
|
||
| let selectedURL = try await showFilePicker() | ||
| let selectedURL = try await showFolderPicker() |
Owner
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.
Problem
chat.dbis a WAL-mode SQLite database. Messages.app appends new rows tochat.db-waland only folds them into the main file at a checkpoint (roughly every 4 MB of changes). iMCP opens the database through Madrid withimmutable=1, which ignores the write-ahead log, and its security-scoped bookmark covers the single filechat.db, so the sandbox could not readchat.db-wal/chat.db-shmanyway. The result is thatmessages_fetchsilently misses everything received since the last checkpoint. On a quiet machine that is hours, sometimes days, of messages.Fix
~/Library/Messagesfolder instead of thechat.dbfile (folder-only picker, preset to~/Library, only theMessagesfolder is selectable). The bookmark is stored read-only exactly as before.DatabaseAccessvalue that keeps the security scope open for the whole tool call. SQLite opens the-wal/-shmcompanions lazily on the first read, so stopping the scope right afterDatabase(path:)would break WAL reads..livemode (mode=ro, WAL honoured). An existing single-file grant keeps working in.immutablemode (today's behaviour), with one warning per launch in the log.chat.dbalone, so switching Messages off and on in the menu offers the folder; declining keeps the old grant and leaves the service on.Dependency
Uses
Database.AccessModefrom Madrid 0.5.0 (mattt/Madrid#19), whichmainpins since #201. Rebased ontomainon 2026-09-03; the branch no longer touches the package pin.Testing
swift format lint --strictclean.chat.dbwas last checkpointed at 17:30: with the folder grant,messages_fetchreturns messages received at 17:39 and 17:45, which the single-file grant did not see (and still would not, the main file is unchanged). That build has been serving a sync client since 2026-09-01 with no lag behind Messages.app.-wal/-shmcompanions, the situation under the sandbox.🤖 Generated with Claude Code
https://claude.ai/code/session_0187kUP2mjhwMfJkwRbP5DG7