From 7ac1366d0a1c55a028b700f2cb41ec2b216cb188 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 00:50:34 +0100 Subject: [PATCH] Thing 2.0 cut 7a h2: pin the apply-before-tick order (apply-tick-order-unpinned) Steward decision 9 of the h2 fix brief. The frame already applied drained results before tick; the order is now stated where it is decided and tested: a result queued for the frame its deadline passes completes the invocation, no InvocationTimedOut, no mark. Co-Authored-By: Claude Opus 5.5 --- crates/thing-core/src/command/lifecycle.rs | 2 ++ crates/thing-core/src/frame.rs | 2 ++ crates/thing-core/tests/command.rs | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/crates/thing-core/src/command/lifecycle.rs b/crates/thing-core/src/command/lifecycle.rs index 1cf8ad2..b8d142b 100644 --- a/crates/thing-core/src/command/lifecycle.rs +++ b/crates/thing-core/src/command/lifecycle.rs @@ -132,6 +132,8 @@ impl Commands { answered } + /// Within a frame results apply before `tick` (`Core::frame` drains and applies, then ticks), so a + /// result queued for the frame its deadline passes wins over the timeout. /// Move every non-terminal invocation whose deadline has come to `TimedOut`. A deadline is /// compared with the time given: a wall clock that went backward delays a timeout, never fires one early. pub fn tick(&mut self, now: Timestamp, port: &mut dyn StatePort, ledger: &mut Ledger) -> Vec { diff --git a/crates/thing-core/src/frame.rs b/crates/thing-core/src/frame.rs index 45bf4fd..8584278 100644 --- a/crates/thing-core/src/frame.rs +++ b/crates/thing-core/src/frame.rs @@ -165,6 +165,8 @@ impl Core { None => self.held.push(resume), } } + // Results of this frame are applied above, before the deadline is judged: a late result that was + // already queued wins over the timeout. diagnostics.extend(self.commands.tick(now, port, &mut self.ledger)); let commands = self.draw(viewport, scale, &mut diagnostics); diff --git a/crates/thing-core/tests/command.rs b/crates/thing-core/tests/command.rs index 36855b0..fac8a63 100644 --- a/crates/thing-core/tests/command.rs +++ b/crates/thing-core/tests/command.rs @@ -1423,3 +1423,24 @@ fn a_tick_also_forgets_the_terminal_invocations_past_their_time() { assert_eq!(codes(&gone.diagnostics), vec![Code::UnknownInvocation]); } +// ----- a result in the frame its deadline passes wins ----- + +#[test] +fn a_result_queued_for_the_frame_its_deadline_passes_wins_over_the_timeout() { + let provider = ProviderId::new(PROVIDER); + let document = go_surface(); + let mut state = MemState::new(); + state.put(&provider, &document); + let mut core = core(); + core.show(provider.clone(), RecordKey::new(document.record_key())); + frame_at(&mut core, &mut state, PINNED_NOW); + core.activate(press("go"), PINNED_NOW, Ports { state: &mut state, ids: &mut SeqIds::new() }); + let invocation = frame_at(&mut core, &mut state, at(1)).outbound.pop().expect("minted"); + state.put(&provider, &completed(&invocation, 1, false, None)); + let late = frame_at(&mut core, &mut state, at(60_000)); + assert!(late.diagnostics.is_empty(), "{:?}", late.diagnostics); + assert_eq!(late.next_wake, None); + // Completed, not timed out: the button is free. + core.activate(press("go"), at(60_001), Ports { state: &mut state, ids: &mut SeqIds::new() }); + assert_eq!(frame_at(&mut core, &mut state, at(60_002)).outbound.len(), 1); +}