D: reuse the shared proxy bounds and status table in MCP peers
The peer follow stream had no byte cap and kept a whole unterminated frame in memory, and the MCP surface carried its own peer status table that already disagreed with REST for peer 400. - mcp::peers::fetch now returns proxy::PreparedResponse, so the status comes from proxy::classify_status and the body from proxy::prepare_response (peer byte cap, deadline, shutdown), the same two steps REST uses. status_error, body_bytes and the local 2xx check are gone. - tail_journal consumes that prepared stream; a Frames cursor keeps a partial frame from being rescanned from byte 0 on every chunk, the entry cap truncates the result, and the end of the stream maps to the note (entry cap, shutdown, byte cap, deadline or close). - Prompts resolve the peer argument against the registry (unknown or disabled peer is refused); list_peers returns the error registry() produced; one wording for an unknown peer name. - Tests: byte cap on an unterminated frame, entry cap, buffered body, follow 404/500, deadline with an open stream, shutdown, frame cursor, REST/MCP parity for peer 400/404/401/5xx, and a full golden snapshot of the peers-off tool table. Peer scripts use the stripped path form C2 forwards.
This commit is contained in:
1 parent
e2c553dbe4
commit
c0e76607f6
5 files changed
+592
-213
No files matched your search
@@ -96,3 +96,15 @@ Both snapshot variants pass; each tool with `peer` returns the peer's data via t
|
||||
**Follow-ups for the merger:** (1) outbound trace context: `mcp::peers::fetch` passes `ProxyOpts { traceparent: None, .. }` because `telemetry::inject_traceparent()` (E2) does not exist yet; when it lands, set the field there (one line) — the MCP surface needs no other change. (2) Re-run `tests/mcp_peers.rs` once B lands to exercise the real registry instead of `registry_with`; the assertions are transport-agnostic. (3) A `peer` argument sent to a peers-off instance (possible only by ignoring the schema) is a tool error `not_found: peer <name>: unknown peer`, matching the registry wording.
|
||||
|
||||
**Verification:** `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `cargo test` green on each of the three commits individually; 17 unit tests (5 in `src/mcp/peers.rs`, 9 peer-tool tests and 3 rewritten snapshot/instruction tests in `src/mcp/mod.rs`) and 8 integration tests in `tests/mcp_peers.rs` (assembled router, fake sources, `FakeTransport`/`registry_with`). No dependency or Cargo.toml change (`cargo tree -i openssl` untouched), no write path, no secrets, no nix build needed. Commits: D1 `1240bd8`, D2 `50fca7d`, D3 `6977074`. WS-T's MCP assertions are covered by `list_peers` output and `list_systemd_units {"peer": ...}` against the fake.
|
||||
- 2026-10-20: **Round-1 review fixes (rebased on C2 + T).** `git rebase main` applied without textual conflicts, but C2 changed the transport's forwarded path form: `proxy::canonical_route` strips the `/api/v1` prefix, so the peer now receives `/systemd/units` and `/journal/follow` rather than `/api/v1/...`. The D1 tests were written against the A0 forwarder and scripted/asserted the prefixed form, so they failed after the rebase; every peer script and path assertion in `src/mcp/mod.rs` and `tests/mcp_peers.rs` now uses the stripped form, which is the form C2 actually ships.
|
||||
|
||||
- **Blocking 1 (byte cap on the follow stream).** `mcp::peers::fetch` now returns `proxy::PreparedResponse`, built by `proxy::prepare_response(&name, resp, reg.config().max_response_bytes, deadline, shutdown)`. The peer `tail_journal` consumes that prepared stream, so the peer byte cap, the follow deadline and the process shutdown token are applied by the shared code, not by a local cap. `Frames` (formerly `take_frames`) keeps a `scan` cursor: a partial frame is searched from the last three bytes of the previous buffer instead of from byte 0, so an unterminated frame costs linear time, and the buffer only ever holds bytes the cap admitted. The `Stop` enum turns the end of the stream into the `note`: entry cap, shutdown, byte cap (`received >= max_bytes`; a cut that lands more than a chunk below the cap is indistinguishable from a close and is reported as one), deadline (no note, like the local tool) or close.
|
||||
- **Blocking 2 (status table).** `status_error`, `body_bytes` and the local 2xx check are deleted; all peer responses now go through `proxy::prepare_response` / `proxy::classify_status`. **Contract note for the plan owner:** contracts section 4 and decision D9 still say peer 400/422 -> `BadRequest`, while C2's `classify_status` (the single table REST and MCP now share) maps 400 to `Http(400)` -> `503 peer <p>: http_400`. D has followed the review's instruction to reuse the table rather than keep a second one, so the contract row is now the thing that disagrees; settling it means either restoring 400/422 in `proxy.rs` (WS-C file) or updating section 4 and D9.
|
||||
- **Major 3 (entry cap).** `out.truncate(entry_cap)` before `capped(...)`, for the stream and the buffered-body branch, so the peer tool cannot return more than `limits.max_lines` entries.
|
||||
- **Major 4 (tests).** New unit tests: `peer_tail_journal_is_bounded_by_the_peer_byte_cap` (100 chunks of 512 bytes, no terminator, 4096-byte peer cap: returns at once, no entries, cap note), `peer_tail_journal_caps_entries_like_the_local_tool`, `peer_tail_journal_accepts_a_buffered_body`, `peer_tail_journal_maps_a_follow_error_like_rest` (404 and 500), `peer_tail_journal_ends_at_the_deadline_with_an_open_stream` (a transport whose stream never ends, paused clock) and `peer_tail_journal_stops_on_shutdown`; plus `Frames` cursor/terminator tests. New integration test `rest_and_mcp_report_the_same_peer_status_errors` compares the REST body (`code`, `message`, HTTP status, `x-slinuxm-peer`) with the MCP tool error for peer 400/404/401/500.
|
||||
- **Minor 5 (golden).** `tool_list_without_peers_is_byte_identical` pins the full serialized `Tool` JSON of the peers-off table (not just property sets), so a reworded description or field doc comment fails the test.
|
||||
- **Minor 6 (literal list).** The integration snapshot uses a literal list of the ten names; the test-only `mcp::peers::tool_names()` helper is gone.
|
||||
- **Minor 7 (one wording).** `peers::registry` keeps its doc honest ("no peers are configured"); the per-name 404 comes from `UnknownPeer`-style wording in `fetch` (only reachable with the feature off, where there is no registry) and from `PeerRegistry` itself otherwise; `list_peers` returns the error `registry()` produced instead of rebuilding the message.
|
||||
- **Minor 8 (prompt peer).** `prompts::get` takes `Option<&PeerRegistry>` instead of a bool and resolves the `peer` argument against it: an unknown name is `not_found: peer <n>: unknown peer`, a name whose entry is disabled is `peer <n>: disabled`. The prompt can no longer send an agent at a peer whose tool calls would fail.
|
||||
|
||||
**Verification (round 1 fixes):** `loop/gate.sh D main` -> GATE PASS (fmt, clippy, all lib + `tests/mcp_peers.rs` tests green, no openssl, ownership, duplication). `TODO.md` is not an owned file for D, so the D1/D2/D3 boxes are left for the merger to tick.
|
||||
Reference in new issue
Block a user