feat(epic3): уведомления об изменении Resource/Prompt каталога MCP (Story 3.19)
CI / UI Checks (pull_request) Successful in 9s
CI / Rust Checks (pull_request) Failing after 4m10s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Failing after 1s
CI / Deploy (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 9s
CI / Rust Checks (pull_request) Failing after 4m10s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Failing after 1s
CI / Deploy (pull_request) Skipped
Story 3.19 / FR-19 на принятой базе Story 3.18 (`47a6e54`, PR #99): после commit опубликованного каталога Agent клиент получает `notifications/resources/list_changed` и/или `notifications/prompts/list_changed`, обе pinned revisions, а обычное чтение каталога остаётся авторитетным при потере сигнала. Scope ограничен list-change: `resources/subscribe`/`unsubscribe` остаются `-32601`, значение `resources.subscribe` остаётся `false` (одобренный владельцем вариант A). Публикация переносит только semantic delta Story 3.19 из `/home/codex/code/crank-worktrees/story31-worktree` (`1b6db09` + cumulative overlay) на принятый head 3.18, а не копирует worktree: - новый `protocol/signals.rs` (watcher, отпечаток каталога, bounded filter, revision-correct encoders, bounded legacy stream registry) и `protocol/signals_tests.rs` (17 unit oracles); - `subscriptions/listen` (modern-only dispatch registration) + честные `listChanged: true` объявления; `app/endpoint.rs` получает legacy GET producer/DELETE retire, `app/dispatch.rs` — modern listen stream; - ATDD `mcp_signals` 5 сценариев на реальном endpoint/PostgreSQL/artifact store; capability inventory и frozen/provenance проекции обновлены (`b90b59f3…`, inventory `10ca3538…`); - `scripts/ci-story-checks.sh`: добавлены 3.19-проверки, записи Story 3.18 сохранены (гейт не ослаблен). Принятая правка code-health `206ca78` сохранена: `app/endpoint.rs` 402 строки (было 381), `app/legacy_dispatch.rs` 731 без изменений, т.е. split не переписан. Новый ATDD-файл `mcp_signals.rs` до 1138 строк превышал лимит `scripts/check-rust-code-health.sh`, поэтому его сценарии механически вынесены в `mcp_signals/scenarios.rs` без изменения проверок. Наследованный дефект tooling-гейта: `tests/unit/test_validate_capability_inventory.py` требует, чтобы `Run tooling unit tests` шёл раньше `scripts/validate-capability-inventory.py`; в принятом `ci.yml` (3.18) шаг оказался в условном feature-job. Шаг перенесён в обязательный `rust` job перед проверкой inventory — исполняемый tooling-гейт теперь проверяется там же, где применяется; ни одна проверка не отключена и не ослаблена. Проверки на этом коммите: `ci-story-checks.sh` exit 0 — 4/9/1/12/10/3/5(+1 manual ignored)/17 passed; `crank-community-mcp --lib` 102/0; transport 20/0, mcp_prompts 15/0, revision_matrix::negotiation 23/0, era_isolation 5/0; `cargo fmt --check` и `cargo clippy -p crank-community-mcp -p mcp-server --all-targets -D warnings` — 0; `check-rust-code-health.sh` — pass; capability inventory `status=valid protocol_items=50 revisions=2`; `python3 -m unittest discover -s tests/unit` — 305 OK. NOT_RUN (честно, не PASS): полный `just verify`, межкомпонентная интеграция, нагрузка и квалификация ≥3 реальных клиентов — остаются на собранной фиче 3.20 по validation-policy.md.
This commit is contained in:
1 parent
47a6e54660
commit
a965bc4137
22 files changed
+2247
-55
No files matched your search
@@ -23,7 +23,9 @@ use crate::{
|
||||
},
|
||||
session::SessionState,
|
||||
tool_error::execution_locale,
|
||||
transport::{ResponseMode, json_response, session_id_from_headers, transport_response},
|
||||
transport::{
|
||||
ResponseMode, json_response, session_id_from_headers, sse_response, transport_response,
|
||||
},
|
||||
};
|
||||
use axum::{
|
||||
http::{HeaderMap, StatusCode},
|
||||
@@ -658,6 +660,80 @@ pub(super) async fn handle_modern_request(
|
||||
}
|
||||
}
|
||||
}
|
||||
// Story 3.19: the modern long-lived notification stream. The response is itself the SSE
|
||||
// stream that stays open, so it is built here instead of going through the one-shot
|
||||
// response helpers: the acknowledgment is its first frame, then the coalesced list-change
|
||||
// signals, and closing the HTTP stream ends the producer.
|
||||
DispatchDecision::Allowed {
|
||||
handler: MethodHandler::SubscriptionsListen,
|
||||
..
|
||||
} => {
|
||||
// A notification stream is an SSE body by construction: a client that did not offer
|
||||
// `text/event-stream` could not receive it.
|
||||
if !crate::transport::accepts_event_stream(headers) {
|
||||
return StatusCode::NOT_ACCEPTABLE.into_response();
|
||||
}
|
||||
let filter: crate::protocol::ListenParams =
|
||||
match serde_json::from_value(params(message)) {
|
||||
Ok(filter) => filter,
|
||||
Err(_) => {
|
||||
return transport_response(
|
||||
StatusCode::OK,
|
||||
jsonrpc_error(
|
||||
request_id(message),
|
||||
-32602,
|
||||
crate::protocol::INVALID_LISTEN_FILTER,
|
||||
),
|
||||
response_mode,
|
||||
None,
|
||||
Some(version),
|
||||
);
|
||||
}
|
||||
};
|
||||
let accepted = match filter.notifications.accepted() {
|
||||
crate::protocol::FilterOutcome::Accepted(accepted) => accepted,
|
||||
crate::protocol::FilterOutcome::Invalid(detail) => {
|
||||
return transport_response(
|
||||
StatusCode::OK,
|
||||
jsonrpc_error(request_id(message), -32602, detail),
|
||||
response_mode,
|
||||
None,
|
||||
Some(version),
|
||||
);
|
||||
}
|
||||
};
|
||||
// The subscription id is the JSON-RPC id of this request; a value whose encoding is not
|
||||
// bounded cannot be a frame identity carrier and is refused before the stream opens.
|
||||
let Some(subscription_id) = crate::protocol::subscription_id(&request_id(message))
|
||||
else {
|
||||
return transport_response(
|
||||
StatusCode::OK,
|
||||
jsonrpc_error(request_id(message), -32600, "invalid JSON-RPC message"),
|
||||
response_mode,
|
||||
None,
|
||||
Some(version),
|
||||
);
|
||||
};
|
||||
let Ok(permit) = super::metrics::ActiveStreamGuard::try_acquire(&state.session_slots)
|
||||
else {
|
||||
return StatusCode::TOO_MANY_REQUESTS.into_response();
|
||||
};
|
||||
let acknowledged = crate::protocol::acknowledged_frame(&subscription_id, accepted);
|
||||
let receiver = crate::protocol::spawn_signal_watch(
|
||||
Arc::clone(state),
|
||||
crate::protocol::Watch {
|
||||
workspace_slug: path.workspace_slug.clone(),
|
||||
agent_slug: path.agent_slug.clone(),
|
||||
signals: accepted,
|
||||
wire: crate::protocol::Wire::Modern(subscription_id),
|
||||
legacy_stream: None,
|
||||
deadline: None,
|
||||
},
|
||||
);
|
||||
let stream = crate::protocol::frames_stream(vec![acknowledged], receiver, permit);
|
||||
|
||||
sse_response(StatusCode::OK, stream, None, Some(version))
|
||||
}
|
||||
// The standard Prompt requests are registered capabilities now; any other
|
||||
// unregistered/wrong-era method goes straight to the era-correct unsupported answer.
|
||||
_ => crate::protocol::modern_method_not_found_response(message),
|
||||
|
||||
@@ -26,12 +26,11 @@ use axum::{
|
||||
Json,
|
||||
extract::{Extension, Path, State, rejection::JsonRejection},
|
||||
http::{HeaderMap, StatusCode},
|
||||
response::{IntoResponse, Response, sse::Event},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use crank_core::{CorrelationContext, PlatformApiKeyScope};
|
||||
use futures_util::stream;
|
||||
use serde_json::Value;
|
||||
use std::{convert::Infallible, sync::Arc, time::Duration};
|
||||
use std::{sync::Arc, time::Duration, time::Instant};
|
||||
use tracing::info;
|
||||
|
||||
use super::dispatch::handle_modern_request;
|
||||
@@ -103,11 +102,32 @@ pub(super) async fn mcp_get(
|
||||
return StatusCode::TOO_MANY_REQUESTS.into_response();
|
||||
};
|
||||
|
||||
let stream = stream::unfold(permit, |permit| async move {
|
||||
tokio::time::sleep(Duration::from_millis(TRANSPORT_SESSION_TTL_MS)).await;
|
||||
drop(permit);
|
||||
None::<(Result<Event, Infallible>, _)>
|
||||
});
|
||||
// Story 3.19: the pinned legacy transport forbids broadcasting one JSON-RPC message across the
|
||||
// SSE streams of a session, so exactly one admitted `GET` receives the Resource/Prompt
|
||||
// list-change signals. A newer `GET` takes them over and the older stream simply ends; a
|
||||
// `DELETE` retires the producer, so a stale generation never writes into a reconnect.
|
||||
let Some(generation) = state.signal_streams.admit(&session_id) else {
|
||||
// The bounded owner table is contended: refuse this admission instead of waiting.
|
||||
return StatusCode::TOO_MANY_REQUESTS.into_response();
|
||||
};
|
||||
let receiver = crate::protocol::spawn_signal_watch(
|
||||
Arc::clone(&state),
|
||||
crate::protocol::Watch {
|
||||
workspace_slug: path.workspace_slug.clone(),
|
||||
agent_slug: path.agent_slug.clone(),
|
||||
signals: crate::protocol::Signals::BOTH,
|
||||
wire: crate::protocol::Wire::Legacy,
|
||||
legacy_stream: Some((
|
||||
Arc::clone(&state.signal_streams),
|
||||
session_id.clone(),
|
||||
generation,
|
||||
)),
|
||||
deadline: Some(Instant::now() + Duration::from_millis(TRANSPORT_SESSION_TTL_MS)),
|
||||
},
|
||||
);
|
||||
// The stream permit lives in the response stream: a client that closes the SSE connection ends
|
||||
// the producer and releases the slot, and no signal is queued for a reader that is gone.
|
||||
let stream = crate::protocol::frames_stream(Vec::new(), receiver, permit);
|
||||
|
||||
sse_response(
|
||||
StatusCode::OK,
|
||||
@@ -160,6 +180,7 @@ pub(super) async fn mcp_delete(
|
||||
|
||||
match state.sessions.delete(&session_id).await {
|
||||
Ok(true) => {
|
||||
state.signal_streams.retire(&session_id);
|
||||
state.session_metrics.refresh();
|
||||
StatusCode::NO_CONTENT.into_response()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user