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/19 15:20:10 UTC
(maka) branch rust-preview updated: perf(event-log): seek handoff roots within their turn
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 650e29463b perf(event-log): seek handoff roots within their turn
650e29463b is described below
commit 650e29463b4cbc0518f18e660f42f79d6e61c4b2
Author: Wang <m4...@gmail.com>
AuthorDate: Mon Oct 19 23:20:04 2026 +0800
perf(event-log): seek handoff roots within their turn
Use the existing Turn opening index while preserving runtime visibility,
exact root identity and ambiguous-root rejection across reopen.
Generated-by: Codex
---
platform/event-log/src/turns/root.rs | 4 +-
.../event-log/tests/continuation/handoff_claim.rs | 127 +++++++++++++++++++++
2 files changed, 130 insertions(+), 1 deletion(-)
diff --git a/platform/event-log/src/turns/root.rs b/platform/event-log/src/turns/root.rs
index 0d4b128dd3..32044759dc 100644
--- a/platform/event-log/src/turns/root.rs
+++ b/platform/event-log/src/turns/root.rs
@@ -42,7 +42,9 @@ pub(super) async fn read(
// The canonical seal already authenticated this root across every handoff.
// Resolve provenance once, without replaying model/tool bodies or guessing latest.
let rows: Vec<String> = sqlx::query_scalar(
- "SELECT event_json FROM runtime_events WHERE kind='invocation_opened'
+ "SELECT event_json FROM event_log INDEXED BY turn_opening_lookup
+ WHERE invocation_id IS NOT NULL AND event_json IS NOT NULL
+ AND kind='invocation_opened'
AND json_extract(event_json,'$.invocation.session_id')=?1
AND json_extract(event_json,'$.invocation.turn_id')=?2
AND json_extract(event_json,'$.invocation.run_id')=?3 LIMIT 2",
diff --git a/platform/event-log/tests/continuation/handoff_claim.rs b/platform/event-log/tests/continuation/handoff_claim.rs
index 6a3e6bf2da..728cb67509 100644
--- a/platform/event-log/tests/continuation/handoff_claim.rs
+++ b/platform/event-log/tests/continuation/handoff_claim.rs
@@ -387,3 +387,130 @@ async fn ineligible_handoff_never_seals_or_reserves_a_successor() {
append(&log, &opening("next-turn", None)).await;
log.close().await.unwrap();
}
+
+#[tokio::test]
+async fn handoff_rejects_ambiguous_private_logical_roots_without_repair_after_reopen() {
+ let directory = tempfile::tempdir().unwrap();
+ let path = directory.path().join("ambiguous-handoff-root.sqlite");
+ let log = EventLog::open(&path).await.unwrap();
+ let root = opening("root", None);
+ append(&log, &root).await;
+ let context = log
+ .context_before_run(&root.invocation, 100, 65536)
+ .await
+ .unwrap();
+ let pause = HandoffPause {
+ intent: HandoffIntent {
+ handoff_id: "handoff".into(),
+ host_epoch: "host".into(),
+ root_run_id: root.invocation.run_id.clone(),
+ successor_run_id: "successor-run".into(),
+ successor_invocation_id: "successor-invocation".into(),
+ claim_id: "successor-claim".into(),
+ },
+ execution: super::handoff::execution(),
+ };
+ append(
+ &log,
+ &RuntimeEvent::new(
+ root.invocation.clone(),
+ Fact::InvocationEnded {
+ outcome: InvocationOutcome::HandoffPaused {
+ pause: pause.clone(),
+ },
+ },
+ ),
+ )
+ .await;
+ let inherited = claim(
+ &log,
+ &pause.intent.claim_id,
+ &root,
+ SessionBase {
+ high_water: context.source_evidence.high_water,
+ digest: context.source_evidence.digest,
+ },
+ )
+ .await;
+ let Fact::InvocationOpened { configuration, .. } = &root.fact else {
+ unreachable!()
+ };
+ let successor = RuntimeEvent::new(
+ pause.intent.successor(&root.invocation),
+ Fact::InvocationOpened {
+ configuration: configuration.clone(),
+ input: InvocationInput::Handoff {
+ claim: Box::new(inherited),
+ pause: Box::new(pause),
+ },
+ },
+ );
+ append(&log, &successor).await;
+ let physical = log
+ .run_boundary("session", &successor.invocation.run_id)
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(physical.invocation, successor.invocation);
+ assert_eq!(physical.opening_event_id, successor.id);
+ assert_eq!(physical.root_invocation(), &root.invocation);
+ assert_eq!(physical.root_opening_event_id(), root.id);
+ assert!(matches!(
+ physical.root_input(),
+ InvocationInput::Message { .. }
+ ));
+
+ // Malformed private evidence, not a supported second admission. This root
+ // has no source Messages; distinct event/invocation IDs preserve uniqueness.
+ let mut duplicate = root.clone();
+ duplicate.id = "malformed-root-event".into();
+ duplicate.invocation.invocation_id = "malformed-root-invocation".into();
+ let db = rusqlite::Connection::open(&path).unwrap();
+ db.execute(
+ "INSERT INTO event_log (event_id, invocation_id, kind, event_json)
+ VALUES (?1, ?2, 'invocation_opened', ?3)",
+ rusqlite::params![
+ duplicate.id,
+ duplicate.invocation.invocation_id,
+ serde_json::to_string(&duplicate).unwrap(),
+ ],
+ )
+ .unwrap();
+ let raw = || {
+ let mut statement = db
+ .prepare("SELECT sequence, event_json FROM event_log ORDER BY sequence")
+ .unwrap();
+ statement
+ .query_map([], |row| {
+ Ok((row.get::<_, i64>(0)?, row.get::<_, String>(1)?))
+ })
+ .unwrap()
+ .collect::<Result<Vec<_>, _>>()
+ .unwrap()
+ };
+ let raw_before = raw();
+ let canonical_before = serde_json::to_value(log.prefix(100, 65536).await.unwrap()).unwrap();
+ assert!(matches!(
+ log.run_boundary("session", &successor.invocation.run_id).await,
+ Err(maka_event_log::StoreError::InvalidTransition(reason))
+ if reason == "handoff has no unique logical root"
+ ));
+ assert_eq!(raw(), raw_before);
+ assert_eq!(
+ serde_json::to_value(log.prefix(100, 65536).await.unwrap()).unwrap(),
+ canonical_before
+ );
+ log.close().await.unwrap();
+ let log = EventLog::open(&path).await.unwrap();
+ assert!(matches!(
+ log.run_boundary("session", &successor.invocation.run_id).await,
+ Err(maka_event_log::StoreError::InvalidTransition(reason))
+ if reason == "handoff has no unique logical root"
+ ));
+ assert_eq!(raw(), raw_before);
+ assert_eq!(
+ serde_json::to_value(log.prefix(100, 65536).await.unwrap()).unwrap(),
+ canonical_before
+ );
+ log.close().await.unwrap();
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org