Skip to content

perf(daemon): bound session insight convergence reads - #1463

Merged
Sinity merged 1 commit into
masterfrom
feature/perf/bounded-session-insight-convergence
May 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/perf/bounded-session-insight-convergence

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026

Copy link
Copy Markdown
Owner

Summary

Bounds daemon session-insight convergence for large conversations by loading only the columns and bounded text previews that the insight materializer needs, then scopes daemon insight debt checks to profiles that are actually missing or stale.

Problem

The deployed #1462 fix removed the remaining source parse/write amplification, but the live daemon still entered unsafe IO pressure during the convergence phase for a 236 MB Codex session. The latest live_ingest_attempt row showed only ~1.17 MB of source payload reads but ~1.19 GB of physical reads over a five-second sample, with cgroup memory dominated by file cache rather than Python heap. The expensive work had moved to session-insight convergence hydrating a 33,150-message session.

Solution

load_sync_batch and load_async_batch now use explicit projections instead of SELECT *, truncating message text to 16 KiB and selected tool/thinking block text to 4 KiB. The archive rows remain exact; this only bounds the heuristic insight-refresh input.

The daemon insights stage now checks freshness before queueing work: missing profile rows, materializer-version mismatch, or session_profiles.source_updated_at != conversations.updated_at. Already-converged source paths/conversation IDs no longer re-trigger full insight rebuilds.

Verification

  • pytest tests/unit/daemon/test_convergence_stages.py tests/unit/storage/test_session_insight_refresh.py -q → 24 passed in 0.68s
  • ruff check polylogue/storage/insights/session/rebuild.py polylogue/daemon/convergence_stages.py tests/unit/storage/test_session_insight_refresh.py tests/unit/daemon/test_convergence_stages.py → All checks passed!
  • mypy polylogue/storage/insights/session/rebuild.py polylogue/daemon/convergence_stages.py tests/unit/storage/test_session_insight_refresh.py tests/unit/daemon/test_convergence_stages.py → Success: no issues found in 4 source files
  • devtools verify --quick → passed locally in 41.31s
  • pre-push devtools verify --quick → passed in 35.07s
  • Real archive probe with polylogued.service stopped: rebuilt codex:019e309f-7614-7381-a8ac-f9080f304ee6 (33,150 messages) in 13.095s, physical read delta 434,913,280 bytes, max RSS 761 MB. After rebuild, the new daemon freshness predicate returned [] for the known large recent Codex sessions.

Ref #1447

Problem: deployed catch-up fixes still left large Codex sessions paying multi-GB physical reads during the insights convergence phase even after source parse and append writes were bounded.

What changed: session insight batch loading now projects explicit columns and bounded text previews instead of hydrating full message and tool-result payloads. The daemon insights stage also queues only missing or stale session profiles, so already-converged conversations are not rebuilt on every source-path check.

Verification: pytest tests/unit/daemon/test_convergence_stages.py tests/unit/storage/test_session_insight_refresh.py -q; ruff check on changed files; mypy on changed files; devtools verify --quick. Real archive probe rebuilt the 33,150-message Codex session in 13.095s with 434,913,280 physical read bytes and 761 MB max RSS, then the daemon freshness predicate returned no stale debt for the known large recent sessions.

Ref #1447
@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 13 minutes and 48 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8c30604d-26b3-446b-baf9-fe71dae71c96

📥 Commits

Reviewing files that changed from the base of the PR and between 591798e and e8b6221.

📒 Files selected for processing (4)
  • polylogue/daemon/convergence_stages.py
  • polylogue/storage/insights/session/rebuild.py
  • tests/unit/daemon/test_convergence_stages.py
  • tests/unit/storage/test_session_insight_refresh.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/perf/bounded-session-insight-convergence

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.

@Sinity
Sinity merged commit cc0bf5b into master May 24, 2026
6 checks passed
@Sinity
Sinity deleted the feature/perf/bounded-session-insight-convergence branch May 24, 2026 01:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e8b6221b6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/daemon/convergence_stages.py Resolved
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 62.F050 / P1: fixed-already at the checked revision: Session-profile validity now compares the persisted input binding with the current content-derived binding at polylogue/storage/derived/session/derivation.py:170. Its inspection computes session_input_bindings at line 237, so unchanged updated_at no longer certifies a profile whose source content changed.

Only the rows listed above are dispositioned. Held findings remain open.

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.

1 participant