From 7cc539f6349fed357433811bf06eef454fa6fcc1 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 13:50:48 -0500 Subject: [PATCH] Her reply is published before her held card's commit and push: the drive returns a must-use CardSync that the turn's owner runs after the say (and before the act question touches the checkout) The sync (up to SYNC_BOUND, 60 s) ran inside drive_in_held_card, so a spoken turn's reply waited on git before publish_own_speech (LOCKS-AND-FIFOS-AUDIT.md row 11). Now: a spoken turn runs it right after the say, and on the two exits that withhold the say; a turn that did not speak runs it before its verdict; her own-time turn runs it where it ran before. Nothing else touches the checkout between the drive and the sync, so the order of git writers is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- core/continuum-mind/src/persona/card_hands.rs | 33 ++++++++++++++++--- .../src/persona/initiative_turn.rs | 3 +- .../src/persona/service_loop/turn_cycle.rs | 16 +++++++-- .../src/persona/service_loop/turn_settle.rs | 6 ++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/core/continuum-mind/src/persona/card_hands.rs b/core/continuum-mind/src/persona/card_hands.rs index 7ea1b02be9..3ac0d5347d 100644 --- a/core/continuum-mind/src/persona/card_hands.rs +++ b/core/continuum-mind/src/persona/card_hands.rs @@ -400,9 +400,32 @@ pub(crate) async fn end_card_turn(card: &CardHands, acts: usize) { crate::persona::card_carry::request(); } +/// A held card's end-of-turn sync (commit and push, up to `SYNC_BOUND`), handed back to the +/// turn's owner instead of awaited inside the drive, so her reply is published first and the +/// sync still runs before anything else touches the checkout (LOCKS-AND-FIFOS-AUDIT.md row 11). +#[must_use = "run the card sync before her next act touches the checkout"] +pub(crate) struct CardSync { + hands: Option, + acts: usize, +} + +impl CardSync { + /// No sync owed: the turn held no card, or its sync already ran. + pub(crate) fn done() -> Self { + Self { hands: None, acts: 0 } + } + + /// Commit and push what the turn did in the card's checkout. + pub(crate) async fn run(self) { + if let Some(hands) = &self.hands { + end_card_turn(hands, self.acts).await; + } + } +} + /// One turn in the hands of the card she holds, start to end (card 959f3d5c): rooted at /// the held card, its credit captured on her act, driven in the card claim's hands, and its -/// work synced to the card's branch. A room turn and her own-time turn are the same turn +/// card sync returned for the caller to run after it publishes what she said. A room turn and her own-time turn are the same turn /// here; with no card held it drives in her default hands with no capture. The credit is /// returned from the CARD, not her hands (see [`HeldCardTurn::credit`]). pub(crate) async fn drive_in_held_card( @@ -417,6 +440,7 @@ pub(crate) async fn drive_in_held_card( ) -> ( crate::cognition::act_observe::SettleOutcome, Option, + CardSync, ) { let held = root_at_held_card(cycle, persona_id, &*conversation).await; // Her credit follows the card she holds through the turn (card 12ddd78f): a turn that @@ -435,10 +459,9 @@ pub(crate) async fn drive_in_held_card( Some(&mut capture as &mut dyn crate::cognition::act_observe::TurnCredit), ) .await; - if let Some(hands) = &held.hands { - end_card_turn(hands, outcome.acts).await; - } - (outcome, capture.into_credit()) + let credit = capture.into_credit(); + let sync = CardSync { hands: held.hands, acts: outcome.acts }; + (outcome, credit, sync) } impl HeldCardTurn { diff --git a/core/continuum-mind/src/persona/initiative_turn.rs b/core/continuum-mind/src/persona/initiative_turn.rs index 921941f897..7d6b90343a 100644 --- a/core/continuum-mind/src/persona/initiative_turn.rs +++ b/core/continuum-mind/src/persona/initiative_turn.rs @@ -106,7 +106,7 @@ pub(crate) async fn drive_initiative_turn( // forever. Her held card's turn, exactly as a room turn drives it; with no card held this // is her default hands and no capture, as before. Bookkeeping on her own act: it changes // neither her framing nor what she is told. - let (settled, _) = crate::persona::card_hands::drive_in_held_card( + let (settled, _, sync) = crate::persona::card_hands::drive_in_held_card( cycle, ctx.identity.peer_id.as_uuid(), &ctx.identity.agent_name, @@ -117,6 +117,7 @@ pub(crate) async fn drive_initiative_turn( conversation, ) .await; + sync.run().await; let acts = settled.acts; let (step, _, _) = SettleStep::from_settled(settled); let capacity = match &step { diff --git a/core/continuum-mind/src/persona/service_loop/turn_cycle.rs b/core/continuum-mind/src/persona/service_loop/turn_cycle.rs index f06a564774..f2631793d0 100644 --- a/core/continuum-mind/src/persona/service_loop/turn_cycle.rs +++ b/core/continuum-mind/src/persona/service_loop/turn_cycle.rs @@ -17,6 +17,8 @@ pub(super) struct SpokenTurn { pub(super) response_text: String, pub(super) turn_credit: Option, pub(super) turn_generation_receipts: Vec, + /// Her held card's sync, run right after the reply is published. + pub(super) card_sync: crate::persona::card_hands::CardSync, } /// What the cycle needs beyond the trigger: the burst it reasons over and the engram of @@ -178,12 +180,12 @@ pub(super) async fn run_turn_cycle( Some(ctx.identity.peer_id.to_string()), ); let turn_act_count; - let (step, turn_metrics, settled_receipts, turn_credit) = { + let (step, turn_metrics, settled_receipts, turn_credit, card_sync) = { // A citizen holding a card works at that repo, in a ROOM turn too: the turn // is bound to her card claim's hands (card fc9e9fd7), its credit captured on // her act, and its work synced to the card's branch, by the one owner her // own-time turn uses as well (card 959f3d5c). - let (outcome, credit) = crate::persona::card_hands::drive_in_held_card( + let (outcome, credit, card_sync) = crate::persona::card_hands::drive_in_held_card( &cycle, ctx.identity.peer_id.as_uuid(), &ctx.identity.agent_name, @@ -202,7 +204,7 @@ pub(super) async fn run_turn_cycle( // The driver stays a driver: no learning policy at any call site. turn_act_count = outcome.acts; let (step, metrics, receipts) = crate::cognition::act_observe::SettleStep::from_settled(outcome); - (step, metrics, receipts, credit) + (step, metrics, receipts, credit, card_sync) }; // The credit is the turn's held CARD, captured with it, NOT read back out of // `acting_card_of`, a mutable persona-global that a later focus rebind would @@ -241,6 +243,13 @@ pub(super) async fn run_turn_cycle( deferred_input.settle(msg, wake_engram, attention, &step); // The room that chose this turn's cycle above, so the notices it read are the ones answered. deferred_input.notices_read(turn_room, &turn_generation_receipts); + // A turn with a reply hands its card sync to the publish; any other runs it now. + let card_sync = if matches!(step, crate::cognition::act_observe::SettleStep::Spoke(_)) { + card_sync + } else { + card_sync.run().await; + crate::persona::card_hands::CardSync::done() + }; match step { crate::cognition::act_observe::SettleStep::CapacityRefused { .. } | crate::cognition::act_observe::SettleStep::DeferredBeforeDispatch => { @@ -251,6 +260,7 @@ pub(super) async fn run_turn_cycle( response_text: text, turn_credit, turn_generation_receipts, + card_sync, }) } crate::cognition::act_observe::SettleStep::Acted { calls, intent } => { diff --git a/core/continuum-mind/src/persona/service_loop/turn_settle.rs b/core/continuum-mind/src/persona/service_loop/turn_settle.rs index e3ed77c02a..5afcf165aa 100644 --- a/core/continuum-mind/src/persona/service_loop/turn_settle.rs +++ b/core/continuum-mind/src/persona/service_loop/turn_settle.rs @@ -19,6 +19,7 @@ pub(super) async fn finish_spoken_turn( response_text, turn_credit, turn_generation_receipts, + card_sync, } = spoken; // Invariant: a raw tool-call envelope must NEVER reach the room — from ANY // path. The cycle's verdict text is sometimes just `{"tool_call":…}` (an @@ -33,6 +34,7 @@ pub(super) async fn finish_spoken_turn( "verdict was a raw tool-call envelope — not broadcasting" ); outcome.turns_skipped += 1; + card_sync.run().await; return SpeechMark::Done; } @@ -53,6 +55,7 @@ pub(super) async fn finish_spoken_turn( "her reply could not be recorded before posting, so it was not posted (fail closed)" ); outcome.turns_errored += 1; + card_sync.run().await; return SpeechMark::Refused; } // Per #195 slice 1: time the airc publish + downstream ack. @@ -68,6 +71,9 @@ pub(super) async fn finish_spoken_turn( ) .await; phase_timings.say_ms = say_started.elapsed().as_millis() as u64; + // Her reply is out; the card's commit and push follow it, before the act question below + // touches the same checkout. + card_sync.run().await; if let Err(e) = say_result { tracing::warn!( lamport = msg.lamport,