Skip to content

perf: reduce interactive coordination and reset latency - #2809

Merged
Sinity merged 7 commits into
masterfrom
feature/fanout/live-performance-2
Jul 13, 2026
Merged

Sinity merged 7 commits into
masterfrom
feature/fanout/live-performance-2

Conversation

@Sinity

@Sinity Sinity commented Jul 13, 2026 •

Copy link
Copy Markdown
Owner

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 check consuming the full two-second command deadline on each compact status request. Nested ops reset --help also imported mutation/query machinery before an operator selected any action.

Solution

  • Record caller-owned coordination stage timings, overlap independent Beads probes, and cap unavailable live probes at 350 ms while retaining their existing error payload.
  • Cache only compact MCP coordination responses for one second; fresh=true and detail requests rebuild live evidence.
  • Move reset-path imports to the helpers that execute reset work.

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.
  • Pre-push devtools verify --quick — all steps passed.
  • Isolated archive measurement: warm direct compact status p50 2.15 s before → 0.51 s after; reset warm nested help 1.18 s before → 0.30 s after.

AC matrix

Bead Acceptance criterion Status
polylogue-s7ae.8 Stage-timed compact core harness, p50/p95, raw artifact support, and live dogfood report In progress — timing sink landed; committed harness/artifact still required.
polylogue-s7ae.8 Warm compact MCP p95 at least 3x faster with measured budget In progress — cache and measured direct route reduction landed; full MCP distribution/budget remains required.
polylogue-s7ae.8 Preserve compact/detail semantics, omissions, process/resource behavior, handoff and 8 KiB bound Satisfied by existing contracts plus focused behavior tests; full regression rerun is planned before finalization.
polylogue-20d.2 Importtime diff artifact proving CLI help avoids surfaces/payloads and api/archive In progress.
polylogue-20d.2 Fixed-budget devtools help-latency gate In progress.
polylogue-20d.2 Nested reset/maintenance/archive-read/analyze sweep under measured budgets In progress — reset improved; maintenance remains above target and is not claimed complete.

Ref polylogue-s7ae.8
Ref polylogue-20d.2

Summary by CodeRabbit

  • New Features
    • Added a coordination-latency benchmarking command with p50/p95 measurements, stage timings, and JSON output.
    • Added caching for compact coordination results to improve response times.
    • Added a fresh option to bypass cached results and retrieve current coordination data.
  • Performance
    • Coordination status now gathers independent Beads checks concurrently, reducing delays.
  • Documentation
    • Documented the new coordination-latency benchmarking command.

Sinity added 3 commits July 13, 2026 02:06
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
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 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: ba19b871-4160-458f-a2ca-f299fa0c354e

📥 Commits

Reviewing files that changed from the base of the PR and between 21c9a70 and 8be0139.

📒 Files selected for processing (1)
  • devtools/coordination_latency_probe.py
📝 Walkthrough

Walkthrough

The 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.

Changes

Coordination observability and reuse

Layer / File(s) Summary
Timed envelope and Beads probes
polylogue/coordination/envelope.py, tests/unit/coordination/test_envelope.py
Envelope stages record optional timings; Beads hooks, gate, and merge-slot probes run concurrently with bounded default-runner timeouts and corresponding tests.
Compact coordination cache
polylogue/mcp/server_tools.py, tests/unit/mcp/test_agent_coordination.py
Compact coordination responses use a TTL cache keyed by view, working directory, and limit; fresh bypasses the cache and detail requests remain uncached.
Coordination latency benchmark
devtools/coordination_latency_probe.py, devtools/command_catalog.py, docs/devtools.md
A benchmark command records raw samples, stage timings, payload sizes, p50/p95 latency, metadata, and optional JSON output.

Lazy command imports

Layer / File(s) Summary
Deferred reset dependencies
polylogue/cli/commands/reset.py
Reset-command runtime helpers are imported inside their consuming functions, while MutationStatus is restricted to type checking.

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
Loading

Suggested labels: area:mcp

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main latency-reduction focus of the changeset.
Description check ✅ Passed The description covers Summary, Problem, Solution, and Verification clearly, with extra rollout detail in the AC matrix.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fanout/live-performance-2

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 13, 2026 02:11
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
@Sinity

Sinity commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b0dc23e and 21c9a70.

📒 Files selected for processing (8)
  • devtools/command_catalog.py
  • devtools/coordination_latency_probe.py
  • docs/devtools.md
  • polylogue/cli/commands/reset.py
  • polylogue/coordination/envelope.py
  • polylogue/mcp/server_tools.py
  • tests/unit/coordination/test_envelope.py
  • tests/unit/mcp/test_agent_coordination.py

Comment on lines 1107 to 1133
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.

@Sinity
Sinity merged commit b034a4b into master Jul 13, 2026
3 of 15 checks passed
@Sinity
Sinity deleted the feature/fanout/live-performance-2 branch July 13, 2026 00:29
@Sinity
Sinity restored the feature/fanout/live-performance-2 branch July 13, 2026 00:49
Sinity added a commit that referenced this pull request Jul 13, 2026
…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]>
@Sinity
Sinity deleted the feature/fanout/live-performance-2 branch July 13, 2026 02:20
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