From 67c011112d50f236661c51b0994685cd586b35e9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 13 Jun 2026 04:59:02 +0100 Subject: [PATCH] Pair latest Hands receipts by time --- epiphany-core/src/runtime_spine.rs | 165 ++++++++++++++++++++++++++--- state/ledgers.msgpack | Bin 180903 -> 181257 bytes 2 files changed, 152 insertions(+), 13 deletions(-) diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 3caae6cf..b563edc2 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -1465,21 +1465,31 @@ pub fn runtime_latest_hands_receipt_chain_after( .iter() .filter(|commit| timestamp_after(&commit.emitted_at, after_timestamp)) { - let Some(patch) = patches.iter().find(|patch| { - patch.intent_id == commit.intent_id - && patch.review_id == commit.review_id - && patch.runtime_job_id == commit.runtime_job_id - && timestamp_after(&patch.emitted_at, after_timestamp) - }) else { + let Some(patch) = patches + .iter() + .filter(|patch| { + patch.intent_id == commit.intent_id + && patch.review_id == commit.review_id + && patch.runtime_job_id == commit.runtime_job_id + && timestamp_after(&patch.emitted_at, after_timestamp) + && patch.emitted_at <= commit.emitted_at + }) + .max_by(|left, right| left.emitted_at.cmp(&right.emitted_at)) + else { continue; }; - let Some(command) = commands.iter().find(|command| { - command.intent_id == commit.intent_id - && command.review_id == commit.review_id - && command.runtime_job_id == commit.runtime_job_id - && command.exit_code == "0" - && timestamp_after(&command.emitted_at, after_timestamp) - }) else { + let Some(command) = commands + .iter() + .filter(|command| { + command.intent_id == commit.intent_id + && command.review_id == commit.review_id + && command.runtime_job_id == commit.runtime_job_id + && command.exit_code == "0" + && timestamp_after(&command.emitted_at, after_timestamp) + && command.emitted_at <= commit.emitted_at + }) + .max_by(|left, right| left.emitted_at.cmp(&right.emitted_at)) + else { continue; }; summaries.push(RuntimeHandsReceiptChainSummary { @@ -3684,6 +3694,135 @@ mod tests { Ok(()) } + #[test] + fn latest_hands_chain_uses_latest_same_gate_receipts_before_commit() -> Result<()> { + let temp = tempdir()?; + let store = temp.path().join("runtime.msgpack"); + initialize_runtime_spine( + &store, + RuntimeSpineInitOptions { + runtime_id: "epiphany-test".to_string(), + display_name: "Epiphany Test".to_string(), + created_at: "2026-06-13T00:00:00Z".to_string(), + }, + )?; + let intent = HandsActionIntent { + schema_version: crate::HANDS_ACTION_INTENT_SCHEMA_VERSION.to_string(), + intent_id: "hands-intent-reused".to_string(), + runtime_job_id: "hands-job-reused".to_string(), + binding_id: "implementation-worker".to_string(), + role: "epiphany-hands".to_string(), + authority_scope: "epiphany.role.implementation".to_string(), + requested_action: "continueImplementation".to_string(), + requested_paths: vec![".".to_string()], + substrate_gate_grant_receipt_id: "substrate-grant-reused".to_string(), + requested_at: "2026-06-13T00:00:01Z".to_string(), + contract: "Test reused Hands gate.".to_string(), + }; + put_hands_action_intent(&store, &intent)?; + let review = crate::hands_action_review_for_intent( + "hands-review-reused".to_string(), + &intent, + "approved".to_string(), + vec![ + "patch".to_string(), + "command".to_string(), + "commit".to_string(), + ], + vec!["test reused gate".to_string()], + "2026-06-13T00:00:02Z".to_string(), + ); + put_hands_action_review(&store, &review)?; + + put_hands_patch_receipt( + &store, + &crate::hands_patch_receipt_for_review( + "hands-patch-old".to_string(), + &intent, + &review, + vec!["old.rs".to_string()], + "old patch".to_string(), + "2026-06-13T00:00:03Z".to_string(), + ), + )?; + put_hands_command_receipt( + &store, + &crate::hands_command_receipt_for_review( + "hands-command-old".to_string(), + &intent, + &review, + "cargo test old".to_string(), + "0".to_string(), + "old-stdout.log".to_string(), + "old-stderr.log".to_string(), + "old command".to_string(), + "2026-06-13T00:00:04Z".to_string(), + ), + )?; + put_hands_commit_receipt( + &store, + &crate::hands_commit_receipt_for_review( + "hands-commit-old".to_string(), + &intent, + &review, + "oldsha".to_string(), + "codex/test".to_string(), + vec!["old.rs".to_string()], + "old commit".to_string(), + "2026-06-13T00:00:05Z".to_string(), + ), + )?; + put_hands_patch_receipt( + &store, + &crate::hands_patch_receipt_for_review( + "hands-patch-new".to_string(), + &intent, + &review, + vec!["new.rs".to_string()], + "new patch".to_string(), + "2026-06-13T00:00:06Z".to_string(), + ), + )?; + put_hands_command_receipt( + &store, + &crate::hands_command_receipt_for_review( + "hands-command-new".to_string(), + &intent, + &review, + "cargo test new".to_string(), + "0".to_string(), + "new-stdout.log".to_string(), + "new-stderr.log".to_string(), + "new command".to_string(), + "2026-06-13T00:00:07Z".to_string(), + ), + )?; + put_hands_commit_receipt( + &store, + &crate::hands_commit_receipt_for_review( + "hands-commit-new".to_string(), + &intent, + &review, + "newsha".to_string(), + "codex/test".to_string(), + vec!["new.rs".to_string()], + "new commit".to_string(), + "2026-06-13T00:00:08Z".to_string(), + ), + )?; + + let chain = runtime_latest_hands_receipt_chain_after(&store, "2026-06-13T00:00:02Z")? + .expect("latest same-gate Hands chain"); + assert_eq!(chain.patch_receipt_id, "hands-patch-new"); + assert_eq!(chain.command_receipt_id, "hands-command-new"); + assert_eq!(chain.commit_receipt_id, "hands-commit-new"); + assert_eq!(chain.command, "cargo test new"); + assert_eq!(chain.stdout_artifact, "new-stdout.log"); + assert_eq!(chain.commit_sha, "newsha"); + assert_eq!(chain.changed_paths, vec!["new.rs".to_string()]); + Ok(()) + } + #[test] fn runtime_spine_opens_heartbeat_job_from_single_typed_call() -> Result<()> { let temp = tempdir()?; diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index e46d8a4261232e49705b5138d8bcc8b73d8e381b..ff01df59d966f6f3da4b88c8dcf75094b0a5a74d 100644 GIT binary patch delta 322 zcmXAjF;2rk5JmB}E)Xe){gt19*BE=kl9x58NSx@3c_HNi&$LS~#0y>IVJ_2Qs zC=eZT!BIE|Yt#Ne^WJ}Z^k1I+_kGWg$CG$`{jedGiJQ%a9VBO$y37Gr3r&~;S)Lj7tRzE{#-kC{>CE43^#5 zoLi)m=DcM`_n>qIggFXJU^9fgD=iQ&Fp$ckvZ2AH#45biQ^&I+11A6~g+QX2(+gb` zU4(_S*72t}(*}FmKiOs7jkJlIFgNZ^Y6YDqam5l1fzH!VVdVrwNI)6ycWZ_H+~eMv S^HPcIMrgNdWt-QQ?fn5FmUB7) delta 41 xcmeC|;9lO!y+MMJ+t|p;&?4#>1Jl8l&B~00jEsEEQ<>VQGBIwS%ETme000Ks3`zh1