feat(epic3): progress и безопасная отмена Tool calls (Story 3.4, FR-14)
- request-scoped lifecycle одного tools/call: валидированный `_meta.progressToken` (строковый/числовой, 1..=128 байт) и bounded очередь реальных этапов (tool_resolved → authorization_resolved → execution_dispatched) в собственный SSE-stream запроса; без token или без stream-carrier результат не меняется; - сериализация `notifications/progress` по pinned схеме обеих revisions (progressToken/progress/message, total не изобретается); - отмена по revision: 2025-11-25 — `notifications/cancelled` через bounded in-flight таблицу (владение = session + platform credential, не progress token); 2026-07-28 — закрытие response stream; в обоих случаях drop будущего вызова = кооперативная остановка, terminal-сообщение не отправляется; - streamed ответ сохраняет проекцию Story 3.18: closed `notifications/message` перед финальным кадром (перенос logging-scope в тело стрима); - ATDD: 12 end-to-end тестов на реальном endpoint/каталоге/counted upstream (обе revisions, malformed/oversized/reused token, owner/foreign/late cancel, disconnect, ambiguous outbound, representative client smoke) + 7 unit-тестов границ lifecycle; entry в scripts/ci-story-checks.sh.
This commit is contained in:
1 parent
49c8af24ed
commit
862cde8559
18 files changed
+2207
-112
No files matched your search
@@ -192,6 +192,46 @@ pub(crate) fn set_active_level(level: Option<LogLevel>) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The request's logging context, carried into a streamed response body (Story 3.4).
|
||||
///
|
||||
/// A streamed `tools/call` response is assembled after the request handler returned, so its terminal
|
||||
/// event would be projected outside the task-local scope of the request. This snapshot carries the
|
||||
/// only two facts the projection needs — the level the client opted in to and whether the request
|
||||
/// offered the SSE carrier — and never a request value.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub(crate) struct CarriedScope {
|
||||
active: Option<LogLevel>,
|
||||
sse_acceptable: bool,
|
||||
}
|
||||
|
||||
/// Snapshot the scope of the request that is being served now. Outside a scope the snapshot is
|
||||
/// "not opted in", which delivers nothing.
|
||||
pub(crate) fn carry_scope() -> CarriedScope {
|
||||
REQUEST_LOG
|
||||
.try_with(|log| {
|
||||
let log = log.borrow();
|
||||
CarriedScope {
|
||||
active: log.active,
|
||||
sse_acceptable: log.sse_acceptable,
|
||||
}
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Run one step of the streamed response inside a scope carrying the request's logging context.
|
||||
pub(crate) async fn in_carried_scope<F: Future>(scope: CarriedScope, future: F) -> F::Output {
|
||||
REQUEST_LOG
|
||||
.scope(
|
||||
RefCell::new(RequestLog {
|
||||
active: scope.active,
|
||||
sse_acceptable: scope.sse_acceptable,
|
||||
pending: Vec::new(),
|
||||
}),
|
||||
future,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Remember that this request offered `text/event-stream`, the only carrier of a notification.
|
||||
pub(crate) fn set_sse_acceptable() {
|
||||
let _ = REQUEST_LOG.try_with(|log| {
|
||||
|
||||
Reference in new issue
Block a user