You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by wy...@apache.org on 2026/10/17 04:47:23 UTC
(maka) branch rust-preview updated: feat(agent): expose durable session diagnostics
This is an automated email from the ASF dual-hosted git repository.
M4n5ter pushed a commit to branch rust-preview
in repository https://gitbox.apache.org/repos/asf/maka.git
The following commit(s) were added to refs/heads/rust-preview by this push:
new 3ae080e3b3 feat(agent): expose durable session diagnostics
3ae080e3b3 is described below
commit 3ae080e3b36ed2e1f82aa995c567a5c255cd0de0
Author: Wang <m4...@gmail.com>
AuthorDate: Sat Oct 17 12:47:08 2026 +0800
feat(agent): expose durable session diagnostics
Project execution and model-step failures with typed safe causes, and record
logical automatic-title failures without changing physical usage or recovery.
Expose bounded session pages and independent watch revisions through the
Agent contract and one diagnostic panel, including late background failures.
Preserve original provenance, owner scope, fixed pagination fences, cleanup
priority and retained material. Regenerate SDK contracts and document the
public read/watch behavior.
Generated-by: Codex
---
packages/plugin-sdk/src/contracts.ts | 421 +++++++++++++++++++++
packages/plugin-sdk/src/generated/runtime.ts | 119 ++++++
.../event-log/migrations/0030_diagnostics.sql | 38 +-
platform/event-log/src/append/history.rs | 12 +
platform/event-log/src/diagnostics.rs | 218 +++++++++++
platform/event-log/src/lib.rs | 2 +
platform/event-log/src/recovery/startup.rs | 2 +
platform/event-log/src/sessions/material.rs | 16 +-
platform/event-log/src/title.rs | 89 +++++
platform/event-log/src/usage/auxiliary.rs | 20 +-
platform/event-log/tests/append_batch.rs | 1 +
platform/event-log/tests/catalog_partial.rs | 2 +
platform/event-log/tests/compact_presentation.rs | 2 +
.../tests/compact_presentation/automatic.rs | 1 +
.../event-log/tests/context_compaction/active.rs | 1 +
.../tests/context_compaction/active_safety.rs | 2 +
.../event-log/tests/context_compaction/fixtures.rs | 3 +
.../event-log/tests/context_compaction/frozen.rs | 1 +
.../event-log/tests/context_compaction/latest.rs | 1 +
.../tests/context_compaction/lineage/cells.rs | 1 +
.../tests/context_compaction/provider_history.rs | 2 +
platform/event-log/tests/continuation/handoff.rs | 1 +
platform/event-log/tests/diagnostics.rs | 391 +++++++++++++++++++
platform/event-log/tests/event_log.rs | 1 +
platform/event-log/tests/interaction_lifecycle.rs | 1 +
platform/event-log/tests/observation.rs | 1 +
platform/event-log/tests/run_prefix.rs | 1 +
platform/event-log/tests/session_material.rs | 25 ++
platform/event-log/tests/stream_delivery.rs | 2 +
platform/event-log/tests/streaming_usage.rs | 1 +
platform/event-log/tests/tool_usage.rs | 1 +
platform/event-log/tests/transcript_index.rs | 1 +
.../event-log/tests/transcript_index/fixtures.rs | 1 +
.../event-log/tests/transcript_index/history.rs | 3 +
.../event-log/tests/transcript_index/source.rs | 1 +
platform/event-log/tests/turn_boundary.rs | 1 +
platform/event-log/tests/usage.rs | 3 +
platform/event-log/tests/visible_tail.rs | 2 +
platform/js-runtime/trusted/provider-errors.js | 33 +-
platform/presentation/src/compact.rs | 1 +
platform/presentation/src/lib.rs | 1 +
platform/presentation/src/message.rs | 2 +-
platform/presentation/tests/projection.rs | 4 +
platform/presentation/tests/tools.rs | 1 +
plugins/agent/agent-screen/README.md | 1 +
plugins/agent/agent-screen/README.zh-CN.md | 1 +
plugins/agent/agent-screen/actions.ts | 20 +-
plugins/agent/agent-screen/diagnostics.ts | 360 ++++++++++++++++++
plugins/agent/agent-screen/events.ts | 14 +-
plugins/agent/agent-screen/frame.ts | 25 +-
plugins/agent/agent-screen/header-view.ts | 8 +
plugins/agent/agent-screen/index.ts | 2 +
plugins/agent/agent-screen/locale.ts | 74 ++++
plugins/agent/agent-screen/raw-events.ts | 3 +
plugins/agent/agent-screen/results.ts | 12 +
plugins/agent/agent-screen/state.ts | 7 +
plugins/agent/api/README.md | 2 +
plugins/agent/api/README.zh-CN.md | 2 +
plugins/agent/api/src/contract.rs | 52 +++
plugins/agent/assistant/src/plan/owner.rs | 2 +-
plugins/agent/engine/src/executor.rs | 2 +
plugins/agent/engine/src/model_attempt.rs | 5 +-
plugins/agent/engine/src/runner.rs | 6 +
.../agent/engine/tests/integration/context_stop.rs | 1 +
.../engine/tests/integration/model_interruption.rs | 7 +-
.../engine/tests/integration/startup_recovery.rs | 6 +-
plugins/agent/facts/src/diagnostics.rs | 96 +++++
plugins/agent/facts/src/event.rs | 6 +-
plugins/agent/facts/src/lib.rs | 1 +
plugins/agent/facts/src/model/error.rs | 46 ++-
plugins/agent/graph/src/projection.rs | 2 +-
plugins/agent/model/src/events.rs | 29 ++
.../agent/model/tests/fixtures/provider-errors.mjs | 23 +-
.../model/tests/integration/context_overflow.rs | 23 +-
.../model/tests/integration/provider_errors.rs | 69 +++-
.../model/tests/integration/provider_responses.rs | 2 +-
plugins/agent/native/README.md | 2 +
plugins/agent/native/README.zh-CN.md | 2 +
plugins/agent/native/src/owner/auxiliary.rs | 55 ++-
plugins/agent/native/src/owner/plan/dispatch.rs | 2 +-
plugins/agent/native/src/owner/queue.rs | 1 +
plugins/agent/native/src/owner/recap.rs | 1 +
plugins/agent/native/src/owner/tests/execution.rs | 27 +-
plugins/agent/native/src/owner/tests/selection.rs | 14 +-
plugins/agent/native/src/owner/tests/title.rs | 171 +++++++++
plugins/agent/native/src/owner/title.rs | 85 ++++-
plugins/agent/native/src/service.rs | 4 +
plugins/agent/native/src/service/diagnostics.rs | 113 ++++++
plugins/agent/responses/src/stream.rs | 27 +-
plugins/shared/locale-messages.ts | 122 ++++++
plugins/workhub/core/src/results.rs | 1 +
products/maka/bundle/tests/task-workbench.test.mjs | 122 ++++++
products/maka/cli/src/code.rs | 2 +
tools/schema/src/lib.rs | 3 +
94 files changed, 2956 insertions(+), 140 deletions(-)
diff --git a/packages/plugin-sdk/src/contracts.ts b/packages/plugin-sdk/src/contracts.ts
index 5135969cef..ec772c5f43 100644
--- a/packages/plugin-sdk/src/contracts.ts
+++ b/packages/plugin-sdk/src/contracts.ts
@@ -9791,6 +9791,393 @@ export const contracts = {
},
resources: {},
},
+ diagnostics: {
+ mode: 'query',
+ input: {
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
+ title: 'AgentDiagnostics',
+ type: 'object',
+ properties: {
+ sessionId: {
+ type: 'string',
+ minLength: 1,
+ maxLength: 128,
+ },
+ position: {
+ $ref: '#/$defs/AgentDiagnosticPosition',
+ },
+ },
+ additionalProperties: false,
+ required: ['sessionId', 'position'],
+ $defs: {
+ AgentDiagnosticPosition: {
+ oneOf: [
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'latest',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ {
+ type: 'object',
+ properties: {
+ through: {
+ type: 'integer',
+ format: 'uint64',
+ minimum: 0,
+ maximum: 9007199254740991,
+ },
+ sequence: {
+ type: 'integer',
+ format: 'uint64',
+ minimum: 1,
+ maximum: 9007199254740991,
+ },
+ kind: {
+ type: 'string',
+ const: 'before',
+ },
+ },
+ additionalProperties: false,
+ required: ['kind', 'through', 'sequence'],
+ },
+ ],
+ },
+ },
+ },
+ output: {
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
+ title: 'AgentDiagnosticPage',
+ type: 'object',
+ properties: {
+ through: {
+ type: 'integer',
+ format: 'uint64',
+ minimum: 0,
+ },
+ entries: {
+ type: 'array',
+ items: {
+ $ref: '#/$defs/AgentDiagnostic',
+ },
+ },
+ nextBefore: {
+ type: ['integer', 'null'],
+ format: 'uint64',
+ minimum: 0,
+ },
+ },
+ additionalProperties: false,
+ required: ['through', 'entries'],
+ $defs: {
+ AgentDiagnostic: {
+ type: 'object',
+ properties: {
+ sequence: {
+ type: 'integer',
+ format: 'uint64',
+ minimum: 0,
+ },
+ eventId: {
+ type: 'string',
+ },
+ recordedAt: {
+ type: 'number',
+ format: 'double',
+ },
+ detail: {
+ $ref: '#/$defs/DiagnosticDetail',
+ },
+ },
+ additionalProperties: false,
+ required: ['sequence', 'eventId', 'recordedAt', 'detail'],
+ },
+ DiagnosticDetail: {
+ oneOf: [
+ {
+ type: 'object',
+ properties: {
+ invocation: {
+ $ref: '#/$defs/Invocation',
+ },
+ reason: {
+ $ref: '#/$defs/ExecutionFailureReason',
+ },
+ modelFailure: {
+ anyOf: [
+ {
+ $ref: '#/$defs/ModelFailureCause',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ },
+ kind: {
+ type: 'string',
+ const: 'execution',
+ },
+ },
+ additionalProperties: false,
+ required: ['kind', 'invocation', 'reason'],
+ },
+ {
+ type: 'object',
+ properties: {
+ invocation: {
+ $ref: '#/$defs/Invocation',
+ },
+ stepId: {
+ type: 'string',
+ },
+ status: {
+ $ref: '#/$defs/ModelInterruption',
+ },
+ modelFailure: {
+ anyOf: [
+ {
+ $ref: '#/$defs/ModelFailureCause',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ },
+ kind: {
+ type: 'string',
+ const: 'model_step',
+ },
+ },
+ additionalProperties: false,
+ required: ['kind', 'invocation', 'stepId', 'status'],
+ },
+ {
+ type: 'object',
+ properties: {
+ invocation: {
+ $ref: '#/$defs/Invocation',
+ },
+ cause: {
+ $ref: '#/$defs/TitleFailureCause',
+ },
+ kind: {
+ type: 'string',
+ const: 'session_title',
+ },
+ },
+ additionalProperties: false,
+ required: ['kind', 'invocation', 'cause'],
+ },
+ ],
+ },
+ Invocation: {
+ type: 'object',
+ properties: {
+ session_id: {
+ type: 'string',
+ },
+ turn_id: {
+ type: 'string',
+ },
+ run_id: {
+ type: 'string',
+ },
+ invocation_id: {
+ type: 'string',
+ },
+ },
+ required: ['session_id', 'turn_id', 'run_id', 'invocation_id'],
+ },
+ ExecutionFailureReason: {
+ type: 'string',
+ enum: [
+ 'session_busy',
+ 'continuation_changed',
+ 'reconciliation_required',
+ 'invalid_input',
+ 'cancelled',
+ 'model_incomplete',
+ 'event_commit',
+ 'event_store',
+ 'model_timeout',
+ 'model_http',
+ 'model_adapter',
+ 'model_provider',
+ 'context_overflow',
+ 'tool_execution',
+ 'runtime_internal',
+ 'cleanup_unconfirmed',
+ 'executor',
+ 'message_preparation_failed',
+ 'host_interrupted',
+ 'outcome_unknown',
+ 'execution_failed',
+ ],
+ },
+ ModelFailureCause: {
+ description: 'Safe failure evidence, separate from provider-owned diagnostic text.',
+ oneOf: [
+ {
+ type: 'object',
+ properties: {
+ status: {
+ type: 'integer',
+ format: 'uint16',
+ minimum: 100,
+ maximum: 599,
+ },
+ kind: {
+ type: 'string',
+ const: 'http',
+ },
+ },
+ additionalProperties: false,
+ required: ['kind', 'status'],
+ },
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'timed_out',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'context_overflow',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ {
+ type: 'object',
+ properties: {
+ reason: {
+ $ref: '#/$defs/ProviderFailureReason',
+ },
+ kind: {
+ type: 'string',
+ const: 'provider',
+ },
+ },
+ additionalProperties: false,
+ required: ['kind', 'reason'],
+ },
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'adapter',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ ],
+ },
+ ProviderFailureReason: {
+ type: 'string',
+ enum: [
+ 'network',
+ 'timed_out',
+ 'rate_limit',
+ 'provider_unavailable',
+ 'stream_truncated',
+ ],
+ },
+ ModelInterruption: {
+ oneOf: [
+ {
+ type: 'string',
+ enum: ['cancelled', 'timed_out', 'failed'],
+ },
+ {
+ description:
+ 'Trusted ingress permits retry: legacy steps can discard observations;\nitem-accepting steps must retain completed items and settle their tools.\nThis records safety evidence, not an instruction to retry.',
+ type: 'string',
+ const: 'retryable_failure',
+ },
+ ],
+ },
+ TitleFailureCause: {
+ oneOf: [
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'preparation',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ {
+ type: 'object',
+ properties: {
+ cause: {
+ $ref: '#/$defs/ModelFailureCause',
+ },
+ kind: {
+ type: 'string',
+ const: 'model',
+ },
+ },
+ additionalProperties: false,
+ required: ['kind', 'cause'],
+ },
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'invalid_output',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'output_limit',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ {
+ type: 'object',
+ properties: {
+ kind: {
+ type: 'string',
+ const: 'empty_output',
+ },
+ },
+ required: ['kind'],
+ additionalProperties: false,
+ },
+ ],
+ },
+ },
+ },
+ resources: {},
+ },
directories: {
mode: 'query',
input: {
@@ -24059,6 +24446,40 @@ export const contracts = {
},
resources: {},
},
+ watchDiagnostics: {
+ mode: 'subscription',
+ input: {
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
+ title: 'AgentSessionRead',
+ type: 'object',
+ properties: {
+ sessionId: {
+ type: 'string',
+ minLength: 1,
+ maxLength: 128,
+ },
+ },
+ additionalProperties: false,
+ required: ['sessionId'],
+ },
+ output: {
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
+ title: 'AgentDiagnosticChange',
+ type: 'object',
+ properties: {
+ revision: {
+ description:
+ 'Latest diagnostic event sequence, independently of transcript progress.',
+ type: 'integer',
+ format: 'uint64',
+ minimum: 0,
+ },
+ },
+ additionalProperties: false,
+ required: ['revision'],
+ },
+ resources: {},
+ },
watchGoal: {
mode: 'subscription',
input: {
diff --git a/packages/plugin-sdk/src/generated/runtime.ts b/packages/plugin-sdk/src/generated/runtime.ts
index bbf83c20b8..2142f678bd 100644
--- a/packages/plugin-sdk/src/generated/runtime.ts
+++ b/packages/plugin-sdk/src/generated/runtime.ts
@@ -310,6 +310,9 @@ export type RuntimeProtocol =
| AgentDeliveryFact
| AgentContentKind
| AgentObservation
+ | AgentDiagnostics
+ | AgentDiagnosticPage
+ | AgentDiagnosticChange
| AgentSessionRead
| AgentHistoryRead
| AgentHistoryPromptRead
@@ -4514,6 +4517,101 @@ export type AgentDeliveryFact =
};
export type AgentContentKind = 'text' | 'thinking';
export type AgentRunState = 'admitted' | 'running' | 'waiting_for_user';
+export type AgentDiagnosticPosition =
+ | {
+ kind: 'latest';
+ }
+ | {
+ through: number;
+ sequence: number;
+ kind: 'before';
+ };
+export type DiagnosticDetail =
+ | {
+ invocation: Invocation;
+ reason: ExecutionFailureReason;
+ modelFailure?: ModelFailureCause | null;
+ kind: 'execution';
+ }
+ | {
+ invocation: Invocation;
+ stepId: string;
+ status: ModelInterruption;
+ modelFailure?: ModelFailureCause | null;
+ kind: 'model_step';
+ }
+ | {
+ invocation: Invocation;
+ cause: TitleFailureCause;
+ kind: 'session_title';
+ };
+export type ExecutionFailureReason =
+ | 'session_busy'
+ | 'continuation_changed'
+ | 'reconciliation_required'
+ | 'invalid_input'
+ | 'cancelled'
+ | 'model_incomplete'
+ | 'event_commit'
+ | 'event_store'
+ | 'model_timeout'
+ | 'model_http'
+ | 'model_adapter'
+ | 'model_provider'
+ | 'context_overflow'
+ | 'tool_execution'
+ | 'runtime_internal'
+ | 'cleanup_unconfirmed'
+ | 'executor'
+ | 'message_preparation_failed'
+ | 'host_interrupted'
+ | 'outcome_unknown'
+ | 'execution_failed';
+/**
+ * Safe failure evidence, separate from provider-owned diagnostic text.
+ */
+export type ModelFailureCause =
+ | {
+ status: number;
+ kind: 'http';
+ }
+ | {
+ kind: 'timed_out';
+ }
+ | {
+ kind: 'context_overflow';
+ }
+ | {
+ reason: ProviderFailureReason;
+ kind: 'provider';
+ }
+ | {
+ kind: 'adapter';
+ };
+export type ProviderFailureReason =
+ | 'network'
+ | 'timed_out'
+ | 'rate_limit'
+ | 'provider_unavailable'
+ | 'stream_truncated';
+export type ModelInterruption = ('cancelled' | 'timed_out' | 'failed') | 'retryable_failure';
+export type TitleFailureCause =
+ | {
+ kind: 'preparation';
+ }
+ | {
+ cause: ModelFailureCause;
+ kind: 'model';
+ }
+ | {
+ kind: 'invalid_output';
+ }
+ | {
+ kind: 'output_limit';
+ }
+ | {
+ kind: 'empty_output';
+ };
/**
* Cursor sequence addresses a sparse transcript row; Event addresses the raw
* event log. Before excludes its end and After includes its start. Returned
@@ -9975,6 +10073,27 @@ export interface AgentPart {
partId: string;
textKind: AgentContentKind;
}
+export interface AgentDiagnostics {
+ sessionId: string;
+ position: AgentDiagnosticPosition;
+}
+export interface AgentDiagnosticPage {
+ through: number;
+ entries: AgentDiagnostic[];
+ nextBefore?: number | null;
+}
+export interface AgentDiagnostic {
+ sequence: number;
+ eventId: string;
+ recordedAt: number;
+ detail: DiagnosticDetail;
+}
+export interface AgentDiagnosticChange {
+ /**
+ * Latest diagnostic event sequence, independently of transcript progress.
+ */
+ revision: number;
+}
export interface AgentSessionRead {
sessionId: string;
}
diff --git a/plugins/agent/facts/src/lib.rs b/platform/event-log/migrations/0030_diagnostics.sql
similarity index 54%
copy from plugins/agent/facts/src/lib.rs
copy to platform/event-log/migrations/0030_diagnostics.sql
index b926e4429a..bf0163d57a 100644
--- a/plugins/agent/facts/src/lib.rs
+++ b/platform/event-log/migrations/0030_diagnostics.sql
@@ -17,37 +17,7 @@
* under the License.
*/
-//! Agent, Session and Run facts shared by persistence and execution; no engine or SQLite dependency.
-pub mod access;
-pub mod accounting;
-pub mod archive;
-pub mod artifact;
-pub mod attachment;
-pub mod capability;
-pub mod composition;
-pub mod configuration;
-pub mod context;
-pub mod continuation;
-pub mod event;
-mod event_write;
-pub mod execution;
-pub mod executor;
-pub mod handoff;
-pub mod import;
-pub mod input;
-pub mod interaction;
-pub mod message;
-pub mod model;
-pub mod oauth;
-pub mod pricing;
-pub mod provider;
-pub mod read;
-pub mod session;
-pub mod shell_result;
-pub mod shell_run;
-pub mod terminal;
-pub mod tool_call;
-pub mod tool_output;
-pub mod tools;
-
-pub mod display;
+-- Only diagnostic candidates, never model body chunks, participate in this lookup.
+CREATE INDEX diagnostic_session_sequence ON event_log(
+ CASE WHEN kind='title_failure' THEN json_extract(event_json,'$.opening.session_id') ELSE json_extract(event_json,'$.invocation.session_id') END, sequence
+) WHERE (kind='title_failure' OR (kind='invocation_ended' AND json_extract(event_json,'$.fact.outcome.kind')='failed') OR (kind='model_interrupted' AND json_extract(event_json,'$.fact.status')!='cancelled'));
diff --git a/platform/event-log/src/append/history.rs b/platform/event-log/src/append/history.rs
index 6c00ada98d..0706a94707 100644
--- a/platform/event-log/src/append/history.rs
+++ b/platform/event-log/src/append/history.rs
@@ -33,6 +33,18 @@ pub(crate) async fn validate(
connection: &mut SqliteConnection,
event: &RuntimeEvent,
) -> Result<(), StoreError> {
+ let model_failure = match &event.fact {
+ Fact::ModelInterrupted { model_failure, .. }
+ | Fact::InvocationEnded {
+ outcome: InvocationOutcome::Failed { model_failure, .. },
+ } => model_failure.as_ref(),
+ _ => None,
+ };
+ if let Some(cause) = model_failure {
+ cause
+ .validate()
+ .map_err(|error| invalid(&error.to_string()))?;
+ }
identity(connection, event).await?;
crate::executor::validate(connection, event).await?;
crate::model_items::validate(connection, event).await?;
diff --git a/platform/event-log/src/diagnostics.rs b/platform/event-log/src/diagnostics.rs
new file mode 100644
index 0000000000..75c0cb521d
--- /dev/null
+++ b/platform/event-log/src/diagnostics.rs
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//! Bounded safe projections of original execution and auxiliary facts.
+
+use crate::{EventLog, StoreError};
+use futures_util::TryStreamExt;
+use maka_agent_facts::diagnostics::DiagnosticDetail;
+use serde::{Deserialize, Serialize};
+use sqlx::{Connection, Row};
+use std::time::SystemTime;
+
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Record {
+ pub sequence: u64,
+ pub event_id: String,
+ pub recorded_at: SystemTime,
+ pub detail: DiagnosticDetail,
+}
+#[derive(Debug, Serialize)]
+pub struct Page {
+ pub through: u64,
+ pub entries: Vec<Record>,
+ pub next_before: Option<u64>,
+}
+impl EventLog {
+ pub async fn diagnostics_page(
+ &self,
+ session: &str,
+ through: Option<u64>,
+ before: Option<u64>,
+ max_entries: usize,
+ max_bytes: usize,
+ ) -> Result<Page, StoreError> {
+ self.validate_root()?;
+ crate::sessions::validate_id(session)?;
+ if max_entries == 0
+ || max_entries > 32
+ || max_bytes == 0
+ || (before.is_some() && through.is_none())
+ {
+ return Err(invalid("invalid diagnostic page bounds"));
+ }
+ let session = session.to_owned();
+ self.connection
+ .read(move |connection| {
+ Box::pin(async move {
+ let mut tx = connection.begin().await?;
+ let high_water = crate::observation::high_water(&mut tx).await?;
+ let through = through.unwrap_or(high_water);
+ validate_bounds(through, before, high_water)?;
+ let mut entries: Vec<Record> = Vec::new();
+ let mut more = false;
+ {
+ let mut rows = sqlx::query(RECORDS)
+ .bind(session)
+ .bind(through as i64)
+ .bind(before.map(|n| n as i64))
+ .bind(max_entries as i64 + 1)
+ .fetch(&mut *tx);
+ while let Some(row) = rows.try_next().await? {
+ let json: &str = row.try_get(0)?;
+ if entries.len() == max_entries || json.len() > max_bytes {
+ if entries.is_empty() {
+ return Err(StoreError::PrefixTooLarge);
+ }
+ more = true;
+ break;
+ }
+ entries.push(serde_json::from_str(json)?);
+ }
+ }
+ let mut page = Page {
+ through,
+ entries,
+ next_before: None,
+ };
+ loop {
+ page.next_before = if more {
+ page.entries.last().map(|entry| entry.sequence)
+ } else {
+ None
+ };
+ if serde_json::to_vec(&page)?.len() <= max_bytes {
+ break;
+ }
+ if page.entries.pop().is_none() || page.entries.is_empty() {
+ return Err(StoreError::PrefixTooLarge);
+ }
+ more = true;
+ }
+ tx.commit().await?;
+ Ok(page)
+ })
+ })
+ .await
+ }
+
+ pub async fn latest_diagnostic_sequence(
+ &self,
+ session: &str,
+ through: u64,
+ ) -> Result<Option<u64>, StoreError> {
+ self.validate_root()?;
+ crate::sessions::validate_id(session)?;
+ let session = session.to_owned();
+ self.connection
+ .read(move |connection| {
+ Box::pin(async move {
+ let mut tx = connection.begin().await?;
+ let high_water = crate::observation::high_water(&mut tx).await?;
+ validate_bounds(through, None, high_water)?;
+ let sequence: Option<i64> = sqlx::query_scalar(LATEST)
+ .bind(session)
+ .bind(through as i64)
+ .fetch_optional(&mut *tx)
+ .await?;
+ tx.commit().await?;
+ sequence.map(crate::sequence_number).transpose()
+ })
+ })
+ .await
+ }
+}
+fn validate_bounds(through: u64, before: Option<u64>, high_water: u64) -> Result<(), StoreError> {
+ if through > high_water || before.is_some_and(|before| before == 0 || before > through) {
+ return Err(invalid("invalid diagnostic fence"));
+ }
+ Ok(())
+}
+fn invalid(message: &str) -> StoreError {
+ StoreError::InvalidTransition(message.into())
+}
+
+const RECORDS: &str = r#"SELECT json_object('sequence',sequence,'event_id',event_id,
+ 'recorded_at',json_extract(event_json,'$.recorded_at'),
+ 'detail',json(CASE kind
+ WHEN 'title_failure' THEN json_object('kind','session_title','invocation',json_extract(event_json,'$.opening'),'cause',json_extract(event_json,'$.cause'))
+ WHEN 'model_interrupted' THEN json_object('kind','model_step','invocation',json_extract(event_json,'$.invocation'),
+ 'stepId',json_extract(event_json,'$.fact.step_id'),'status',json_extract(event_json,'$.fact.status'),
+ 'modelFailure',json_extract(event_json,'$.fact.model_failure'))
+ ELSE json_object('kind','execution','invocation',json_extract(event_json,'$.invocation'),
+ 'reason',CASE WHEN json_extract(event_json,'$.fact.outcome.class') IN ('session_busy','continuation_changed','reconciliation_required','invalid_input','cancelled','model_incomplete','event_commit','event_store','model_timeout','model_http','model_adapter','model_provider','context_overflow','tool_execution','runtime_internal','cleanup_unconfirmed','executor','message_preparation_failed','host_interrupted','outcome_unknown') THEN json_extract(event_json,'$.fact.outcome.class') ELSE 'e [...]
+ 'modelFailure',json_extract(event_json,'$.fact.outcome.model_failure')) END))
+FROM event_log INDEXED BY diagnostic_session_sequence
+WHERE (kind='title_failure' OR (kind='invocation_ended' AND json_extract(event_json,'$.fact.outcome.kind')='failed') OR (kind='model_interrupted' AND json_extract(event_json,'$.fact.status')!='cancelled')) AND (CASE WHEN kind='title_failure' THEN json_extract(event_json,'$.opening.session_id') ELSE json_extract(event_json,'$.invocation.session_id') END)=?1 AND sequence<=min(?2,coalesce(?3-1,?2))
+ORDER BY sequence DESC LIMIT ?4"#;
+const LATEST: &str = r#"SELECT sequence FROM event_log INDEXED BY diagnostic_session_sequence
+WHERE (kind='title_failure' OR (kind='invocation_ended' AND json_extract(event_json,'$.fact.outcome.kind')='failed') OR (kind='model_interrupted' AND json_extract(event_json,'$.fact.status')!='cancelled')) AND (CASE WHEN kind='title_failure' THEN json_extract(event_json,'$.opening.session_id') ELSE json_extract(event_json,'$.invocation.session_id') END)=?1 AND sequence<=?2
+ORDER BY sequence DESC LIMIT 1"#;
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[tokio::test]
+ async fn diagnostic_queries_use_the_candidate_index_without_body_scans() {
+ let directory = tempfile::tempdir().unwrap();
+ let log = EventLog::open(&directory.path().join("plan.sqlite"))
+ .await
+ .unwrap();
+ log.connection
+ .read(|connection| {
+ Box::pin(async move {
+ for (query, paged) in [(RECORDS, true), (LATEST, false)] {
+ let explain = format!("EXPLAIN QUERY PLAN {query}");
+ let query = sqlx::query(sqlx::AssertSqlSafe(explain.as_str()))
+ .bind("session")
+ .bind(100i64);
+ let rows = if paged {
+ query
+ .bind(None::<i64>)
+ .bind(33i64)
+ .fetch_all(&mut *connection)
+ .await?
+ } else {
+ query.fetch_all(&mut *connection).await?
+ };
+ let plan = rows
+ .iter()
+ .map(|row| row.get::<String, _>(3))
+ .collect::<Vec<_>>()
+ .join("\n");
+ assert!(
+ plan.contains(
+ "SEARCH event_log USING INDEX diagnostic_session_sequence"
+ ),
+ "{plan}"
+ );
+ assert!(
+ !plan.contains("SCAN event_log") && !plan.contains("USE TEMP B-TREE"),
+ "{plan}"
+ );
+ }
+ Ok(())
+ })
+ })
+ .await
+ .unwrap();
+ log.close().await.unwrap();
+ }
+}
diff --git a/platform/event-log/src/lib.rs b/platform/event-log/src/lib.rs
index 695536b395..04fd66bfa1 100644
--- a/platform/event-log/src/lib.rs
+++ b/platform/event-log/src/lib.rs
@@ -28,6 +28,7 @@ mod catalog_changes;
pub mod connection;
pub mod context;
mod continuation;
+pub mod diagnostics;
pub mod effects;
mod executor;
mod handoff;
@@ -55,6 +56,7 @@ pub mod shell_runs;
mod sqlite_functions;
pub mod steering;
mod steering_delivery;
+pub mod title;
mod tool_calls;
mod tool_payloads;
pub mod transcript;
diff --git a/platform/event-log/src/recovery/startup.rs b/platform/event-log/src/recovery/startup.rs
index 78c3bcf9aa..8b7869b107 100644
--- a/platform/event-log/src/recovery/startup.rs
+++ b/platform/event-log/src/recovery/startup.rs
@@ -64,6 +64,7 @@ pub async fn recover_invocations(log: &EventLog) -> Result<usize, RecoveryError>
};
for step_id in state.unfinished_model_steps {
append(Fact::ModelInterrupted {
+ model_failure: None,
step_id,
status: ModelInterruption::Failed,
diagnostic: Some("Host stopped before the model request settled.".into()),
@@ -83,6 +84,7 @@ pub async fn recover_invocations(log: &EventLog) -> Result<usize, RecoveryError>
}
append(Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: if state.uncertain_operations.is_empty() && !state.unfinished_executor {
"host_interrupted"
} else {
diff --git a/platform/event-log/src/sessions/material.rs b/platform/event-log/src/sessions/material.rs
index daa20979cd..ac5ef826a5 100644
--- a/platform/event-log/src/sessions/material.rs
+++ b/platform/event-log/src/sessions/material.rs
@@ -145,11 +145,15 @@ fn retained(event: &RuntimeEvent) -> Value {
step_id,
status,
diagnostic,
+ model_failure,
} => {
let mut material = json!({"step_id":step_id,"status":status});
if let Some(diagnostic) = diagnostic {
material["diagnostic"] = json!(diagnostic);
}
+ if let Some(cause) = model_failure {
+ material["model_failure"] = json!(cause);
+ }
material
}
Fact::ModelObserved {
@@ -178,7 +182,17 @@ fn retained(event: &RuntimeEvent) -> Value {
Fact::InvocationEnded { outcome } => {
let outcome = match outcome {
InvocationOutcome::Completed => json!({"kind":"completed"}),
- InvocationOutcome::Failed { class, .. } => json!({"kind":"failed","class":class}),
+ InvocationOutcome::Failed {
+ class,
+ model_failure,
+ ..
+ } => {
+ let mut material = json!({"kind":"failed","class":class});
+ if let Some(cause) = model_failure {
+ material["model_failure"] = json!(cause);
+ }
+ material
+ }
InvocationOutcome::Cancelled { source } => {
json!({"kind":"cancelled","source":source})
}
diff --git a/platform/event-log/src/title.rs b/platform/event-log/src/title.rs
new file mode 100644
index 0000000000..f7b7ba6583
--- /dev/null
+++ b/platform/event-log/src/title.rs
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//! Logical title failure evidence does not create a physical model attempt.
+
+use crate::{EventLog, StoreError};
+use maka_agent_facts::{
+ diagnostics::TitleFailureCause,
+ event::{Fact, Invocation},
+ execution::ModelBinding,
+};
+use serde::Serialize;
+use sqlx::{Connection, SqliteConnection};
+use std::time::SystemTime;
+
+#[derive(Serialize)]
+struct Failure {
+ // A non-runtime event must not populate the generated runtime event_session.
+ opening: Invocation,
+ recorded_at: SystemTime,
+ cause: TitleFailureCause,
+}
+
+impl EventLog {
+ pub async fn record_title_failure(
+ &self,
+ invocation: Invocation,
+ cause: TitleFailureCause,
+ ) -> Result<u64, StoreError> {
+ self.validate_root()?;
+ cause
+ .validate()
+ .map_err(|error| invalid(&error.to_string()))?;
+ let commits = self.commits.clone();
+ self.connection.run(move |connection| Box::pin(async move {
+ let mut tx = connection.begin_with("BEGIN IMMEDIATE").await?;
+ original_title_binding(&mut tx, &invocation).await?;
+ let failure = Failure { opening: invocation, recorded_at: SystemTime::now(), cause };
+ let result = sqlx::query("INSERT INTO event_log(event_id,kind,event_json) VALUES (?,'title_failure',?)")
+ .bind(uuid::Uuid::new_v4().to_string()).bind(serde_json::to_string(&failure)?)
+ .execute(&mut *tx).await?;
+ let sequence = crate::sequence_number(result.last_insert_rowid())?;
+ tx.commit().await.map_err(StoreError::CommitUnknown)?;
+ commits.send_replace(sequence);
+ Ok(sequence)
+ })).await
+ }
+}
+
+/// Original provenance only; current admission and attempt policy belong to the caller.
+pub(crate) async fn original_title_binding(
+ connection: &mut SqliteConnection,
+ invocation: &Invocation,
+) -> Result<ModelBinding, StoreError> {
+ let opening = crate::message_sources::first_message_opening(connection, &invocation.session_id)
+ .await?
+ .ok_or_else(|| invalid("Session title has no committed user opening"))?;
+ if opening.event.invocation != *invocation {
+ return Err(invalid("Session title must use its first user opening"));
+ }
+ match opening.event.fact {
+ Fact::InvocationOpened {
+ configuration: Some(config),
+ ..
+ } => config
+ .model
+ .ok_or_else(|| invalid("Session title has no frozen model binding")),
+ _ => Err(invalid("Session title has no frozen configuration")),
+ }
+}
+fn invalid(message: &str) -> StoreError {
+ StoreError::InvalidTransition(message.into())
+}
diff --git a/platform/event-log/src/usage/auxiliary.rs b/platform/event-log/src/usage/auxiliary.rs
index a627b9bd10..48bd8dbb7d 100644
--- a/platform/event-log/src/usage/auxiliary.rs
+++ b/platform/event-log/src/usage/auxiliary.rs
@@ -240,23 +240,9 @@ async fn binding(
return Err(invalid("Session title was already attempted"));
}
- let opening =
- crate::message_sources::first_message_opening(connection, &invocation.session_id)
- .await?
- .ok_or_else(|| invalid("Session title has no committed user opening"))?;
- if opening.event.invocation != *invocation {
- return Err(invalid("Session title must use its first user opening"));
- }
- match opening.event.fact {
- maka_agent_facts::event::Fact::InvocationOpened {
- configuration: Some(config),
- ..
- } => config
- .model
- .map(|binding| (binding, Some(invocation.session_id.clone())))
- .ok_or_else(|| invalid("Session title has no frozen model binding")),
- _ => Err(invalid("Session title has no frozen configuration")),
- }
+ crate::title::original_title_binding(connection, invocation)
+ .await
+ .map(|binding| (binding, Some(invocation.session_id.clone())))
}
Source::Agent {
invocation,
diff --git a/platform/event-log/tests/append_batch.rs b/platform/event-log/tests/append_batch.rs
index 19b36c330a..1c6cf7ff14 100644
--- a/platform/event-log/tests/append_batch.rs
+++ b/platform/event-log/tests/append_batch.rs
@@ -136,6 +136,7 @@ async fn batch_rolls_back_every_fact_and_catalog_change_then_replays_exactly_aft
// A replay mixed with a new terminal still validates and commits in order.
let terminal = event(Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "host_interrupted".into(),
message: None,
},
diff --git a/platform/event-log/tests/catalog_partial.rs b/platform/event-log/tests/catalog_partial.rs
index 4d65e8c169..80114173aa 100644
--- a/platform/event-log/tests/catalog_partial.rs
+++ b/platform/event-log/tests/catalog_partial.rs
@@ -86,6 +86,7 @@ async fn interrupted_and_terminal_fallback_catalog_match_committed_presentation_
(
false,
InvocationOutcome::Failed {
+ model_failure: None,
class: "event_commit".into(),
message: None,
},
@@ -188,6 +189,7 @@ async fn interrupted_and_terminal_fallback_catalog_match_committed_presentation_
&log,
&mut view,
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "step".into(),
status: ModelInterruption::Cancelled,
diff --git a/platform/event-log/tests/compact_presentation.rs b/platform/event-log/tests/compact_presentation.rs
index ea05c8a1c7..43bb0f5bd4 100644
--- a/platform/event-log/tests/compact_presentation.rs
+++ b/platform/event-log/tests/compact_presentation.rs
@@ -222,6 +222,7 @@ async fn compact_attempts_preserve_visible_history_read_markers_and_rebuild() {
&mut view,
&compact,
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "summary".into(),
status: ModelInterruption::Cancelled,
@@ -233,6 +234,7 @@ async fn compact_attempts_preserve_visible_history_read_markers_and_rebuild() {
}
}
_ => InvocationOutcome::Failed {
+ model_failure: None,
class: "provider".into(),
message: None,
},
diff --git a/platform/event-log/tests/compact_presentation/automatic.rs b/platform/event-log/tests/compact_presentation/automatic.rs
index 4cfa68377e..26abb8ab5a 100644
--- a/platform/event-log/tests/compact_presentation/automatic.rs
+++ b/platform/event-log/tests/compact_presentation/automatic.rs
@@ -140,6 +140,7 @@ async fn automatic_summary_is_hidden_without_interrupting_main_delivery_or_read_
&log,
&inv,
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "summary".into(),
status: ModelInterruption::Failed,
diff --git a/platform/event-log/tests/context_compaction/active.rs b/platform/event-log/tests/context_compaction/active.rs
index ab690502a6..ee5928aba7 100644
--- a/platform/event-log/tests/context_compaction/active.rs
+++ b/platform/event-log/tests/context_compaction/active.rs
@@ -344,6 +344,7 @@ async fn active_cut_rejects_pending_child_and_changed_summary_repair_source() {
log.append(&event(
"active",
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "repair".into(),
status: maka_agent_facts::event::ModelInterruption::Failed,
diff --git a/platform/event-log/tests/context_compaction/active_safety.rs b/platform/event-log/tests/context_compaction/active_safety.rs
index 30206f455c..e66a6871a9 100644
--- a/platform/event-log/tests/context_compaction/active_safety.rs
+++ b/platform/event-log/tests/context_compaction/active_safety.rs
@@ -64,6 +64,7 @@ async fn active_cuts_require_settled_effects_or_explicit_retry_safety() {
log.append(&event(
"active",
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "main".into(),
status: if retryable {
@@ -165,6 +166,7 @@ async fn private_summary_failure_allows_main_progress_only_without_provider_effe
log.append(&event(
"active",
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "summary".into(),
status: maka_agent_facts::event::ModelInterruption::Failed,
diff --git a/platform/event-log/tests/context_compaction/fixtures.rs b/platform/event-log/tests/context_compaction/fixtures.rs
index edfea322b5..f7d7677b58 100644
--- a/platform/event-log/tests/context_compaction/fixtures.rs
+++ b/platform/event-log/tests/context_compaction/fixtures.rs
@@ -188,6 +188,7 @@ pub(super) async fn prepare_trace(
event(
id,
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: format!("{id}-summary"),
status: maka_agent_facts::event::ModelInterruption::Failed,
@@ -197,6 +198,7 @@ pub(super) async fn prepare_trace(
id,
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "summary_failed".into(),
message: None,
},
@@ -407,6 +409,7 @@ async fn adoption_markers_are_durable_timed_and_hidden_from_recall() {
Fact::InvocationEnded {
outcome: if !adopt {
InvocationOutcome::Failed {
+ model_failure: None,
class: "summary_failed".into(),
message: None,
}
diff --git a/platform/event-log/tests/context_compaction/frozen.rs b/platform/event-log/tests/context_compaction/frozen.rs
index 007925c59f..1d5bfc7c8c 100644
--- a/platform/event-log/tests/context_compaction/frozen.rs
+++ b/platform/event-log/tests/context_compaction/frozen.rs
@@ -251,6 +251,7 @@ async fn a_closed_frozen_boundary_does_not_prove_that_tool_effects_are_settled()
"live",
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "outcome_unknown".into(),
message: None,
},
diff --git a/platform/event-log/tests/context_compaction/latest.rs b/platform/event-log/tests/context_compaction/latest.rs
index d90b5c4590..cb814ca7e7 100644
--- a/platform/event-log/tests/context_compaction/latest.rs
+++ b/platform/event-log/tests/context_compaction/latest.rs
@@ -86,6 +86,7 @@ async fn preturn_keeps_anchor_and_latest_main_never_falls_back_a_broken_newer_tr
"current",
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "later_tool_failure".into(),
message: None,
},
diff --git a/platform/event-log/tests/context_compaction/lineage/cells.rs b/platform/event-log/tests/context_compaction/lineage/cells.rs
index 5e25b303fd..db27b07e8f 100644
--- a/platform/event-log/tests/context_compaction/lineage/cells.rs
+++ b/platform/event-log/tests/context_compaction/lineage/cells.rs
@@ -148,6 +148,7 @@ async fn lineage_model_cut_allows_only_independent_cell_progress_not_compaction_
log.append(&event(
"child",
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "attempt".into(),
status: maka_agent_facts::event::ModelInterruption::RetryableFailure,
diff --git a/platform/event-log/tests/context_compaction/provider_history.rs b/platform/event-log/tests/context_compaction/provider_history.rs
index 5c061a41f4..064b5e2944 100644
--- a/platform/event-log/tests/context_compaction/provider_history.rs
+++ b/platform/event-log/tests/context_compaction/provider_history.rs
@@ -107,6 +107,7 @@ async fn interrupted_history_preserves_provider_effect_uncertainty_without_rejec
event(
"old",
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "interrupted".into(),
status: maka_agent_facts::event::ModelInterruption::Failed,
@@ -116,6 +117,7 @@ async fn interrupted_history_preserves_provider_effect_uncertainty_without_rejec
"old",
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "stream_failed".into(),
message: None,
},
diff --git a/platform/event-log/tests/continuation/handoff.rs b/platform/event-log/tests/continuation/handoff.rs
index 230a434ba7..0e12e4044c 100644
--- a/platform/event-log/tests/continuation/handoff.rs
+++ b/platform/event-log/tests/continuation/handoff.rs
@@ -147,6 +147,7 @@ async fn handoff_rejects_unresolved_provider_effects_but_accepts_effect_free_sum
&RuntimeEvent::new(
source.invocation.clone(),
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "step".into(),
status: ModelInterruption::Failed,
diff --git a/platform/event-log/tests/diagnostics.rs b/platform/event-log/tests/diagnostics.rs
new file mode 100644
index 0000000000..4b55453844
--- /dev/null
+++ b/platform/event-log/tests/diagnostics.rs
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use maka_agent_facts::{
+ diagnostics::{DiagnosticDetail, ExecutionFailureReason, TitleFailureCause},
+ event::{
+ EventWrite, Fact, Invocation, InvocationOutcome, LogScope, ModelInterruption, RuntimeEvent,
+ },
+ execution::*,
+ input::InvocationInput,
+ model::error::ModelFailureCause,
+ session::{CopyPurpose, CopyRequest},
+};
+use maka_event_log::{EventLog, StoreError, sessions::SessionCopyResult};
+use serde_json::{Value, json};
+
+async fn append(log: &EventLog, invocation: &Invocation, fact: Fact) -> u64 {
+ log.append(&EventWrite::plain(RuntimeEvent::new(invocation.clone(), fact)).unwrap())
+ .await
+ .unwrap()
+}
+async fn opening(log: &EventLog, session: &str, id: &str) -> Invocation {
+ let invocation = Invocation {
+ session_id: session.into(),
+ turn_id: id.into(),
+ run_id: id.into(),
+ invocation_id: id.into(),
+ };
+ append(
+ log,
+ &invocation,
+ Fact::InvocationOpened {
+ configuration: Some(Box::new(InvocationConfiguration {
+ compaction_prompt: None,
+ workspace_origin: WorkspaceOrigin::Selected,
+ approval_policy: ApprovalPolicy::OnRequest,
+ boundary_revision: 0,
+ cwd: "/tmp".into(),
+ workspace_identity: None,
+ model: Some(ModelBinding {
+ connection_id: "connection".into(),
+ connection_slug: "original".into(),
+ model: "requested".into(),
+ }),
+ editing_tools: None,
+ tool_discovery: false,
+ tool_composition: None,
+ system_prompt: None,
+ thinking_level: None,
+ sandbox_mode: SandboxMode::ReadOnly,
+ collaboration_mode: CollaborationMode::Agent,
+ orchestration_mode: BehaviorId::default(),
+ tool_mode: ToolMode::Direct,
+ })),
+ input: InvocationInput::Message {
+ source_messages: vec![],
+ content: "original question".into(),
+ request_fingerprint: None,
+ },
+ },
+ )
+ .await;
+ invocation
+}
+
+#[tokio::test]
+async fn diagnostic_pages_preserve_sources_fences_and_operational_copy_scope() {
+ let directory = tempfile::tempdir().unwrap();
+ let path = directory.path().join("diagnostics.sqlite");
+ let log = EventLog::open(&path).await.unwrap();
+ log.create_session("session", "create", &json!({}), 1)
+ .await
+ .unwrap();
+ log.create_session("other", "other", &json!({}), 1)
+ .await
+ .unwrap();
+ let invocation = opening(&log, "session", "first").await;
+ append(
+ &log,
+ &invocation,
+ Fact::ModelRequested {
+ item_acceptance: false,
+ step_id: "step".into(),
+ model_id: "requested".into(),
+ source_scope: LogScope::Root,
+ source_high_water: 0,
+ source_digest: "fixture".into(),
+ input_digest: "fixture".into(),
+ route_identity: "route".into(),
+ checkpoint_event_id: None,
+ purpose: maka_agent_facts::context::ModelPurpose::Main,
+ context: None,
+ effective_source_digest: None,
+ },
+ )
+ .await;
+ let step = append(
+ &log,
+ &invocation,
+ Fact::ModelInterrupted {
+ step_id: "step".into(),
+ status: ModelInterruption::Failed,
+ diagnostic: Some("provider-secret-must-not-be-exported".into()),
+ model_failure: Some(ModelFailureCause::Http { status: 400 }),
+ },
+ )
+ .await;
+ let terminal = append(
+ &log,
+ &invocation,
+ Fact::InvocationEnded {
+ outcome: InvocationOutcome::Failed {
+ class: "model_http".into(),
+ message: Some("provider-secret-must-not-be-exported".into()),
+ model_failure: Some(ModelFailureCause::Http { status: 400 }),
+ },
+ },
+ )
+ .await;
+ let old_page = log
+ .diagnostics_page("session", Some(terminal), None, 32, 48 * 1024)
+ .await
+ .unwrap();
+ assert_eq!(
+ old_page
+ .entries
+ .iter()
+ .map(|entry| entry.sequence)
+ .collect::<Vec<_>>(),
+ vec![terminal, step]
+ );
+ assert_eq!(
+ old_page.entries[0].detail,
+ DiagnosticDetail::Execution {
+ invocation: invocation.clone(),
+ reason: ExecutionFailureReason::ModelHttp,
+ model_failure: Some(ModelFailureCause::Http { status: 400 }),
+ }
+ );
+ assert_eq!(
+ old_page.entries[1].detail,
+ DiagnosticDetail::ModelStep {
+ invocation: invocation.clone(),
+ step_id: "step".into(),
+ status: ModelInterruption::Failed,
+ model_failure: Some(ModelFailureCause::Http { status: 400 }),
+ }
+ );
+ assert!(
+ !serde_json::to_string(&old_page)
+ .unwrap()
+ .contains("provider-secret")
+ );
+ let revision = log
+ .get_session::<Value>("session")
+ .await
+ .unwrap()
+ .unwrap()
+ .revision;
+ assert!(matches!(
+ log.copy_session(
+ CopyRequest {
+ source_session_id: "session".into(),
+ target_session_id: "copy".into(),
+ expected_source_revision: revision,
+ purpose: CopyPurpose::Branch {
+ turn_id: None,
+ side_conversation: false
+ },
+ },
+ &json!({}),
+ 2
+ )
+ .await
+ .unwrap(),
+ SessionCopyResult::Committed(_)
+ ));
+ log.set_session_archived::<Value>("session", true, 3)
+ .await
+ .unwrap();
+ let title = log
+ .record_title_failure(invocation.clone(), TitleFailureCause::EmptyOutput)
+ .await
+ .unwrap();
+ let newest = log
+ .diagnostics_page("session", None, None, 1, 48 * 1024)
+ .await
+ .unwrap();
+ assert_eq!(
+ newest.entries[0].detail,
+ DiagnosticDetail::SessionTitle {
+ invocation: invocation.clone(),
+ cause: TitleFailureCause::EmptyOutput
+ }
+ );
+ assert_eq!(newest.next_before, Some(title));
+ assert_eq!(
+ log.latest_diagnostic_sequence("session", terminal)
+ .await
+ .unwrap(),
+ Some(terminal)
+ );
+ assert_eq!(
+ log.latest_diagnostic_sequence("session", title)
+ .await
+ .unwrap(),
+ Some(title)
+ );
+ let older = log
+ .diagnostics_page(
+ "session",
+ Some(newest.through),
+ newest.next_before,
+ 32,
+ 48 * 1024,
+ )
+ .await
+ .unwrap();
+ assert_eq!(older.entries, old_page.entries);
+ assert_eq!(
+ log.diagnostics_page("session", Some(terminal), None, 32, 48 * 1024)
+ .await
+ .unwrap()
+ .entries,
+ old_page.entries
+ );
+ assert!(
+ log.diagnostics_page("other", None, None, 32, 48 * 1024)
+ .await
+ .unwrap()
+ .entries
+ .is_empty()
+ );
+ assert!(
+ log.diagnostics_page("copy", None, None, 32, 48 * 1024)
+ .await
+ .unwrap()
+ .entries
+ .is_empty()
+ );
+ let inherited = log
+ .scoped_prefix(LogScope::Session { id: "copy".into() }, 32, 128 * 1024)
+ .await
+ .unwrap();
+ assert!(
+ inherited
+ .events
+ .iter()
+ .any(|entry| entry.event.invocation == invocation
+ && matches!(entry.event.fact, Fact::InvocationEnded { .. }))
+ );
+ assert!(matches!(
+ log.diagnostics_page("session", Some(title), Some(0), 32, 48 * 1024)
+ .await,
+ Err(StoreError::InvalidTransition(_))
+ ));
+ assert!(matches!(
+ log.diagnostics_page("session", Some(title), Some(title + 1), 32, 48 * 1024)
+ .await,
+ Err(StoreError::InvalidTransition(_))
+ ));
+ assert!(matches!(
+ log.diagnostics_page("session", None, None, 32, 1).await,
+ Err(StoreError::PrefixTooLarge)
+ ));
+ let timestamp = newest.entries[0].recorded_at;
+ log.close().await.unwrap();
+ let log = EventLog::open(&path).await.unwrap();
+ let reopened = log
+ .diagnostics_page("session", Some(title), None, 32, 48 * 1024)
+ .await
+ .unwrap();
+ assert_eq!(reopened.entries[0].sequence, title);
+ assert_eq!(reopened.entries[0].recorded_at, timestamp);
+ assert_eq!(reopened.entries[0].detail, newest.entries[0].detail);
+ log.close().await.unwrap();
+}
+
+#[tokio::test]
+async fn title_failure_requires_original_opening_without_inventing_attempts() {
+ let directory = tempfile::tempdir().unwrap();
+ let log = EventLog::open(&directory.path().join("title.sqlite"))
+ .await
+ .unwrap();
+ log.create_session("session", "create", &json!({}), 1)
+ .await
+ .unwrap();
+ let original = opening(&log, "session", "first").await;
+ let mut forged = original.clone();
+ forged.run_id = "not-original".into();
+ assert!(matches!(
+ log.record_title_failure(forged, TitleFailureCause::Preparation)
+ .await,
+ Err(StoreError::InvalidTransition(_))
+ ));
+ let invalid = EventWrite::plain(RuntimeEvent::new(
+ original.clone(),
+ Fact::InvocationEnded {
+ outcome: InvocationOutcome::Failed {
+ class: "model_http".into(),
+ message: None,
+ model_failure: Some(ModelFailureCause::Http { status: 200 }),
+ },
+ },
+ ))
+ .unwrap();
+ assert!(matches!(
+ log.append(&invalid).await,
+ Err(maka_agent_facts::event::CommitError::Rejected(_))
+ ));
+ append(
+ &log,
+ &original,
+ Fact::InvocationEnded {
+ outcome: InvocationOutcome::Completed,
+ },
+ )
+ .await;
+ let later = opening(&log, "session", "later").await;
+ assert!(matches!(
+ log.record_title_failure(later.clone(), TitleFailureCause::Preparation)
+ .await,
+ Err(StoreError::InvalidTransition(_))
+ ));
+ append(
+ &log,
+ &later,
+ Fact::InvocationEnded {
+ outcome: InvocationOutcome::Completed,
+ },
+ )
+ .await;
+ assert!(matches!(
+ log.record_title_failure(
+ original.clone(),
+ TitleFailureCause::Model {
+ cause: ModelFailureCause::Http { status: 200 }
+ }
+ )
+ .await,
+ Err(StoreError::InvalidTransition(_))
+ ));
+ let sequence = log
+ .record_title_failure(original.clone(), TitleFailureCause::Preparation)
+ .await
+ .unwrap();
+ let page = log
+ .diagnostics_page("session", None, None, 32, 48 * 1024)
+ .await
+ .unwrap();
+ assert_eq!(page.entries.len(), 1);
+ assert_eq!(page.entries[0].sequence, sequence);
+ assert_eq!(
+ page.entries[0].detail,
+ DiagnosticDetail::SessionTitle {
+ invocation: original,
+ cause: TitleFailureCause::Preparation
+ }
+ );
+ let attempts = log
+ .model_attempts(
+ maka_event_log::usage::Query {
+ from: 0.0,
+ to: f64::MAX,
+ session_id: Some("session".into()),
+ through: None,
+ },
+ 0,
+ 32,
+ )
+ .await
+ .unwrap();
+ assert_eq!(attempts.total, 0);
+ log.close().await.unwrap();
+}
diff --git a/platform/event-log/tests/event_log.rs b/platform/event-log/tests/event_log.rs
index 65dee00a0e..841847c7e8 100644
--- a/platform/event-log/tests/event_log.rs
+++ b/platform/event-log/tests/event_log.rs
@@ -222,6 +222,7 @@ async fn committed_prefix_survives_reopen_with_exact_replay_and_terminal_sealing
invocation(),
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "tool_outcome_unknown".into(),
message: Some("tool outcome was not committed".into()),
},
diff --git a/platform/event-log/tests/interaction_lifecycle.rs b/platform/event-log/tests/interaction_lifecycle.rs
index 1debb9155a..3dc5e7e3ae 100644
--- a/platform/event-log/tests/interaction_lifecycle.rs
+++ b/platform/event-log/tests/interaction_lifecycle.rs
@@ -106,6 +106,7 @@ async fn run_closure_guards_every_terminal_and_restart_closes_even_sealed_runs()
source: "test".into(),
},
InvocationOutcome::Failed {
+ model_failure: None,
class: "test".into(),
message: None,
},
diff --git a/platform/event-log/tests/observation.rs b/platform/event-log/tests/observation.rs
index c63e66d539..2f275dcd5f 100644
--- a/platform/event-log/tests/observation.rs
+++ b/platform/event-log/tests/observation.rs
@@ -282,6 +282,7 @@ async fn active_stream_seeds_are_fenced_bounded_and_survive_reopen() {
log.append(
&EventWrite::plain(
(event(Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "interrupted".into(),
status: ModelInterruption::Cancelled,
diff --git a/platform/event-log/tests/run_prefix.rs b/platform/event-log/tests/run_prefix.rs
index 4c7bd1f01b..175a396dcf 100644
--- a/platform/event-log/tests/run_prefix.rs
+++ b/platform/event-log/tests/run_prefix.rs
@@ -124,6 +124,7 @@ async fn exact_run_cuts_bind_identity_and_bytes_without_admitting_unproven_repla
first.invocation.clone(),
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "outcome_unknown".into(),
message: None,
},
diff --git a/platform/event-log/tests/session_material.rs b/platform/event-log/tests/session_material.rs
index f65fed7f9d..069240c982 100644
--- a/platform/event-log/tests/session_material.rs
+++ b/platform/event-log/tests/session_material.rs
@@ -92,6 +92,11 @@ async fn collection_waits_for_the_last_history_owner_and_preserves_frozen_accoun
.unwrap();
log.append(&event(
Fact::ModelInterrupted {
+ model_failure: Some(
+ maka_agent_facts::model::error::ModelFailureCause::Provider {
+ reason: maka_agent_facts::model::error::ProviderFailureReason::Network,
+ },
+ ),
diagnostic: None,
step_id: "observed".into(),
status: maka_agent_facts::event::ModelInterruption::Failed,
@@ -104,6 +109,11 @@ async fn collection_waits_for_the_last_history_owner_and_preserves_frozen_accoun
log.append(&event(
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: Some(
+ maka_agent_facts::model::error::ModelFailureCause::Provider {
+ reason: maka_agent_facts::model::error::ProviderFailureReason::Network,
+ },
+ ),
class: "connection_lost".into(),
message: None,
},
@@ -198,6 +208,21 @@ async fn collection_waits_for_the_last_history_owner_and_preserves_frozen_accoun
)
.unwrap();
assert_eq!((bodies, leaked), (0, 0));
+ let retained: Vec<String> = inspect.prepare(
+ "SELECT json_extract(retained_json, CASE kind WHEN 'model_interrupted' THEN '$.fact.model_failure' ELSE '$.fact.outcome.model_failure' END)
+ FROM event_log WHERE kind IN ('model_interrupted','invocation_ended') ORDER BY sequence"
+ ).unwrap().query_map([], |row| row.get(0)).unwrap().collect::<Result<_,_>>().unwrap();
+ assert_eq!(
+ retained
+ .iter()
+ .map(|value| serde_json::from_str::<Value>(value).unwrap())
+ .collect::<Vec<_>>(),
+ vec![
+ json!({"kind":"provider","reason":"network"}),
+ json!({"kind":"provider","reason":"network"})
+ ]
+ );
+
let pages_after: i64 = inspect
.query_row("PRAGMA page_count", [], |row| row.get(0))
.unwrap();
diff --git a/platform/event-log/tests/stream_delivery.rs b/platform/event-log/tests/stream_delivery.rs
index b0087d47f7..5714e02399 100644
--- a/platform/event-log/tests/stream_delivery.rs
+++ b/platform/event-log/tests/stream_delivery.rs
@@ -171,6 +171,7 @@ async fn giant_bodies_and_metadata_do_not_block_stream_delivery() {
))
.await;
let interrupted = append(Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "second".into(),
status: maka_agent_facts::event::ModelInterruption::Failed,
@@ -178,6 +179,7 @@ async fn giant_bodies_and_metadata_do_not_block_stream_delivery() {
.await;
let terminal = append(Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "provider".into(),
message: None,
},
diff --git a/platform/event-log/tests/streaming_usage.rs b/platform/event-log/tests/streaming_usage.rs
index 8ec32b2739..5140cc3b34 100644
--- a/platform/event-log/tests/streaming_usage.rs
+++ b/platform/event-log/tests/streaming_usage.rs
@@ -193,6 +193,7 @@ async fn early_tool_results_and_retained_interrupted_items_invalidate_stale_usag
observe(&log, "interrupted", &mut builder, observation).await;
}
log.append(&event(Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "interrupted".into(),
status: ModelInterruption::RetryableFailure,
diff --git a/platform/event-log/tests/tool_usage.rs b/platform/event-log/tests/tool_usage.rs
index 2b5aa74286..dbf61b8474 100644
--- a/platform/event-log/tests/tool_usage.rs
+++ b/platform/event-log/tests/tool_usage.rs
@@ -148,6 +148,7 @@ async fn tool_accounting_preserves_dispatch_truth_and_snapshot_without_private_b
request("model-step", 6000),
event(
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "model-step".into(),
status: maka_agent_facts::event::ModelInterruption::RetryableFailure,
diff --git a/platform/event-log/tests/transcript_index.rs b/platform/event-log/tests/transcript_index.rs
index 13cba12d13..df45b11ae3 100644
--- a/platform/event-log/tests/transcript_index.rs
+++ b/platform/event-log/tests/transcript_index.rs
@@ -276,6 +276,7 @@ async fn bounded_progress_and_session_isolation() {
async fn terminal_without_model_interruption_seals_only_committed_partial_evidence() {
for outcome in [
InvocationOutcome::Failed {
+ model_failure: None,
class: "event_commit".into(),
message: None,
},
diff --git a/platform/event-log/tests/transcript_index/fixtures.rs b/platform/event-log/tests/transcript_index/fixtures.rs
index 67cabb6270..66c7ae9f28 100644
--- a/platform/event-log/tests/transcript_index/fixtures.rs
+++ b/platform/event-log/tests/transcript_index/fixtures.rs
@@ -98,6 +98,7 @@ pub(super) async fn interrupt(log: &EventLog, session: &str) -> u64 {
log.append(&event(
session,
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: format!("step-{session}"),
status: ModelInterruption::Cancelled,
diff --git a/platform/event-log/tests/transcript_index/history.rs b/platform/event-log/tests/transcript_index/history.rs
index 025c5d1d18..9e18c003e9 100644
--- a/platform/event-log/tests/transcript_index/history.rs
+++ b/platform/event-log/tests/transcript_index/history.rs
@@ -1934,6 +1934,7 @@ async fn failed_turn_and_retry_diagnostics_are_visible_with_exact_sources_and_fe
.append(&event(
"failed",
Fact::ModelInterrupted {
+ model_failure: None,
step_id: "step-first".into(),
status: ModelInterruption::RetryableFailure,
diagnostic: Some("Connection lost 中😀; retry permitted".into()),
@@ -1947,6 +1948,7 @@ async fn failed_turn_and_retry_diagnostics_are_visible_with_exact_sources_and_fe
log.append(&event(
"failed",
Fact::ModelInterrupted {
+ model_failure: None,
step_id: "step-second".into(),
status: ModelInterruption::Failed,
diagnostic: Some("Provider rejected request".into()),
@@ -1959,6 +1961,7 @@ async fn failed_turn_and_retry_diagnostics_are_visible_with_exact_sources_and_fe
&log,
"failed",
InvocationOutcome::Failed {
+ model_failure: None,
class: "provider_rejected".into(),
message: None,
},
diff --git a/platform/event-log/tests/transcript_index/source.rs b/platform/event-log/tests/transcript_index/source.rs
index 831d7ba748..1ff1e74e22 100644
--- a/platform/event-log/tests/transcript_index/source.rs
+++ b/platform/event-log/tests/transcript_index/source.rs
@@ -377,6 +377,7 @@ async fn failure_search_reads_original_diagnostic_fields_and_visible_body() {
&log,
"failed",
InvocationOutcome::Failed {
+ model_failure: None,
class: "failure-class-hit".into(),
message: Some(message.clone()),
},
diff --git a/platform/event-log/tests/turn_boundary.rs b/platform/event-log/tests/turn_boundary.rs
index 2807e88328..3b1eb1b9e0 100644
--- a/platform/event-log/tests/turn_boundary.rs
+++ b/platform/event-log/tests/turn_boundary.rs
@@ -144,6 +144,7 @@ async fn turn_control_reads_survive_history_budget_exhaustion_and_reopen() {
log.append(
&EventWrite::plain(
(event(Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "step".into(),
status: ModelInterruption::Cancelled,
diff --git a/platform/event-log/tests/usage.rs b/platform/event-log/tests/usage.rs
index a2160ad7d5..b52dce0924 100644
--- a/platform/event-log/tests/usage.rs
+++ b/platform/event-log/tests/usage.rs
@@ -79,6 +79,7 @@ async fn physical_attempt_usage_survives_rejection_copy_removal_and_reopen() {
),
event(
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "rejected".into(),
status: ModelInterruption::Failed,
@@ -88,6 +89,7 @@ async fn physical_attempt_usage_survives_rejection_copy_removal_and_reopen() {
retry.clone(),
event(
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "retry".into(),
status: ModelInterruption::RetryableFailure,
@@ -260,6 +262,7 @@ async fn lost_request_outcome_is_unknown_not_a_success_with_zero_usage() {
log.append(&event(
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "worker_lost".into(),
message: None,
},
diff --git a/platform/event-log/tests/visible_tail.rs b/platform/event-log/tests/visible_tail.rs
index 909468f086..42563ed763 100644
--- a/platform/event-log/tests/visible_tail.rs
+++ b/platform/event-log/tests/visible_tail.rs
@@ -230,6 +230,7 @@ async fn visible_ids_match_presentation_for_accepted_and_partial_parts_across_ca
&mut view,
&mut ids,
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "step".into(),
status: ModelInterruption::Cancelled,
@@ -249,6 +250,7 @@ async fn visible_ids_match_presentation_for_accepted_and_partial_parts_across_ca
InvocationOutcome::Completed
} else {
InvocationOutcome::Failed {
+ model_failure: None,
class: "test".into(),
message: None,
}
diff --git a/platform/js-runtime/trusted/provider-errors.js b/platform/js-runtime/trusted/provider-errors.js
index 467a253291..f018391d2e 100644
--- a/platform/js-runtime/trusted/provider-errors.js
+++ b/platform/js-runtime/trusted/provider-errors.js
@@ -113,9 +113,28 @@ export async function forwardProviderStream(open, normalize, emit, kind) {
await emit({ type: 'error', error: { kind: 'context_overflow', observedOutput } });
return;
}
- const failure = transientFailure(error);
- if (!failure) throw error;
- await emit({ type: 'error', error: { kind: 'provider', ...failure, replaySafe } });
+ let transport = false;
+ for (let cause = error, depth = 0; record(cause) && depth < 8; depth++, cause = cause.cause) {
+ if (cause.name === 'AbortError' || cause.name === 'ProviderResponseLimitError') throw error;
+ transport ||= isTransportFailure(cause);
+ }
+ const failure = transientFailure(error, transport);
+ if (failure) {
+ await emit({ type: 'error', error: { kind: 'provider', ...failure, replaySafe } });
+ return;
+ }
+ if (
+ error instanceof Error &&
+ error.name === 'AI_APICallError' &&
+ Number.isInteger(error.statusCode) &&
+ error.statusCode >= 100 &&
+ error.statusCode <= 599 &&
+ !(error.statusCode >= 200 && error.statusCode < 300)
+ ) {
+ await emit({ type: 'error', error: { kind: 'http', status: error.statusCode } });
+ return;
+ }
+ throw error;
};
let result;
try {
@@ -180,14 +199,8 @@ export async function forwardProviderStream(open, normalize, emit, kind) {
// Only native transport or structured provider evidence authorizes a retry. A local
// response-size failure wrapped by the SDK must not reset its budget by retrying.
-function transientFailure(error) {
+function transientFailure(error, transport) {
if (!record(error)) return;
- let cause = error;
- let transport = false;
- for (let depth = 0; record(cause) && depth < 8; depth++, cause = cause.cause) {
- if (cause.name === 'AbortError' || cause.name === 'ProviderResponseLimitError') return;
- transport ||= isTransportFailure(cause);
- }
const status = error.name === 'AI_APICallError' ? error.statusCode : undefined;
const identifiers = new Set(
providerRecords(error).flatMap((value) =>
diff --git a/platform/presentation/src/compact.rs b/platform/presentation/src/compact.rs
index dff0d34997..94f455d443 100644
--- a/platform/presentation/src/compact.rs
+++ b/platform/presentation/src/compact.rs
@@ -262,6 +262,7 @@ mod tests {
5500,
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "summary_failed".into(),
message: None,
},
diff --git a/platform/presentation/src/lib.rs b/platform/presentation/src/lib.rs
index 0b355fa1f3..dd579f05f5 100644
--- a/platform/presentation/src/lib.rs
+++ b/platform/presentation/src/lib.rs
@@ -354,6 +354,7 @@ impl InvocationView {
step_id,
status,
diagnostic,
+ ..
} => {
let interrupted = step
.take()
diff --git a/platform/presentation/src/message.rs b/platform/presentation/src/message.rs
index 5c3275e038..fa9db76f75 100644
--- a/platform/presentation/src/message.rs
+++ b/platform/presentation/src/message.rs
@@ -331,7 +331,7 @@ impl TurnState {
InvocationOutcome::Completed | InvocationOutcome::ContextCompactFinished { .. } => {
Self::Completed
}
- InvocationOutcome::Failed { class, message } => Self::Failed {
+ InvocationOutcome::Failed { class, message, .. } => Self::Failed {
error_class: class.clone(),
failure_message: message.as_ref().map(|text| {
let mut end = text.len().min(256);
diff --git a/platform/presentation/tests/projection.rs b/platform/presentation/tests/projection.rs
index dec0fb90b6..697dae9859 100644
--- a/platform/presentation/tests/projection.rs
+++ b/platform/presentation/tests/projection.rs
@@ -132,6 +132,7 @@ fn events(outcome: InvocationOutcome) -> Vec<StoredEvent> {
]);
} else {
facts.push(Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "step".into(),
status: if matches!(outcome, InvocationOutcome::Cancelled { .. }) {
@@ -165,6 +166,7 @@ fn completed_and_interrupted_rows_keep_overlay_identity_time() {
source: "user".into(),
},
InvocationOutcome::Failed {
+ model_failure: None,
class: "provider".into(),
message: Some("factual failure".into()),
},
@@ -303,6 +305,7 @@ fn completed_and_interrupted_rows_keep_overlay_identity_time() {
] {
for kind in [TextKind::Text, TextKind::Thinking] {
let mut facts = events(InvocationOutcome::Failed {
+ model_failure: None,
class: "provider".into(),
message: None,
});
@@ -394,6 +397,7 @@ fn interrupted_request_without_output_has_a_durable_diagnostic_not_an_assistant_
event: RuntimeEvent::new(
source[0].event.invocation.clone(),
Fact::ModelInterrupted {
+ model_failure: None,
step_id: "step".into(),
status: ModelInterruption::RetryableFailure,
diagnostic: Some("Responses WebSocket closed: fixture diagnostic".into()),
diff --git a/platform/presentation/tests/tools.rs b/platform/presentation/tests/tools.rs
index 465651e34f..91f7d20334 100644
--- a/platform/presentation/tests/tools.rs
+++ b/platform/presentation/tests/tools.rs
@@ -155,6 +155,7 @@ fn accepted_tools_replay_with_distinct_ids_parentage_rejections() {
});
facts.push(Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "unknown_outcome".into(),
message: None,
},
diff --git a/plugins/agent/agent-screen/README.md b/plugins/agent/agent-screen/README.md
index 4b93ec51a5..fa99658035 100644
--- a/plugins/agent/agent-screen/README.md
+++ b/plugins/agent/agent-screen/README.md
@@ -28,6 +28,7 @@
| `actions.ts` | Available commands and explicit service intents |
| `results.ts` | Query results, mutation receipts and live deliveries |
| `messages.ts` | Bounded live text and timeline display projections |
+| `diagnostics.ts` | Session failure pages, live refresh and original-record details |
| `events.ts`, `component-events.ts`, `raw-events.ts` | Lifecycle/action routing, child callbacks and raw commands within one candidate-frame transaction |
| `frame.ts` | Retained root composition, dialogs and subscriptions |
| `conversation-view.ts` | Conversation, composer and its footer |
diff --git a/plugins/agent/agent-screen/README.zh-CN.md b/plugins/agent/agent-screen/README.zh-CN.md
index 1cde8ae97a..e1182ec1f0 100644
--- a/plugins/agent/agent-screen/README.zh-CN.md
+++ b/plugins/agent/agent-screen/README.zh-CN.md
@@ -28,6 +28,7 @@
| `actions.ts` | 可用命令与明确的服务调用意图 |
| `results.ts` | 查询结果、修改回执及实时事件 |
| `messages.ts` | 有界实时文本和时间线展示投影 |
+| `diagnostics.ts` | 会话失败分页、实时刷新及原记录详情 |
| `events.ts`、`component-events.ts`、`raw-events.ts` | 同一候选帧事务内的统一路由、子组件回调和原始命令 |
| `frame.ts` | 根组合、对话框及订阅 |
| `conversation-view.ts` | 对话、输入区和 footer |
diff --git a/plugins/agent/agent-screen/actions.ts b/plugins/agent/agent-screen/actions.ts
index ff9748746c..dc020e17b9 100644
--- a/plugins/agent/agent-screen/actions.ts
+++ b/plugins/agent/agent-screen/actions.ts
@@ -52,6 +52,7 @@ import { toolCards } from '../../shared/tool-cards.js';
import { readingKey } from './state.js';
import { newGoalState, watchGoal } from './goal.js';
import { newPlanState, watchPlan } from './plan.js';
+import { newDiagnostics, readDiagnostics } from './diagnostics.js';
import { newGraphState, watchGraph } from './graph.js';
import { messages } from './messages.js';
@@ -434,6 +435,7 @@ export function select(state: State, actions: Action[], session: AgentSession |
state.executor = null;
state.modelRefreshing = false;
state.epoch++;
+ state.diagnostics = newDiagnostics(session?.id, state.epoch);
state.graph = newGraphState(state.graph.enabled);
if (session) watchGraph(state);
state.plan = newPlanState();
@@ -470,7 +472,10 @@ export function select(state: State, actions: Action[], session: AgentSession |
state.latestKnown = state.window?.page.through ?? 0;
state.loading = session !== null;
state.notice = null;
- if (session) observe(state, actions);
+ if (session) {
+ observe(state, actions);
+ if (state.inspector === 'diagnostics') readDiagnostics(state, actions);
+ }
}
export function readRecap(state: State, actions: Action[]) {
@@ -720,6 +725,13 @@ export function rootCommands(
? copied
: null;
const commands: (PaletteCommand & { kind: RootCommand })[] = [
+ {
+ kind: 'diagnostics-open',
+ id: 'diagnostics-open',
+ label: text.diagnosticsTitleLabel,
+ hint: '',
+ disabled: !route || !state.selected,
+ },
{
kind: 'compact-open',
id: 'compact-open',
@@ -1089,7 +1101,11 @@ export function rootCommand(
)
)
return false;
- if (kind === 'compact-open') openCompact(state, actions);
+ if (kind === 'diagnostics-open') {
+ if (target === 'tui') state.inspector = 'diagnostics';
+ else state.dialog = 'diagnostics';
+ readDiagnostics(state, actions);
+ } else if (kind === 'compact-open') openCompact(state, actions);
else if (kind === 'outputs-open') {
state.inspector = 'outputs';
const visit = state.visits.find((entry) => entry.id === state.selected?.id);
diff --git a/plugins/agent/agent-screen/diagnostics.ts b/plugins/agent/agent-screen/diagnostics.ts
new file mode 100644
index 0000000000..f5076e906e
--- /dev/null
+++ b/plugins/agent/agent-screen/diagnostics.ts
@@ -0,0 +1,360 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type {
+ Action,
+ AgentDiagnostics,
+ AgentDiagnostic,
+ AgentDiagnosticPage,
+ AgentDiagnosticChange,
+} from '../../../packages/plugin-sdk/src/index.js';
+import type { Theme } from '../../shared/contracts.js';
+import { type Presentation, type Node, fill } from '../../shared/view.js';
+import { copy, type Copy } from './locale.js';
+import { intent } from './actions.js';
+import type { State } from './state.js';
+
+export interface DiagnosticsState {
+ watch: { key: string; input: { sessionId: string } } | null;
+ revision: number;
+ through: number;
+ page: AgentDiagnosticPage | null;
+ position: AgentDiagnostics['position'];
+ selected: AgentDiagnostic | null;
+ attempt: number;
+ loading: number | null;
+ failed: boolean;
+}
+export type DiagnosticsRequest = {
+ kind: 'diagnostics';
+ epoch: number;
+ attempt: number;
+ position: AgentDiagnostics['position'];
+};
+export function newDiagnostics(sessionId?: string, epoch = 0): DiagnosticsState {
+ return {
+ watch: sessionId ? { key: 'diagnostics-watch-' + epoch, input: { sessionId } } : null,
+ revision: 0,
+ through: 0,
+ page: null,
+ position: { kind: 'latest' },
+ selected: null,
+ attempt: 0,
+ loading: null,
+ failed: false,
+ };
+}
+function open(state: State) {
+ return state.inspector === 'diagnostics' || state.dialog === 'diagnostics';
+}
+export function readDiagnostics(
+ state: State,
+ actions: Action[],
+ position: AgentDiagnostics['position'] = { kind: 'latest' },
+) {
+ if (!state.selected) return;
+ if (!state.diagnostics.watch)
+ state.diagnostics.watch = {
+ key: `diagnostics-watch-${state.epoch}-${++state.serial}`,
+ input: { sessionId: state.selected.id },
+ };
+ const attempt = ++state.serial;
+ state.diagnostics.attempt = attempt;
+ state.diagnostics.loading = attempt;
+ state.diagnostics.position = position;
+ state.diagnostics.failed = false;
+ intent(
+ state,
+ actions,
+ { kind: 'diagnostics', epoch: state.epoch, attempt, position },
+ 'agent',
+ 'diagnostics',
+ {
+ sessionId: state.selected.id,
+ position,
+ } satisfies AgentDiagnostics,
+ );
+}
+export function diagnosticChange(state: State, actions: Action[], change: AgentDiagnosticChange) {
+ if (change.revision <= state.diagnostics.revision) return;
+ state.diagnostics.revision = change.revision;
+ if (
+ open(state) &&
+ state.diagnostics.position.kind === 'latest' &&
+ change.revision > state.diagnostics.through
+ )
+ readDiagnostics(state, actions);
+}
+export function diagnosticResult(
+ state: State,
+ request: DiagnosticsRequest,
+ page: AgentDiagnosticPage | null,
+) {
+ const diagnostics = state.diagnostics;
+ if (request.epoch !== state.epoch || request.attempt !== diagnostics.attempt) return;
+ diagnostics.loading = null;
+ if (!page || page.through < diagnostics.through) {
+ diagnostics.failed = true;
+ return;
+ }
+ diagnostics.through = page.through;
+ diagnostics.position = request.position;
+ diagnostics.page = page;
+ diagnostics.failed = false;
+}
+export function diagnosticEvent(state: State, actions: Action[], key: string): boolean {
+ if (!key.startsWith('diagnostic')) return false;
+ const diagnostics = state.diagnostics;
+ if (key === 'diagnostics-close') {
+ if (state.dialog === 'diagnostics') state.dialog = null;
+ if (state.inspector === 'diagnostics') state.inspector = null;
+ } else if (key === 'diagnostics-back') diagnostics.selected = null;
+ else if (key === 'diagnostics-refresh') readDiagnostics(state, actions);
+ else if (key === 'diagnostics-older' && diagnostics.page?.nextBefore != null) {
+ diagnostics.selected = null;
+ readDiagnostics(state, actions, {
+ kind: 'before',
+ through: diagnostics.page.through,
+ sequence: diagnostics.page.nextBefore,
+ });
+ } else if (key.startsWith('diagnostic-open-')) {
+ diagnostics.selected =
+ diagnostics.page?.entries.find((entry) => key === 'diagnostic-open-' + entry.sequence) ??
+ null;
+ } else return false;
+ return true;
+}
+type ModelFailure = NonNullable<
+ Extract<AgentDiagnostic['detail'], { kind: 'execution' }>['modelFailure']
+>;
+function modelCause(cause: ModelFailure, text: Copy): string {
+ switch (cause.kind) {
+ case 'http':
+ return 'HTTP ' + cause.status;
+ case 'timed_out':
+ return text.diagnosticsTimedOut;
+ case 'context_overflow':
+ return text.diagnosticsContextOverflow;
+ case 'adapter':
+ return text.diagnosticsAdapter;
+ case 'provider':
+ return {
+ network: text.diagnosticsNetwork,
+ timed_out: text.diagnosticsTimedOut,
+ rate_limit: text.diagnosticsRateLimit,
+ provider_unavailable: text.diagnosticsProviderUnavailable,
+ stream_truncated: text.diagnosticsStreamTruncated,
+ }[cause.reason];
+ }
+}
+function source(record: AgentDiagnostic, text: Copy): string {
+ switch (record.detail.kind) {
+ case 'execution':
+ return record.detail.reason === 'message_preparation_failed'
+ ? text.diagnosticsPreparation
+ : text.diagnosticsAnswer;
+ case 'model_step':
+ return text.diagnosticsModelStep;
+ case 'session_title':
+ return text.diagnosticsTitle;
+ }
+}
+function executionCause(
+ reason: Extract<AgentDiagnostic['detail'], { kind: 'execution' }>['reason'],
+ text: Copy,
+): string {
+ const labels: Record<typeof reason, string> = {
+ session_busy: text.diagnosticsSessionBusy,
+ continuation_changed: text.diagnosticsContinuationChanged,
+ reconciliation_required: text.diagnosticsReconciliationRequired,
+ invalid_input: text.diagnosticsInvalidInput,
+ cancelled: text.diagnosticsCancelled,
+ model_incomplete: text.diagnosticsIncomplete,
+ event_commit: text.diagnosticsPersistence,
+ event_store: text.diagnosticsStorage,
+ model_timeout: text.diagnosticsTimedOut,
+ model_http: text.diagnosticsProviderRejected,
+ model_adapter: text.diagnosticsAdapter,
+ model_provider: text.diagnosticsProviderFailed,
+ context_overflow: text.diagnosticsContextOverflow,
+ tool_execution: text.diagnosticsToolFailed,
+ runtime_internal: text.diagnosticsRuntimeFailed,
+ cleanup_unconfirmed: text.diagnosticsCleanup,
+ executor: text.diagnosticsExecutorFailed,
+ message_preparation_failed: text.diagnosticsPreparationFailed,
+ host_interrupted: text.diagnosticsHostInterrupted,
+ outcome_unknown: text.diagnosticsOutcomeUnknown,
+ execution_failed: text.diagnosticsExecutionFailed,
+ };
+ return labels[reason];
+}
+function failureColor(record: AgentDiagnostic, theme: Theme): number {
+ return record.detail.kind === 'execution' ||
+ (record.detail.kind === 'model_step' && record.detail.status !== 'retryable_failure')
+ ? theme.error
+ : theme.warning;
+}
+function cause(record: AgentDiagnostic, text: Copy): string {
+ const detail = record.detail;
+ switch (detail.kind) {
+ case 'execution':
+ return detail.modelFailure
+ ? modelCause(detail.modelFailure, text)
+ : executionCause(detail.reason, text);
+ case 'model_step':
+ return detail.modelFailure
+ ? modelCause(detail.modelFailure, text)
+ : text.diagnosticsStepFailed;
+ case 'session_title':
+ switch (detail.cause.kind) {
+ case 'preparation':
+ return text.diagnosticsTitlePreparationFailed;
+ case 'model':
+ return modelCause(detail.cause.cause, text);
+ case 'invalid_output':
+ return text.diagnosticsInvalidOutput;
+ case 'output_limit':
+ return text.diagnosticsOutputLimit;
+ case 'empty_output':
+ return text.diagnosticsEmptyOutput;
+ }
+ }
+}
+export function diagnosticsView<N extends Node>(
+ presentation: Presentation<N>,
+ state: State,
+ theme: Theme,
+ locale: string,
+): N {
+ const ui = presentation.paint(theme),
+ text = copy(locale),
+ diagnostics = state.diagnostics;
+ const selected = diagnostics.selected;
+ return ui.box(
+ 'diagnostics-panel',
+ [
+ ui.box(
+ 'diagnostics-header',
+ [
+ ui.text('diagnostics-title', text.diagnosticsTitleLabel, 17, theme.text, 550),
+ ui.button('diagnostics-close', text.closeModels),
+ ],
+ { row: true, gap: 1 },
+ ),
+ ...(diagnostics.failed
+ ? [ui.text('diagnostics-error', text.recoveryRefreshFailed, 13, theme.warning)]
+ : []),
+ ...(selected
+ ? [
+ ui.button('diagnostics-back', text.back),
+ ui.text('diagnostic-detail-source', source(selected, text), 15, theme.text, 550),
+ ui.text(
+ 'diagnostic-detail-cause',
+ cause(selected, text),
+ 14,
+ failureColor(selected, theme),
+ ),
+ ui.text(
+ 'diagnostic-detail-time',
+ new Date(selected.recordedAt).toISOString(),
+ 12,
+ theme.muted,
+ ),
+ ui.text(
+ 'diagnostic-detail-invocation',
+ selected.detail.invocation.invocation_id,
+ 12,
+ theme.muted,
+ ),
+ ui.text('diagnostic-detail-event', selected.eventId, 12, theme.muted),
+ ...(selected.detail.kind === 'model_step'
+ ? [ui.text('diagnostic-detail-step', selected.detail.stepId, 12, theme.muted)]
+ : []),
+ ]
+ : [
+ presentation.reading(
+ 'diagnostics-reading',
+ {
+ command: null,
+ content: ui.box(
+ 'diagnostics-records',
+ diagnostics.page
+ ? diagnostics.page.entries.length
+ ? diagnostics.page.entries.map((record) => {
+ const tone = failureColor(record, theme);
+ return ui.box(
+ 'diagnostic-' + record.sequence,
+ [
+ ui.button('diagnostic-open-' + record.sequence, source(record, text)),
+ ui.text(
+ 'diagnostic-cause-' + record.sequence,
+ cause(record, text),
+ 13,
+ tone,
+ ),
+ ui.text(
+ 'diagnostic-time-' + record.sequence,
+ new Date(record.recordedAt).toISOString(),
+ 12,
+ theme.muted,
+ ),
+ ],
+ { gap: 0 },
+ );
+ })
+ : [ui.text('diagnostics-empty', text.diagnosticsEmpty, 13, theme.muted)]
+ : [ui.text('diagnostics-loading', text.loading, 13, theme.muted)],
+ {
+ gap: 1,
+ scroll: 'manual',
+ terminal: { grow: 1 },
+ style: { width: fill, height: fill },
+ },
+ ),
+ },
+ {},
+ ),
+ ui.box(
+ 'diagnostics-controls',
+ [
+ ui.button(
+ 'diagnostics-refresh',
+ diagnostics.position.kind === 'before' ? text.latest : text.check,
+ ),
+ ui.button(
+ 'diagnostics-older',
+ text.older,
+ diagnostics.loading !== null || diagnostics.page?.nextBefore == null,
+ ),
+ ],
+ { row: true, gap: 1 },
+ ),
+ ]),
+ ],
+ {
+ visible:
+ presentation.target === 'tui'
+ ? state.inspector === 'diagnostics' && state.dialog === null
+ : state.dialog === 'diagnostics',
+ gap: 1,
+ terminal: { grow: 1 },
+ style: { width: fill, height: fill },
+ },
+ );
+}
diff --git a/plugins/agent/agent-screen/events.ts b/plugins/agent/agent-screen/events.ts
index f13120328c..ec21e80ec9 100644
--- a/plugins/agent/agent-screen/events.ts
+++ b/plugins/agent/agent-screen/events.ts
@@ -31,6 +31,7 @@ import type {
Emission,
} from '../../../packages/plugin-sdk/src/index.js';
import { appearanceEvent, effectiveLocale } from '../../shared/appearance-editor.js';
+import { diagnosticChange } from './diagnostics.js';
import { observeBookmark, retryBookmark } from '../../shared/bookmark.js';
import type { AgentScreenProps, Theme } from '../../shared/contracts.js';
import { settingsCategory } from '../../shared/settings.js';
@@ -201,7 +202,18 @@ export function handleEvent<N extends Node>(
return frame(presentation, configuredLocale, state, values, actions);
if (input.kind === 'action') {
const outcome = input.event as ActionOutcome;
- if (state.graph.watch?.key === input.key) {
+ if (state.diagnostics.watch?.key === input.key) {
+ if (outcome.status === 'updated')
+ diagnosticChange(
+ state,
+ actions,
+ outcome.value as import('../../../packages/plugin-sdk/src/index.js').AgentDiagnosticChange,
+ );
+ else if (outcome.status === 'failed' || outcome.status === 'not_accepted') {
+ state.diagnostics.watch = null;
+ state.diagnostics.failed = true;
+ }
+ } else if (state.graph.watch?.key === input.key) {
if (outcome.status === 'updated') graphUpdate(state, outcome.value as WorkHubGraphView);
else {
state.graph.watch = null;
diff --git a/plugins/agent/agent-screen/frame.ts b/plugins/agent/agent-screen/frame.ts
index 73cf71b8cf..cb635348ed 100644
--- a/plugins/agent/agent-screen/frame.ts
+++ b/plugins/agent/agent-screen/frame.ts
@@ -50,6 +50,7 @@ import {
type Presentation,
} from '../../shared/view.js';
+import { diagnosticsView } from './diagnostics.js';
import { checklistView } from './checklist-view.js';
import { goalView } from './goal.js';
import { planView } from './plan.js';
@@ -249,6 +250,7 @@ export function frame<N extends Node>(
const inspectorOpen =
conversationRoute(state) && !!state.selected && (state.inspector !== null || inlineInteraction);
const inspectorSlots = [
+ diagnosticsView(presentation, state, theme, locale),
graphView(presentation, state, theme, locale),
planView(presentation, state, theme, locale),
goalView(presentation, state, theme, locale),
@@ -520,11 +522,13 @@ export function frame<N extends Node>(
? text.checklistTitle
: state.dialog === 'details'
? text.detailsTitle
- : state.dialog === 'queue'
- ? text.queueEdit
- : state.dialog === 'help'
- ? text.helpTitle
- : text.paletteTitle,
+ : state.dialog === 'diagnostics'
+ ? text.diagnosticsTitleLabel
+ : state.dialog === 'queue'
+ ? text.queueEdit
+ : state.dialog === 'help'
+ ? text.helpTitle
+ : text.paletteTitle,
background,
ui.box(
'dialog-content',
@@ -702,6 +706,17 @@ export function frame<N extends Node>(
out.actions = actions;
out.events = events;
out.subscriptions = [
+ ...(state.diagnostics.watch
+ ? [
+ {
+ ...state.diagnostics.watch,
+ binding: 'agent',
+ member: 0,
+ method: 'watchDiagnostics',
+ resources: {},
+ },
+ ]
+ : []),
...(state.graph.watch
? [
{
diff --git a/plugins/agent/agent-screen/header-view.ts b/plugins/agent/agent-screen/header-view.ts
index 395fe038ec..f9cd2a7018 100644
--- a/plugins/agent/agent-screen/header-view.ts
+++ b/plugins/agent/agent-screen/header-view.ts
@@ -69,6 +69,13 @@ export function headerView<N extends Node>(
style: { width: pixels(0), grow: 1, minWidth: 0 },
}),
ui.button('palette-open', text.paletteTitle),
+ ui.button(
+ 'diagnostics-open',
+ text.diagnosticsTitleLabel,
+ !rootCommands(state, locale, target).some(
+ (command) => command.kind === 'diagnostics-open' && !command.disabled,
+ ),
+ ),
ui.button(
'details-open',
text.detailsOpen,
@@ -159,6 +166,7 @@ export function headerView<N extends Node>(
'toolbar',
[
...[
+ ['diagnostics-open', text.diagnosticsTitleLabel, '!'],
['outputs-open', tuiText(locale, 'task-outputs'), theme.ascii ? '[o]' : '▧'],
['details-open', text.detailsOpen, theme.ascii ? '(i)' : 'ⓘ'],
['terminal-open', text.terminalTitle, '>_'],
diff --git a/plugins/agent/agent-screen/index.ts b/plugins/agent/agent-screen/index.ts
index 0813c76fa0..fe9e2ba158 100644
--- a/plugins/agent/agent-screen/index.ts
+++ b/plugins/agent/agent-screen/index.ts
@@ -23,6 +23,7 @@ import type { AgentScreenProps } from '../../shared/contracts.js';
import { bookmark } from '../../shared/bookmark.js';
import { type Presentation, type Node } from '../../shared/view.js';
+import { newDiagnostics } from './diagnostics.js';
import { newGoalState } from './goal.js';
import { newPlanState } from './plan.js';
import { newGraphState } from './graph.js';
@@ -104,6 +105,7 @@ export function agentScreen<N extends Node>(
skills,
dialog: null,
sessionChange: null,
+ diagnostics: newDiagnostics(),
inspector: null,
image: null,
window: null,
diff --git a/plugins/agent/agent-screen/locale.ts b/plugins/agent/agent-screen/locale.ts
index d96436a1c8..fb6c4c0c57 100644
--- a/plugins/agent/agent-screen/locale.ts
+++ b/plugins/agent/agent-screen/locale.ts
@@ -19,6 +19,43 @@
import { createCopy } from '../../shared/locale.js';
import {
+ msg_recoveryRefreshFailed,
+ msg_diagnosticsSessionBusy,
+ msg_diagnosticsContinuationChanged,
+ msg_diagnosticsReconciliationRequired,
+ msg_diagnosticsInvalidInput,
+ msg_diagnosticsCancelled,
+ msg_diagnosticsIncomplete,
+ msg_diagnosticsPersistence,
+ msg_diagnosticsStorage,
+ msg_diagnosticsProviderRejected,
+ msg_diagnosticsProviderFailed,
+ msg_diagnosticsToolFailed,
+ msg_diagnosticsRuntimeFailed,
+ msg_diagnosticsCleanup,
+ msg_diagnosticsExecutorFailed,
+ msg_diagnosticsHostInterrupted,
+ msg_diagnosticsOutcomeUnknown,
+ msg_diagnosticsTitlePreparationFailed,
+ msg_diagnosticsTitleLabel,
+ msg_diagnosticsAnswer,
+ msg_diagnosticsPreparation,
+ msg_diagnosticsModelStep,
+ msg_diagnosticsTitle,
+ msg_diagnosticsEmpty,
+ msg_diagnosticsPreparationFailed,
+ msg_diagnosticsExecutionFailed,
+ msg_diagnosticsStepFailed,
+ msg_diagnosticsTimedOut,
+ msg_diagnosticsContextOverflow,
+ msg_diagnosticsAdapter,
+ msg_diagnosticsNetwork,
+ msg_diagnosticsRateLimit,
+ msg_diagnosticsProviderUnavailable,
+ msg_diagnosticsStreamTruncated,
+ msg_diagnosticsInvalidOutput,
+ msg_diagnosticsOutputLimit,
+ msg_diagnosticsEmptyOutput,
msg_allSessions,
msg_approvalTitle,
msg_appsTitle,
@@ -338,6 +375,43 @@ import type {
// This feature owns this explicit message catalog; shared messages remain tree-shakeable.
const messages = {
+ recoveryRefreshFailed: msg_recoveryRefreshFailed,
+ diagnosticsSessionBusy: msg_diagnosticsSessionBusy,
+ diagnosticsContinuationChanged: msg_diagnosticsContinuationChanged,
+ diagnosticsReconciliationRequired: msg_diagnosticsReconciliationRequired,
+ diagnosticsInvalidInput: msg_diagnosticsInvalidInput,
+ diagnosticsCancelled: msg_diagnosticsCancelled,
+ diagnosticsIncomplete: msg_diagnosticsIncomplete,
+ diagnosticsPersistence: msg_diagnosticsPersistence,
+ diagnosticsStorage: msg_diagnosticsStorage,
+ diagnosticsProviderRejected: msg_diagnosticsProviderRejected,
+ diagnosticsProviderFailed: msg_diagnosticsProviderFailed,
+ diagnosticsToolFailed: msg_diagnosticsToolFailed,
+ diagnosticsRuntimeFailed: msg_diagnosticsRuntimeFailed,
+ diagnosticsCleanup: msg_diagnosticsCleanup,
+ diagnosticsExecutorFailed: msg_diagnosticsExecutorFailed,
+ diagnosticsHostInterrupted: msg_diagnosticsHostInterrupted,
+ diagnosticsOutcomeUnknown: msg_diagnosticsOutcomeUnknown,
+ diagnosticsTitlePreparationFailed: msg_diagnosticsTitlePreparationFailed,
+ diagnosticsTitleLabel: msg_diagnosticsTitleLabel,
+ diagnosticsAnswer: msg_diagnosticsAnswer,
+ diagnosticsPreparation: msg_diagnosticsPreparation,
+ diagnosticsModelStep: msg_diagnosticsModelStep,
+ diagnosticsTitle: msg_diagnosticsTitle,
+ diagnosticsEmpty: msg_diagnosticsEmpty,
+ diagnosticsPreparationFailed: msg_diagnosticsPreparationFailed,
+ diagnosticsExecutionFailed: msg_diagnosticsExecutionFailed,
+ diagnosticsStepFailed: msg_diagnosticsStepFailed,
+ diagnosticsTimedOut: msg_diagnosticsTimedOut,
+ diagnosticsContextOverflow: msg_diagnosticsContextOverflow,
+ diagnosticsAdapter: msg_diagnosticsAdapter,
+ diagnosticsNetwork: msg_diagnosticsNetwork,
+ diagnosticsRateLimit: msg_diagnosticsRateLimit,
+ diagnosticsProviderUnavailable: msg_diagnosticsProviderUnavailable,
+ diagnosticsStreamTruncated: msg_diagnosticsStreamTruncated,
+ diagnosticsInvalidOutput: msg_diagnosticsInvalidOutput,
+ diagnosticsOutputLimit: msg_diagnosticsOutputLimit,
+ diagnosticsEmptyOutput: msg_diagnosticsEmptyOutput,
allSessions: msg_allSessions,
approvalTitle: msg_approvalTitle,
appsTitle: msg_appsTitle,
diff --git a/plugins/agent/agent-screen/raw-events.ts b/plugins/agent/agent-screen/raw-events.ts
index 282078fd19..514040b45f 100644
--- a/plugins/agent/agent-screen/raw-events.ts
+++ b/plugins/agent/agent-screen/raw-events.ts
@@ -17,6 +17,7 @@
* under the License.
*/
+import { diagnosticEvent } from './diagnostics.js';
import { compactConfirm } from './compact.js';
import type {
Action,
@@ -75,6 +76,8 @@ export function handleRaw<N extends Node>(
locale: string,
) {
const target = presentation.target;
+ if (diagnosticEvent(state, actions, input.key))
+ return frame(presentation, configuredLocale, state, values, actions);
if (input.key === 'compact-confirm') compactConfirm(state, actions);
if (
input.key === 'compact-check' &&
diff --git a/plugins/agent/agent-screen/results.ts b/plugins/agent/agent-screen/results.ts
index f951340b39..556591890d 100644
--- a/plugins/agent/agent-screen/results.ts
+++ b/plugins/agent/agent-screen/results.ts
@@ -18,6 +18,7 @@
*/
import { compactQuery, compactSettled } from './compact.js';
+import { diagnosticResult } from './diagnostics.js';
import type {
Action,
AgentRecapReceipt,
@@ -305,6 +306,10 @@ export function receipt(state: State, actions: Action[], request: Mutation, repl
}
export function queryFailed(state: State, request: Request) {
+ if (request.kind === 'diagnostics') {
+ diagnosticResult(state, request, null);
+ return;
+ }
if (
request.kind === 'compactPrompt' ||
request.kind === 'compactField' ||
@@ -436,6 +441,13 @@ export function queryFailed(state: State, request: Request) {
export function querySucceeded(state: State, actions: Action[], request: Request, value: unknown) {
switch (request.kind) {
+ case 'diagnostics':
+ diagnosticResult(
+ state,
+ request,
+ value as import('../../../packages/plugin-sdk/src/index.js').AgentDiagnosticPage,
+ );
+ break;
case 'compactPrompt':
case 'compactField':
compactQuery(state, actions, request, value);
diff --git a/plugins/agent/agent-screen/state.ts b/plugins/agent/agent-screen/state.ts
index d9093a1c87..ea62a31339 100644
--- a/plugins/agent/agent-screen/state.ts
+++ b/plugins/agent/agent-screen/state.ts
@@ -65,6 +65,8 @@ import { type AttachmentDrafts } from '../../shared/attachments.js';
import { type ComposerReadiness } from '../../shared/drafts.js';
+import type { DiagnosticsState, DiagnosticsRequest } from './diagnostics.js';
+
import type { CompactState, CompactRequest } from './compact.js';
import type { GoalState, GoalRequest } from './goal.js';
@@ -76,6 +78,7 @@ type BackendPreference = import('../../../packages/plugin-sdk/src/index.js').Age
type Notice = keyof Copy | null;
export type Request =
+ | DiagnosticsRequest
| CompactRequest
| { kind: 'sandboxChange'; epoch: number; sessionId: string }
| GoalRequest
@@ -299,7 +302,9 @@ export interface State {
settingsCategory: SettingsCategory;
insightsScope: InsightsProps['scope'];
sidebar: { open: boolean } | { command: TerminalPaneCommand | null };
+ diagnostics: DiagnosticsState;
inspector:
+ | 'diagnostics'
| 'details'
| 'terminal'
| 'outputs'
@@ -329,6 +334,7 @@ export interface State {
| 'goal'
| 'plan'
| 'graph'
+ | 'diagnostics'
| 'details'
| 'help'
| 'queue'
@@ -408,6 +414,7 @@ export interface State {
}
export type RootCommand =
+ | 'diagnostics-open'
| 'browse'
| 'outputs-open'
| 'copy-file-path'
diff --git a/plugins/agent/api/README.md b/plugins/agent/api/README.md
index 6474dc0510..ba771604c0 100644
--- a/plugins/agent/api/README.md
+++ b/plugins/agent/api/README.md
@@ -27,4 +27,6 @@ Independent Desktop clients consume the same persisted Agent service through the
Read `history` pages under one fixed `through` fence and resume `watch` from its last `nextAfter`; watch also publishes queue and pending-interaction updates. `send` admits work and returns its identity; `stop` names that exact invocation. Use `pendingInteractions`, `interaction` and `respond` to reconstruct and answer the original request after reconnecting. Mutations retain their original operation receipts: a lost response does not authorize another send. See [native acceptance](../na [...]
+`diagnostics` reads bounded, newest-first pages of execution, model-step and automatic-title failures under a fixed `through` fence. `watchDiagnostics` emits the current diagnostic revision on subscription and after changes; reconnect by reading the latest page again. These session-scoped operational records retain original invocation/event identities and safe typed causes. They exclude provider bodies and failures belonging to copied source sessions. Their revision is independent of con [...]
+
[Source](src/lib.rs) · [Cargo manifest](Cargo.toml)
diff --git a/plugins/agent/api/README.zh-CN.md b/plugins/agent/api/README.zh-CN.md
index c562481568..c02db6ea45 100644
--- a/plugins/agent/api/README.zh-CN.md
+++ b/plugins/agent/api/README.zh-CN.md
@@ -27,4 +27,6 @@
`history` 分页保持同一个 `through` 边界,`watch` 从最后的 `nextAfter` 继续,并发布队列与待处理交互更新。`send` 接受工作并返回其身份,`stop` 指定该次 invocation。重连后通过 `pendingInteractions`、`interaction` 和 `respond` 重建并回答原请求。修改保留原操作回执;丢失响应不代表可以重新发送。参见[原生接入验收](../native/README.zh-CN.md)及[传输所有权与退出方式](../../../platform/transport/README.zh-CN.md)。
+`diagnostics` 在固定的 `through` 边界内,从新到旧分页读取执行、模型步骤及自动标题失败。`watchDiagnostics` 在订阅时及变化后发送当前诊断版本;重连后重新读取最新页。这些会话范围内的运行记录保留原 invocation/event 标识和安全的类型化原因,不包含提供方响应正文或复制来源会话的失败。诊断版本独立于对话历史,因此回答结束后才发生的标题失败仍可发现。
+
[源码](src/lib.rs) · [Cargo 配置](Cargo.toml)
diff --git a/plugins/agent/api/src/contract.rs b/plugins/agent/api/src/contract.rs
index 7d7a53f4ed..214ef30779 100644
--- a/plugins/agent/api/src/contract.rs
+++ b/plugins/agent/api/src/contract.rs
@@ -823,6 +823,50 @@ pub struct SessionRead {
#[schemars(length(min = 1, max = 128))]
pub session_id: String,
}
+#[derive(Deserialize, JsonSchema)]
+#[serde(rename_all = "camelCase", deny_unknown_fields)]
+#[schemars(rename = "AgentDiagnostics")]
+pub struct Diagnostics {
+ #[schemars(length(min = 1, max = 128))]
+ pub session_id: String,
+ pub position: DiagnosticPosition,
+}
+#[derive(Deserialize, JsonSchema)]
+#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
+#[schemars(rename = "AgentDiagnosticPosition")]
+pub enum DiagnosticPosition {
+ Latest,
+ Before {
+ #[schemars(range(max = 9_007_199_254_740_991u64))]
+ through: u64,
+ #[schemars(range(min = 1, max = 9_007_199_254_740_991u64))]
+ sequence: u64,
+ },
+}
+#[derive(Serialize, Deserialize, JsonSchema)]
+#[serde(rename_all = "camelCase", deny_unknown_fields)]
+#[schemars(rename = "AgentDiagnostic")]
+pub struct Diagnostic {
+ pub sequence: u64,
+ pub event_id: String,
+ pub recorded_at: f64,
+ pub detail: maka_agent_facts::diagnostics::DiagnosticDetail,
+}
+#[derive(Serialize, Deserialize, JsonSchema)]
+#[serde(rename_all = "camelCase", deny_unknown_fields)]
+#[schemars(rename = "AgentDiagnosticPage")]
+pub struct DiagnosticPage {
+ pub through: u64,
+ pub entries: Vec<Diagnostic>,
+ pub next_before: Option<u64>,
+}
+#[derive(Serialize, Deserialize, JsonSchema)]
+#[serde(rename_all = "camelCase", deny_unknown_fields)]
+#[schemars(rename = "AgentDiagnosticChange")]
+pub struct DiagnosticChange {
+ /// Latest diagnostic event sequence, independently of transcript progress.
+ pub revision: u64,
+}
#[derive(Serialize, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[schemars(rename = "AgentObservation")]
@@ -1411,6 +1455,14 @@ pub fn contract() -> Contract {
"observe".into(),
method::<SessionRead, Observation>(MethodMode::Query),
),
+ (
+ "diagnostics".into(),
+ method::<Diagnostics, DiagnosticPage>(MethodMode::Query),
+ ),
+ (
+ "watchDiagnostics".into(),
+ method::<SessionRead, DiagnosticChange>(MethodMode::Subscription),
+ ),
(
"history".into(),
method::<History, HistoryPage>(MethodMode::Query),
diff --git a/plugins/agent/assistant/src/plan/owner.rs b/plugins/agent/assistant/src/plan/owner.rs
index 0486b32dfc..b2d757c1e3 100644
--- a/plugins/agent/assistant/src/plan/owner.rs
+++ b/plugins/agent/assistant/src/plan/owner.rs
@@ -357,7 +357,7 @@ impl Owner {
};
let outcome = match outcome {
InvocationOutcome::Completed => Settlement::Completed,
- InvocationOutcome::Failed { class, message } => Settlement::Interrupted {
+ InvocationOutcome::Failed { class, message, .. } => Settlement::Interrupted {
reason: bounded(&message.unwrap_or(class)),
},
InvocationOutcome::Cancelled { source } => Settlement::Interrupted {
diff --git a/plugins/agent/engine/src/executor.rs b/plugins/agent/engine/src/executor.rs
index b00bc3e8c9..d6147ca3e7 100644
--- a/plugins/agent/engine/src/executor.rs
+++ b/plugins/agent/engine/src/executor.rs
@@ -143,10 +143,12 @@ fn outcome(result: &Result<Outcome, Error>, cancellation: &CancellationToken) ->
source: "executor_retired".into(),
},
Ok(Outcome::Failed { message, .. }) => InvocationOutcome::Failed {
+ model_failure: None,
class: "executor".into(),
message: Some(message.chars().take(2048).collect()),
},
Err(error) => InvocationOutcome::Failed {
+ model_failure: None,
class: if matches!(error, Error::CleanupUnconfirmed | Error::Unknown) {
"outcome_unknown"
} else {
diff --git a/plugins/agent/engine/src/model_attempt.rs b/plugins/agent/engine/src/model_attempt.rs
index 3fbb6e735d..1c6b40c987 100644
--- a/plugins/agent/engine/src/model_attempt.rs
+++ b/plugins/agent/engine/src/model_attempt.rs
@@ -716,7 +716,9 @@ async fn finish(
let status = match error {
maka_model::ModelError::Cancelled => ModelInterruption::Cancelled,
maka_model::ModelError::TimedOut => ModelInterruption::TimedOut,
- maka_model::ModelError::Adapter(_) => ModelInterruption::Failed,
+ maka_model::ModelError::Adapter(_) | maka_model::ModelError::Http { .. } => {
+ ModelInterruption::Failed
+ }
maka_model::ModelError::ContextOverflow { .. } => ModelInterruption::Failed,
maka_model::ModelError::Provider(ref failure)
if failure.replay_safe()
@@ -738,6 +740,7 @@ async fn finish(
step_id: step_id.clone(),
status,
diagnostic: Some(error.to_string().chars().take(1024).collect()),
+ model_failure: error.failure_cause(),
},
)
.await?;
diff --git a/plugins/agent/engine/src/runner.rs b/plugins/agent/engine/src/runner.rs
index e77c3ebe45..c9ca3efdb1 100644
--- a/plugins/agent/engine/src/runner.rs
+++ b/plugins/agent/engine/src/runner.rs
@@ -232,6 +232,10 @@ pub async fn run(
Err(error) => (
InvocationOutcome::Failed {
class: failure_class(error).into(),
+ model_failure: match error {
+ RunError::Model(error) => error.failure_cause(),
+ _ => None,
+ },
message: Some(error.to_string().chars().take(2048).collect()),
},
None,
@@ -253,6 +257,7 @@ pub async fn run(
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
class: "event_commit".into(),
+ model_failure: None,
message: Some(error.to_string().chars().take(2048).collect()),
},
},
@@ -286,6 +291,7 @@ fn failure_class(error: &RunError) -> &'static str {
RunError::ModelIncomplete => "model_incomplete",
RunError::Commit(_) => "event_commit",
RunError::Store(_) => "event_store",
+ RunError::Model(maka_model::ModelError::Http { .. }) => "model_http",
RunError::Model(maka_model::ModelError::TimedOut) => "model_timeout",
RunError::Model(maka_model::ModelError::Adapter(_)) => "model_adapter",
RunError::Model(maka_model::ModelError::Provider(failure))
diff --git a/plugins/agent/engine/tests/integration/context_stop.rs b/plugins/agent/engine/tests/integration/context_stop.rs
index 71da3acd23..d2fed58e8e 100644
--- a/plugins/agent/engine/tests/integration/context_stop.rs
+++ b/plugins/agent/engine/tests/integration/context_stop.rs
@@ -92,6 +92,7 @@ async fn stopping_summary_drains_attempt_without_checkpoint_or_retry() {
event.event.fact,
Fact::ModelInterrupted {
status: ModelInterruption::Cancelled,
+ model_failure: None,
..
}
)));
diff --git a/plugins/agent/engine/tests/integration/model_interruption.rs b/plugins/agent/engine/tests/integration/model_interruption.rs
index 4b87ea3663..f784fa939e 100644
--- a/plugins/agent/engine/tests/integration/model_interruption.rs
+++ b/plugins/agent/engine/tests/integration/model_interruption.rs
@@ -32,6 +32,7 @@ use maka_agent_facts::event::InvocationOutcome;
use maka_agent_facts::event::ModelInterruption;
use maka_agent_facts::event::TerminalStatus;
use maka_agent_facts::model::ModelEvent;
+use maka_agent_facts::model::error::ModelFailureCause;
use maka_event_log::EventLog;
use maka_js_runtime::{CellLimits, CodeExecutor};
use maka_model::{ModelError, ModelExecutor, ProviderConfig, ProviderKind};
@@ -295,7 +296,7 @@ async fn continuation_claim_replays_only_its_lineage_and_retries_with_frozen_inp
title: None, operation_id: "unknown".into(),
call: maka_agent_facts::tool_call::ToolCallIdentity::standalone("unknown-call".into()),
name: "write".into(), input: json!({}) },
- Fact::InvocationEnded { outcome: InvocationOutcome::Failed { class: "outcome_unknown".into(), message: None } },
+ Fact::InvocationEnded { outcome: InvocationOutcome::Failed { class: "outcome_unknown".into(), message: None, model_failure: None } },
] {
log.append(&EventWrite::plain(RuntimeEvent::new(input(&base, "unknown").invocation, fact)).unwrap()).await.unwrap();
}
@@ -341,9 +342,11 @@ async fn model_timeout_cause_survives_reopening_the_log() {
assert!(matches!(
&prefix.events.last().unwrap().event.fact,
Fact::InvocationEnded {
- outcome: InvocationOutcome::Failed { class, message: Some(message) }
+ outcome: InvocationOutcome::Failed { class, message: Some(message), model_failure: Some(ModelFailureCause::TimedOut) }
} if class == "model_timeout" && message == &ModelError::TimedOut.to_string()
));
+ assert!(prefix.events.iter().any(|event| matches!(&event.event.fact,
+ Fact::ModelInterrupted { model_failure: Some(ModelFailureCause::TimedOut), .. })));
assert_eq!(
prefix.project_invocation("invocation-timeout").terminal,
Some(TerminalStatus::Failed)
diff --git a/plugins/agent/engine/tests/integration/startup_recovery.rs b/plugins/agent/engine/tests/integration/startup_recovery.rs
index 81aea24c6e..c178ed35fa 100644
--- a/plugins/agent/engine/tests/integration/startup_recovery.rs
+++ b/plugins/agent/engine/tests/integration/startup_recovery.rs
@@ -142,12 +142,12 @@ async fn reopened_pending_main_and_summary_are_failed_without_replaying_admissio
let end = prefix.events.len();
assert!(
matches!(&prefix.events[end - 2].event.fact, Fact::ModelInterrupted {
- step_id, status: ModelInterruption::Failed, ..
+ step_id, status: ModelInterruption::Failed, model_failure: None, ..
} if step_id == if summary { "summary" } else { "step" })
);
assert!(
matches!(&prefix.events[end - 1].event.fact, Fact::InvocationEnded {
- outcome: InvocationOutcome::Failed { class, .. }
+ outcome: InvocationOutcome::Failed { class, model_failure: None, .. }
} if class == "host_interrupted")
);
assert!(
@@ -635,6 +635,7 @@ async fn accepted_history_budget_counts_complete_items_not_token_envelopes() {
&log,
if interrupted {
Fact::ModelInterrupted {
+ model_failure: None,
diagnostic: None,
step_id: "step".into(),
status: ModelInterruption::RetryableFailure,
@@ -651,6 +652,7 @@ async fn accepted_history_budget_counts_complete_items_not_token_envelopes() {
&log,
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "fixture_end".into(),
message: None,
},
diff --git a/plugins/agent/facts/src/diagnostics.rs b/plugins/agent/facts/src/diagnostics.rs
new file mode 100644
index 0000000000..a80aeaba4e
--- /dev/null
+++ b/plugins/agent/facts/src/diagnostics.rs
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//! Safe diagnostic projections bind each domain's cause to its actual origin.
+
+use crate::event::{Invocation, ModelInterruption};
+use crate::model::error::ModelFailureCause;
+use schemars::JsonSchema;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
+#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
+pub enum TitleFailureCause {
+ Preparation,
+ Model { cause: ModelFailureCause },
+ InvalidOutput,
+ OutputLimit,
+ EmptyOutput,
+}
+impl TitleFailureCause {
+ pub fn validate(&self) -> Result<(), crate::model::error::ModelError> {
+ match self {
+ Self::Model { cause } => cause.validate(),
+ _ => Ok(()),
+ }
+ }
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
+#[serde(rename_all = "snake_case")]
+pub enum ExecutionFailureReason {
+ SessionBusy,
+ ContinuationChanged,
+ ReconciliationRequired,
+ InvalidInput,
+ Cancelled,
+ ModelIncomplete,
+ EventCommit,
+ EventStore,
+ ModelTimeout,
+ ModelHttp,
+ ModelAdapter,
+ ModelProvider,
+ ContextOverflow,
+ ToolExecution,
+ RuntimeInternal,
+ CleanupUnconfirmed,
+ Executor,
+ MessagePreparationFailed,
+ HostInterrupted,
+ OutcomeUnknown,
+ ExecutionFailed,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
+#[serde(
+ tag = "kind",
+ rename_all = "snake_case",
+ rename_all_fields = "camelCase",
+ deny_unknown_fields
+)]
+pub enum DiagnosticDetail {
+ Execution {
+ invocation: Invocation,
+ reason: ExecutionFailureReason,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ model_failure: Option<ModelFailureCause>,
+ },
+ ModelStep {
+ invocation: Invocation,
+ step_id: String,
+ status: ModelInterruption,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ model_failure: Option<ModelFailureCause>,
+ },
+ SessionTitle {
+ invocation: Invocation,
+ cause: TitleFailureCause,
+ },
+}
diff --git a/plugins/agent/facts/src/event.rs b/plugins/agent/facts/src/event.rs
index 9fc67d5cbd..7297e3deb1 100644
--- a/plugins/agent/facts/src/event.rs
+++ b/plugins/agent/facts/src/event.rs
@@ -55,6 +55,8 @@ pub enum InvocationOutcome {
Failed {
class: String,
message: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ model_failure: Option<crate::model::error::ModelFailureCause>,
},
Cancelled {
source: String,
@@ -167,6 +169,8 @@ pub enum Fact {
/// or retry authority. Missing on journals written by older Hosts.
#[serde(default, skip_serializing_if = "Option::is_none")]
diagnostic: Option<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ model_failure: Option<crate::model::error::ModelFailureCause>,
},
ModelCompleted {
step_id: String,
@@ -273,7 +277,7 @@ impl Fact {
}
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ModelInterruption {
Cancelled,
diff --git a/plugins/agent/facts/src/lib.rs b/plugins/agent/facts/src/lib.rs
index b926e4429a..3ce11e35aa 100644
--- a/plugins/agent/facts/src/lib.rs
+++ b/plugins/agent/facts/src/lib.rs
@@ -50,4 +50,5 @@ pub mod tool_call;
pub mod tool_output;
pub mod tools;
+pub mod diagnostics;
pub mod display;
diff --git a/plugins/agent/facts/src/model/error.rs b/plugins/agent/facts/src/model/error.rs
index 1ba012f4bd..57129d30da 100644
--- a/plugins/agent/facts/src/model/error.rs
+++ b/plugins/agent/facts/src/model/error.rs
@@ -33,7 +33,7 @@ pub struct ProviderFailure {
retry_after_ms: Option<u64>,
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ProviderFailureReason {
Network,
@@ -107,8 +107,37 @@ impl ProviderFailure {
}
}
+/// Safe failure evidence, separate from provider-owned diagnostic text.
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
+#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
+pub enum ModelFailureCause {
+ Http {
+ #[schemars(range(min = 100, max = 599))]
+ status: u16,
+ },
+ TimedOut,
+ ContextOverflow,
+ Provider {
+ reason: ProviderFailureReason,
+ },
+ Adapter,
+}
+impl ModelFailureCause {
+ pub fn validate(&self) -> Result<(), ModelError> {
+ if matches!(self, Self::Http { status } if !(100..=599).contains(status) || (200..300).contains(status))
+ {
+ return Err(ModelError::Adapter(
+ "invalid model HTTP failure status".into(),
+ ));
+ }
+ Ok(())
+ }
+}
+
#[derive(Clone, Debug, Serialize, Deserialize, thiserror::Error)]
pub enum ModelError {
+ #[error("model HTTP request failed (status {status})")]
+ Http { status: u16 },
#[error("model request cancelled")]
Cancelled,
#[error("model stream idle timeout exceeded")]
@@ -120,3 +149,18 @@ pub enum ModelError {
#[error("model adapter failed: {0}")]
Adapter(String),
}
+
+impl ModelError {
+ pub fn failure_cause(&self) -> Option<ModelFailureCause> {
+ Some(match self {
+ Self::Cancelled => return None,
+ Self::Http { status } => ModelFailureCause::Http { status: *status },
+ Self::TimedOut => ModelFailureCause::TimedOut,
+ Self::ContextOverflow { .. } => ModelFailureCause::ContextOverflow,
+ Self::Provider(failure) => ModelFailureCause::Provider {
+ reason: failure.reason(),
+ },
+ Self::Adapter(_) => ModelFailureCause::Adapter,
+ })
+ }
+}
diff --git a/plugins/agent/graph/src/projection.rs b/plugins/agent/graph/src/projection.rs
index a5a957e42b..7e910fe71c 100644
--- a/plugins/agent/graph/src/projection.rs
+++ b/plugins/agent/graph/src/projection.rs
@@ -197,7 +197,7 @@ impl Execution {
};
let mut text = self.last_answer.clone();
let mut truncated = self.answer_truncated;
- if let InvocationOutcome::Failed { class, message } = outcome {
+ if let InvocationOutcome::Failed { class, message, .. } = outcome {
append(
&mut text,
&format!(
diff --git a/plugins/agent/model/src/events.rs b/plugins/agent/model/src/events.rs
index 99e858bfa6..a67177729f 100644
--- a/plugins/agent/model/src/events.rs
+++ b/plugins/agent/model/src/events.rs
@@ -232,6 +232,9 @@ impl Normalizer {
#[derive(serde::Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
enum Failure {
+ Http {
+ status: u16,
+ },
ContextOverflow {
#[serde(rename = "observedOutput")]
observed_output: bool,
@@ -241,6 +244,11 @@ impl Normalizer {
let failure = serde_json::from_value(value["error"].clone())
.map_err(|_| invalid("invalid provider error envelope"))?;
return Err(match failure {
+ Failure::Http { status } => {
+ maka_agent_facts::model::error::ModelFailureCause::Http { status }
+ .validate()?;
+ ModelError::Http { status }
+ }
Failure::ContextOverflow { observed_output } => {
ModelError::ContextOverflow { observed_output }
}
@@ -275,6 +283,27 @@ mod tests {
Err(ModelError::Adapter(_))
));
}
+ for status in [100, 199, 300, 400, 599] {
+ assert!(
+ matches!(Normalizer::default().push(json!({"type":"error","error":{"kind":"http","status":status}})), Err(ModelError::Http { status: actual }) if actual == status)
+ );
+ }
+ for status in [
+ json!(99),
+ json!(200),
+ json!(299),
+ json!(600),
+ json!(400.5),
+ json!("400"),
+ json!(null),
+ ] {
+ assert!(matches!(
+ Normalizer::default()
+ .push(json!({"type":"error","error":{"kind":"http","status":status}})),
+ Err(ModelError::Adapter(_))
+ ));
+ }
+ assert!(matches!(Normalizer::default().push(json!({"type":"error","error":{"kind":"http","status":400,"message":"private provider body"}})), Err(ModelError::Adapter(_))));
for observed in [false, true] {
assert!(
matches!(Normalizer::default().push(json!({"type":"error","error":{"kind":"context_overflow","observedOutput":observed}})),Err(ModelError::ContextOverflow{observed_output}) if observed_output == observed)
diff --git a/plugins/agent/model/tests/fixtures/provider-errors.mjs b/plugins/agent/model/tests/fixtures/provider-errors.mjs
index 8851cddd7f..e8c40f2396 100644
--- a/plugins/agent/model/tests/fixtures/provider-errors.mjs
+++ b/plugins/agent/model/tests/fixtures/provider-errors.mjs
@@ -152,6 +152,7 @@ globalThis.Deno = {
},
};
await assert.rejects(networkFetch(1)('http://fixture.invalid'), (error) => error === native);
+const privateFailure = 'PRIVATE_PROVIDER_HTTP_FAILURE_SENTINEL';
for (const [statusCode, responseHeaders, reason, code] of [
[200, {}, 'network'],
[401, {}, undefined],
@@ -163,13 +164,16 @@ for (const [statusCode, responseHeaders, reason, code] of [
[409, {}, undefined],
[500, {}, 'provider_unavailable', 'resource-exhausted'],
]) {
- const error = Object.assign(new Error('HTTP error body reset'), {
- name: 'AI_APICallError',
- statusCode,
- responseHeaders,
- cause: native,
- responseBody: JSON.stringify({ error: { type: code } }),
- });
+ const error = Object.assign(
+ new Error(reason === undefined ? privateFailure : 'HTTP error body reset'),
+ {
+ name: 'AI_APICallError',
+ statusCode,
+ responseHeaders,
+ cause: native,
+ responseBody: JSON.stringify({ error: { type: code, message: privateFailure } }),
+ },
+ );
const emitted = [];
const forward = () =>
forwardProviderStream(
@@ -181,8 +185,9 @@ for (const [statusCode, responseHeaders, reason, code] of [
'openai_chat',
);
if (reason === undefined) {
- await assert.rejects(forward(), (value) => value === error);
- assert.deepEqual(emitted, []);
+ await forward();
+ assert.deepEqual(emitted, [{ type: 'error', error: { kind: 'http', status: statusCode } }]);
+ assert(!JSON.stringify(emitted).includes(privateFailure));
} else {
await forward();
assert.equal(emitted.at(-1).error.reason, reason);
diff --git a/plugins/agent/model/tests/integration/context_overflow.rs b/plugins/agent/model/tests/integration/context_overflow.rs
index 02d5bbfd8b..25f650e4c7 100644
--- a/plugins/agent/model/tests/integration/context_overflow.rs
+++ b/plugins/agent/model/tests/integration/context_overflow.rs
@@ -114,14 +114,29 @@ async fn responses_unexpected_http_body_preserves_diagnostics_without_replaying(
(
400,
"application/json",
- json!({"detail":"Unsupported parameter: example"}).to_string(),
- "Unsupported parameter: example",
+ json!({"detail":"PRIVATE_PROVIDER_BODY_SENTINEL"}).to_string(),
+ "PRIVATE_PROVIDER_BODY_SENTINEL",
+ ),
+ (
+ 700,
+ "application/json",
+ json!({"detail":"PRIVATE_PROVIDER_BODY_SENTINEL"}).to_string(),
+ "invalid model HTTP failure status",
),
] {
let error = failure(ProviderKind::OpenaiResponses, status, content_type, body).await;
+ if status == 400 {
+ assert!(matches!(&error, ModelError::Http { status: 400 }));
+ assert!(!error.to_string().contains(detail));
+ continue;
+ }
let ModelError::Adapter(message) = error else {
panic!("unexpected response must remain a terminal protocol failure");
};
+ if status == 700 {
+ assert_eq!(message, detail);
+ continue;
+ }
assert!(message.contains(&format!("HTTP {status}")), "{message}");
assert!(message.contains(detail), "{message}");
assert!(!message.contains("private-page-content"));
@@ -149,7 +164,7 @@ async fn http_and_sse_failures_preserve_typed_evidence_across_sdk_families() {
ModelError::ContextOverflow { observed_output: false }));
}
for body in [json!({"error":{"message":"context length rejected"}}).to_string(), String::new()] {
- assert!(matches!(failure(ProviderKind::OpenaiChat,413,"application/json",body).await,ModelError::Adapter(_)));
+ assert!(matches!(failure(ProviderKind::OpenaiChat,413,"application/json",body).await,ModelError::Http { status: 413 }));
}
for (status, header, reason) in [
(503, None, Some(maka_model::ProviderFailureReason::ProviderUnavailable)),
@@ -167,7 +182,7 @@ async fn http_and_sse_failures_preserve_typed_evidence_across_sdk_families() {
assert!(failure.replay_safe());
assert_eq!(failure.retry_after(), header.filter(|h| *h == "0.01").map(|_| Duration::from_millis(10)));
}
- (None, ModelError::Adapter(_)) => {}
+ (None, ModelError::Http { status: 401 }) => {}
(_, result) => panic!("unexpected failure classification: {result}"),
}
}
diff --git a/plugins/agent/model/tests/integration/provider_errors.rs b/plugins/agent/model/tests/integration/provider_errors.rs
index 7478516e18..6e3d6c58f7 100644
--- a/plugins/agent/model/tests/integration/provider_errors.rs
+++ b/plugins/agent/model/tests/integration/provider_errors.rs
@@ -19,8 +19,7 @@
use deno_core::JsRuntime;
-#[tokio::test(flavor = "current_thread")]
-async fn provider_evidence_is_bounded_and_output_survives_normalization() {
+fn provider_runtime() -> JsRuntime {
let mut runtime = JsRuntime::new(Default::default());
runtime
.execute_script(
@@ -40,6 +39,12 @@ async fn provider_evidence_is_bounded_and_output_survives_normalization() {
.replace("export ", ""),
)
.unwrap();
+ runtime
+}
+
+#[tokio::test(flavor = "current_thread")]
+async fn provider_evidence_is_bounded_and_output_survives_normalization() {
+ let mut runtime = provider_runtime();
let promise = runtime.execute_script("overflow-contract", r#"
(async () => {
const assert = (ok, message) => { if (!ok) throw Error(message); };
@@ -104,3 +109,63 @@ async fn provider_evidence_is_bounded_and_output_survives_normalization() {
.await
.unwrap();
}
+
+#[tokio::test(flavor = "current_thread")]
+async fn nontransient_sdk_http_failures_preserve_only_status_across_provider_boundaries() {
+ let mut runtime = provider_runtime();
+ let promise = runtime.execute_script("http-failure-contract", r#"
+ (async () => {
+ const assert = (ok, message) => { if (!ok) throw Error(message); };
+ const secret = 'PRIVATE_PROVIDER_BODY_SENTINEL';
+ const api = (statusCode, fields = {}) => Object.assign(new Error(secret), {
+ name: 'AI_APICallError', statusCode, responseBody: secret,
+ data: {error: {message: secret}}, ...fields,
+ });
+ const errorPart = error => async () => ({stream: (async function* () {
+ yield {type: 'error', error};
+ })()});
+ const throwing = error => async () => { throw error; };
+ const collect = async open => {
+ const emitted = [];
+ let escaped;
+ try {
+ await forwardProviderStream(open, part => part, async part => emitted.push(part), 'openai_chat');
+ } catch (error) { escaped = error; }
+ return {emitted, escaped};
+ };
+ for (const open of [throwing(api(400)), errorPart(api(400))]) {
+ const {emitted, escaped} = await collect(open);
+ assert(escaped === undefined, 'nontransient SDK HTTP failure escaped typed boundary');
+ assert(JSON.stringify(emitted) === '[{"type":"error","error":{"kind":"http","status":400}}]',
+ 'HTTP envelope lost status or exposed provider details');
+ }
+ // Non-2xx is the HTTP contract, rather than a hand-picked 4xx allowlist.
+ for (const status of [100, 300]) {
+ const {emitted, escaped} = await collect(throwing(api(status)));
+ assert(escaped === undefined && JSON.stringify(emitted) ===
+ JSON.stringify([{type:'error',error:{kind:'http',status}}]), 'valid non-2xx status lost');
+ }
+ const overflow = await collect(throwing(api(400, {data:{error:{code:'context_length_exceeded'}}})));
+ assert(JSON.stringify(overflow.emitted) === '[{"type":"error","error":{"kind":"context_overflow","observedOutput":false}}]',
+ 'HTTP classification overrode context overflow');
+ const transient = await collect(errorPart(Object.assign(new Error('rate limited'), {
+ name:'AI_APICallError',statusCode:429,
+ })));
+ assert(transient.escaped === undefined && transient.emitted.length === 1 &&
+ transient.emitted[0].error.kind === 'provider' && transient.emitted[0].error.reason === 'rate_limit',
+ 'HTTP classification overrode retry evidence');
+ for (const error of [api(200), api(400.5), api(600),
+ {name:'AI_APICallError',statusCode:400}, Object.assign(new Error(secret),{statusCode:400}),
+ api(400,{cause:Object.assign(new Error('cancelled'),{name:'AbortError'})}),
+ api(400,{cause:Object.assign(new Error('limit'),{name:'ProviderResponseLimitError'})})]) {
+ const {emitted, escaped} = await collect(throwing(error));
+ assert(escaped === error && emitted.length === 0, 'unrecognized failure became HTTP evidence');
+ }
+ })()
+ "#).unwrap();
+ let resolving = runtime.resolve(promise);
+ runtime
+ .with_event_loop_promise(resolving, Default::default())
+ .await
+ .unwrap();
+}
diff --git a/plugins/agent/model/tests/integration/provider_responses.rs b/plugins/agent/model/tests/integration/provider_responses.rs
index e2c65951c2..e83fb3c7f1 100644
--- a/plugins/agent/model/tests/integration/provider_responses.rs
+++ b/plugins/agent/model/tests/integration/provider_responses.rs
@@ -424,7 +424,7 @@ async fn idle_http_reads_keep_protocol_safety_and_explicit_rejections() {
if mode == "untyped" {
assert!(matches!(error, ModelError::Adapter(message) if message.contains("missing Content-Type and no SSE events")));
} else if status == 401 {
- assert!(matches!(error, ModelError::Adapter(message) if message.contains("HTTP 401")));
+ assert!(matches!(error, ModelError::Http { status: 401 }));
} else {
let ModelError::Provider(failure) = error else { panic!("expected recoverable evidence: {error}") };
assert_eq!(failure.reason(), match status { 429 => ProviderFailureReason::RateLimit, 503 => ProviderFailureReason::ProviderUnavailable, _ => ProviderFailureReason::TimedOut });
diff --git a/plugins/agent/native/README.md b/plugins/agent/native/README.md
index 2c78b8a295..f6c541deb1 100644
--- a/plugins/agent/native/README.md
+++ b/plugins/agent/native/README.md
@@ -45,6 +45,8 @@ The default Maka composition enables `todo`: `todo_read` and `todo_write` mainta
The default Maka composition enables `automaticTitles`. Conversations created with `automaticTitle: true` receive one title attempt after their first admitted message, using the accepted model with a bounded, separately accounted request. Explicit titles, manual renames (including the unchanged placeholder), archived and managed sessions retain their names. Retries and Host restarts do not repeat an admitted title attempt; Host shutdown waits for its physical cleanup.
+Automatic-title preparation, model and invalid-output failures are durable session diagnostics. Empty or output-limited responses retain their actual physical usage while recording the logical title failure. Stopping the owner and policy skips do not report title failures; uncertain persistence or cleanup retains its original recovery priority.
+
Model context capacity, any independent input ceiling and the compaction threshold are captured with the accepted model selection and retained across queueing and restart. Without an explicit threshold, known input capacity sets the proactive threshold at 85%; output reserve remains a separate engine calculation.
The default composition enables `recaps`. The Session recap command reads cached text; generating a new recap requires explicit confirmation of the selected model and possible charges. Each request reads at most 256 bounded history pages, keeps at most 32 KiB of history text, and limits output to 1,024 tokens and 30 seconds. Incognito mode and session access are checked even for cached reads. Refresh and original operation recovery never regenerate; an unknown request remains pending acr [...]
diff --git a/plugins/agent/native/README.zh-CN.md b/plugins/agent/native/README.zh-CN.md
index f45a3b5ac3..3628f94187 100644
--- a/plugins/agent/native/README.zh-CN.md
+++ b/plugins/agent/native/README.zh-CN.md
@@ -45,6 +45,8 @@ Maka 默认组合启用 `todo`:`todo_read` 和 `todo_write` 维护当前会话
Maka 默认组合启用 `automaticTitles`。通过 `automaticTitle: true` 创建的会话在首条消息获准后,使用该消息选定的模型发起一次有界、独立计费的标题请求。显式命名、手动改名(包括保留原占位名称)、归档及托管会话保留原名称。重试和 Host 重启不会重复已接收的标题尝试;Host 关闭会等待请求实际清理完成。
+自动标题的准备、模型及无效输出失败会持久记录到会话诊断。空响应或输出达到上限时,保留实际请求用量,同时记录标题生成失败。服务停止及策略性跳过不报告标题失败;持久化或清理结果不确定时,保留原有恢复优先级。
+
模型上下文总容量、独立输入上限与压缩阈值随模型选择一起保存,排队和重启后继续使用接收时的值。未显式设置压缩阈值时,使用已知输入容量的 85%;输出预留仍由引擎单独计算。
默认组合启用 `recaps`。「会话回顾」命令读取缓存;生成新回顾前需明确确认所选模型及可能产生的费用。每次最多扫描 256 个有界历史页,保留不超过 32 KiB 的历史文本,输出上限为 1,024 token,生成限时 30 秒。读取缓存也检查隐私模式和会话访问范围。刷新和原始操作恢复不会重新生成;结果未知的请求在重启后仍保留为待定。辅助用量归属于原始应用操作,关闭时等待模型请求实际清理完成。
diff --git a/plugins/agent/native/src/owner/auxiliary.rs b/plugins/agent/native/src/owner/auxiliary.rs
index 964091bc34..558281b8c1 100644
--- a/plugins/agent/native/src/owner/auxiliary.rs
+++ b/plugins/agent/native/src/owner/auxiliary.rs
@@ -20,13 +20,34 @@
//! Auxiliary requests retain their physical worker and original usage journal.
use super::*;
use maka_agent_facts::{
- model::{ModelEvent, ModelFinishReason, ModelGeneration, ModelPart, TextKind},
+ model::{
+ ModelEvent, ModelFinishReason, ModelGeneration, ModelPart, TextKind, error::ModelError,
+ },
tools::ToolError,
};
use maka_capabilities::call::Resources;
use maka_event_log::usage::{AuxiliarySource, Outcome};
use maka_model::{ModelRequest, ModelStream, StepBuilder};
+pub(super) enum Error {
+ Model(ModelError),
+ Admission(ToolError),
+ Tool(ToolError),
+}
+impl From<ToolError> for Error {
+ fn from(error: ToolError) -> Self {
+ Self::Tool(error)
+ }
+}
+impl From<Error> for ToolError {
+ fn from(error: Error) -> Self {
+ match error {
+ Error::Model(error) => failed(error),
+ Error::Admission(error) | Error::Tool(error) => error,
+ }
+ }
+}
+
pub(super) enum Admission {
Source(AuxiliarySource),
Operation {
@@ -54,9 +75,9 @@ impl Auxiliary {
log: &EventLog,
admission: Admission,
quote: maka_agent_facts::pricing::Quote,
- ) -> Result<ModelGeneration, ToolError> {
+ ) -> Result<ModelGeneration, Error> {
if cancellation.is_cancelled() {
- return Err(failed("Auxiliary generation cancelled before dispatch"));
+ return Err(Error::Model(ModelError::Cancelled));
}
let id = match admission {
Admission::Operation {
@@ -69,8 +90,8 @@ impl Auxiliary {
.map_err(|error| match error {
maka_event_log::StoreError::SessionNotFound
| maka_event_log::StoreError::SessionRetired
- | maka_event_log::StoreError::SessionBusy => failed(error),
- other => persistence(other),
+ | maka_event_log::StoreError::SessionBusy => Error::Admission(failed(error)),
+ other => Error::Tool(persistence(other)),
})?,
Admission::Source(source) => log
.begin_auxiliary_model(source, Some(quote))
@@ -80,8 +101,8 @@ impl Auxiliary {
| maka_event_log::StoreError::SessionNotFound
| maka_event_log::StoreError::SessionRetired
| maka_event_log::StoreError::SessionBusy
- | maka_event_log::StoreError::PrefixTooLarge => failed(error),
- _ => persistence(error),
+ | maka_event_log::StoreError::PrefixTooLarge => Error::Admission(failed(error)),
+ _ => Error::Tool(persistence(error)),
})?,
};
let model_id = request.provider.model.clone();
@@ -90,10 +111,10 @@ impl Auxiliary {
.models
.stream(request, cancellation.clone())
.await
- .map_err(failed)?;
+ .map_err(Error::Model)?;
let step = receive(stream, log, id).await?;
if step.finish_reason == ModelFinishReason::ToolCalls {
- return Err(failed("Auxiliary generation cannot finish with tool calls"));
+ return Err(failed("Auxiliary generation cannot finish with tool calls").into());
}
Ok(ModelGeneration {
text: step
@@ -117,7 +138,9 @@ impl Auxiliary {
// Neither an uncertain commit nor lost physical custody permits a success/failure replacement.
if matches!(
result,
- Err(ToolError::Persistence(_) | ToolError::CleanupUnconfirmed(_))
+ Err(Error::Tool(
+ ToolError::Persistence(_) | ToolError::CleanupUnconfirmed(_)
+ ))
) {
return result;
}
@@ -136,7 +159,7 @@ async fn receive(
mut stream: ModelStream,
log: &EventLog,
id: Uuid,
-) -> Result<maka_agent_facts::model::ModelStep, ToolError> {
+) -> Result<maka_agent_facts::model::ModelStep, Error> {
let result = async {
let mut builder = StepBuilder::default();
let mut bytes = 0usize;
@@ -145,7 +168,7 @@ async fn receive(
let maka_model::Emission {
event,
reservation: _reservation,
- } = event.map_err(failed)?;
+ } = event.map_err(Error::Model)?;
if let ModelEvent::Finished { usage, .. } = &event
&& !observed_usage
{
@@ -159,17 +182,17 @@ async fn receive(
.map_err(failed)? as usize,
);
if bytes > 2 * 1024 * 1024 {
- return Err(failed("Auxiliary generation exceeds 2 MiB stream limit"));
+ return Err(failed("Auxiliary generation exceeds 2 MiB stream limit").into());
}
if matches!(
event,
ModelEvent::ToolCall(_) | ModelEvent::ProviderToolResult { .. }
) {
- return Err(failed("Auxiliary generation cannot call tools"));
+ return Err(failed("Auxiliary generation cannot call tools").into());
}
- builder.push(event).map_err(failed)?;
+ builder.push(event).map_err(Error::Model)?;
}
- builder.finish().map_err(failed)
+ builder.finish().map_err(Error::Model)
}
.await;
stream
diff --git a/plugins/agent/native/src/owner/plan/dispatch.rs b/plugins/agent/native/src/owner/plan/dispatch.rs
index e98aab74e2..e40e961efa 100644
--- a/plugins/agent/native/src/owner/plan/dispatch.rs
+++ b/plugins/agent/native/src/owner/plan/dispatch.rs
@@ -193,7 +193,7 @@ impl Owner {
};
let outcome = match outcome {
InvocationOutcome::Completed => Settlement::Completed,
- InvocationOutcome::Failed { class, message } => Settlement::Interrupted { reason: bounded(&message.unwrap_or(class)) },
+ InvocationOutcome::Failed { class, message, .. } => Settlement::Interrupted { reason: bounded(&message.unwrap_or(class)) },
InvocationOutcome::Cancelled { source } => Settlement::Interrupted { reason: bounded(&format!("Execution cancelled: {source}")) },
InvocationOutcome::HandoffPaused { .. } => Settlement::Interrupted { reason: "Original execution is paused; resume the Session before approving another attempt".into() },
_ => Settlement::Interrupted { reason: "Execution ended without Plan completion".into() },
diff --git a/plugins/agent/native/src/owner/queue.rs b/plugins/agent/native/src/owner/queue.rs
index e2febb095b..977c57b99e 100644
--- a/plugins/agent/native/src/owner/queue.rs
+++ b/plugins/agent/native/src/owner/queue.rs
@@ -438,6 +438,7 @@ impl Owner {
outcome: InvocationOutcome::Failed {
class: "message_preparation_failed".into(),
message: Some(reason),
+ model_failure: None,
},
},
]
diff --git a/plugins/agent/native/src/owner/recap.rs b/plugins/agent/native/src/owner/recap.rs
index 4d0b470e6b..697fd7ab35 100644
--- a/plugins/agent/native/src/owner/recap.rs
+++ b/plugins/agent/native/src/owner/recap.rs
@@ -308,6 +308,7 @@ impl Owner {
quote,
)
.await
+ .map_err(ToolError::from)
};
tokio::pin!(operation);
let result = tokio::select! {
diff --git a/plugins/agent/native/src/owner/tests/execution.rs b/plugins/agent/native/src/owner/tests/execution.rs
index 576d79cb90..a33fd84840 100644
--- a/plugins/agent/native/src/owner/tests/execution.rs
+++ b/plugins/agent/native/src/owner/tests/execution.rs
@@ -95,6 +95,7 @@ async fn assert_computer_output(fixture: &Fixture, session: &str, expected: &str
async fn computer_resume_replays_original_input_without_duplicate_effects(stop: bool) {
use maka_agent_facts::event::Fact;
use maka_agent_facts::interaction::InteractionRequest;
+ const SECRET: &str = "SECRET_MAIN_PROVIDER_BODY_SENTINEL";
tokio::time::timeout(Duration::from_secs(90), async {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
@@ -146,13 +147,15 @@ async fn computer_resume_replays_original_input_without_duplicate_effects(stop:
if stop {
assert_eq!(fixture.mutation(2, "stop", json!({"sessionId":session,"invocationId":sent["invocationId"]}), Uuid::new_v4()).await.unwrap()["requested"], true);
} else {
- let body = json!({"error":{"message":"resume fixture model failure","type":"invalid_request_error","code":"invalid_request"}}).to_string();
+ let body = json!({"error":{"message":SECRET,"type":"invalid_request_error","code":"invalid_request"}}).to_string();
socket.write_all(format!("HTTP/1.1 400 Bad Request\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", body.len()).as_bytes()).await.unwrap();
}
drop(socket);
fixture.drained().await;
let source = fixture.query("execution", json!({"sessionId":session,"invocationId":sent["invocationId"]})).await.unwrap()["execution"].clone();
assert_eq!(source["state"], if stop { "cancelled" } else { "failed" }, "{source}");
+ let failed_invocation=fixture.store.invocation_boundary(&session,sent["invocationId"].as_str().unwrap()).await.unwrap().unwrap().0.invocation;
+ let diagnostics=fixture.query("diagnostics",json!({"sessionId":session,"position":{"kind":"latest"}})).await;
// A later message must not replace the selected source's original input.
fixture.mutation(2, "send", json!({"sessionId":session,"message":"Later unrelated Computer request","model":fixture.selection().await}), Uuid::new_v4()).await.unwrap();
@@ -199,6 +202,27 @@ async fn computer_resume_replays_original_input_without_duplicate_effects(stop:
assert!(fixture.store.pending_interactions(&session).await.unwrap().is_empty());
fixture.app.shutdown().await.unwrap();
fixture.config.shutdown().await.unwrap();
+ if !stop {
+ let diagnostics=diagnostics.expect("actual main HTTP failure must be readable through public diagnostics");
+ let entries=diagnostics["entries"].as_array().unwrap();
+ assert_eq!(entries.len(),2,"both original model-step and terminal execution evidence must be visible");
+ for entry in entries {
+ assert!(entry["sequence"].as_u64().is_some_and(|sequence|sequence>0));
+ assert!(entry["eventId"].as_str().is_some_and(|id|!id.is_empty()));
+ assert!(entry["recordedAt"].as_f64().is_some());
+ assert_eq!(entry["detail"]["invocation"],serde_json::to_value(&failed_invocation).unwrap());
+ assert_eq!(entry["detail"]["modelFailure"],json!({"kind":"http","status":400}));
+ }
+ let execution=entries.iter().find(|entry|entry["detail"]["kind"] == "execution").unwrap();
+ assert_eq!(execution["detail"]["reason"],"model_http");
+ let step=entries.iter().find(|entry|entry["detail"]["kind"] == "model_step").unwrap();
+ assert_eq!(step["detail"]["status"],"failed");
+ let interrupted=facts.iter().find(|fact|matches!(fact,Fact::ModelInterrupted {..})).unwrap();
+ let ended=facts.iter().find(|fact|matches!(fact,Fact::InvocationEnded {outcome:maka_agent_facts::event::InvocationOutcome::Failed {..}})).unwrap();
+ assert_eq!(serde_json::to_value(interrupted).unwrap()["model_failure"],json!({"kind":"http","status":400}));
+ assert_eq!(serde_json::to_value(ended).unwrap()["outcome"]["model_failure"],json!({"kind":"http","status":400}));
+ assert!(!diagnostics.to_string().contains(SECRET),"safe diagnostics must not expose provider response bodies");
+ }
}).await.unwrap();
}
@@ -504,6 +528,7 @@ async fn resume_refuses_unsettled_effect_outside_its_selected_lineage() {
},
Fact::InvocationEnded {
outcome: InvocationOutcome::Failed {
+ model_failure: None,
class: "outcome_unknown".into(),
message: None,
},
diff --git a/plugins/agent/native/src/owner/tests/selection.rs b/plugins/agent/native/src/owner/tests/selection.rs
index 4325a598a1..96096bbc0c 100644
--- a/plugins/agent/native/src/owner/tests/selection.rs
+++ b/plugins/agent/native/src/owner/tests/selection.rs
@@ -560,11 +560,23 @@ async fn queued_model_route_change_settles_original_message_without_retargeting(
response(&mut socket).await;
fixture.drained().await;
assert!(fixture.store.pending_messages(&session).await.unwrap().is_empty());
- let facts = fixture.store.scoped_prefix(maka_agent_facts::event::LogScope::Session { id: session }, 256, 1024 * 1024).await.unwrap();
+ let facts = fixture.store.scoped_prefix(maka_agent_facts::event::LogScope::Session { id: session.clone() }, 256, 1024 * 1024).await.unwrap();
assert!(facts.events.iter().any(|event| matches!(&event.event.fact, maka_agent_facts::event::Fact::InvocationEnded { outcome: maka_agent_facts::event::InvocationOutcome::Failed { class, .. } } if class == "message_preparation_failed")));
assert_eq!(facts.events.iter().filter(|event| matches!(event.event.fact, maka_agent_facts::event::Fact::InvocationOpened { .. })).count(), 2);
+ let diagnostics=fixture.query("diagnostics",json!({"sessionId":session,"position":{"kind":"latest"}})).await;
fixture.app.shutdown().await.unwrap();
fixture.config.shutdown().await.unwrap();
+ let failed = facts.events.iter().find(|event|matches!(&event.event.fact,maka_agent_facts::event::Fact::InvocationEnded {
+ outcome:maka_agent_facts::event::InvocationOutcome::Failed {class,..}} if class == "message_preparation_failed")).unwrap();
+ let diagnostics=diagnostics.expect("queued preparation failure must be available through public diagnostics");
+ assert_eq!(diagnostics["entries"].as_array().unwrap().len(),1);
+ let entry=&diagnostics["entries"][0];
+ assert_eq!(entry["sequence"],failed.sequence);
+ assert_eq!(entry["eventId"],failed.event.id);
+ assert_eq!(entry["detail"]["kind"],"execution");
+ assert_eq!(entry["detail"]["invocation"],serde_json::to_value(&failed.event.invocation).unwrap());
+ assert_eq!(entry["detail"]["reason"],"message_preparation_failed");
+ assert!(entry["detail"]["modelFailure"].is_null(),"a deterministic queued route conflict is not a provider failure");
}).await.unwrap();
}
diff --git a/plugins/agent/native/src/owner/tests/title.rs b/plugins/agent/native/src/owner/tests/title.rs
index 960147d456..7e401ebdc0 100644
--- a/plugins/agent/native/src/owner/tests/title.rs
+++ b/plugins/agent/native/src/owner/tests/title.rs
@@ -434,3 +434,174 @@ async fn title_settlement_fault_fences_owner_and_preserves_original_usage_for_re
f.config.shutdown().await.unwrap();
}).await.unwrap();
}
+
+#[derive(Clone, Copy)]
+enum VisibleTitleFailure {
+ Http,
+ OutputLimit,
+ EmptyOutput,
+}
+
+#[tokio::test]
+async fn title_http_failure_is_public_sanitized_and_survives_restart() {
+ verify_visible_title_failure(VisibleTitleFailure::Http).await;
+}
+
+#[tokio::test]
+async fn title_output_limit_is_public_without_changing_successful_physical_accounting() {
+ verify_visible_title_failure(VisibleTitleFailure::OutputLimit).await;
+}
+
+#[tokio::test]
+async fn title_empty_output_is_public_without_changing_successful_physical_accounting() {
+ verify_visible_title_failure(VisibleTitleFailure::EmptyOutput).await;
+}
+
+async fn verify_visible_title_failure(case: VisibleTitleFailure) {
+ tokio::time::timeout(Duration::from_secs(30), async {
+ const SECRET: &str = "SECRET_TITLE_PROVIDER_BODY_SENTINEL";
+ let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let mut f = fixture(&format!("http://{}/v1", listener.local_addr().unwrap())).await;
+ let session = automatic(&f).await;
+ let other = f.create("Unaffected session").await;
+ let sent = f.send(&session).await.unwrap();
+ let ((_,mut main),(_,mut title)) = pair(&listener).await;
+ response(&mut main).await;
+ let completed = loop {
+ let boundary = f.store.invocation_boundary(&session,sent["invocationId"].as_str().unwrap()).await.unwrap().unwrap().0;
+ if matches!(boundary.state,maka_event_log::turns::InvocationState::Ended {..}) {break boundary;}
+ tokio::task::yield_now().await;
+ };
+ let diagnostic_watch = if matches!(case,VisibleTitleFailure::Http) {
+ let mut watch=f.app.client().subscribe(f.binding(2).await,"watchDiagnostics".into(),json!({"sessionId":session}),
+ scope(&f.issuer,true),Attachments::default().into()).await.unwrap();
+ let initial=watch.recv().await.unwrap();
+ Some((watch,initial))
+ } else {None};
+ let before_failure = now();
+ let (status,content_type,body,cause,physical_outcome) = match case {
+ VisibleTitleFailure::Http => (
+ "400 Bad Request", "application/json",
+ json!({"error":{"type":"invalid_request_error","message":SECRET}}).to_string(),
+ json!({"kind":"model","cause":{"kind":"http","status":400}}), Outcome::Error,
+ ),
+ VisibleTitleFailure::OutputLimit | VisibleTitleFailure::EmptyOutput => {
+ let limited = matches!(case,VisibleTitleFailure::OutputLimit);
+ let text = if limited {"A partial title"} else {" \n\t\u{0000}\u{202e} "};
+ let delta = json!({"id":"title-failure","choices":[{"index":0,"delta":{"content":text},"finish_reason":null}]});
+ let end = json!({"id":"title-failure","choices":[{"index":0,"delta":{},"finish_reason":if limited {"length"} else {"stop"}}],"usage":{"prompt_tokens":7,"completion_tokens":9,"total_tokens":16}});
+ ("200 OK","text/event-stream",format!("data: {delta}\n\ndata: {end}\n\ndata: [DONE]\n\n"),
+ json!({"kind":if limited {"output_limit"} else {"empty_output"}}),Outcome::Success)
+ }
+ };
+ title.write_all(format!("HTTP/1.1 {status}\r\nContent-Type: {content_type}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",body.len()).as_bytes()).await.unwrap();
+ f.drained().await;
+ let after_failure = now();
+ let watched = if let Some((mut watch,initial))=diagnostic_watch {
+ let late=watch.recv().await.unwrap();
+ let revision=f.owner.session(&other).await.unwrap().revision;
+ f.mutation(2,"metadata",json!({"sessionId":other,"expectedRevision":revision,"title":"Unrelated metadata commit","labels":[]}),Uuid::new_v4()).await.unwrap();
+ let unrelated_update=tokio::time::timeout(Duration::from_millis(30),watch.recv()).await.is_ok();
+ drop(watch);
+ Some((initial,late,unrelated_update))
+ } else {None};
+ let observed = f.query("observe",json!({"sessionId":session})).await.unwrap();
+ let record = f.owner.session(&session).await.unwrap();
+ let original_attempts = attempts(&f,&session).await;
+ let diagnostics = f.query("diagnostics",json!({"sessionId":session,"position":{"kind":"latest"}})).await;
+ let scoped = f.query("diagnostics",json!({"sessionId":other,"position":{"kind":"latest"}})).await;
+ let foreign = f.query("diagnostics",json!({"sessionId":"foreign_session","position":{"kind":"latest"}})).await;
+ todo_tests::reopen(&mut f).await;
+ let restored = f.query("diagnostics",json!({"sessionId":session,"position":{"kind":"latest"}})).await;
+ let restored_attempts = attempts(&f,&session).await;
+ let reconnected = if matches!(case,VisibleTitleFailure::Http) {
+ let mut watch=f.app.client().subscribe(f.binding(2).await,"watchDiagnostics".into(),json!({"sessionId":session}),
+ scope(&f.issuer,true),Attachments::default().into()).await.unwrap();
+ let initial=watch.recv().await.unwrap();
+ drop(watch);
+ Some(initial)
+ } else {None};
+ let redispatched = tokio::time::timeout(Duration::from_millis(30),listener.accept()).await.is_ok();
+ f.app.shutdown().await.unwrap();
+ f.config.shutdown().await.unwrap();
+ assert!(matches!(completed.state,maka_event_log::turns::InvocationState::Ended {
+ outcome:maka_agent_facts::event::InvocationOutcome::Completed,..}));
+ assert!(observed["run"].is_null());
+ assert_eq!(record.configuration.title,"Untitled");
+ assert!(!record.configuration.title_is_manual);
+ assert_eq!(original_attempts.len(),2);
+ let auxiliary = original_attempts.iter().find(|attempt|matches!(attempt.origin,Origin::Auxiliary {..})).unwrap();
+ assert_eq!(auxiliary.outcome,physical_outcome);
+ if !matches!(case,VisibleTitleFailure::Http) {
+ assert_eq!(auxiliary.usage.input_tokens,Some(7));
+ assert_eq!(auxiliary.usage.output_tokens,Some(9));
+ }
+ assert_eq!(restored_attempts,original_attempts);
+ assert!(!redispatched);
+ let diagnostics = diagnostics.expect("public diagnostics must expose the actual title failure");
+ let restored = restored.expect("public diagnostics must persist across restart");
+ let scoped = scoped.expect("owned-session diagnostics must be readable");
+ assert_eq!(diagnostics["entries"].as_array().unwrap().len(),1);
+ let failure = &diagnostics["entries"][0];
+ let sequence = failure["sequence"].as_u64().expect("diagnostic must identify its durable sequence");
+ assert!(sequence > 0);
+ let event_id = failure["eventId"].as_str().expect("diagnostic must identify its actual event");
+ assert!(!event_id.is_empty());
+ let recorded_at = failure["recordedAt"].as_f64().expect("diagnostic must include its Host capture time");
+ assert!((before_failure as f64..=(after_failure+1) as f64).contains(&recorded_at));
+ assert_eq!(*failure,json!({"sequence":sequence,"eventId":event_id,"recordedAt":recorded_at,
+ "detail":{"kind":"session_title","invocation":completed.invocation,"cause":cause}}));
+ assert_eq!(restored["entries"],diagnostics["entries"]);
+ if let Some((initial,late,unrelated_update))=watched {
+ assert_eq!(initial,json!({"revision":0}));
+ assert_eq!(late,json!({"revision":sequence}),"late title completion must notify after the main invocation ends");
+ assert!(!unrelated_update,"another session's metadata commit must not emit a diagnostic revision");
+ assert_eq!(reconnected,Some(json!({"revision":sequence})),"reconnect must begin with the latest diagnostic independent of transcript progress");
+ }
+ assert_eq!(scoped["entries"],json!([]),"failure must not leak into another owned session");
+ assert!(foreign.is_err(),"foreign-session diagnostics must remain unauthorized");
+ assert!(!diagnostics.to_string().contains(SECRET));
+ assert!(!restored.to_string().contains(SECRET));
+ }).await.unwrap();
+}
+
+#[tokio::test]
+async fn title_preparation_failure_is_public_without_a_physical_title_attempt() {
+ tokio::time::timeout(Duration::from_secs(30),async {
+ let listener=TcpListener::bind("127.0.0.1:0").await.unwrap();
+ // Automatic dispatch is disabled; this test calls generation once from
+ // the actual first opening's frozen source after its connection changes.
+ let f=Fixture::new(&format!("http://{}/v1",listener.local_addr().unwrap()),None).await;
+ let session=automatic(&f).await;
+ let sent=f.send(&session).await.unwrap();
+ let (mut socket,_)=listener.accept().await.unwrap();
+ request(&mut socket).await;
+ let accepted=f.owner.runs.lock().await.controls.get(&session).unwrap().basis.model.clone().unwrap();
+ response(&mut socket).await;
+ f.drained().await;
+ let opening=f.store.invocation_boundary(&session,sent["invocationId"].as_str().unwrap()).await.unwrap().unwrap().0;
+ selection::edit(&f,|changes| changes.enabled=Some(false)).await;
+ f.owner.generate_title(opening.invocation.clone(),accepted).await.unwrap();
+ let diagnostics=f.query("diagnostics",json!({"sessionId":session,"position":{"kind":"latest"}})).await;
+ let actual_attempts=attempts(&f,&session).await;
+ let record=f.owner.session(&session).await.unwrap();
+ let dispatched=tokio::time::timeout(Duration::from_millis(30),listener.accept()).await.is_ok();
+ f.app.shutdown().await.unwrap();
+ f.config.shutdown().await.unwrap();
+ assert!(matches!(opening.state,maka_event_log::turns::InvocationState::Ended {
+ outcome:maka_agent_facts::event::InvocationOutcome::Completed,..}));
+ assert_eq!(actual_attempts.len(),1);
+ assert!(matches!(actual_attempts[0].origin,Origin::Agent {..}));
+ assert_eq!(actual_attempts[0].outcome,Outcome::Success);
+ assert!(!dispatched,"capture failure must not invent a physical request or title attempt");
+ assert_eq!(record.configuration.title,"Untitled");
+ assert!(!record.configuration.title_is_manual);
+ let diagnostics=diagnostics.expect("actual pre-capture title failure must be public");
+ let entries=diagnostics["entries"].as_array().unwrap();
+ assert_eq!(entries.len(),1);
+ assert_eq!(entries[0]["detail"],json!({"kind":"session_title","invocation":opening.invocation,"cause":{"kind":"preparation"}}));
+ assert!(entries[0]["sequence"].as_u64().is_some_and(|sequence|sequence>0));
+ assert!(entries[0]["eventId"].as_str().is_some_and(|id|!id.is_empty()));
+ assert!(entries[0]["recordedAt"].as_f64().is_some());
+ }).await.unwrap();
+}
diff --git a/plugins/agent/native/src/owner/title.rs b/plugins/agent/native/src/owner/title.rs
index e3c06bf3a3..d195959ef3 100644
--- a/plugins/agent/native/src/owner/title.rs
+++ b/plugins/agent/native/src/owner/title.rs
@@ -21,8 +21,9 @@ use super::*;
use auxiliary::{failed, persistence};
use futures_util::FutureExt;
use maka_agent_facts::{
+ diagnostics::TitleFailureCause,
event::{Fact, InvocationInput},
- model::ModelFinishReason,
+ model::{ModelFinishReason, error::ModelFailureCause},
tools::ToolError,
};
use maka_agent_ports::session::title::Policy;
@@ -35,6 +36,33 @@ pub(super) struct WriteGate {
pub(super) release: tokio::sync::Semaphore,
}
+enum GenerationError {
+ Failure(TitleFailureCause),
+ Operation(ToolError),
+ Skipped,
+}
+impl From<ToolError> for GenerationError {
+ fn from(error: ToolError) -> Self {
+ Self::Operation(error)
+ }
+}
+impl From<auxiliary::Error> for GenerationError {
+ fn from(error: auxiliary::Error) -> Self {
+ match error {
+ auxiliary::Error::Model(error) => {
+ error.failure_cause().map_or(Self::Skipped, |cause| {
+ Self::Failure(TitleFailureCause::Model { cause })
+ })
+ }
+ auxiliary::Error::Admission(_) => Self::Skipped,
+ auxiliary::Error::Tool(ToolError::Failed(_)) => {
+ Self::Failure(TitleFailureCause::InvalidOutput)
+ }
+ auxiliary::Error::Tool(error) => Self::Operation(error),
+ }
+ }
+}
+
impl Owner {
// Called under the original run admission gate; its TaskTracker owns the work through cleanup.
pub(super) fn title_after_message(
@@ -73,7 +101,7 @@ impl Owner {
}
});
}
- async fn generate_title(
+ pub(super) async fn generate_title(
&self,
invocation: Invocation,
model: crate::model::AcceptedModel,
@@ -135,10 +163,12 @@ impl Owner {
let Some(input) = maka_session_title::Title.prepare(text) else {
return Ok(());
};
- input.validate().map_err(failed)?;
let cancellation = self.stop.child_token();
let _cancel = cancellation.clone().drop_guard();
let operation = async {
+ input
+ .validate()
+ .map_err(|_| GenerationError::Failure(TitleFailureCause::Preparation))?;
let source = crate::model::Source::restore(
self.configuration.clone(),
self.credentials.clone(),
@@ -146,8 +176,11 @@ impl Owner {
invocation.session_id.clone(),
self.revision.clone(),
)
- .map_err(failed)?;
- let prepared = source.capture_auxiliary().await.map_err(failed)?;
+ .map_err(|_| GenerationError::Failure(TitleFailureCause::Preparation))?;
+ let prepared = source
+ .capture_auxiliary()
+ .await
+ .map_err(|_| GenerationError::Failure(TitleFailureCause::Preparation))?;
let requested = input.max_output_tokens.unwrap_or(2048).min(2048);
let quote = self
.configuration
@@ -183,18 +216,42 @@ impl Owner {
quote,
)
.await
+ .map_err(GenerationError::from)
};
tokio::pin!(operation);
- let generated = tokio::select! {
+ let (result, timed_out) = tokio::select! {
biased;
- _ = tokio::time::sleep(Duration::from_secs(30)) => { cancellation.cancel(); operation.await },
- result = &mut operation => result,
- }?;
- if cancellation.is_cancelled() || generated.finish_reason != ModelFinishReason::Stop {
- return Ok(());
- }
- let Some(title) = maka_session_title::normalize(&generated.text) else {
- return Ok(());
+ _ = tokio::time::sleep(Duration::from_secs(30)) => { cancellation.cancel(); (operation.await, true) },
+ result = &mut operation => (result, false),
+ };
+ // Uncertain persistence or physical cleanup outranks the logical deadline.
+ let result = match result {
+ Err(GenerationError::Operation(error)) => return Err(error),
+ _ if self.stop.is_cancelled() => return Ok(()),
+ _ if timed_out => Err(TitleFailureCause::Model {
+ cause: ModelFailureCause::TimedOut,
+ }),
+ Err(GenerationError::Skipped) => return Ok(()),
+ Err(GenerationError::Failure(cause)) => Err(cause),
+ Ok(generated) if generated.finish_reason == ModelFinishReason::Length => {
+ Err(TitleFailureCause::OutputLimit)
+ }
+ Ok(generated) if generated.finish_reason != ModelFinishReason::Stop => {
+ Err(TitleFailureCause::InvalidOutput)
+ }
+ Ok(generated) => {
+ maka_session_title::normalize(&generated.text).ok_or(TitleFailureCause::EmptyOutput)
+ }
+ };
+ let title = match result {
+ Ok(title) => title,
+ Err(cause) => {
+ self.store
+ .record_title_failure(invocation.clone(), cause)
+ .await
+ .map_err(persistence)?;
+ return Ok(());
+ }
};
// Main execution also moves the public revision. Retry metadata only;
// each attempt gives queued manual changes and shutdown a turn at the gate.
diff --git a/plugins/agent/native/src/service.rs b/plugins/agent/native/src/service.rs
index 52094228da..9983304d43 100644
--- a/plugins/agent/native/src/service.rs
+++ b/plugins/agent/native/src/service.rs
@@ -30,6 +30,8 @@ use serde::{Serialize, de::DeserializeOwned};
use serde_json::Value;
use std::sync::Arc;
+mod diagnostics;
+
pub(crate) struct Agent(pub Arc<Owner>);
impl Handler for Agent {
fn call(
@@ -285,6 +287,8 @@ impl Handler for Agent {
context.operation().ok_or("agent_mutation_required")?;
encode(owner.metadata(decode(input)?).await?)
}
+ "diagnostics" => diagnostics::query(&owner, decode(input)?, &context).await,
+ "watchDiagnostics" => diagnostics::watch(&owner, decode(input)?, &context).await,
"observe" => {
use maka_event_log::turns::InvocationState;
let input: SessionRead = decode(input)?;
diff --git a/plugins/agent/native/src/service/diagnostics.rs b/plugins/agent/native/src/service/diagnostics.rs
new file mode 100644
index 0000000000..4397a51968
--- /dev/null
+++ b/plugins/agent/native/src/service/diagnostics.rs
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use super::*;
+
+const PAGE_BYTES: usize = 48 * 1024;
+
+pub(super) async fn query(
+ owner: &Owner,
+ input: Diagnostics,
+ context: &Context,
+) -> Result<Value, String> {
+ owner.session(&input.session_id).await?;
+ let (through, before) = match input.position {
+ DiagnosticPosition::Latest => (None, None),
+ DiagnosticPosition::Before { through, sequence } => (Some(through), Some(sequence)),
+ };
+ let page = owner
+ .store
+ .diagnostics_page(&input.session_id, through, before, 32, PAGE_BYTES)
+ .await
+ .map_err(|_| "agent_diagnostics_unavailable")?;
+ let mut page = DiagnosticPage {
+ through: page.through,
+ next_before: page.next_before,
+ entries: page
+ .entries
+ .into_iter()
+ .map(|entry| Diagnostic {
+ sequence: entry.sequence,
+ event_id: entry.event_id,
+ recorded_at: entry
+ .recorded_at
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_secs_f64()
+ * 1000.0,
+ detail: entry.detail,
+ })
+ .collect(),
+ };
+ let value = loop {
+ let value = encode(&page)?;
+ if maka_plugin_core::json::check_delivery(&value, PAGE_BYTES).is_ok() {
+ break value;
+ }
+ if page.entries.len() <= 1 {
+ return Err("agent_diagnostics_unavailable".into());
+ }
+ page.entries.pop();
+ page.next_before = page.entries.last().map(|entry| entry.sequence);
+ };
+ owner.session(&input.session_id).await?;
+ if context.scope().cancellation.is_cancelled() {
+ return Err("agent_observation_cancelled".into());
+ }
+ Ok(value)
+}
+
+pub(super) async fn watch(
+ owner: &Owner,
+ input: SessionRead,
+ context: &Context,
+) -> Result<Value, String> {
+ owner.session(&input.session_id).await?;
+ let mut commits = owner.store.subscribe_commits();
+ let mut previous = None;
+ loop {
+ if context.scope().cancellation.is_cancelled() {
+ return Err("agent_observation_cancelled".into());
+ }
+ owner.session(&input.session_id).await?;
+ let through = *commits.borrow_and_update();
+ let revision = owner
+ .store
+ .latest_diagnostic_sequence(&input.session_id, through)
+ .await
+ .map_err(|_| "agent_diagnostics_unavailable")?
+ .unwrap_or(0);
+ owner.session(&input.session_id).await?;
+ if context.scope().cancellation.is_cancelled() {
+ return Err("agent_observation_cancelled".into());
+ }
+ if previous != Some(revision) {
+ let value = encode(DiagnosticChange { revision })?;
+ maka_plugin_core::json::check_delivery(&value, PAGE_BYTES)
+ .map_err(|_| "agent_diagnostics_unavailable")?;
+ context.emit(value).await?;
+ previous = Some(revision);
+ }
+ tokio::select! {
+ biased;
+ _ = context.scope().cancellation.cancelled() => return Err("agent_observation_cancelled".into()),
+ result = commits.changed() => result.map_err(|_| "agent_observation_closed")?,
+ }
+ }
+}
diff --git a/plugins/agent/responses/src/stream.rs b/plugins/agent/responses/src/stream.rs
index fb1cf45913..e8aff99da5 100644
--- a/plugins/agent/responses/src/stream.rs
+++ b/plugins/agent/responses/src/stream.rs
@@ -22,9 +22,9 @@ use crate::{
decode::Decoder,
transport::{Exchange, ResponsesLane, Shared},
};
-use maka_agent_facts::model::error::ModelError;
use maka_agent_facts::model::error::ProviderFailure;
use maka_agent_facts::model::error::ProviderFailureReason;
+use maka_agent_facts::model::error::{ModelError, ModelFailureCause};
use maka_agent_ports::model::Context;
use maka_agent_ports::model::Credentials as ProviderAuth;
use maka_agent_ports::model::Events;
@@ -66,6 +66,12 @@ pub async fn stream(
result = operation => result,
}
}
+fn http_failure(status: u16) -> ModelError {
+ match (ModelFailureCause::Http { status }).validate() {
+ Ok(()) => ModelError::Http { status },
+ Err(error) => error,
+ }
+}
fn interruption(
decoder: &Decoder,
reason: ProviderFailureReason,
@@ -219,6 +225,7 @@ async fn run(
true,
retry_after,
)),
+ None if !(200..300).contains(&status) => http_failure(status),
None => ModelError::Adapter(format!("Responses HTTP {status}: error body interrupted")),
};
let mut bytes = Vec::new();
@@ -262,14 +269,14 @@ async fn run(
retry_after,
)));
}
- let message = value["error"]["message"]
- .as_str()
- .or_else(|| value["detail"].as_str())
- .unwrap_or("request rejected")
- .chars()
- .take(4096)
- .collect::<String>();
if (200..300).contains(&status) {
+ let message = value["error"]["message"]
+ .as_str()
+ .or_else(|| value["detail"].as_str())
+ .unwrap_or("request rejected")
+ .chars()
+ .take(4096)
+ .collect::<String>();
let content_type = content_type
.unwrap_or("missing Content-Type")
.chars()
@@ -279,9 +286,7 @@ async fn run(
"Responses HTTP {status} returned {content_type}, expected text/event-stream: {message}"
)));
}
- return Err(ModelError::Adapter(format!(
- "Responses HTTP {status}: {message}"
- )));
+ return Err(http_failure(status));
}
let mut sse = crate::sse::Sse::default();
let mut received_event = false;
diff --git a/plugins/shared/locale-messages.ts b/plugins/shared/locale-messages.ts
index 01c05bbb6d..9d9d76ec64 100644
--- a/plugins/shared/locale-messages.ts
+++ b/plugins/shared/locale-messages.ts
@@ -19,6 +19,128 @@
import type { Message } from './locale.js';
+export const msg_diagnosticsSessionBusy: Message = ['Session busy', '会话正忙', '對話忙碌中'];
+export const msg_diagnosticsContinuationChanged: Message = [
+ 'Continuation changed',
+ '续跑来源已变化',
+ '續跑來源已變更',
+];
+export const msg_diagnosticsReconciliationRequired: Message = [
+ 'Original outcome needs reconciliation',
+ '需要核对原操作结果',
+ '需要核對原操作結果',
+];
+export const msg_diagnosticsInvalidInput: Message = ['Invalid input', '输入无效', '輸入無效'];
+export const msg_diagnosticsCancelled: Message = ['Cancelled', '已取消', '已取消'];
+export const msg_diagnosticsIncomplete: Message = [
+ 'Model response incomplete',
+ '模型响应不完整',
+ '模型回應不完整',
+];
+export const msg_diagnosticsPersistence: Message = [
+ 'Event commit failed',
+ '事件提交失败',
+ '事件提交失敗',
+];
+export const msg_diagnosticsStorage: Message = [
+ 'Event storage failed',
+ '事件存储失败',
+ '事件儲存失敗',
+];
+export const msg_diagnosticsProviderRejected: Message = [
+ 'Provider rejected the request',
+ '提供方拒绝了请求',
+ '供應方拒絕了請求',
+];
+export const msg_diagnosticsProviderFailed: Message = [
+ 'Model provider failed',
+ '模型提供方失败',
+ '模型供應方失敗',
+];
+export const msg_diagnosticsToolFailed: Message = [
+ 'Tool execution failed',
+ '工具执行失败',
+ '工具執行失敗',
+];
+export const msg_diagnosticsRuntimeFailed: Message = [
+ 'Runtime failed',
+ '运行时失败',
+ '執行環境失敗',
+];
+export const msg_diagnosticsCleanup: Message = [
+ 'Cleanup unconfirmed',
+ '清理尚未确认',
+ '清理尚未確認',
+];
+export const msg_diagnosticsExecutorFailed: Message = [
+ 'Executor failed',
+ '执行器失败',
+ '執行器失敗',
+];
+export const msg_diagnosticsHostInterrupted: Message = [
+ 'Host interrupted the execution',
+ '主机中断了执行',
+ '主機中斷了執行',
+];
+export const msg_diagnosticsOutcomeUnknown: Message = ['Outcome unknown', '结果未知', '結果未知'];
+export const msg_diagnosticsTitlePreparationFailed: Message = [
+ 'Title preparation failed',
+ '标题准备失败',
+ '標題準備失敗',
+];
+
+export const msg_diagnosticsTitleLabel: Message = ['Diagnostics', '诊断', '診斷'];
+export const msg_diagnosticsAnswer: Message = ['Answer', '回答', '回答'];
+export const msg_diagnosticsPreparation: Message = ['Message preparation', '消息准备', '訊息準備'];
+export const msg_diagnosticsModelStep: Message = ['Model step', '模型步骤', '模型步驟'];
+export const msg_diagnosticsTitle: Message = ['Automatic title', '自动标题', '自動標題'];
+export const msg_diagnosticsEmpty: Message = [
+ 'No recorded failures',
+ '没有已记录的失败',
+ '沒有已記錄的失敗',
+];
+export const msg_diagnosticsPreparationFailed: Message = [
+ 'Message preparation failed',
+ '消息准备失败',
+ '訊息準備失敗',
+];
+export const msg_diagnosticsExecutionFailed: Message = ['Execution failed', '执行失败', '執行失敗'];
+export const msg_diagnosticsStepFailed: Message = [
+ 'Model step failed',
+ '模型步骤失败',
+ '模型步驟失敗',
+];
+export const msg_diagnosticsTimedOut: Message = ['Timed out', '请求超时', '請求逾時'];
+export const msg_diagnosticsContextOverflow: Message = [
+ 'Context limit exceeded',
+ '超过上下文限制',
+ '超過上下文限制',
+];
+export const msg_diagnosticsAdapter: Message = [
+ 'Model adapter failed',
+ '模型适配器失败',
+ '模型配接器失敗',
+];
+export const msg_diagnosticsNetwork: Message = ['Network failure', '网络失败', '網路失敗'];
+export const msg_diagnosticsRateLimit: Message = ['Rate limited', '请求被限流', '請求受到速率限制'];
+export const msg_diagnosticsProviderUnavailable: Message = [
+ 'Provider unavailable',
+ '提供方不可用',
+ '供應方無法使用',
+];
+export const msg_diagnosticsStreamTruncated: Message = [
+ 'Response stream interrupted',
+ '响应流中断',
+ '回應串流中斷',
+];
+export const msg_diagnosticsInvalidOutput: Message = ['Invalid output', '输出无效', '輸出無效'];
+export const msg_diagnosticsOutputLimit: Message = [
+ 'Output limit reached',
+ '达到输出限制',
+ '達到輸出限制',
+];
+export const msg_diagnosticsEmptyOutput: Message = ['Empty output', '输出为空', '輸出為空'];
+
export const msg_historyModel: Message = ['Model', '模型', '模型'];
export const msg_historyRequestedModel: Message = ['Requested model', '请求模型', '請求模型'];
export const msg_historyImportedModel: Message = ['Imported model', '导入来源模型', '匯入來源模型'];
diff --git a/plugins/workhub/core/src/results.rs b/plugins/workhub/core/src/results.rs
index 760c809263..43fd4088ca 100644
--- a/plugins/workhub/core/src/results.rs
+++ b/plugins/workhub/core/src/results.rs
@@ -242,6 +242,7 @@ mod tests {
progress: Box::new(Progress::Ended {
outcome: if failed {
InvocationOutcome::Failed {
+ model_failure: None,
class: "provider".into(),
message: Some("error".repeat(20_000)),
}
diff --git a/products/maka/bundle/tests/task-workbench.test.mjs b/products/maka/bundle/tests/task-workbench.test.mjs
index ad804aea39..08c4cd5e47 100644
--- a/products/maka/bundle/tests/task-workbench.test.mjs
+++ b/products/maka/bundle/tests/task-workbench.test.mjs
@@ -1666,3 +1666,125 @@ test('historical captions use recorded response models and keep requested and im
}
}
});
+
+test('Diagnostics reads common failures and refreshes late background results without reloading the conversation', () => {
+ const c = client()
+ .observe(100)
+ .history(page(100, [chunk(90, 'Completed main answer')]));
+ c.raw('palette-open');
+ const command = c
+ .find('command-palette')
+ .props.commands.find((entry) => entry.id === 'diagnostics-open');
+ assert.ok(
+ command && !command.disabled,
+ 'Diagnostics entry must be available after the main answer completes',
+ );
+ c.child('command-palette', 'invoked', { id: 'diagnostics-open' });
+ assert.deepEqual(c.action('diagnostics').input, {
+ sessionId: 'Task A',
+ position: { kind: 'latest' },
+ });
+ const invocation = {
+ session_id: 'Task A',
+ turn_id: 'original-turn',
+ run_id: 'original-run',
+ invocation_id: 'original-invocation',
+ };
+ const main = {
+ sequence: 90,
+ eventId: 'main-failure',
+ recordedAt: 1000,
+ detail: {
+ kind: 'execution',
+ invocation,
+ reason: 'execution_failed',
+ modelFailure: { kind: 'http', status: 400 },
+ },
+ };
+ const preparation = {
+ sequence: 80,
+ eventId: 'prepare-failure',
+ recordedAt: 900,
+ detail: {
+ kind: 'execution',
+ invocation,
+ reason: 'message_preparation_failed',
+ modelFailure: null,
+ },
+ };
+ c.reply(c.action('diagnostics'), { through: 100, entries: [main, preparation], nextBefore: 80 });
+ assert.equal(c.find('diagnostic-cause-90').text, 'HTTP 400');
+ assert.equal(c.find('diagnostic-cause-80').text, 'Message preparation failed');
+ const diagnosticWatch = c.out.subscriptions.find(
+ (subscription) => subscription.method === 'watchDiagnostics',
+ );
+ assert.ok(diagnosticWatch, 'Diagnostics must subscribe independently of transcript progress');
+ assert.deepEqual(diagnosticWatch.input, { sessionId: 'Task A' });
+ c.raw('diagnostics-refresh');
+ const olderRead = c.action('diagnostics');
+ c.event({
+ kind: 'action',
+ key: diagnosticWatch.key,
+ event: { status: 'updated', value: { revision: 120 } },
+ });
+ const latestRead = c.action('diagnostics');
+ assert.notEqual(latestRead.key, olderRead.key);
+ assert.equal(c.action('observe'), undefined);
+ assert.equal(c.action('history'), undefined);
+ const title = {
+ sequence: 120,
+ eventId: 'title-failure',
+ recordedAt: 2000,
+ detail: { kind: 'session_title', invocation, cause: { kind: 'empty_output' } },
+ };
+ c.reply(latestRead, { through: 120, entries: [title, main, preparation], nextBefore: 80 });
+ assert.equal(c.find('diagnostic-cause-120').text, 'Empty output');
+ assert.equal(c.state.run, null);
+ assert.deepEqual(
+ c.find(c.reader()).props.messages.map((message) => message.text),
+ ['Completed main answer'],
+ );
+ assert.equal(c.action('observe'), undefined);
+ assert.equal(c.action('history'), undefined);
+ c.reply(olderRead, { through: 100, entries: [], nextBefore: null });
+ assert.equal(
+ c.find('diagnostic-cause-120').text,
+ 'Empty output',
+ 'An older empty query cannot clear the newer diagnostic page',
+ );
+ c.raw('diagnostic-open-120');
+ assert.equal(c.find('diagnostic-detail-cause').text, 'Empty output');
+ assert.equal(c.find('diagnostic-detail-source').text, 'Automatic title');
+ c.raw('diagnostics-back').raw('diagnostics-older');
+ assert.deepEqual(c.action('diagnostics').input, {
+ sessionId: 'Task A',
+ position: { kind: 'before', through: 120, sequence: 80 },
+ });
+ c.reply(c.action('diagnostics'), {
+ through: 120,
+ entries: [
+ {
+ sequence: 70,
+ eventId: 'step-failure',
+ recordedAt: 800,
+ detail: {
+ kind: 'model_step',
+ invocation,
+ stepId: 'retryable-step',
+ status: 'retryable_failure',
+ modelFailure: { kind: 'provider', reason: 'network' },
+ },
+ },
+ ],
+ nextBefore: null,
+ });
+ assert.equal(c.find('diagnostic-cause-70').text, 'Network failure');
+ c.select('Task B')
+ .observe(130)
+ .history(page(130, [chunk(130, 'Another conversation')]));
+ assert.equal(c.find('diagnostic-cause-120'), undefined);
+ assert.deepEqual(
+ c.find(c.reader()).props.messages.map((message) => message.text),
+ ['Another conversation'],
+ );
+});
diff --git a/products/maka/cli/src/code.rs b/products/maka/cli/src/code.rs
index cc9a7cf402..00a8256b1c 100644
--- a/products/maka/cli/src/code.rs
+++ b/products/maka/cli/src/code.rs
@@ -238,6 +238,7 @@ pub(super) async fn run(args: Args) -> Result<(), maka_host_runtime::HostError>
}
.into(),
message: Some(error.message.chars().take(2048).collect()),
+ model_failure: None,
},
Err(CellAbort::Cancelled) => InvocationOutcome::Cancelled {
source: "runtime_cancellation".into(),
@@ -250,6 +251,7 @@ pub(super) async fn run(args: Args) -> Result<(), maka_host_runtime::HostError>
}
.into(),
message: Some(error.to_string().chars().take(2048).collect()),
+ model_failure: None,
},
};
log.append(&EventWrite::plain(RuntimeEvent::new(
diff --git a/tools/schema/src/lib.rs b/tools/schema/src/lib.rs
index a8ad70662f..f808bc6d57 100644
--- a/tools/schema/src/lib.rs
+++ b/tools/schema/src/lib.rs
@@ -341,6 +341,9 @@ pub fn catalog() -> Value {
root::<maka_agent_api::contract::DeliveryFact>(&mut g),
root::<maka_agent_api::contract::ContentKind>(&mut g),
root::<maka_agent_api::contract::Observation>(&mut g),
+ root::<maka_agent_api::contract::Diagnostics>(&mut g),
+ root::<maka_agent_api::contract::DiagnosticPage>(&mut g),
+ root::<maka_agent_api::contract::DiagnosticChange>(&mut g),
root::<maka_agent_api::contract::SessionRead>(&mut g),
root::<maka_agent_api::contract::History>(&mut g),
root::<maka_agent_api::contract::HistoryPromptRead>(&mut g),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org