Skip to content

Always rebuild analytics cache after write operations#241

Merged
wesm merged 16 commits intomainfrom
robelkin/fix/sync-error-logging-and-cache-rebuild
Apr 2, 2026
Merged

Always rebuild analytics cache after write operations#241
wesm merged 16 commits intomainfrom
robelkin/fix/sync-error-logging-and-cache-rebuild

Conversation

@wesm
Copy link
Copy Markdown
Owner

@wesm wesm commented Apr 2, 2026

Summary

  • Add shared rebuildCacheAfterWrite(dbPath) helper that checks staleness, runs incremental or full rebuild as needed, and warns on failure
  • Every write command now rebuilds the cache unconditionally before returning: sync, sync-full, import-emlx, import-imessage, import-gvoice, import-whatsapp, import-mbox, repair-encoding, delete-staged
  • Remove --rebuild-cache flag from sync commands (redundant — cache always rebuilds)
  • Log message IDs when fetch returns nil during sync (aids debugging)

Cache rebuild failure is a warning, not a command error — the primary operation (sync/import) succeeded and data is safe in SQLite.

🤖 Generated with Claude Code

robelkin-rational-partners and others added 16 commits April 2, 2026 08:26
When GetMessagesRawBatch returns nil for a message (typically a 404
because the message was deleted between listing and fetching), the
error count was incremented but no message ID was logged. This made
it impossible to diagnose which messages failed to sync.

Add Warn-level logging with the message ID in both incremental and
full sync paths so failed fetches are visible in logs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The serve command rebuilds the Parquet analytics cache after each
sync, but the standalone CLI commands did not. This caused stale
search results when syncs were triggered via launchd or manual CLI.

Rather than always rebuilding (which couples sync and caching), add
an opt-in --rebuild-cache flag that users can enable in their
launchd config or scripts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the flag is set, always run buildCache rather than gating on
cacheNeedsBuild. The staleness check is still consulted to decide
whether a full rebuild is needed, but the cache build itself runs
unconditionally so users can recover from bad-but-undetected cache
states.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the user explicitly requests cache rebuild via --rebuild-cache,
failures should cause a non-zero exit so automation can detect them.
Previously these were silently downgraded to log warnings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Report cache failures independently rather than mixing them into the
"account(s) failed to sync" message. Sync failures and cache failures
are now distinct error paths with accurate messages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Apr 2, 2026

roborev: Combined Review (3ee218a)

Verdict: No medium-or-higher issues found; the reviewed changes look clean.


Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

@wesm wesm merged commit fc6f2cd into main Apr 2, 2026
4 checks passed
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.

2 participants