feat: harden community production foundation through story 1.5

This commit is contained in:
bsodfather committed 2026-08-14 00:21:59 +03:00
1 parent c30461cc92
commit f6fc2e5c9b
161 files changed
+16758 -2515

No files matched your search

@@ -15,6 +15,7 @@ use super::AppState;
pub(crate) struct InvocationRecord<'a> {
pub(crate) request_id: Option<&'a str>,
pub(crate) trace_id: Option<&'a str>,
pub(crate) tool_name: &'a str,
pub(crate) status: InvocationStatus,
pub(crate) level: InvocationLevel,
@@ -42,6 +43,7 @@ pub(crate) async fn persist_invocation(
tool_name: record.tool_name.to_owned(),
message: record.message.to_owned(),
request_id: record.request_id.map(ToOwned::to_owned),
trace_id: record.trace_id.map(ToOwned::to_owned),
status_code: record.status_code,
duration_ms: u64::try_from(record.duration.as_millis()).unwrap_or(u64::MAX),
error_kind: record.error_kind.map(ToOwned::to_owned),
@@ -79,6 +81,7 @@ pub(crate) async fn persist_invocation(
observe_invocation_history_outcome(
outcome,
record.request_id,
record.trace_id,
record.status,
InvocationSource::AgentToolCall,
);
@@ -88,6 +91,7 @@ pub(crate) async fn persist_invocation(
pub(super) fn observe_invocation_history_outcome(
outcome: InvocationHistoryWriteOutcome,
request_id: Option<&str>,
trace_id: Option<&str>,
status: InvocationStatus,
source: InvocationSource,
) {
@@ -100,6 +104,7 @@ pub(super) fn observe_invocation_history_outcome(
warn!(
name: "mcp.invocation_history.lost",
request_id = request_id.unwrap_or_default(),
trace_id = trace_id.unwrap_or_default(),
source = invocation_source_label(source),
invocation_status = invocation_status_label(status),
error_category = loss.category.as_str(),
@@ -37,6 +37,7 @@ async fn tool_error_response_includes_structured_context() {
"streaming_payload_error",
"request root must be an object",
"req-1",
"0af7651916cd43dd8448eb211c80319c",
false,
Some("Проверьте параметры вызова инструмента."),
),
@@ -59,6 +60,7 @@ async fn tool_error_response_includes_structured_context() {
"message": "request root must be an object",
"recoverable": false,
"request_id": "req-1",
"trace_id": "0af7651916cd43dd8448eb211c80319c",
"suggested_action": "Проверьте параметры вызова инструмента."
})
);
@@ -146,6 +148,7 @@ fn emits_bounded_history_loss_incident() {
category: InvocationHistoryLossCategory::Unavailable,
}),
Some("req_mcp_dc08"),
Some("0af7651916cd43dd8448eb211c80319c"),
InvocationStatus::Ok,
crank_core::InvocationSource::AgentToolCall,
);
@@ -0,0 +1,23 @@
use crank_registry::PublishedAgentTool;
use crank_runtime::RuntimeOperation;
use super::ResolvedToolCall;
pub(crate) fn resolve_generated_tool(
tools: &[PublishedAgentTool],
tool_name: &str,
) -> Option<ResolvedToolCall> {
tools
.iter()
.find(|tool| tool.tool_name == tool_name)
.cloned()
.map(|tool| ResolvedToolCall { tool })
}
pub(crate) fn runtime_operation(tool: &PublishedAgentTool) -> RuntimeOperation {
let mut operation = RuntimeOperation::from(tool.operation.clone());
operation.tool_name = tool.tool_name.clone();
operation.tool_description.title = tool.tool_title.clone();
operation.tool_description.description = tool.tool_description.clone();
operation
}