From f659b9d7cab4c82f3ecf8ce3f59cf8ab2eb23474 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 10 Sep 2026 23:00:29 +0200 Subject: [PATCH] Retire one resident terminal transaction per tick Transactions that finished before finished transactions travelled to history are still resident with their commands, gating nothing but growing the store every decision reads. They leave the same way a transaction finishing today does, one per tick. Verified with cargo test --lib in rust:1.95-bookworm on yggdrasil: 116 passed. Co-Authored-By: Claude Fable 5.1 --- src/control_plane.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/control_plane.rs b/src/control_plane.rs index 80a329b..616da32 100644 --- a/src/control_plane.rs +++ b/src/control_plane.rs @@ -2911,7 +2911,33 @@ impl Engine { /// One pass of the scheduler, with the loop's ordering preserved exactly: /// `Ok(true)` means "went round again immediately", which is what the /// caller's `continue` did. + /// One resident terminal transaction goes to history per tick. + /// + /// Transactions that finished before finished transactions travelled to + /// history are still resident with their commands, gating nothing and + /// consuming their commands correctly, but growing the store every decision + /// reads. They leave the same way a transaction finishing today does. + fn retire_one_terminal_transaction(&self) -> Result { + let snapshot = ControlSnapshot::read(&self.options.state_store)?; + let Some(stored) = snapshot + .transactions + .iter() + .find(|stored| stored.value.is_terminal()) + else { + return Ok(false); + }; + archive_terminal_transaction(&self.options.state_store, &stored.envelope)?; + eprintln!( + "Idunn retired resident terminal transaction {} to history", + stored.value.transaction_id + ); + Ok(true) + } + fn run_scheduler_tick(&self) -> Result { + if self.retire_one_terminal_transaction()? { + return Ok(true); + } let transaction_progress = self.resume_one_transaction()?; let continuity_progress = self.supervise_one_admitted_generation()?; Ok(!transaction_progress && !continuity_progress && self.freeze_one_queued_command()?) @@ -6567,6 +6593,25 @@ mod tests { Ok(()) } + #[test] + fn a_resident_terminal_transaction_is_retired_by_the_tick_with_its_command() -> Result<()> { + let world = EngineFixture::new()?; + let (finished, command) = terminal_transaction_with_command("ghostlight")?; + SingleFileMessagePackBackingStore::new(&world.state_store).insert_entry_if_absent( + command_envelope(&command, command.requested_at_unix_millis)?, + )?; + SingleFileMessagePackBackingStore::new(&world.state_store).insert_entry_if_absent( + transaction_envelope(&finished, finished.updated_at_unix_millis)?, + )?; + assert!(world.engine.retire_one_terminal_transaction()?); + let live = ControlSnapshot::read(&world.state_store)?; + assert!(live.transactions.is_empty() && live.commands.is_empty()); + assert_eq!(read_history_transactions(&world.state_store).len(), 1); + assert_eq!(read_history_commands(&world.state_store).len(), 1); + assert!(!world.engine.retire_one_terminal_transaction()?); + Ok(()) + } + #[test] fn re_archiving_after_a_crash_window_is_a_no_op() -> Result<()> { // History is written before the live copy is removed, so a crash