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/20 10:44:12 UTC
(maka) 07/10: feat(agent): identify final output in canonical history
This is an automated email from the ASF dual-hosted git repository.
M4n5ter pushed a commit to branch feat/nsh-tui-shell
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 0bf951878c0121222516e68333e3c8f16c5d06c0
Author: M4n5ter <m4...@gmail.com>
AuthorDate: Tue Oct 20 17:19:56 2026 +0800
feat(agent): identify final output in canonical history
Resolve the final successful model or executor output at the history fence so clients can separate every final body part and citation from turn activity. Reuse the canonical producer evidence and bounded per-turn lookups without storing another transcript projection.
Generated-by: OpenAI Codex
---
platform/event-log/src/transcript.rs | 1 +
platform/event-log/src/transcript/final_output.rs | 95 +++++++++++++++
platform/event-log/src/transcript/history.rs | 17 ++-
platform/event-log/src/transcript/model.rs | 42 +++++--
platform/event-log/src/transcript/source.rs | 2 +-
platform/event-log/tests/executor.rs | 8 ++
.../transcript_index/accepted_observations.rs | 32 +++++
.../event-log/tests/transcript_index/history.rs | 130 +++++++++++++++++----
plugins/agent/api/src/contract.rs | 4 +
plugins/agent/assistant/src/recall/rank.rs | 1 +
plugins/agent/native/src/service.rs | 1 +
plugins/agent/ports/src/session/history.rs | 5 +
plugins/agent/session-recap/src/recap.rs | 1 +
products/maka/acp/src/projection/messages.rs | 4 +
14 files changed, 307 insertions(+), 36 deletions(-)
diff --git a/platform/event-log/src/transcript.rs b/platform/event-log/src/transcript.rs
index 68e606df3c..4c2e0f5a6f 100644
--- a/platform/event-log/src/transcript.rs
+++ b/platform/event-log/src/transcript.rs
@@ -25,6 +25,7 @@ mod bodycache;
pub(crate) mod directory;
mod emit;
mod evidence;
+mod final_output;
mod history;
mod image;
mod model;
diff --git a/platform/event-log/src/transcript/final_output.rs b/platform/event-log/src/transcript/final_output.rs
new file mode 100644
index 0000000000..f7d1b33354
--- /dev/null
+++ b/platform/event-log/src/transcript/final_output.rs
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+//! Final output membership from a logical Turn's original successful terminal.
+use super::model::Producer;
+use crate::StoreError;
+use sqlx::SqliteConnection;
+
+// Choose the latest logical state first, including a later running/failed state.
+// A copied Session's directory and membership retain the same original evidence.
+const TERMINAL: &str = "WITH latest AS (
+ SELECT source_sequence, state_status FROM transcript_directory
+ WHERE session_id = ?1 AND turn_id = ?2 AND source_sequence <= ?3
+ AND role = 'turn_state'
+ ORDER BY source_sequence DESC, item_index DESC LIMIT 1
+) SELECT e.invocation_id, e.sequence FROM latest
+JOIN runtime_events e ON e.sequence = latest.source_sequence
+WHERE latest.state_status = 'completed' AND e.kind = 'invocation_ended'
+ AND json_extract(e.event_json, '$.fact.outcome.kind') = 'completed'
+ AND (e.event_session = ?1 OR EXISTS(
+ SELECT 1 FROM session_history_members h WHERE h.session_id = ?1 AND h.sequence = e.sequence))";
+const REQUESTED: &str = "SELECT e.operation_id FROM runtime_events e
+WHERE e.invocation_id = ?2 AND e.kind = 'model_requested' AND e.sequence <= ?3
+ AND json_extract(e.event_json, '$.fact.purpose') = 'main'
+ AND (e.event_session = ?1 OR EXISTS(
+ SELECT 1 FROM session_history_members h WHERE h.session_id = ?1 AND h.sequence = e.sequence))
+ORDER BY e.sequence DESC LIMIT 1";
+const COMPLETED: &str = "SELECT EXISTS(SELECT 1 FROM runtime_events e
+WHERE e.operation_id = ?3 AND e.kind = 'model_completed' AND e.invocation_id = ?2
+ AND e.sequence <= ?4 AND json_extract(e.event_json, '$.fact.step_id') = ?3
+ AND (e.event_session = ?1 OR EXISTS(
+ SELECT 1 FROM session_history_members h WHERE h.session_id = ?1 AND h.sequence = e.sequence)))";
+const EXECUTOR: &str = "SELECT e.sequence FROM runtime_events e
+WHERE e.invocation_id = ?2 AND e.kind = 'executor_completed' AND e.sequence <= ?3
+ AND (e.event_session = ?1 OR EXISTS(
+ SELECT 1 FROM session_history_members h WHERE h.session_id = ?1 AND h.sequence = e.sequence))
+ORDER BY e.sequence DESC LIMIT 1";
+
+/// One lookup per Turn in a history page; never hydrate model output bodies.
+pub(super) async fn resolve(
+ tx: &mut SqliteConnection,
+ session: &str,
+ turn: &str,
+ through: i64,
+) -> Result<Option<Producer>, StoreError> {
+ let terminal: Option<(String, i64)> = sqlx::query_as(TERMINAL)
+ .bind(session)
+ .bind(turn)
+ .bind(through)
+ .fetch_optional(&mut *tx)
+ .await?;
+ let Some((invocation, terminal)) = terminal else {
+ return Ok(None);
+ };
+ let requested: Option<String> = sqlx::query_scalar(REQUESTED)
+ .bind(session)
+ .bind(&invocation)
+ .bind(terminal)
+ .fetch_optional(&mut *tx)
+ .await?;
+ if let Some(step) = requested {
+ let completed: bool = sqlx::query_scalar(COMPLETED)
+ .bind(session)
+ .bind(&invocation)
+ .bind(&step)
+ .bind(terminal)
+ .fetch_one(&mut *tx)
+ .await?;
+ // An interrupted/latest request must never fall back to an earlier answer.
+ return Ok(completed.then_some(Producer::Model { invocation, step }));
+ }
+ let executor: Option<i64> = sqlx::query_scalar(EXECUTOR)
+ .bind(session)
+ .bind(&invocation)
+ .bind(terminal)
+ .fetch_optional(&mut *tx)
+ .await?;
+ Ok(executor.map(|_| Producer::Executor { invocation }))
+}
diff --git a/platform/event-log/src/transcript/history.rs b/platform/event-log/src/transcript/history.rs
index a45121c159..c186b01060 100644
--- a/platform/event-log/src/transcript/history.rs
+++ b/platform/event-log/src/transcript/history.rs
@@ -117,6 +117,7 @@ impl EventLog {
let session = session.to_owned();
self.connection.run(move |connection| Box::pin(async move {
let mut tx = connection.begin().await?;
+ let mut final_outputs = std::collections::HashMap::new();
super::directory::check_read(&mut tx, &session, fence).await?;
let exists: bool = sqlx::query_scalar(
"SELECT EXISTS(SELECT 1 FROM session_control WHERE id = ?)"
@@ -276,10 +277,18 @@ impl EventLog {
).bind(&session).bind(sql_position(locator)?.0).bind(sql_position(locator)?.1).fetch_one(&mut *tx).await?;
Some(maka_agent_ports::session::history::Compaction { duration_ms: sequence_number(duration)? })
} else { None };
- let model = if role == Role::Assistant {
- super::model::resolve(&mut tx, &session, locator, sql_number(through)?).await?
- } else { None };
- let chunk = Chunk { field, timing, compaction, origin: row.origin, model,
+ let (model, final_output) = if role == Role::Assistant {
+ let output = match final_outputs.entry(row.turn.clone()) {
+ std::collections::hash_map::Entry::Occupied(entry) => entry.into_mut(),
+ std::collections::hash_map::Entry::Vacant(entry) => entry.insert(
+ super::final_output::resolve(&mut tx, &session, &row.turn, through_sql).await?),
+ };
+ let metadata = super::model::resolve(&mut tx, &session, locator, through_sql).await?;
+ let final_output = field == HistoryField::Body && row.total > 0 && metadata.producer.as_ref().is_some_and(|producer|
+ output.as_ref() == Some(producer));
+ (metadata.model, final_output)
+ } else { (None, false) };
+ let chunk = Chunk { field, timing, compaction, origin: row.origin, model, final_output,
message_id: row.message, turn_id: row.turn, timestamp: row.timestamp, role,
position: locator, offset: start, total_bytes: row.total, text: text.to_owned(), attachments, tool,
};
diff --git a/platform/event-log/src/transcript/model.rs b/platform/event-log/src/transcript/model.rs
index 2033bd6b20..7d4ec244cc 100644
--- a/platform/event-log/src/transcript/model.rs
+++ b/platform/event-log/src/transcript/model.rs
@@ -17,12 +17,23 @@
* under the License.
*/
-//! Scalar canonical evidence for the model that produced an assistant row.
+//! Scalar canonical evidence for an assistant row's model and output producer.
use crate::StoreError;
use maka_agent_facts::history::RowPosition;
use maka_agent_ports::session::history::HistoryModel;
use sqlx::{Row, SqliteConnection};
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub(super) enum Producer {
+ Model { invocation: String, step: String },
+ Executor { invocation: String },
+}
+
+pub(super) struct Metadata {
+ pub model: Option<HistoryModel>,
+ pub producer: Option<Producer>,
+}
+
// Drive each lookup from the canonical sequence/operation/step index. Membership
// validates each candidate; the history UNION must not drive a whole-session scan.
const PRODUCER: &str = "SELECT e.invocation_id, e.kind, e.operation_id
@@ -62,7 +73,7 @@ pub(super) async fn resolve(
session: &str,
position: RowPosition,
through: i64,
-) -> Result<Option<HistoryModel>, StoreError> {
+) -> Result<Metadata, StoreError> {
let producer_sequence = super::read::sql_position(position)?.0;
let producer = sqlx::query(PRODUCER)
.bind(session)
@@ -85,10 +96,16 @@ pub(super) async fn resolve(
if content != "assistant" {
return Err(invalid());
}
- return Ok(model.map(|model_id| HistoryModel::Imported { model_id }));
+ return Ok(Metadata {
+ model: model.map(|model_id| HistoryModel::Imported { model_id }),
+ producer: None,
+ });
}
if matches!(kind.as_str(), "executor_observed" | "executor_completed") {
- return Ok(None);
+ return Ok(Metadata {
+ model: None,
+ producer: (kind == "executor_completed").then_some(Producer::Executor { invocation }),
+ });
}
let step: Option<String> = if kind == "invocation_ended" {
let executor: bool = sqlx::query_scalar(EXECUTOR)
@@ -98,7 +115,10 @@ pub(super) async fn resolve(
.fetch_one(&mut *tx)
.await?;
if executor {
- return Ok(None);
+ return Ok(Metadata {
+ model: None,
+ producer: None,
+ });
}
// Resolve the unfinished step at the actual sealing fact, never from a
// later public fence that may contain unrelated model steps.
@@ -140,10 +160,14 @@ pub(super) async fn resolve(
.chain(completed)
.max_by_key(|(sequence, _)| *sequence)
.map(|(_, model)| model);
- Ok(Some(HistoryModel::Native {
- requested_model_id,
- reported_model_id,
- }))
+ Ok(Metadata {
+ model: Some(HistoryModel::Native {
+ requested_model_id,
+ reported_model_id,
+ }),
+ producer: matches!(kind.as_str(), "model_observed" | "model_completed")
+ .then_some(Producer::Model { invocation, step }),
+ })
}
fn invalid() -> StoreError {
StoreError::InvalidTransition("invalid canonical history model evidence".into())
diff --git a/platform/event-log/src/transcript/source.rs b/platform/event-log/src/transcript/source.rs
index 359df5b04d..e74efccf1c 100644
--- a/platform/event-log/src/transcript/source.rs
+++ b/platform/event-log/src/transcript/source.rs
@@ -274,7 +274,7 @@ impl EventLog {
None
};
let model = if role == SourceRole::Assistant {
- super::model::resolve(&mut tx, &session, locator, sql_number(through)?).await?
+ super::model::resolve(&mut tx, &session, locator, sql_number(through)?).await?.model
} else { None };
let source = HistorySource {
model,
diff --git a/platform/event-log/tests/executor.rs b/platform/event-log/tests/executor.rs
index e2820bb416..68efa56bdb 100644
--- a/platform/event-log/tests/executor.rs
+++ b/platform/event-log/tests/executor.rs
@@ -225,6 +225,14 @@ async fn external_output_is_durable_observation_not_native_dispatch_and_rebuilds
.find(|chunk| chunk.text == "final authoritative answer")
.expect("actual executor answer");
assert!(chunks.iter().all(|chunk| chunk.model.is_none()));
+ assert_eq!(
+ chunks
+ .iter()
+ .filter(|chunk| chunk.final_output)
+ .map(|chunk| chunk.text.as_str())
+ .collect::<Vec<_>>(),
+ vec!["final authoritative answer"],
+ );
let source = log
.history_source(
"session",
diff --git a/platform/event-log/tests/transcript_index/accepted_observations.rs b/platform/event-log/tests/transcript_index/accepted_observations.rs
index 463643337e..794b4857ea 100644
--- a/platform/event-log/tests/transcript_index/accepted_observations.rs
+++ b/platform/event-log/tests/transcript_index/accepted_observations.rs
@@ -238,6 +238,38 @@ async fn accepted_kinds_publish_at_observation_and_unaccepted_kinds_wait_for_sea
assert_eq!(page(&reopened, unaccepted).await, unaccepted_page);
assert_eq!(canonical_bytes(&db), canonical);
drop(db);
+ let before_terminal = page(&reopened, later).await;
+ let through = end(
+ &reopened,
+ "a",
+ if interrupted {
+ InvocationOutcome::Failed {
+ class: "provider".into(),
+ message: None,
+ model_failure: None,
+ }
+ } else {
+ InvocationOutcome::Completed
+ },
+ )
+ .await;
+ let completed = page(&reopened, through).await;
+ let final_text: Vec<_> = completed["chunks"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .filter(|chunk| chunk["finalOutput"] == true)
+ .map(|chunk| chunk["text"].as_str().unwrap())
+ .collect();
+ assert_eq!(
+ final_text,
+ if interrupted {
+ vec![]
+ } else {
+ vec!["acceptedä¸ðŸ˜€", "Source: Ref\nhttps://example.test/ref"]
+ }
+ );
+ assert_eq!(page(&reopened, later).await, before_terminal);
reopened.close().await.unwrap();
}
}
diff --git a/platform/event-log/tests/transcript_index/history.rs b/platform/event-log/tests/transcript_index/history.rs
index 5e2e93ddff..612bbcba68 100644
--- a/platform/event-log/tests/transcript_index/history.rs
+++ b/platform/event-log/tests/transcript_index/history.rs
@@ -2152,7 +2152,7 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
HistoryField, HistoryModel, SourceField, SourcePosition,
};
use maka_event_log::sessions::{SessionCopy, SessionRetirement};
- type Expected = BTreeMap<String, (HistoryField, String, HistoryModel)>;
+ type Expected = BTreeMap<String, (HistoryField, String, HistoryModel, bool)>;
async fn step(
log: &EventLog,
invocation: &Invocation,
@@ -2160,13 +2160,35 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
requested: &str,
reported: Option<&str>,
parts: &[(TextKind, &str)],
+ item_acceptance: bool,
) -> (u64, Expected) {
let write = |fact| EventWrite::plain(RuntimeEvent::new(invocation.clone(), fact)).unwrap();
let mut request = request(id);
- let Fact::ModelRequested { model_id, .. } = &mut request else {
+ let Fact::ModelRequested {
+ model_id,
+ item_acceptance: acceptance,
+ ..
+ } = &mut request
+ else {
unreachable!()
};
*model_id = requested.into();
+ *acceptance = item_acceptance;
+ if item_acceptance {
+ let source = log.prefix(256, 1024 * 1024).await.unwrap();
+ let Fact::ModelRequested {
+ source_scope,
+ source_high_water,
+ source_digest,
+ ..
+ } = &mut request
+ else {
+ unreachable!()
+ };
+ *source_scope = source.scope;
+ *source_high_water = source.high_water;
+ *source_digest = source.digest;
+ }
log.append(&write(request)).await.unwrap();
let metadata = HistoryModel::Native {
requested_model_id: requested.into(),
@@ -2195,6 +2217,7 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
},
(*text).into(),
metadata.clone(),
+ false,
),
);
log.append(&start).await.unwrap();
@@ -2217,6 +2240,19 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
provider_options: None,
});
}
+ let source = maka_agent_facts::model::ModelSource::Url {
+ id: format!("source-{id}"),
+ url: "https://example.com/evidence".into(),
+ title: Some("Evidence".into()),
+ provider_options: None,
+ };
+ let citation = write(Fact::ModelObserved {
+ step_id: format!("step-{id}"),
+ event: ModelEvent::Source(source.clone()),
+ });
+ let citation_event = citation.event().id.clone();
+ log.append(&citation).await.unwrap();
+ accepted.push(ModelPart::Source { source });
log.append(&write(Fact::ModelObserved {
step_id: format!("step-{id}"),
event: ModelEvent::ResponseMetadata {
@@ -2237,21 +2273,33 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
}))
.await
.unwrap();
- let through = log
- .append(&write(Fact::ModelCompleted {
- step_id: format!("step-{id}"),
- output: ModelStep {
- parts: accepted,
- finish_reason: maka_agent_facts::model::ModelFinishReason::Stop,
- usage: ModelUsage::default(),
- provider_options: None,
- response_id: None,
- model: reported.map(str::to_owned),
- timestamp: None,
- },
- }))
- .await
- .unwrap();
+ let completion = write(Fact::ModelCompleted {
+ step_id: format!("step-{id}"),
+ output: ModelStep {
+ parts: accepted,
+ finish_reason: maka_agent_facts::model::ModelFinishReason::Stop,
+ usage: ModelUsage::default(),
+ provider_options: None,
+ response_id: None,
+ model: reported.map(str::to_owned),
+ timestamp: None,
+ },
+ });
+ let citation_id = if item_acceptance {
+ citation_event
+ } else {
+ completion.event().id.clone()
+ };
+ expected.insert(
+ format!("{citation_id}:source:{}", parts.len()),
+ (
+ HistoryField::Body,
+ "Source: Evidence\nhttps://example.com/evidence".into(),
+ metadata,
+ false,
+ ),
+ );
+ let through = log.append(&completion).await.unwrap();
(through, expected)
}
async fn read(log: &EventLog, session: &str, through: u64, expected: &Expected) {
@@ -2278,9 +2326,11 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
for chunk in chunks {
if chunk.role != Role::Assistant {
assert!(chunk.model.is_none());
+ assert!(!chunk.final_output);
continue;
}
- let (field, text, model) = &expected[&chunk.message_id];
+ let (field, text, model, final_output) = &expected[&chunk.message_id];
+ assert_eq!(chunk.final_output, *final_output, "{}", chunk.message_id);
assert_eq!(chunk.field, *field);
assert_eq!(chunk.model.as_ref(), Some(model));
let assembled = actual.entry(chunk.message_id.clone()).or_default();
@@ -2330,7 +2380,7 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
actual,
expected
.iter()
- .map(|(id, (_, text, _))| (id.clone(), text.clone()))
+ .map(|(id, (_, text, _, _))| (id.clone(), text.clone()))
.collect()
);
}
@@ -2360,6 +2410,7 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
"requested-alias",
Some("reported-concrete"),
&[(TextKind::Thinking, &thinking), (TextKind::Text, &body)],
+ false,
)
.await;
let (_, second_expected) = step(
@@ -2369,6 +2420,7 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
"second-request",
None,
&[(TextKind::Text, "second step without reported identity")],
+ false,
)
.await;
let copied_fence = log
@@ -2411,13 +2463,21 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
..first
};
log.append(&write(&successor, opening())).await.unwrap();
- let (_, successor_expected) = step(
+ let (unfinished_fence, successor_expected) = step(
&log,
&successor,
"three",
"resumed-request",
Some("resumed-reported"),
- &[(TextKind::Text, "same turn, distinct physical invocation")],
+ &[
+ (
+ TextKind::Thinking,
+ "Final reasoning remains in the activity panel",
+ ),
+ (TextKind::Text, "First final body part"),
+ (TextKind::Text, "Second final body part"),
+ ],
+ true,
)
.await;
let through = log
@@ -2429,9 +2489,18 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
))
.await
.unwrap();
+ let mut unfinished_expected = copied_expected.clone();
+ unfinished_expected.extend(successor_expected.clone());
let mut all_expected = copied_expected.clone();
- all_expected.extend(successor_expected);
+ all_expected.extend(
+ successor_expected
+ .into_iter()
+ .map(|(id, (field, text, model, _))| {
+ (id, (field, text, model, field == HistoryField::Body))
+ }),
+ );
read(&log, "models", first_fence, &first_expected).await;
+ read(&log, "models", unfinished_fence, &unfinished_expected).await;
read(&log, "models", through, &all_expected).await;
read(&log, "model-copy", through, &copied_expected).await;
let revision = log
@@ -2440,6 +2509,22 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
.unwrap()
.unwrap()
.revision;
+ log.copy_session(
+ SessionCopy {
+ source_session_id: "models".into(),
+ target_session_id: "completed-copy".into(),
+ expected_source_revision: revision,
+ purpose: maka_agent_facts::session::CopyPurpose::Branch {
+ turn_id: None,
+ side_conversation: false,
+ },
+ },
+ &serde_json::json!({}),
+ 3,
+ )
+ .await
+ .unwrap();
+ read(&log, "completed-copy", through, &all_expected).await;
log.begin_session_removal("models", revision).await.unwrap();
assert_eq!(
log.finish_session_retirement("models").await.unwrap(),
@@ -2452,6 +2537,7 @@ async fn response_models_follow_exact_steps_fences_and_retained_copied_history()
log.close().await.unwrap();
let reopened = EventLog::open(&path).await.unwrap();
read(&reopened, "model-copy", copied_fence, &copied_expected).await;
+ read(&reopened, "completed-copy", through, &all_expected).await;
reopened.close().await.unwrap();
}
diff --git a/plugins/agent/api/src/contract.rs b/plugins/agent/api/src/contract.rs
index 5e75595e1d..46f4e53522 100644
--- a/plugins/agent/api/src/contract.rs
+++ b/plugins/agent/api/src/contract.rs
@@ -1094,6 +1094,10 @@ pub struct HistoryAttachment {
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[schemars(rename = "AgentHistoryChunk")]
pub struct HistoryChunk {
+ /// Part of the successfully completed native Turn's final output at `through`.
+ /// Includes all body parts and source citations; never a Thinking field.
+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]
+ pub final_output: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model: Option<maka_agent_ports::session::history::HistoryModel>,
#[serde(default, skip_serializing_if = "Option::is_none")]
diff --git a/plugins/agent/assistant/src/recall/rank.rs b/plugins/agent/assistant/src/recall/rank.rs
index e5e8b4a4a4..2c6234da21 100644
--- a/plugins/agent/assistant/src/recall/rank.rs
+++ b/plugins/agent/assistant/src/recall/rank.rs
@@ -254,6 +254,7 @@ mod tests {
session,
0,
Chunk {
+ final_output: false,
model: None,
origin: None,
field: Default::default(),
diff --git a/plugins/agent/native/src/service.rs b/plugins/agent/native/src/service.rs
index 755669a208..c667362260 100644
--- a/plugins/agent/native/src/service.rs
+++ b/plugins/agent/native/src/service.rs
@@ -462,6 +462,7 @@ impl Handler for Agent {
chunks: chunks
.into_iter()
.map(|chunk| HistoryChunk {
+ final_output: chunk.final_output,
model: chunk.model,
origin: chunk.origin,
compaction: chunk.compaction,
diff --git a/plugins/agent/ports/src/session/history.rs b/plugins/agent/ports/src/session/history.rs
index bd903dd784..a1ec26c77f 100644
--- a/plugins/agent/ports/src/session/history.rs
+++ b/plugins/agent/ports/src/session/history.rs
@@ -401,6 +401,11 @@ pub struct HistorySource {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Chunk {
+ /// This body belongs to the final output of a successfully completed native
+ /// Turn at the page's fence. Includes every text part and source citation;
+ /// absence does not establish liveness or identify an imported final answer.
+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]
+ pub final_output: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model: Option<HistoryModel>,
#[serde(default, skip_serializing_if = "Option::is_none")]
diff --git a/plugins/agent/session-recap/src/recap.rs b/plugins/agent/session-recap/src/recap.rs
index 39bdefe662..28a602b1a2 100644
--- a/plugins/agent/session-recap/src/recap.rs
+++ b/plugins/agent/session-recap/src/recap.rs
@@ -525,6 +525,7 @@ mod tests {
Ok(history::Page::Ready {
through: 7,
chunks: vec![history::Chunk {
+ final_output: false,
model: None,
origin: None,
compaction: None,
diff --git a/products/maka/acp/src/projection/messages.rs b/products/maka/acp/src/projection/messages.rs
index c064e31482..7f20a553e4 100644
--- a/products/maka/acp/src/projection/messages.rs
+++ b/products/maka/acp/src/projection/messages.rs
@@ -124,6 +124,7 @@ mod tests {
"!"
);
let mut chunk = HistoryChunk {
+ final_output: false,
model: None,
origin: None,
compaction: None,
@@ -177,6 +178,7 @@ mod tests {
fn missing_history_fragment_is_rejected() {
let mut projection = Projection::default();
let chunk = HistoryChunk {
+ final_output: false,
model: None,
origin: None,
compaction: None,
@@ -202,6 +204,7 @@ mod tests {
fn attachment_only_user_message_keeps_safe_descriptions_during_replay() {
let mut projection = Projection::default();
let chunk = HistoryChunk {
+ final_output: false,
model: None,
origin: Some(maka_agent_facts::message::MessageOrigin::WorkhubTask {
task_id: "task-original".into(),
@@ -253,6 +256,7 @@ mod tests {
fn diagnostic_history_replays_as_marked_text_without_tool_metadata() {
let mut projection = Projection::default();
let mut chunk = HistoryChunk {
+ final_output: false,
model: None,
origin: None,
compaction: None,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org