Skip to content

perf(daemon): bound SQLite cache pressure (#2172) - #2173

Merged
Sinity merged 1 commit into
masterfrom
feature/perf/daemon-sqlite-memory-profile
Jun 19, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/perf/daemon-sqlite-memory-profile

Conversation

@Sinity

@Sinity Sinity commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

Bound daemon-side SQLite cache pressure by separating long-running daemon/ops writes from the batch-ingest write profile, and by moving recurring daemon read probes onto the read-only profile.

Problem

The live memory snapshot after #2171 showed a different pressure shape from the pytest harness issue: polylogued.service was near 950 MiB current cgroup memory with a 2.9 GiB peak, but the daemon process itself was only about 235 MiB PSS. memory.stat attributed most current usage to file cache rather than anonymous heap. Several daemon loops still opened the full write profile for small ops/maintenance work, and heartbeat counts opened a write-profile connection for read-only counts.

Solution

Added an explicit daemon write profile in polylogue/storage/sqlite/connection_profile.py with a 16 MiB SQLite cache and 64 MiB mmap allowance, leaving the existing 128 MiB / 1 GiB batch-ingest write profile untouched. Moved small daemon/ops writes (daemon_events, cursor-lag samples, embedding catch-up rows, OTLP telemetry, daily optimize) to open_daemon_connection, and moved heartbeat plus two ops health probes to open_readonly_connection.

The existing status/metrics memory reporting already distinguishes RSS, cgroup current/peak, cgroup file, and inactive file, so this change relies on that live observability rather than adding another reporting layer.

Verification

  • devtools test tests/unit/storage/test_wal_journal_size_limit.py::test_daemon_write_profile_uses_bounded_cache_and_mmap tests/unit/storage/test_wal_journal_size_limit.py::test_open_daemon_connection_applies_bounded_cache_and_mmap tests/unit/daemon/test_daemon_cli.py::test_daemon_cli_heartbeat_counts_uses_read_only_probe tests/unit/daemon/test_daemon_cli.py::test_daemon_cli_heartbeat_counts_archive tests/unit/daemon/test_cursor_lag_baseline.py tests/unit/daemon/test_cursor_lag_integration.py tests/unit/daemon/test_otlp_receiver.py tests/unit/daemon/test_metrics_endpoint.py::TestFormatMetricsReadsArchiveState::test_fts_freshness_and_memory_state — 46 passed.
  • devtools verify --quick — exit 0.
  • devtools verify — run 20260619T163716Z-testmon-1662720-33dfc22a; 505 passed in 256.73s, selected_count=1247, peak_tree_pss=2813.7 MiB, diagnosis=pytest_passed.

Closes #2172

Problem: live daemon evidence after the pytest harness fix showed service-level memory dominated by cgroup file cache, not retained Python heap. Several small daemon/ops paths still used the batch-ingest SQLite write profile, and heartbeat counts opened write-profile connections for read-only probes.\n\nWhat changed: add a smaller daemon write profile, move small ops and maintenance writes onto it, move recurring read-only daemon probes to read-only connections, and document the profile split. Focused tests cover real pragma application and heartbeat read-only behavior.\n\nCloses #2172
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 11 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a51ade56-8306-4fe7-8a8a-88c0ea146b52

📥 Commits

Reviewing files that changed from the base of the PR and between d150845 and 5ddc3df.

📒 Files selected for processing (11)
  • AGENTS.md
  • docs/internals.md
  • polylogue/daemon/cli.py
  • polylogue/daemon/cursor_lag_baseline.py
  • polylogue/daemon/embedding_backlog.py
  • polylogue/daemon/events.py
  • polylogue/daemon/health.py
  • polylogue/daemon/otlp_receiver.py
  • polylogue/storage/sqlite/connection_profile.py
  • tests/unit/daemon/test_daemon_cli.py
  • tests/unit/storage/test_wal_journal_size_limit.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/perf/daemon-sqlite-memory-profile

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

github-actions Bot pushed a commit that referenced this pull request Jun 19, 2026
@Sinity
Sinity merged commit 0227d0f into master Jun 19, 2026
14 checks passed
@Sinity
Sinity deleted the feature/perf/daemon-sqlite-memory-profile branch June 19, 2026 16:44
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.

perf(daemon): bound SQLite cache pressure in long-running services

1 participant