Skip to content

fix(daemon): make periodic status refresh resume slow embedding readiness - #3377

Merged
Sinity merged 1 commit into
masterfrom
feature/perf/daemon-status-embedding-resumability
Jul 28, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/perf/daemon-status-embedding-resumability

Conversation

@Sinity

@Sinity Sinity commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

Extends polylogue-20d.17's budgeted-component-snapshot protocol (PR #3107/#3116/#3131) with the resumable-detail-query pattern for the daemon's own periodic status refresh, following live measurement that found a real, unfixed instance of the exact resumability gap PR #3131 fixed for coordination's archive_evidence stage.

Problem

Live measurement against the real archive at /realm/db/polylogue found embedding_readiness_info taking ~5.06s while its declared deadline_s in build_daemon_status's component list is 2.0s. The daemon's periodic status-snapshot refresh (_periodic_status_snapshot_refresh, every 10s for the process lifetime — daemon/cli.py) calls daemon_status_payload -> build_daemon_status, which built a brand-new ephemeral StatusComponentRegistry on every tick. A component slower than its own deadline therefore timed out and was discarded on every single tick, forever — it could never converge on a real value — and each tick leaked one orphaned collector thread (a timed-out attempt cannot be cancelled and keeps running past the deadline on its own background thread). This is the same resumability gap PR #3131 fixed for coordination's archive_evidence stage, now found and fixed on the daemon status side.

None of build_daemon_status's ~14 components had a fingerprint either, so even a persistent registry would have hidden a changed archive/ops source behind the 10s ttl_s window (polylogue-20d.17 AC #5).

Solution

  • Extracted build_daemon_status's inline StatusComponentSpec list into _daemon_status_component_specs(), shared by the existing ephemeral per-call path and a new persistent factory.
  • periodic_status_component_registry() lazily builds ONE process-wide StatusComponentRegistry (module singleton) with the same fixed parameters refresh_status_snapshot always passes (include_raw_replay_backlog=False, include_exact_raw_materialization_readiness=False, fast-tier health only), plus a real source fingerprint (_daemon_status_fingerprint: index db + ops db + their -wal mtimes) so a changed archive/ops source forces a refresh even inside the ttl window.
  • build_daemon_status/daemon_status_payload gained an optional registry parameter, threaded through by refresh_status_snapshot's periodic call. Direct one-shot CLI/API status calls keep the default None — unchanged fresh-per-call ephemeral registry, correct for their pure-recompute contract (all pre-existing parameterized tests pass unmodified).

Investigated and found NOT to need this treatment (false alarm, same methodology as polylogue-dhjz): coordination/envelope.py's beads and handoff stages, and daemon/status.py's archive_debt/assertion_candidate_queue ephemeral registries.

  • Beads probes are already bounded via real subprocess-timeout cancellation (unlike the unbounded blocking-SQL problem archive_evidence had, which is why it needed a background-thread registry in the first place).
  • handoff is a cheap filesystem glob + LIMIT-bounded SQLite query.
  • archive_debt/assertion_candidate_queue are only ever reached from one-shot polylogue check/polylogued status CLI invocations (verified by grepping every call site) — no cross-call state exists for a persistent registry to preserve.

Full detail recorded on the polylogue-20d.17 bead notes.

Verification

  • New anti-vacuity test test_periodic_status_component_registry_resumes_slow_embedding_readiness_across_ticks: proves the collector is invoked exactly once across three ticks (timed_out -> refreshing -> fresh) despite exceeding its deadline. Confirmed it fails on the pre-fix ephemeral-registry behavior (reverted the registry-reuse check, reran, saw a duplicated attempt) and fails when refresh_status_snapshot stops threading the registry through (reverted that wiring, reran, saw the same failure).
  • New test test_periodic_status_component_registry_fingerprint_forces_refresh proves a changed index db forces a fresh recollection inside the ttl_s window.
  • Live dogfood (read-only) against the real archive at /realm/db/polylogue: embedding_readiness_info measured ~5.06s standalone; against the fixed registry, tick 0 times out at the 2.0s deadline, ticks 1-2 (0.2s apart) observe refreshing without re-invoking the collector, and once the background attempt finishes (~8s total), a later poll returns fresh with the real embedding_coverage_percent=44.1. Artifact: .local/coordination/20d17-embedding-resumability-dogfood.json (untracked, .local/ per repo convention).
  • devtools test tests/unit/daemon/test_daemon_status.py — 63 passed.
  • mypy --strict polylogue/daemon/status.py polylogue/daemon/status_snapshot.py tests/unit/daemon/test_daemon_status.py — clean.
  • devtools verify --quick — exit 0 (ran twice: once pre-push, once via the pre-push hook).
  • Confirmed tests/unit/cli/test_status.py::test_archive_facade_route_catalog_covers_public_async_facade fails identically on baseline master (unrelated, pre-existing — not introduced by this change).

Ref polylogue-20d.17

…ness

