Skip to content

docs(storage): document why session_insights doctor repair isn't redundant - #3579

Merged
Sinity merged 2 commits into
masterfrom
feature/docs/session-insights-repair-keep-reason
Aug 2, 2026
Merged

docs(storage): document why session_insights doctor repair isn't redundant#3579
Sinity merged 2 commits into
masterfrom
feature/docs/session-insights-repair-keep-reason

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Documents, inline on repair_session_insights, the concrete mechanism gap that makes doctor --repair --target session_insights genuinely not redundant with the daemon's automatic convergence paths. No behavior change.

Problem

polylogue-cfvvt's automagic-invariants audit found doctor --repair --target session_insights structurally similar to the redundancy shape that justified removing blob-gc's --yes mutate path (#3575): two automatic mechanisms already exist (the per-ingest insights ConvergenceStage, and a periodic convergence_debt retry loop). It deliberately deferred a final delete-or-keep call to polylogue-ygfwa rather than rushing it, since session_insights repair is threaded through more surface (REPAIR_HANDLERS, the maintenance planner/replay executor, archive-debt status reporting) than a single CLI file.

Solution

Traced both automatic mechanisms end to end:

  • make_insights_stage (polylogue/daemon/convergence_stages.py)
  • the periodic drain loop (_periodic_convergence_check_retry_convergence_debt_once_drain_convergence_debt_once in polylogue/daemon/cli.py), which just re-drives make_default_convergence_stages

Both only ever call rebuild_session_insights_sync (per-session profile/work_events/phases). Neither calls refresh_session_insight_aggregates_sync — the archive-wide refresh of thread materialization (threads/thread_sessions), tag rollups (session_tag_rollups), and provider-day aggregates. repair_session_insights is the only caller of refresh_session_insight_aggregates_sync in the tree (confirmed by grep across daemon/ and the rest of the codebase); it invokes that refresh whenever _session_insight_aggregate_debt_count (missing_thread_materialization_count, stale_thread_count, orphan_thread_count, stale_tag_rollup_count, stale_day_summary_count) is nonzero.

So a SESSION_INSIGHT_MATERIALIZER_VERSION bump (or anything else that stales thread/tag-rollup aggregates archive-wide) leaves that debt stuck forever unless the manual repair runs — the daemon has no automatic route to clear it. repair_session_insights is also reused directly (not via the doctor CLI) by maintenance/rebuild_index.py's terminal stage, to materialize insights for a freshly built inactive generation before promotion — a scenario the daemon (which only ever touches the live/active generation) cannot reach at all.

Disposition: KEEP-WITH-REASON, following the same evidence bar as the rebuild-index investigation (polylogue-rpuqn), which similarly found the daemon path was not actually equivalent at full scope and correctly kept the manual command.

Verification

devtools verify --quick — exit 0, all 19 checks pass (docstring-only change, static gates only; no behavior touched, no test selection needed).

Ref polylogue-ygfwa

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 reviews.

How do review limits work?

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

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, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6c245335-fea0-4c78-afcf-e0dd4d536b76

📥 Commits

Reviewing files that changed from the base of the PR and between b914b3d and 9de444e.

📒 Files selected for processing (2)
  • .beads/issues.jsonl
  • polylogue/storage/repair.py

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.

Sinity added 2 commits August 2, 2026 21:34
…ndant

Problem: polylogue-cfvvt's automagic-invariants audit found that
`doctor --repair --target session_insights` looks covered by two
daemon automatic mechanisms (the per-ingest insights ConvergenceStage
and the periodic convergence_debt retry loop), the same redundancy
shape used to justify removing blob-gc's --yes mutate path (#3575).
It deferred a final call to polylogue-ygfwa pending a closer look,
since session_insights repair is threaded through more surface than a
single-file deletion.

Solution: traced both automatic mechanisms (make_insights_stage in
daemon/convergence_stages.py and the periodic drain in daemon/cli.py)
and confirmed they only ever call rebuild_session_insights_sync
(per-session profile/work_events/phases). Neither calls
refresh_session_insight_aggregates_sync, the archive-wide refresh of
thread materialization, tag rollups, and provider-day aggregates that
repair_session_insights runs when aggregate debt is nonzero --
verified via grep that repair.py is the only caller of that function
in the tree. repair_session_insights is also reused directly by
maintenance/rebuild_index.py's terminal stage to materialize insights
for a freshly built inactive generation before promotion, a scenario
the daemon (which only touches the live/active generation) cannot
reach. This is a real gap, not audit-summary redundancy: KEEP-WITH-
REASON, not DELETE. Documented the specific mechanism gap inline on
repair_session_insights so a future redundancy pass doesn't have to
re-derive it.

Verification: devtools verify --quick (exit 0, all 19 checks pass);
docstring-only change, no behavior touched.

Ref polylogue-ygfwa
@Sinity
Sinity force-pushed the feature/docs/session-insights-repair-keep-reason branch from 4ce8196 to 9de444e Compare August 2, 2026 19:36
@Sinity
Sinity merged commit f992b11 into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/docs/session-insights-repair-keep-reason branch August 2, 2026 19:38
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