Skip to content

fix(mcp): wire status(scope=coordination) to coordination logic - #3128

Merged
Sinity merged 1 commit into
masterfrom
feature/perf/snappy-surfaces
Jul 18, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/perf/snappy-surfaces

Conversation

@Sinity

@Sinity Sinity commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

status(scope="coordination") on the six-tool MCP cutover surface silently returned generic archive.stats() instead of coordination status.

Problem

register_cutover_read_tools's status verb dispatched every scope except "operation" to the same archive.stats() projection. An agent calling status(scope="coordination") got archive stats, not coordination data — discovered while porting polylogue-20d.17's budgeted component-snapshot protocol to coordination status (#3116).

Solution

  • status(scope="coordination") now dispatches to real coordination logic: compact requests reuse a lazily-constructed CoordinationEnvelopeCache (fingerprint-invalidated on git HEAD/logs/.beads/issues.jsonl/index db-WAL mtimes, per perf(coordination): bound the archive_evidence stage to a deadline #3116's substrate), "detail" requests bypass the cache and call build_coordination_envelope directly — matching the fresh/detail semantics the other status scopes already use.
  • The cache is constructed lazily inside register_cutover_read_tools's closure so sessions that never call status(scope="coordination") don't pay polylogue.coordination's import cost.

Scope note (polylogue-qink AC-3)

qink's AC also asked to "decide and act on register_read_tools/agent_coordination's fate" (the old standalone MCP tool, unreachable from the live server). That deletion is Lane C's in-flight six-tool-cutover scope (polylogue-t46.8) and has since landed on master via #3118 (refactor(mcp): delete dead legacy MCP registrar code) — no action needed here.

Verification

  • devtools test tests/unit/mcp/test_status_scope_coordination.py — 2 passed. Drives the live registered status tool function end-to-end (not a hand-built registrar): proves the response is coordination-shaped with no "archive" key (regression for the silent-fallthrough bug), and that a second compact call hits the warm cache (1 build call across 2 compact + 1 detail invocation) while detail always goes live.
  • mypy --strict polylogue/mcp/server_cutover.py — clean.
  • devtools verify --quick — exit 0 (ran pre-commit and pre-push).

Ref polylogue-qink

Problem: the six-tool cutover surface's status(scope=...) fell through to
generic archive.stats() for every scope except "operation" -- an agent
calling status(scope="coordination") silently got archive stats and never
touched coordination status at all.

What changed: register_cutover_read_tools dispatches scope="coordination"
to real coordination logic -- compact requests reuse a lazily-constructed
CoordinationEnvelopeCache (fingerprint-invalidated per #3116's substrate),
detail requests call build_coordination_envelope directly, bypassing the
cache to match the fresh/detail semantics other status scopes already use.

Verification: tests/unit/mcp/test_status_scope_coordination.py drives the
live registered tool function end-to-end and proves (a) the response has
coordination-shaped fields with no "archive" key, where before it silently
returned archive stats, and (b) the second compact call hits the warm cache
while a detail call always goes live. devtools test
tests/unit/mcp/test_status_scope_coordination.py: 2 passed. mypy --strict
polylogue/mcp/server_cutover.py: clean. devtools verify --quick: exit 0.

Ref polylogue-qink
@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: 41 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: 18b26c5e-8ada-4264-a869-67e1adee230d

📥 Commits

Reviewing files that changed from the base of the PR and between 336584e and c9ccfb6.

📒 Files selected for processing (2)
  • polylogue/mcp/server_cutover.py
  • tests/unit/mcp/test_status_scope_coordination.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
Sinity merged commit 44d9b20 into master Jul 18, 2026
3 checks passed
@Sinity
Sinity deleted the feature/perf/snappy-surfaces branch July 18, 2026 21:22
Sinity added a commit that referenced this pull request Jul 18, 2026
## Summary
`build_coordination_envelope`'s expensive `archive_evidence` sub-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_stage` built a throwaway `StatusComponentRegistry` on every
call. Live measurement found `archive_evidence` alone 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_stage` now accepts an optional persistent `registry`. When
given, it's reused as-is (the `call` argument is ignored — the
registry's own collector already knows how to recompute what it needs).
- `CoordinationEnvelopeCache` owns one persistent `archive_evidence`
`StatusComponentRegistry` per cwd (fingerprint-invalidated the same way
as the outer envelope registry), threaded into
`build_coordination_envelope` via a 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; 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, since a one-shot process has nothing to resume across.
- Fixed a self-deadlock found during development: `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, unchanged by this
PR: "bounded" (existing `deadline_s`), and "limit constrains collection
work" — the underlying archive_evidence SQL already uses `LIMIT ?` in
every query (verified by reading `_archive_activity_rows` and siblings),
not fetch-all-then-slice. "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, 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
Sinity added a commit that referenced this pull request Jul 18, 2026
…ver (#3132)

## Summary

Closes the three documented "Known gaps" from PR #3095's six-tool MCP
read algebra: no way to list personal-state records back, no
postmortem/pathology reports, and `status(scope="sources"/"embeddings")`
silently falling through to archive stats.

## Problem

PR #3095 replaced the ~97-tool MCP surface with six read transactions
(`query`/`read`/`get`/`explain`/`context`/`status`) plus four privileged
transactions. It shipped with a documented "Known gaps" section
admitting three read capabilities lost no equivalent dispatch in the new
surface:

1. Personal-state listing
(marks/annotations/saved-views/recall-packs/workspaces/corrections/blackboard
notes) — `write()` could create these records but nothing could list
them back.
2. Postmortem/pathology reports — the retired
`get_postmortem_bundle`/`get_pathologies` tools had no successor.
3. `status(scope="sources"/"embeddings")` — declared in the `status()`
signature but both silently fell through to the same `scope="archive"`
payload.

All three were confirmed "trivial": the underlying `Polylogue` facade
calls stayed live and independently tested through the cutover
(unchanged by it); only the MCP dispatch wiring was missing.

## Solution

All changes are in `polylogue/mcp/server_cutover.py`:

- **`query(projection=...)`** gains 7 personal-state projections
(`marks`, `annotations`, `saved_views`, `recall_packs`, `workspaces`,
`corrections`, `blackboard`), each a thin dispatch onto the existing
`list_*` facade call + `page_items` + the existing typed payload class
(`MCPUserMarkListPayload` etc., which survived the cleanup PR unused).
Offset pagination is not yet exposed (mirrors the existing
`projection="sessions"` precedent, which also fixes offset at 0).
- **`query(projection=...)`** gains `postmortem`/`pathologies`, reusing
`build_session_query_request`'s filter scaffolding and dropping the MCP
default page limit (`replace(spec, limit=None)`) before handing the spec
to the 200-session analysis cap — the same trick the retired
`get_postmortem_bundle`/`get_pathologies` tools used, otherwise the
shared page-size default of 10 silently caps the matched scope and
defeats the facade's own analysis cap. Also adds
`abandoned_sessions`/`stuck_sessions` as two more thin projections (no
semantic overlap found with postmortem/pathologies, so kept separate per
the plan's documented fallback).
- **`status(scope="sources")`** wires the existing
`named_source_freshness` handler through the already-unused `ref`
parameter (single-source by design, matching the retired tool's own
scope).
- **`status(scope="embeddings")`** wires `embedding_status_payload` via
a small `_EmbeddingStatusEnv` config adapter (mirrors the retired
`embedding_status` tool), with
`include=("detail",)`/`include=("bands",)` mapping to its
`include_detail`/`include_retrieval_bands` params.

Rebased onto master after #3128 landed a fifth `status()` scope
(`coordination`) concurrently — merged cleanly since it's a disjoint `if
scope == ...` branch in the same function; also updated `status()`'s
docstring to describe all four now-wired non-archive scopes.

No new MCP declaration rows needed: `query`/`status` already exist in
`TARGET_DEFAULT_READ_ALGEBRA` with result-semantics broad enough to
cover the new projections/scopes (documented in each function's
docstring, matching the `context(intent="resume")` precedent).

## Verification

- `devtools test tests/unit/mcp/` — 184 passed (16 new, in
`tests/unit/mcp/test_query_gap_projections.py`).
- `devtools verify --quick` — green (format/lint/mypy
--strict/render-all-check).
- Live read-only smoke pass
(`POLYLOGUE_ARCHIVE_ROOT=~/.local/share/polylogue` via `sinnix-scope
background`, same pattern as #3095) against the real ~18k-session
archive: all 12 new projections/scopes returned valid payloads with no
errors — `postmortem`/`pathologies` matched 153 sessions over the last 7
days, `abandoned_sessions` found 74, `status(scope=embeddings)` reported
real catch-up state (`total_sessions=2498`), `status(scope=sources)`
returned a real freshness projection.

Ref polylogue-t46.8.2

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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