feat(server): add in-flight task coordinator, soft wait window, and result caching #4

Merged
piotr merged 1 commit from feature/inflight-coordinator-soft-wait into main 2026-11-07 22:09:22 -08:00
Owner

Summary

This PR implements an in-flight review task coordinator, soft wait timeout, and caching layer to prevent client transport timeouts during multi-minute OpenCode reviews, as specified in ~/tmp/review-gate.md.

Key Changes

  1. ReviewRunCoordinator (src/review_gate/coordinator.py):

    • Single owner of mutable review and session state.
    • Background execution of reviews with asyncio.shield so tasks survive client cancellation or timeout.
    • Cache completed reviews by content-addressed ReviewCacheKey for 30 minutes (capped at 256 entries).
    • Retain session latest completed result on SessionRecord across the full 2-hour session lifetime so retries can collect verdicts.
    • Read-once failure slot (TTL 120s) so transient errors/exceptions are reported once and subsequent calls re-run cleanly.
  2. Soft Wait Window (src/review_gate/server.py):

    • Controlled by REVIEW_GATE_WAIT_TIMEOUT (default: 150s, clamped <= 170.0s to stay beneath the 180s MCP transport deadline).
    • Returns ## [REVIEW IN PROGRESS: RETRY TO COLLECT] when execution extends beyond the window.
    • Duplicate calls join existing in-flight tasks.
  3. Fail-Closed Guardrails:

    • Truncated diff, sensitive secret files, remote fetch failure, and branch sync checks are strictly evaluated before serving any cached results or session retry hits.
  4. Admission Control & Lifecycle:

    • Global cap (4 reviews) and per-repository cap (2 reviews). Returns ## [REVIEW QUEUE FULL: RETRY LATER] when capacity is reached.
    • Session collision guard returning ## [REVIEW BUSY: SESSION ROUND RUNNING].
    • Queued (unstarted) tasks in the same lane are superseded on newer snapshots (## [REVIEW SUPERSEDED: RETRY]).
    • Caching decoupled from issue titles; determined solely by structured execution_status: Literal["completed", "transient_failure"].
  5. Tests & Documentation:

    • Updated RULES.md, AGENTS_TEMPLATE.md, and README.md.
    • Added test lifecycle fixtures in tests/conftest.py with deterministic completion (drain(), fresh_coordinator, wait_until).
    • 70 unit and integration tests passing. Independent CL review verified with verdict LGTM with nits.
### Summary This PR implements an in-flight review task coordinator, soft wait timeout, and caching layer to prevent client transport timeouts during multi-minute OpenCode reviews, as specified in `~/tmp/review-gate.md`. ### Key Changes 1. **ReviewRunCoordinator (`src/review_gate/coordinator.py`)**: - Single owner of mutable review and session state. - Background execution of reviews with `asyncio.shield` so tasks survive client cancellation or timeout. - Cache completed reviews by content-addressed `ReviewCacheKey` for 30 minutes (capped at 256 entries). - Retain session latest completed result on `SessionRecord` across the full 2-hour session lifetime so retries can collect verdicts. - Read-once failure slot (TTL 120s) so transient errors/exceptions are reported once and subsequent calls re-run cleanly. 2. **Soft Wait Window (`src/review_gate/server.py`)**: - Controlled by `REVIEW_GATE_WAIT_TIMEOUT` (default: 150s, clamped <= 170.0s to stay beneath the 180s MCP transport deadline). - Returns `## [REVIEW IN PROGRESS: RETRY TO COLLECT]` when execution extends beyond the window. - Duplicate calls join existing in-flight tasks. 3. **Fail-Closed Guardrails**: - Truncated diff, sensitive secret files, remote fetch failure, and branch sync checks are strictly evaluated *before* serving any cached results or session retry hits. 4. **Admission Control & Lifecycle**: - Global cap (4 reviews) and per-repository cap (2 reviews). Returns `## [REVIEW QUEUE FULL: RETRY LATER]` when capacity is reached. - Session collision guard returning `## [REVIEW BUSY: SESSION ROUND RUNNING]`. - Queued (unstarted) tasks in the same lane are superseded on newer snapshots (`## [REVIEW SUPERSEDED: RETRY]`). - Caching decoupled from issue titles; determined solely by structured `execution_status: Literal["completed", "transient_failure"]`. 5. **Tests & Documentation**: - Updated `RULES.md`, `AGENTS_TEMPLATE.md`, and `README.md`. - Added test lifecycle fixtures in `tests/conftest.py` with deterministic completion (`drain()`, `fresh_coordinator`, `wait_until`). - 70 unit and integration tests passing. Independent CL review verified with verdict **LGTM with nits**.
feat(server): add in-flight task coordinator, soft wait window, and result caching
All checks were successful
CI / Run Test Suite (pull_request) Successful in 11s
CI / Run Test Suite (push) Successful in 12s
e55ce4f911
- Add ReviewRunCoordinator for in-flight task coordination, session tracking,
  completed-result caching (30m TTL, max 256), and read-once failure slot (120s TTL).
- Implement soft wait window via REVIEW_GATE_WAIT_TIMEOUT (default 150s, clamped
  to <= 170s) returning ## [REVIEW IN PROGRESS: RETRY TO COLLECT] to avoid MCP client
  transport timeouts while background execution continues.
- Execute background reviews via asyncio.shield so they survive caller cancellation
  and allow concurrent identical requests to join existing runs.
- Run fail-closed guardrails (diff truncated, sensitive files, strict fetch, branch
  sync) before returning cached results or session retry hits.
- Add admission control: global cap (4), per-repo cap (2), session busy rejection,
  and automatic superseding of unstarted queued tasks on newer snapshots.
- Replace issue title string matching with structured execution_status on ReviewResult.
- Update RULES.md, AGENTS_TEMPLATE.md, and README.md with new non-verdict temporary states.
- Add regression test suite and deterministic test lifecycle fixtures.
piotr merged commit e55ce4f911 into main 2026-11-07 22:09:22 -08:00
piotr deleted branch feature/inflight-coordinator-soft-wait 2026-11-07 22:09:22 -08:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
piotr/mcp-review-gate!4
No description provided.