Repository navigation
perf: reduce interactive coordination and reset latency - #2809
Conversation
Problem: compact coordination status spent roughly two seconds waiting for\nan optional Beads merge-slot probe that timed out.\n\nWhat changed: record caller-owned stage timings, overlap independent\nBeads reads, cap live Beads probes at 350 ms with their existing error\npayload, and cache compact MCP responses for one second with an explicit\nfresh bypass.\n\nCompatibility: detail requests and fresh=true always rebuild; timed-out\nBeads data is reported as unavailable rather than reused.\n\nRef polylogue-s7ae.8
Problem: nested reset help imported archive mutation machinery before any\noperator selected a reset action.\n\nWhat changed: move query-path, tier-write, and mutation-payload imports to\nthe reset helpers that execute them.\n\nVerification: isolated-root warm help samples fell from the earlier 1.18 s\nto 0.30 s; tests/unit/cli/test_reset.py passed (30 tests).\n\nRef polylogue-20d.2
Keep the deferred reset payload import type-checked without restoring it to\nthe command module's help-time import path.\n\nRef polylogue-20d.2
|
Warning Review limit reached
Next review available in: 48 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 (1)
📝 WalkthroughWalkthroughThe PR adds coordination-envelope timing and concurrent Beads probing, introduces compact MCP response caching with a freshness override, adds a coordination-latency benchmark and documentation, and defers several reset-command imports. ChangesCoordination observability and reuse
Lazy command imports
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant MCPClient
participant agent_coordination
participant compact_coordination_cache
participant build_coordination_envelope
participant BeadsCLI
MCPClient->>agent_coordination: request coordination data
agent_coordination->>compact_coordination_cache: check compact cache
alt cache miss or fresh
agent_coordination->>build_coordination_envelope: build envelope with requested detail
build_coordination_envelope->>BeadsCLI: run hooks, gate, and merge-slot probes
BeadsCLI-->>build_coordination_envelope: return probe results
build_coordination_envelope-->>agent_coordination: return envelope
agent_coordination->>compact_coordination_cache: cache compact payload
else cached compact response
compact_coordination_cache-->>agent_coordination: return cached payload
end
agent_coordination-->>MCPClient: return coordination response
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
Produce raw compact coordination samples with per-stage timings, git head,\narchive context, and p50/p95 distribution summary.\n\nVerification: devtools bench coordination-latency --samples 7 produced a\nraw local artifact through the production envelope builder.\n\nRef polylogue-s7ae.8
Keep raw latency sample values typed before computing percentiles.\n\nRef polylogue-s7ae.8
Regenerate the devtools command reference for the new latency artifact\nproducer.\n\nRef polylogue-s7ae.8
|
Adversarial review iteration 1: I re-read both bead ACs, fetched master, inspected the full diff, and checked PR comments. Findings: the new harness measures only warm in-process core status—not randomized cold CLI or warm MCP—and its cache is TTL-keyed rather than source-fingerprint invalidated; neither is claimed as satisfying the full s7ae.8 AC. The fixed help-latency gate, importtime diff, and maintenance/archive-read nested-help work are also absent; 20d.2 remains explicitly in progress. The implemented tests are non-vacuous: the Beads test exercises production envelope fanout/timeout selection (removing either changes its stage timing/deadline), and the MCP test invokes the registered production tool (removing cache/fresh behavior changes builder calls). No substantive review feedback is available yet. |
Include non-content archive state alongside raw latency samples so campaign\ncomparisons retain their archive context.\n\nRef polylogue-s7ae.8
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@polylogue/mcp/server_tools.py`:
- Around line 1107-1133: Update the async run function so
build_coordination_envelope executes off the event-loop thread via the existing
async executor/offload pattern, including cache misses and every fresh=True
request. Await the offloaded result before caching and serializing it, while
preserving the current arguments and cache behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: b1ec9064-98e9-4350-9f62-fa329b587456
📒 Files selected for processing (8)
devtools/command_catalog.pydevtools/coordination_latency_probe.pydocs/devtools.mdpolylogue/cli/commands/reset.pypolylogue/coordination/envelope.pypolylogue/mcp/server_tools.pytests/unit/coordination/test_envelope.pytests/unit/mcp/test_agent_coordination.py
| async def run() -> str: | ||
| path = Path(cwd).expanduser().resolve() if cwd else None | ||
| payload = build_coordination_envelope( | ||
| view=view, | ||
| cwd=path, | ||
| limit=hooks.clamp_limit(limit), | ||
| detail=detail, | ||
| clamped_limit = hooks.clamp_limit(limit) | ||
| payload = ( | ||
| None | ||
| if detail or fresh | ||
| else compact_coordination_cache.get( | ||
| view=view, | ||
| cwd=path, | ||
| limit=clamped_limit, | ||
| ) | ||
| ) | ||
| if payload is None: | ||
| payload = build_coordination_envelope( | ||
| view=view, | ||
| cwd=path, | ||
| limit=clamped_limit, | ||
| detail=detail, | ||
| ) | ||
| if not detail: | ||
| compact_coordination_cache.put( | ||
| view=view, | ||
| cwd=path, | ||
| limit=clamped_limit, | ||
| payload=payload, | ||
| ) | ||
| return hooks.json_payload(payload, exclude_none=True) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔵 Trivial
build_coordination_envelope still runs synchronously on the event-loop thread; fresh=True now guarantees hitting it every call.
The cache mitigates repeated compact calls, but a cache miss (and every fresh=True request) still executes build_coordination_envelope — including the ThreadPoolExecutor.result() waits inside _beads_payload — synchronously inside the async def run() coroutine with no await/executor offload, blocking the event loop for the full envelope-build duration. This isn't new in this diff, but fresh=True widens exposure to it on every such call.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@polylogue/mcp/server_tools.py` around lines 1107 - 1133, Update the async run
function so build_coordination_envelope executes off the event-loop thread via
the existing async executor/offload pattern, including cache misses and every
fresh=True request. Await the offloaded result before caching and serializing
it, while preserving the current arguments and cache behavior.
…807,2780,2790,2791,2795,2802,2806,2809 uwk3, jph5 (rigor-contracts #2783), bby.17 (web-cockpit #2793), dmp (terminal-note #2801), ra3w (basetemp-fix #2807), r4no/bkff/r2kb (extension-redesign #2780) fully satisfied — closed. nhjs (#2793), peo (daemon-forensics #2802), 4g3n (#2780), 67ac/212.11 (demo-corpus #2795), rsad (mcp-ergonomics #2790, real gaps remain per 5-iteration adversarial cap), 9e5.8.4/jnj.7 (provider-origin #2806), mrxt/37t.12/p5g/rxdo.4 (annotation-judgment #2791), s7ae.8/20d.2 (live-performance-2 #2809) partially satisfied — noted with disposition, left open. Also discovered and documented the actual root cause of this session's recurring bead-revert incidents: bd reimports the live database from .beads/issues.jsonl on every CLI invocation, so a write not immediately exported is lost the moment the next bd command runs. Every mutation in this commit was individually export-verified against that behavior. Co-Authored-By: Claude <[email protected]>
Summary
Reduce live compact coordination latency by bounding optional Beads probes and add explicit, short-lived compact MCP reuse; defer reset-only imports from nested CLI help.
Problem
Isolated-root stage measurements showed
bd merge-slot checkconsuming the full two-second command deadline on each compact status request. Nestedops reset --helpalso imported mutation/query machinery before an operator selected any action.Solution
fresh=trueand detail requests rebuild live evidence.Verification
POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest devtools test tests/unit/coordination/test_envelope.py tests/unit/mcp/test_agent_coordination.py -k 'coordination_envelope_overlaps_independent_beads_probes or coordination_envelope_bounds_live_beads_probe_timeout or agent_coordination_compact_cache_is_bypassable or agent_coordination_tool_returns_shared_payload'— 4 passed.POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest devtools test tests/unit/cli/test_reset.py— 30 passed.devtools verify --quick— all steps passed.AC matrix
Ref polylogue-s7ae.8
Ref polylogue-20d.2
Summary by CodeRabbit
freshoption to bypass cached results and retrieve current coordination data.