Skip to content

feat(daemon,status): budgeted component-snapshot protocol for status surfaces - #3107

Merged
Sinity merged 3 commits into
masterfrom
feature/perf/snappy-surfaces
Jul 18, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/perf/snappy-surfaces

Conversation

@Sinity

@Sinity Sinity commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

Introduces a shared, budgeted component-snapshot protocol and cuts the
daemon/archive status surface over to it, fixing the reported polylogued status hang. This is PR 1/2-3 for polylogue-20d.17 (agent-coordination
status + polylogue-20d.14 measured budgets land in a follow-up PR per the
lane cadence).

Problem

Live dogfood found polylogued status producing no result within 15
seconds 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):

  1. polylogued status always recomputed the full rich status
    synchronously 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/status route. Reproduced: >60s
    timeout
    even with a healthy daemon running.
  2. build_daemon_status() chained ~14 facts (FTS readiness, raw
    materialization, 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 outside
    build_daemon_status(), in the wrapping daemon_status_payload(),
    uncovered by any existing bound. Reproduced (no daemon, direct path):
    >90s timeout.

Solution

  • 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 and
    fingerprint-based invalidation so a changed source can't hide behind an
    unexpired TTL. Collectors run on plain daemon=True threads rather than
    concurrent.futures.ThreadPoolExecutor, whose executor registers a
    process-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 while
    one hangs.
  • build_daemon_status() now runs its ~14 facts through a fresh per-call
    registry instead of a sequential call chain. component_readiness gains
    an additive collection block exposing the new state/age/deadline axis
    alongside 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()'s archive_debt listing is now bounded the
    same way (3s deadline, falls back to the existing cheap excluded-pointer
    payload on timeout).
  • 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 already does, fix(tests): workspace_env doesn't isolate POLYLOGUE_* env vars from live host daemon #1325), falling back to the
    now-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 ~50
tests 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

devtools test tests/unit/operations/test_status_protocol.py \
  tests/unit/daemon/test_daemon_status.py tests/unit/daemon/test_daemon_cli.py
# 151 passed, including a new anti-vacuity test
# (test_daemon_status_payload_stalled_component_does_not_block_healthy_components)
# that patches one collector to sleep past its deadline and asserts the
# whole daemon_status_payload() call still returns within ~3s with that
# component reporting timed_out while a healthy sibling reports fresh —
# this fails on the pre-PR synchronous call chain.

devtools verify --quick   # green (format, lint, mypy --strict, render all --check,
                          # topology, layering, test-clock-hygiene, ...)

Pre-existing, unrelated failures classified before starting (confirmed
present on the unmodified baseline via git stash, unaffected by this
diff): 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 a
RuntimeServices has no config projection composition-root error and one
stale 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)

Scenario Before After
polylogued status, live daemon running >60s (timeout) — reproduces the reported bug verbatim 2.2–2.4s (dominated by cold Python import; status_snapshot.age_s<1, confirmed reading the daemon's fresh cached snapshot, not recomputing)
polylogued status, no daemon (direct path) >90s (timeout) ~8.5s, bounded and deterministic across 3 runs (8.47/8.53/8.75s); raw_materialization/embeddings report timed_out, search/archive_storage report fresh
polylogued status / polylogue status, demo archive (16 sessions, no daemon) ~2.2–2.5s ~2.2–2.5s (unchanged — at demo scale no component is ever slow enough to exercise the fix; included per the lane's Phase-0 method, cited honestly rather than omitted)

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

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 18, 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: 55 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

Run ID: 031b84cd-ce11-44d7-ba44-5c48e1ced49e

📥 Commits

Reviewing files that changed from the base of the PR and between 64172d0 and fa301ac.

📒 Files selected for processing (7)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/daemon/cli.py
  • polylogue/daemon/status.py
  • polylogue/operations/status_protocol.py
  • tests/unit/daemon/test_daemon_status.py
  • tests/unit/operations/test_status_protocol.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/perf/snappy-surfaces

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 3 commits July 18, 2026 18:41
…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
@Sinity
Sinity force-pushed the feature/perf/snappy-surfaces branch from c5a7768 to fa301ac Compare July 18, 2026 16:43
@Sinity
Sinity merged commit 861210c into master Jul 18, 2026
3 checks passed
@Sinity
Sinity deleted the feature/perf/snappy-surfaces branch July 18, 2026 16:45
Sinity added a commit that referenced this pull request Jul 18, 2026
…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
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