feat(epic4): публиковать execution mode и применять общий admission (Story 4.1, FR-21, FR-24)
CI / UI Checks (pull_request) Successful in 11s
CI / Rust Checks (pull_request) Successful in 12m45s
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) Successful in 1s
CI / Deploy (pull_request) Skipped
Community Release / release (push) Successful in 40m35s
CI / UI Checks (pull_request) Successful in 11s
CI / Rust Checks (pull_request) Successful in 12m45s
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) Successful in 1s
CI / Deploy (pull_request) Skipped
Community Release / release (push) Successful in 40m35s
Tool Draft фиксирует synchronous/background/adaptive, deadline и fallback; runtime применяет единый снимок политики (concurrency, очередь, approval, deadline) до внешнего действия. Насыщение отклоняется typed overload с retry guidance, mandatory safety store fail closed, background/adaptive используют опубликованный synchronous/unsupported fallback. Refs: #29
This commit is contained in:
1 parent
44774883a0
commit
e80d30ddb0
72 files changed
+4157
-121
No files matched your search
@@ -270,6 +270,72 @@ pub struct OperationApprovalPolicy {
|
||||
pub elicitation_message: Option<String>,
|
||||
}
|
||||
|
||||
/// Published execution mode of one Tool (Story 4.1, FR-21).
|
||||
///
|
||||
/// This is a scheduling policy of the Published Tool version. It is deliberately separate from
|
||||
/// `ext::protocol::ExecutionMode`, which describes the protocol adapter (streaming vs unary).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ToolExecutionMode {
|
||||
#[default]
|
||||
Synchronous,
|
||||
Background,
|
||||
Adaptive,
|
||||
}
|
||||
|
||||
/// Behaviour promised to a client that does not negotiate durable Tasks (Story 4.1).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum NoTasksFallback {
|
||||
/// Execute through the same synchronous admission path.
|
||||
#[default]
|
||||
Synchronous,
|
||||
/// Reject with a typed unsupported-execution-mode failure; never a Task ID.
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
pub const MAX_TOOL_DEADLINE_MS: u64 = 3_600_000;
|
||||
|
||||
/// Execution policy pinned by a Published Tool version.
|
||||
///
|
||||
/// Absence of the policy keeps the pre-4.1 behaviour: synchronous execution bounded by
|
||||
/// `ExecutionConfig::timeout_ms`, with no background path.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ToolExecutionPolicy {
|
||||
#[serde(default)]
|
||||
pub mode: ToolExecutionMode,
|
||||
/// Absolute budget of one execution, counted from the start of admission.
|
||||
pub deadline_ms: u64,
|
||||
#[serde(default)]
|
||||
pub no_tasks_fallback: NoTasksFallback,
|
||||
}
|
||||
|
||||
impl Default for ToolExecutionPolicy {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mode: ToolExecutionMode::Synchronous,
|
||||
deadline_ms: 30_000,
|
||||
no_tasks_fallback: NoTasksFallback::Synchronous,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolExecutionPolicy {
|
||||
pub fn validate(&self) -> Result<(), ToolExecutionPolicyError> {
|
||||
if !(1..=MAX_TOOL_DEADLINE_MS).contains(&self.deadline_ms) {
|
||||
return Err(ToolExecutionPolicyError::DeadlineOutOfRange);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
|
||||
pub enum ToolExecutionPolicyError {
|
||||
#[error("tool execution deadline must be between 1 and {MAX_TOOL_DEADLINE_MS} ms")]
|
||||
DeadlineOutOfRange,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ExecutionConfig {
|
||||
@@ -285,6 +351,8 @@ pub struct ExecutionConfig {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub approval_policy: Option<OperationApprovalPolicy>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub execution_policy: Option<ToolExecutionPolicy>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auth_profile_ref: Option<AuthProfileId>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub headers: BTreeMap<String, String>,
|
||||
@@ -444,9 +512,10 @@ mod tests {
|
||||
edition::OperationSecurityLevel,
|
||||
ids::{AuthProfileId, OperationId},
|
||||
operation::{
|
||||
ConfigExport, ExecutionConfig, Operation, OperationAvailability, OperationLifecycle,
|
||||
OperationLifecycleAction, OperationLifecycleError, OperationStatus,
|
||||
ConfigExport, ExecutionConfig, NoTasksFallback, Operation, OperationAvailability,
|
||||
OperationLifecycle, OperationLifecycleAction, OperationLifecycleError, OperationStatus,
|
||||
OperationVersionState, RestTarget, Samples, Target, ToolDescription, ToolExample,
|
||||
ToolExecutionMode, ToolExecutionPolicy,
|
||||
},
|
||||
protocol::{AuthKind, ExportMode, HttpMethod, Protocol},
|
||||
};
|
||||
@@ -664,6 +733,7 @@ updated_at: 2026-03-25T08:10:00Z
|
||||
idempotency: None,
|
||||
safety: None,
|
||||
approval_policy: None,
|
||||
execution_policy: None,
|
||||
auth_profile_ref: Some(AuthProfileId::new("auth_01")),
|
||||
headers: BTreeMap::new(),
|
||||
},
|
||||
@@ -684,4 +754,76 @@ updated_at: 2026-03-25T08:10:00Z
|
||||
published_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn execution_policy_round_trips_all_modes_and_fallbacks() {
|
||||
for (mode, fallback) in [
|
||||
(ToolExecutionMode::Synchronous, NoTasksFallback::Synchronous),
|
||||
(ToolExecutionMode::Background, NoTasksFallback::Synchronous),
|
||||
(ToolExecutionMode::Background, NoTasksFallback::Unsupported),
|
||||
(ToolExecutionMode::Adaptive, NoTasksFallback::Unsupported),
|
||||
] {
|
||||
let config = ExecutionConfig {
|
||||
execution_policy: Some(ToolExecutionPolicy {
|
||||
mode,
|
||||
deadline_ms: 45_000,
|
||||
no_tasks_fallback: fallback,
|
||||
}),
|
||||
..ExecutionConfig::default()
|
||||
};
|
||||
let encoded = serde_json::to_value(&config).unwrap();
|
||||
assert_eq!(encoded["execution_policy"]["deadline_ms"], json!(45_000));
|
||||
let decoded: ExecutionConfig = serde_json::from_value(encoded).unwrap();
|
||||
assert_eq!(decoded, config);
|
||||
assert_eq!(
|
||||
decoded.execution_policy.unwrap().mode,
|
||||
mode,
|
||||
"the published mode must survive the JSON round-trip"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_execution_config_without_policy_stays_synchronous() {
|
||||
let legacy: ExecutionConfig =
|
||||
serde_json::from_value(json!({ "timeout_ms": 12_000 })).unwrap();
|
||||
assert_eq!(legacy.execution_policy, None);
|
||||
assert_eq!(legacy.timeout_ms, 12_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn execution_policy_rejects_explicit_invalid_deadline() {
|
||||
assert!(
|
||||
ToolExecutionPolicy {
|
||||
mode: ToolExecutionMode::Background,
|
||||
deadline_ms: 0,
|
||||
no_tasks_fallback: NoTasksFallback::Synchronous,
|
||||
}
|
||||
.validate()
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
ToolExecutionPolicy {
|
||||
mode: ToolExecutionMode::Adaptive,
|
||||
deadline_ms: crate::operation::MAX_TOOL_DEADLINE_MS + 1,
|
||||
no_tasks_fallback: NoTasksFallback::Unsupported,
|
||||
}
|
||||
.validate()
|
||||
.is_err()
|
||||
);
|
||||
assert!(ToolExecutionPolicy::default().validate().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn execution_policy_rejects_unknown_fields() {
|
||||
assert!(
|
||||
serde_json::from_value::<ToolExecutionPolicy>(json!({
|
||||
"mode": "background",
|
||||
"deadline_ms": 1000,
|
||||
"no_tasks_fallback": "synchronous",
|
||||
"task_queue": "default"
|
||||
}))
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user