Skip to content

fix(daemon): defer hot insight rebuilds - #1468

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/hot-insight-convergence-debt
May 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/hot-insight-convergence-debt

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026

Copy link
Copy Markdown
Owner

Summary

Defers expensive session-insight rebuilds for very large source files while they are still actively appending, without reducing daemon convergence scope. Archive writes and targeted FTS repair still run immediately; insight convergence becomes durable debt until the source is quiet.

Problem

After #1467 was deployed, the failed-file hot requeue loop stopped, but live monitoring still showed severe physical reads on tiny appends to huge active Codex sessions. source_payload_read_bytes was only a few KB per attempt while /proc/$pid/io showed roughly 2.36 GB of reads over 10s, pointing at derived session insight rebuilds rehydrating whole conversations on every append.

Solution

  • Add a 64 MiB / 60s quiet-window guard to the daemon insights stage.
  • Return convergence debt, not success, when a huge source is still hot so the daemon must still converge once the file quiets.
  • Mark this expected deferral with a fixed 60s retry cadence instead of exponential failure backoff.
  • Shorten the daemon's convergence-debt retry loop from 10 minutes to 60 seconds.
  • Add focused coverage for hot large deferral, quiet large rebuild, small active rebuild, and fixed retry scheduling.

Ref #1447

Verification

  • pytest -q tests/unit/daemon/test_convergence_stages.py tests/unit/daemon/test_daemon_convergence.py tests/unit/daemon/test_daemon_cli.py tests/unit/sources/test_live_catchup_planning.py -> 45 passed
  • pytest -q tests/unit/sources/test_live_watcher.py -> 60 passed
  • devtools verify --quick -> exit_code 0, total_duration_s 34.58
  • pre-push devtools verify --quick -> exit_code 0, total_duration_s 34.61

Problem: live deploy after the failed-file backoff fix still showed severe physical reads on tiny appends to very large active Codex session files. The source payload reads were only a few KB, so the remaining pressure came from derived session insight rebuilds rehydrating whole conversations on every append.

What changed: keep archive ingest and targeted FTS repair immediate, but defer session insight rebuild for source files at least 64 MiB that were modified within the last 60 seconds. The deferral records convergence debt instead of claiming success, retries on a fixed 60 second quiet-window cadence, and shortens the periodic debt drain to 60 seconds.

Verification: pytest -q tests/unit/daemon/test_convergence_stages.py tests/unit/daemon/test_daemon_convergence.py tests/unit/daemon/test_daemon_cli.py tests/unit/sources/test_live_catchup_planning.py; pytest -q tests/unit/sources/test_live_watcher.py; devtools verify --quick.

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 33 minutes and 59 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: bb8e7345-d114-4d2f-b707-059d8135ba25

📥 Commits

Reviewing files that changed from the base of the PR and between 154232c and ed8bb77.

📒 Files selected for processing (6)
  • polylogue/daemon/cli.py
  • polylogue/daemon/convergence.py
  • polylogue/daemon/convergence_stages.py
  • polylogue/sources/live/cursor.py
  • tests/unit/daemon/test_convergence_stages.py
  • tests/unit/sources/test_live_catchup_planning.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/hot-insight-convergence-debt

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 3ff28fd into master May 24, 2026
6 checks passed
@Sinity
Sinity deleted the feature/fix/hot-insight-convergence-debt branch May 24, 2026 03: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: ed8bb77f53

ℹ️ 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.py Resolved
Comment thread polylogue/daemon/convergence_stages.py Resolved
Sinity added a commit that referenced this pull request May 24, 2026
## Summary

Daemon FTS convergence now trusts an FTS surface only when durable freshness state is `ready` and the expected live sync triggers are present, avoiding whole-conversation docsize scans on every append to huge active sessions. This also adds targeted session-insight FTS repair so duplicate/stale insight FTS rows can be fixed without rebuilding all session insights.

## Problem

After #1468 was deployed, hot insight deferral worked, but live `polylogued` still read `879,820,800` physical bytes over a 10s append sample while `source_payload_read_bytes` stayed in the KB range. The remaining broad read path was `_fts_repair_needs_for_conversations`, which exact-scanned `messages`/`action_events` against FTS docsize tables for each changed huge conversation even when FTS was already marked ready and triggers were present.

## Solution

- `polylogue/daemon/convergence_stages.py` skips exact per-conversation FTS docsize scans for `messages_fts` and `action_events_fts` only when the FTS table, docsize table, all expected sync triggers, and `fts_freshness_state=ready` agree.
- Missing tables, stale/unknown freshness, missing freshness state, or missing triggers still use the existing exact scan/repair path.
- `polylogue/storage/fts/fts_lifecycle.py` exposes `rebuild_session_insight_fts_sync` for targeted session insight FTS rebuilds.
- `polylogue/storage/repair.py` uses the new repair assessment helper to clean FTS-only insight debt without forcing a full session insight rebuild.

Closes #1447

## Verification

- `pytest -q tests/unit/daemon/test_convergence_stages.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/integration/test_health.py::TestMaintenanceSelection::test_session_insight_repair_cleans_duplicate_fts_rows` -> `26 passed in 0.57s`
- `devtools verify-topology` -> `realized=830 declared=830 blocking=False`
- `devtools render-all --check` -> pass
- `devtools verify --quick` -> `exit_code 0`, `total_duration_s 34.84`
- pre-push `devtools verify --quick` -> `exit_code 0`, `total_duration_s 34.52`

## Changelog

Skip: internal daemon convergence and repair behavior only.

## Risks and Follow-ups

The live daemon is intentionally still stopped until this lands, updates the Sinnix flake input, and is deployed. The next validation step is another live `/proc/$pid/io`, cgroup memory, cursor/debt, and ingest-attempt sample against the real archive.
@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.F045 / P1: fixed-already at the checked revision: _stage_false_error no longer rewrites insights failures to a source-quiet deferral. It reports the actual stage and false result at polylogue/daemon/convergence.py:832-835; the insights-specific diagnostic and forced quiet-retry classification have been removed.
  • 62.F051 / P1: fixed-already at the checked revision: Session profiles now run through the per-key derivation kernel. A quiet/hot key is recorded as pending and returned from that key's work at polylogue/daemon/derivation.py:905-907, rather than aborting execution for every session in the mixed batch.

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