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
@@ -181,6 +181,7 @@ mod tests {
|
||||
idempotency: None,
|
||||
safety: None,
|
||||
approval_policy: None,
|
||||
execution_policy: None,
|
||||
auth_profile_ref: None,
|
||||
headers: BTreeMap::new(),
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{io, net::SocketAddr, process::ExitCode, time::Duration};
|
||||
use admin_api::{
|
||||
app::build_app,
|
||||
auth::{AuthSettings, BootstrapAdminConfig},
|
||||
pool_metrics::spawn_postgres_pool_metrics,
|
||||
pool_metrics::{spawn_admission_metrics, spawn_postgres_pool_metrics},
|
||||
reconciliation::{open_reconciliation_store, spawn_artifact_reconciliation},
|
||||
service::AdminServiceBuilder,
|
||||
state::AppState,
|
||||
@@ -169,6 +169,7 @@ async fn run(
|
||||
};
|
||||
if metrics_enabled {
|
||||
spawn_postgres_pool_metrics(registry.pool().clone());
|
||||
spawn_admission_metrics(registry.pool().clone());
|
||||
}
|
||||
let base_url = config
|
||||
.runtime
|
||||
@@ -214,6 +215,16 @@ async fn run(
|
||||
.with_limits(runtime_limits)
|
||||
.with_response_cache(cache_stores.response.clone())
|
||||
.with_coordination_store(cache_stores.coordination.clone())
|
||||
.with_admission(std::sync::Arc::new(
|
||||
crank_registry::PostgresExecutionAdmission::new(
|
||||
registry.pool().clone(),
|
||||
crank_registry::AdmissionLimits {
|
||||
global_limit: runtime_limits.max_concurrent_unary,
|
||||
..crank_registry::AdmissionLimits::default()
|
||||
},
|
||||
crank_core::AdmissionSchedulerConfig::default(),
|
||||
)?,
|
||||
))
|
||||
.build();
|
||||
let identity_provider =
|
||||
PasswordIdentityProvider::new(registry.clone(), auth_settings.password_pepper.clone());
|
||||
@@ -321,6 +332,12 @@ fn preflight_config(config: &AdminProcessConfig) -> Result<(), crank_config::Con
|
||||
config.runtime.max_concurrent_sessions,
|
||||
)
|
||||
.map_err(|_| invalid("runtime.limits"))?;
|
||||
crank_registry::AdmissionLimits {
|
||||
global_limit: config.runtime.max_concurrent_unary,
|
||||
..crank_registry::AdmissionLimits::default()
|
||||
}
|
||||
.validate()
|
||||
.map_err(|_| invalid("runtime.admission"))?;
|
||||
runtime_cache_config(config).map_err(|_| invalid("cache"))?;
|
||||
RequestRateLimitConfig::new(
|
||||
config.rate_limit.requests_per_second,
|
||||
|
||||
@@ -11,3 +11,17 @@ pub fn spawn_postgres_pool_metrics(pool: PgPool) -> tokio::task::JoinHandle<()>
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Story 4.1: samples the authoritative admission queue so the oldest-waiting age grows (and returns
|
||||
/// to zero) without waiting for a new request.
|
||||
pub fn spawn_admission_metrics(pool: PgPool) -> tokio::task::JoinHandle<()> {
|
||||
tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if let Ok(snapshot) = crank_registry::admission_snapshot(&pool).await {
|
||||
crank_observability::record_admission_oldest_waiting(snapshot.oldest_waiting_ms);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -37,13 +37,22 @@ pub async fn readiness(State(state): State<AppState>) -> impl IntoResponse {
|
||||
} else {
|
||||
"not_ready"
|
||||
};
|
||||
let execution_admission = if checks.execution_admission {
|
||||
"ready"
|
||||
} else {
|
||||
"not_ready"
|
||||
};
|
||||
if checks.is_ready() {
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(json!({
|
||||
"service": "admin-api",
|
||||
"status": "ready",
|
||||
"checks": { "postgres": postgres, "artifact_storage": artifact_storage }
|
||||
"checks": {
|
||||
"postgres": postgres,
|
||||
"artifact_storage": artifact_storage,
|
||||
"execution_admission": execution_admission
|
||||
}
|
||||
})),
|
||||
)
|
||||
} else {
|
||||
@@ -52,7 +61,11 @@ pub async fn readiness(State(state): State<AppState>) -> impl IntoResponse {
|
||||
Json(json!({
|
||||
"service": "admin-api",
|
||||
"status": "not_ready",
|
||||
"checks": { "postgres": postgres, "artifact_storage": artifact_storage }
|
||||
"checks": {
|
||||
"postgres": postgres,
|
||||
"artifact_storage": artifact_storage,
|
||||
"execution_admission": execution_admission
|
||||
}
|
||||
})),
|
||||
)
|
||||
}
|
||||
@@ -67,6 +80,7 @@ mod tests {
|
||||
let checks = ReadinessChecks {
|
||||
postgres: false,
|
||||
artifact_storage: true,
|
||||
execution_admission: true,
|
||||
};
|
||||
assert!(!checks.is_ready());
|
||||
assert_eq!(
|
||||
@@ -92,6 +106,7 @@ mod tests {
|
||||
let checks = ReadinessChecks {
|
||||
postgres: true,
|
||||
artifact_storage: false,
|
||||
execution_admission: true,
|
||||
};
|
||||
assert!(!checks.is_ready());
|
||||
assert_eq!(
|
||||
@@ -111,4 +126,14 @@ mod tests {
|
||||
"not_ready"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn readiness_checks_identify_an_admission_state_failure() {
|
||||
let checks = ReadinessChecks {
|
||||
postgres: true,
|
||||
artifact_storage: true,
|
||||
execution_admission: false,
|
||||
};
|
||||
assert!(!checks.is_ready());
|
||||
}
|
||||
}
|
||||
@@ -55,8 +55,8 @@ use crate::{
|
||||
storage::LocalArtifactStorage,
|
||||
};
|
||||
use operation_validation::{
|
||||
validate_approval_policy, validate_execution_timeout, validate_idempotency_policy,
|
||||
validate_protocol_target, validate_response_cache_policy,
|
||||
validate_approval_policy, validate_execution_policy, validate_execution_timeout,
|
||||
validate_idempotency_policy, validate_protocol_target, validate_response_cache_policy,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -104,11 +104,12 @@ pub use crate::dto::*;
|
||||
pub struct ReadinessChecks {
|
||||
pub postgres: bool,
|
||||
pub artifact_storage: bool,
|
||||
pub execution_admission: bool,
|
||||
}
|
||||
|
||||
impl ReadinessChecks {
|
||||
pub const fn is_ready(self) -> bool {
|
||||
self.postgres && self.artifact_storage
|
||||
self.postgres && self.artifact_storage && self.execution_admission
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +151,8 @@ pub(super) struct CredentialAuditRecord<'a> {
|
||||
impl AdminService {
|
||||
pub async fn readiness(&self) -> ReadinessChecks {
|
||||
let postgres = self.registry.ping().await.is_ok();
|
||||
// Story 4.1: the mandatory admission state is a readiness dependency of every execution.
|
||||
let execution_admission = self.registry.execution_admission_health().await.is_ok();
|
||||
let store = Arc::clone(&self.artifact_store);
|
||||
let artifact_storage = tokio::task::spawn_blocking(move || store.check_health())
|
||||
.await
|
||||
@@ -157,6 +160,7 @@ impl AdminService {
|
||||
ReadinessChecks {
|
||||
postgres,
|
||||
artifact_storage,
|
||||
execution_admission,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,6 +729,7 @@ impl AdminService {
|
||||
validate_response_cache_policy(&payload.target, &payload.execution_config)?;
|
||||
validate_idempotency_policy(&payload.target, &payload.execution_config)?;
|
||||
validate_approval_policy(&payload.execution_config)?;
|
||||
validate_execution_policy(&payload.execution_config)?;
|
||||
payload.input_mapping.validate_paths()?;
|
||||
payload.output_mapping.validate_paths()?;
|
||||
Ok(())
|
||||
@@ -738,6 +743,7 @@ impl AdminService {
|
||||
validate_response_cache_policy(&operation.target, &operation.execution_config)?;
|
||||
validate_idempotency_policy(&operation.target, &operation.execution_config)?;
|
||||
validate_approval_policy(&operation.execution_config)?;
|
||||
validate_execution_policy(&operation.execution_config)?;
|
||||
operation.input_mapping.validate_paths()?;
|
||||
operation.output_mapping.validate_paths()?;
|
||||
Ok(())
|
||||
|
||||
@@ -441,6 +441,7 @@ fn demo_rest_operation_payload() -> OperationPayload {
|
||||
idempotency: None,
|
||||
safety: None,
|
||||
approval_policy: None,
|
||||
execution_policy: None,
|
||||
auth_profile_ref: None,
|
||||
headers: BTreeMap::new(),
|
||||
},
|
||||
|
||||
@@ -635,6 +635,7 @@ impl AdminService {
|
||||
idempotency: None,
|
||||
safety: None,
|
||||
approval_policy: None,
|
||||
execution_policy: None,
|
||||
auth_profile_ref: None,
|
||||
headers: BTreeMap::new(),
|
||||
},
|
||||
|
||||
@@ -610,6 +610,7 @@ impl AdminService {
|
||||
idempotency: None,
|
||||
safety: None,
|
||||
approval_policy: None,
|
||||
execution_policy: None,
|
||||
auth_profile_ref,
|
||||
headers: BTreeMap::new(),
|
||||
},
|
||||
|
||||
@@ -160,6 +160,23 @@ pub(super) fn validate_approval_policy(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn validate_execution_policy(
|
||||
execution_config: &crank_core::ExecutionConfig,
|
||||
) -> Result<(), ApiError> {
|
||||
let Some(policy) = execution_config.execution_policy.as_ref() else {
|
||||
return Ok(());
|
||||
};
|
||||
if let Err(error) = policy.validate() {
|
||||
return Err(ApiError::validation_with_context(
|
||||
error.to_string(),
|
||||
json!({
|
||||
"field": "execution_config.execution_policy.deadline_ms",
|
||||
}),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::BTreeMap;
|
||||
@@ -171,8 +188,8 @@ mod tests {
|
||||
};
|
||||
|
||||
use super::{
|
||||
validate_approval_policy, validate_execution_timeout, validate_idempotency_policy,
|
||||
validate_response_cache_policy,
|
||||
validate_approval_policy, validate_execution_policy, validate_execution_timeout,
|
||||
validate_idempotency_policy, validate_response_cache_policy,
|
||||
};
|
||||
|
||||
fn cacheable_execution_config() -> ExecutionConfig {
|
||||
@@ -183,6 +200,7 @@ mod tests {
|
||||
idempotency: None,
|
||||
safety: None,
|
||||
approval_policy: None,
|
||||
execution_policy: None,
|
||||
auth_profile_ref: None,
|
||||
headers: BTreeMap::new(),
|
||||
}
|
||||
@@ -201,6 +219,7 @@ mod tests {
|
||||
}),
|
||||
safety: None,
|
||||
approval_policy: None,
|
||||
execution_policy: None,
|
||||
auth_profile_ref: None,
|
||||
headers: BTreeMap::new(),
|
||||
}
|
||||
@@ -365,4 +384,36 @@ mod tests {
|
||||
"approval ttl must be between 1 and 300 seconds"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_published_execution_policy_and_absent_legacy_policy() {
|
||||
let mut config = cacheable_execution_config();
|
||||
validate_execution_policy(&config).unwrap();
|
||||
|
||||
config.execution_policy = Some(crank_core::ToolExecutionPolicy {
|
||||
mode: crank_core::ToolExecutionMode::Adaptive,
|
||||
deadline_ms: 120_000,
|
||||
no_tasks_fallback: crank_core::NoTasksFallback::Unsupported,
|
||||
});
|
||||
validate_execution_policy(&config).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_zero_and_overflowing_execution_policy_deadline() {
|
||||
let mut config = cacheable_execution_config();
|
||||
config.execution_policy = Some(crank_core::ToolExecutionPolicy {
|
||||
mode: crank_core::ToolExecutionMode::Synchronous,
|
||||
deadline_ms: 0,
|
||||
no_tasks_fallback: crank_core::NoTasksFallback::Synchronous,
|
||||
});
|
||||
let error = validate_execution_policy(&config).unwrap_err();
|
||||
assert!(matches!(error, crate::error::ApiError::Validation { .. }));
|
||||
|
||||
config.execution_policy = Some(crank_core::ToolExecutionPolicy {
|
||||
mode: crank_core::ToolExecutionMode::Background,
|
||||
deadline_ms: crank_core::MAX_TOOL_DEADLINE_MS + 1,
|
||||
no_tasks_fallback: crank_core::NoTasksFallback::Synchronous,
|
||||
});
|
||||
assert!(validate_execution_policy(&config).is_err());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user