Repository navigation
perf(coordination): make archive_evidence collection resumable - #3131
Conversation
Problem: build_coordination_envelope's archive_evidence stage is bounded to a 3s deadline (#3116), but _bounded_stage built a throwaway StatusComponentRegistry on every call. A query slower than the deadline (observed live: ~10s) could never actually finish within any single attempt -- CoordinationEnvelopeCache's own ~1s outer TTL meant every refresh tick abandoned the previous attempt's still-running background thread and launched an equally-doomed new one, forever falling back to the degraded/empty result instead of ever converging on the real answer (polylogue-20d.17 AC #6: resumable detail collection). What changed: _bounded_stage now accepts an optional persistent registry; CoordinationEnvelopeCache owns one archive_evidence StatusComponentRegistry per cwd (fingerprint-invalidated the same way as the outer envelope registry) and threads it through build_coordination_envelope's new archive_evidence_registry parameter. A later tick that finds the registry's attempt still in flight now observes "refreshing" immediately instead of restarting the query, and once the background attempt actually finishes, every subsequent tick reuses that real result until its own TTL/fingerprint expires. Direct/CLI calls to build_coordination_envelope (detail requests, one-shot processes) are unaffected -- they still get a fresh ephemeral registry, matching pre-existing behavior, since a one-shot process has nothing to resume across. Fixed a self-deadlock introduced during development: CoordinationEnvelopeCache's get_or_build held its own lock while calling the new _archive_evidence_registry helper, which re-acquired the same lock -- threading.Lock isn't reentrant. Switched to RLock. The other two AC #6 properties were already satisfied and are unchanged: "bounded" (existing deadline_s), "limit constrains collection work" (the underlying archive_evidence SQL already uses LIMIT ? in every query, not fetch-all-then-slice -- verified by reading _archive_activity_rows and siblings). "Cancellable" means the caller is never blocked past deadline_s (already true); Python cannot safely preempt a blocking SQLite call mid-query, so this does not attempt true thread cancellation. Verification: new test test_coordination_envelope_cache_resumes_slow_archive_evidence_across_ticks proves the collector is invoked exactly once across three ticks (timed out, refreshing, fresh) despite the query taking longer than the deadline -- this fails on the pre-fix ephemeral-registry code (each tick would re-invoke the collector). devtools test tests/unit/coordination/test_envelope.py tests/unit/mcp/test_status_scope_coordination.py: 28 passed. mypy --strict polylogue/coordination/envelope.py: clean. devtools verify --quick: exit 0. Ref polylogue-20d.17
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 11 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
…t registry (#3377) ## Summary Fixes a real daemon bug: the periodic (10s-cadence) status snapshot refresh built a brand-new ephemeral StatusComponentRegistry every tick, so any component slower than its own declared deadline was restarted from scratch and discarded forever, leaking one orphaned collector thread per tick. Live measurement found embedding_readiness_info alone takes ~5s against the real archive against a declared 2.0s deadline -- this component never converged, ever, under the periodic path. ## Problem This is the same resumability gap PR #3131 already fixed for coordination's archive_evidence stage, but on the daemon status side. None of build_daemon_status's ~14 components had a fingerprint either (AC #5 gap). ## Solution Extracted the component spec list into _daemon_status_component_specs() (shared by both paths), added periodic_status_component_registry() -- a lazily-built, process-wide persistent registry, fingerprinted on index/ops db + WAL mtimes via a new _daemon_status_fingerprint() helper mirroring coordination's _coordination_fingerprint. Threaded an optional registry param through build_daemon_status/daemon_status_payload, wired only from refresh_status_snapshot's periodic call. One-shot CLI/API status paths are unaffected (registry=None default, unchanged ephemeral behavior). Investigated the rest of the AC #5 fingerprint gap and the other components; found most (beads, handoff, archive_debt, assertion_candidate_queue) are either already safely bounded or verified (by grepping every call site) to only ever run in one-shot processes with no cross-call state to lose -- documented honestly rather than force-changing things that weren't actually broken (same methodology as polylogue-dhjz). ## Verification - mypy --strict: clean - ruff check/format --check: clean - devtools test tests/unit/daemon/test_daemon_status.py -> 63 passed - devtools verify --quick -> exit 0 (one pre-existing unrelated failure, test_archive_facade_route_catalog_covers_public_async_facade, confirmed identical on baseline master) - Anti-vacuity: two new tests (resumability across ticks, fingerprint forcing refresh) both fail when reverting the fix, pass with it restored. - Live dogfood (read-only, real archive /realm/db/polylogue): tick 0 times out at 2.0s, ticks 1-2 observe refreshing without re-invoking the collector, tick after ~8s returns fresh with real embedding_coverage_percent=44.1. - CI: GitGuardian/CircleCI quick-gate pass, CodeRabbit review completed clean. Ref polylogue-20d.17
Summary
build_coordination_envelope's expensivearchive_evidencesub-stage (bounded to a 3s deadline in #3116) could never actually finish under sustained polling — it was silently restarted from scratch on every refresh tick, forever.Problem
_bounded_stagebuilt a throwawayStatusComponentRegistryon every call. Live measurement foundarchive_evidencealone taking ~10s while bounded to 3s (#3116).CoordinationEnvelopeCache's own outer envelope TTL is ~1s, so every refresh tick abandoned the previous attempt's still-running background thread (which kept executing, unobserved) and launched an equally-doomed new one — the query never got a chance to finish within any single attempt's window, and the coordination status MCP consumer (#3128) would degrade forever instead of eventually converging on the real answer. This is polylogue-20d.17 AC #6 ("exact expensive diagnostics are ... resumable").Solution
_bounded_stagenow accepts an optional persistentregistry. When given, it's reused as-is (thecallargument is ignored — the registry's own collector already knows how to recompute what it needs).CoordinationEnvelopeCacheowns one persistentarchive_evidenceStatusComponentRegistryper cwd (fingerprint-invalidated the same way as the outer envelope registry), threaded intobuild_coordination_envelopevia a newarchive_evidence_registryparameter.refreshingimmediately instead of restarting the query; once the background attempt actually finishes, every subsequent tick reuses that real result until its own TTL/fingerprint expires.build_coordination_envelope(detail requests, one-shot processes) are unaffected — they still get a fresh ephemeral registry, since a one-shot process has nothing to resume across.get_or_buildheld its own lock while calling the new_archive_evidence_registryhelper, which re-acquired the same lock (threading.Lockisn't reentrant). Switched toRLock.The other two AC #6 properties were already satisfied, unchanged by this PR: "bounded" (existing
deadline_s), and "limit constrains collection work" — the underlying archive_evidence SQL already usesLIMIT ?in every query (verified by reading_archive_activity_rowsand siblings), not fetch-all-then-slice. "Cancellable" means the caller is never blocked pastdeadline_s(already true); Python cannot safely preempt a blocking SQLite call mid-query, so this does not attempt true thread cancellation.Verification
test_coordination_envelope_cache_resumes_slow_archive_evidence_across_ticksproves the collector is invoked exactly once across three ticks (timed out → refreshing → fresh) despite the query taking longer than the deadline — this fails on the pre-fix ephemeral-registry code (each tick would re-invoke the collector, incrementing the call counter each time).devtools test tests/unit/coordination/test_envelope.py tests/unit/mcp/test_status_scope_coordination.py— 28 passed.mypy --strict polylogue/coordination/envelope.py— clean.devtools verify --quick— exit 0.Ref polylogue-20d.17