Problem
-------
Live measurement against the real archive found embedding_readiness_info
taking ~5s while its declared deadline is 2.0s. The daemon's periodic
status-snapshot refresh (_periodic_status_snapshot_refresh, every 10s for
the process lifetime) called daemon_status_payload -> build_daemon_status,
which built a brand-new ephemeral StatusComponentRegistry on every tick.
A component slower than its own deadline_s therefore timed out and was
discarded on every single tick, forever -- it could never converge on a
real value -- and each tick leaked one orphaned collector thread (the
timed-out attempt cannot be cancelled and keeps running past the
deadline). This is the same resumability gap PR #3131 fixed for
coordination's archive_evidence stage, on the daemon status side.

Solution
--------
- Extracted build_daemon_status's inline StatusComponentSpec list into
  _daemon_status_component_specs(), shared by the existing ephemeral
  per-call path and a new persistent factory.
- periodic_status_component_registry() lazily builds ONE process-wide
  StatusComponentRegistry (module singleton) with the same fixed
  parameters refresh_status_snapshot always passes
  (include_raw_replay_backlog=False,
  include_exact_raw_materialization_readiness=False, fast-tier health),
  and a real source fingerprint (_daemon_status_fingerprint: index db +
  ops db + their -wal mtimes) so a changed archive/ops source forces a
  refresh even inside the 10s ttl_s window (polylogue-20d.17 AC #5 --
  previously none of these ~14 components had a fingerprint at all).
- build_daemon_status/daemon_status_payload gained an optional `registry`
  parameter, threaded through by refresh_status_snapshot's periodic call.
  Direct one-shot CLI/API status calls keep the default None -- unchanged
  fresh-per-call ephemeral registry, correct for their pure-recompute
  contract (all ~63 pre-existing parameterized tests pass unmodified).

Investigated and found NOT to need this treatment (false alarm, same
methodology as polylogue-dhjz): coordination/envelope.py's beads and
handoff stages, and daemon/status.py's archive_debt/
assertion_candidate_queue ephemeral registries. Beads probes are already
bounded via real subprocess-timeout cancellation (not the unbounded
blocking-SQL problem archive_evidence had); handoff is a cheap glob +
LIMIT-bounded query; archive_debt/assertion_candidate_queue are only ever
reached from one-shot `polylogue check`/`polylogued status` CLI
invocations (verified by grepping every call site), so there is no
cross-call state for a persistent registry to preserve. Detail in the
polylogue-20d.17 bead notes.

Verification
------------
- New anti-vacuity test
  test_periodic_status_component_registry_resumes_slow_embedding_readiness_across_ticks:
  proves the collector is invoked exactly once across three ticks
  (timed_out -> refreshing -> fresh) despite exceeding its deadline --
  fails on the pre-fix ephemeral-registry code (verified by reverting the
  registry-reuse check and confirming the test fails with a duplicated
  attempt), and fails when refresh_status_snapshot stops threading the
  registry through (verified the same way).
- New test test_periodic_status_component_registry_fingerprint_forces_refresh
  proves a changed index db forces a refresh inside the ttl_s window.
- Live dogfood (read-only) against the real archive at /realm/db/polylogue:
  embedding_readiness_info measured ~5.06s standalone; against the fixed
  registry, tick 0 times out at the 2.0s deadline, ticks 1-2 (0.2s apart)
  observe "refreshing" without re-invoking the collector, and once the
  background attempt finishes (~8s total), a later poll returns "fresh"
  with the real embedding_coverage_percent=44.1 -- artifact at
  .local/coordination/20d17-embedding-resumability-dogfood.json.
- devtools test tests/unit/daemon/test_daemon_status.py -- 63 passed.
- mypy --strict polylogue/daemon/status.py polylogue/daemon/status_snapshot.py
  tests/unit/daemon/test_daemon_status.py -- clean.
- devtools verify --quick -- exit 0.
- Confirmed tests/unit/cli/test_status.py::test_archive_facade_route_catalog_covers_public_async_facade
  fails identically on baseline master (unrelated, pre-existing).

Ref polylogue-20d.17

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 28, 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: 49 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: 13732acc-ddf7-4eff-aa97-f91b1e8cdd45

📥 Commits

Reviewing files that changed from the base of the PR and between 200606a and 45c17ad.

📒 Files selected for processing (3)
  • polylogue/daemon/status.py
  • polylogue/daemon/status_snapshot.py
  • tests/unit/daemon/test_daemon_status.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/perf/daemon-status-embedding-resumability

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
Sinity merged commit 1c1fdaf into master Jul 28, 2026
3 checks passed
@Sinity
Sinity deleted the feature/perf/daemon-status-embedding-resumability branch July 28, 2026 17:59

@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: 45c17adb22

ℹ️ 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/status_snapshot.py Resolved
@Sinity

Sinity commented Sep 30, 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.

  • 65.F014 / P2: Fix and current-source recheck assigned to polylogue-bwuz0; not claimed fixed. The current registry still finalizes a completed refresh and immediately continues at polylogue/operations/status_protocol.py:202-204, without starting a replacement on that tick. Submission-time age is now preserved at line 345, but the alternating start/finalize cadence remains when a cached component expires between periodic status ticks.

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