Repository navigation
feat(daemon,status): budgeted component-snapshot protocol for status surfaces - #3107
Conversation
|
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: 55 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 (7)
✨ 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 |
…surfaces Problem: polylogue-20d.17 — polylogued status hung >15s (reproduced here as >60-90s unbounded) even with a healthy daemon, because it always recomputed the full rich status synchronously in a fresh process instead of asking the already-running daemon for its periodically-refreshed cached snapshot. The daemon's own build_daemon_status() sequentially chained ~14 facts (FTS, raw materialization, embedding readiness, archive debt, health, ...), so one slow probe on a large archive stalled every fact behind it in the chain, with no explicit per-component state — a stalled component was indistinguishable from a fast one until the whole call finally returned or never did. What changed: - New polylogue/operations/status_protocol.py: a generic StatusComponentSpec/StatusComponentRegistry protocol. Each declared component collects on its own daemon thread under its own deadline; overall wall time is bounded by the slowest unresolved component, not the sum. States: fresh/stale/refreshing/timed_out/unavailable/degraded, with last-good evidence retained across failures. Collectors run on daemon threads (not concurrent.futures, whose executor would otherwise hang interpreter exit behind a permanently-stuck collector). - build_daemon_status() now collects its ~14 facts through a fresh per-call registry instead of one sequential call chain; component_readiness gains an additive "collection" block exposing the new state/age/deadline axis alongside the existing business-readiness vocabulary. - daemon_status_payload()'s archive_debt listing (previously unbounded, outside build_daemon_status entirely) is now bounded the same way. - polylogued status now asks the running daemon's /api/status for its cached snapshot first (honouring POLYLOGUE_DAEMON_URL like the archive CLI's polylogue status, #1325), falling back to the now-bounded direct computation only when no daemon answers. Verification: - devtools test tests/unit/operations/test_status_protocol.py tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_daemon_cli.py — 149 passed, including a new anti-vacuity test proving a stalled collector times out without delaying a healthy sibling. - devtools verify --quick — green. - Live-archive read-only measurement (POLYLOGUE_ARCHIVE_ROOT=live archive, provisional: archive is mid-restore per 2026-07-18 incident): - polylogued status, live daemon running: >60s (timeout, reproduces the reported bug) -> 2.2-2.4s (bounded by cold Python import, now serving the daemon's fresh cached snapshot, age_s<1). - polylogued status, no daemon (direct path): >90s (timeout) -> ~8.5s bounded and deterministic, with raw_materialization/embeddings reporting timed_out while search/archive_storage report fresh. Ref polylogue-20d.17
Ref polylogue-20d.17
Ref polylogue-20d.17
c5a7768 to
fa301ac
Compare
…3116) ## Summary Second PR for polylogue-20d.17: extends the budgeted component-snapshot protocol from PR #3107 (daemon/archive status) to the agent-coordination envelope, bounding its one genuinely expensive, unbounded stage. Scope narrowed mid-implementation after a real architectural discovery — see "Scope note" below. ## Problem Live measurement of `build_coordination_envelope` against the real (large, currently mid-restore) archive found its `archive_evidence` stage — session trees, activity episodes, subagent exchanges, proof refs, and context-flow refs, one read-only SQLite connection with no per-query timeout — taking **~10s**, while every other stage (repo, process, self, work_item, beads, peers, resources, archive, handoff, overlaps, advisories) stayed under 1s. Any caller of `build_coordination_envelope` paid this cost on every call, including the live `polylogue agents status` CLI command — the same "one slow probe stalls the whole answer" failure shape PR #3107 fixed for daemon status. ## Solution - `polylogue/coordination/envelope.py`: new `_bounded_stage` helper, backed by the shared `StatusComponentRegistry` protocol from PR #3107, wraps `archive_evidence` with a 3s deadline and an explicit degraded fallback (surfaced in the envelope's `advisories`) instead of blocking however long the query takes. The query keeps running on its own thread past the deadline (no cooperative cancellation for a blocking SQLite read), but the caller gets control back. - New `CoordinationEnvelopeCache` class (also `StatusComponentRegistry`- backed, fingerprint-invalidated on git HEAD/logs, `.beads/issues.jsonl`, and the active index db/WAL mtimes) is ready substrate for a future warm-cached coordination-status consumer. Not wired to a live surface in this PR — see below. ## Scope note (read this before reviewing the diff) This PR originally also rewired the MCP `agent_coordination` tool's ad-hoc 1s TTL-only cache onto `CoordinationEnvelopeCache`, mirroring PR #3107's MCP-cache treatment. While rebasing onto master (which had moved past a six-tool MCP surface cutover, `feature/mcp/retire-legacy-registrars`), I found that tool is **already dead code**: `register_tools()` — the actual live MCP server wiring in `polylogue/mcp/server.py` — only calls `register_cutover_read_tools`/`register_cutover_privileged_tools` from `server_cutover.py`, never `register_read_tools` (where `agent_coordination` lives). Its dedicated test file was already deleted by the six-tool cutover (#3095) with no replacement coverage, which is how this went unnoticed. The live, reachable coordination-status path today is `status(scope="coordination")` in `server_cutover.py` — and it has a separate, pre-existing bug: every scope value except `"operation"` falls through to the same generic `archive.stats()` projection, so `status(scope="coordination")` silently returns archive stats, never coordination data. Wiring `CoordinationEnvelopeCache` into that handler is real, valuable follow-up work, but it sits inside another lane's actively in-flight cutover and risks colliding with concurrent changes there. Filed as **polylogue-qink** instead of attempted here. ## Verification ``` devtools test tests/unit/coordination/ tests/unit/mcp/ # 199 passed mypy --strict polylogue/coordination/envelope.py polylogue/coordination/__init__.py # clean devtools verify --quick # green ``` Live-archive read-only measurement (provisional — archive mid-restore from the 2026-07-18 incident): | Path | Before | After | | --- | --- | --- | | `archive_evidence` stage (in-process) | ~10.0s (unbounded) | capped at the 3.0s deadline, degraded reason surfaced in `advisories` | | `polylogue agents status --format json` (live CLI, no MCP) | would be ~11s+ with the unbounded stage | ~5.1s (import tax + bounded stages) | Ref polylogue-20d.17
Summary
Introduces a shared, budgeted component-snapshot protocol and cuts the
daemon/archive status surface over to it, fixing the reported
polylogued statushang. This is PR 1/2-3 for polylogue-20d.17 (agent-coordinationstatus + polylogue-20d.14 measured budgets land in a follow-up PR per the
lane cadence).
Problem
Live dogfood found
polylogued statusproducing no result within 15seconds although daemon heartbeat and database descriptors were healthy
(polylogue-20d.17). Root-caused to two distinct issues, both reproduced
below against the real live archive (read-only):
polylogued statusalways recomputed the full rich statussynchronously in a fresh process — it never asked the already-running
daemon for the periodically-refreshed cached snapshot the daemon already
maintains for its own HTTP
/api/statusroute. Reproduced: >60stimeout even with a healthy daemon running.
build_daemon_status()chained ~14 facts (FTS readiness, rawmaterialization, embedding readiness, health, ...) as one sequential
synchronous call, each with every expensive diagnostic flag defaulted
on, so one slow probe on a large archive stalled every fact behind it —
with no way to tell a stalled component from a fast one until the whole
call returned or never did. A fourth unbounded call
(
_archive_debt_status_summary()) lived entirely outsidebuild_daemon_status(), in the wrappingdaemon_status_payload(),uncovered by any existing bound. Reproduced (no daemon, direct path):
>90s timeout.
Solution
polylogue/operations/status_protocol.py: a genericStatusComponentSpec/StatusComponentRegistryprotocol. Each declaredcomponent collects on its own daemon thread under its own deadline;
overall wall time is bounded by the slowest unresolved component, not
the sum. States:
fresh/stale/refreshing/timed_out/unavailable/degraded, with last-good evidence retained across failures andfingerprint-based invalidation so a changed source can't hide behind an
unexpired TTL. Collectors run on plain
daemon=Truethreads rather thanconcurrent.futures.ThreadPoolExecutor, whose executor registers aprocess-exit join that would hang the interpreter forever behind one
permanently-stuck collector — a real risk here (blocking SQLite/subprocess
work). At most one attempt is ever in flight per component, so thread
count stays bounded regardless of how many
collect()calls happen whileone hangs.
build_daemon_status()now runs its ~14 facts through a fresh per-callregistry instead of a sequential call chain.
component_readinessgainsan additive
collectionblock exposing the new state/age/deadline axisalongside the existing business-readiness vocabulary (a component can be
business-ready from a stale collection, or business-degraded from a
fresh one — independent axes, not collapsed).
daemon_status_payload()'sarchive_debtlisting is now bounded thesame way (3s deadline, falls back to the existing cheap excluded-pointer
payload on timeout).
polylogued statusnow asks the running daemon's/api/statusfor itscached snapshot first (honouring
POLYLOGUE_DAEMON_URLlike the archiveCLI's
polylogue statusalready does, fix(tests): workspace_env doesn't isolate POLYLOGUE_* env vars from live host daemon #1325), falling back to thenow-bounded direct computation only when no daemon answers.
Deferred (named, not silently dropped): a persistent daemon-lifetime
registry with real cross-tick staleness/last-good reuse (this PR uses a
fresh ephemeral registry per call, which is correct for
build_daemon_status()'s existing "pure recompute" contract used by ~50tests with varying params, but doesn't yet give the daemon's own periodic
refresh loop cross-tick caching benefits beyond what it already had);
per-component dependency declarations (a few facts are still combined via
cheap pure post-processing after independent collection, not through the
registry's own dependency graph); agent-coordination status onto the same
protocol and polylogue-20d.14's measured budgets (next PR).
Verification
Pre-existing, unrelated failures classified before starting (confirmed
present on the unmodified baseline via
git stash, unaffected by thisdiff): 8 failures + 8 errors across
test_check.py,test_check_support_runtime.py,test_plain_cli_snapshots.py,test_tool_contracts.py::TestStatsTool,test_web_reader.py— a mix of aRuntimeServices has no config projectioncomposition-root error and onestale snapshot, none touching status/daemon/operations code.
Before/after latency (live archive, read-only; provisional — the
archive is mid-restore from the 2026-07-18 poisoned-index incident per
lane notes, so absolute numbers will shift once the drain completes)
polylogued status, live daemon runningstatus_snapshot.age_s<1, confirmed reading the daemon's fresh cached snapshot, not recomputing)polylogued status, no daemon (direct path)raw_materialization/embeddingsreporttimed_out,search/archive_storagereportfreshpolylogued status/polylogue status, demo archive (16 sessions, no daemon)The residual ~8.5s on the direct/no-daemon live-archive path (vs. the
individual 1.5–3s per-component deadlines) is Python cold-import overhead
plus real concurrent SQLite contention on a large file, not sequential
summation — the anti-vacuity test proves the isolation property directly.
Tightening these deadlines from measured distributions is exactly
polylogue-20d.14's job in the follow-up PR, not invented here.
Ref polylogue-20d.17