From 01c9141fdc90ef7fe0bc720ea343afbffd62c385 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 07:42:50 +0100 Subject: [PATCH 1/3] Thing 2.0 cut 9b-0: Code::ActivationBlocked splits user-state refusals from caller bugs A command waiting for confirmation, a disabled control and a control waiting for its own result now say ActivationBlocked through blocked(); node not in surface, no command for the kind, bad change value, no surface shown and a dropped resume stay ActivationRefused. One table test pins each site. Co-Authored-By: Claude Opus 5.5 --- crates/thing-core/src/command/mod.rs | 25 +++++++++----- crates/thing-core/src/diagnostic.rs | 10 ++++-- crates/thing-core/src/input/tests.rs | 10 +++--- crates/thing-core/tests/command.rs | 50 ++++++++++++++++++++++++++-- 4 files changed, 76 insertions(+), 19 deletions(-) diff --git a/crates/thing-core/src/command/mod.rs b/crates/thing-core/src/command/mod.rs index 0b320ca..606e507 100644 --- a/crates/thing-core/src/command/mod.rs +++ b/crates/thing-core/src/command/mod.rs @@ -178,11 +178,19 @@ fn fault(surface: &str, node: Option<&NodeId>, code: Code, detail: impl Into Diagnostic { fault(surface, Some(node), Code::ActivationRefused, detail) } +/// An otherwise valid activation a user state stopped (a command waits for confirmation, or the control +/// is disabled or waits for its result); nothing was minted and no draft was written. A host may show +/// or drop it and never treats it as a bug. +fn blocked(surface: &str, node: &NodeId, detail: &str) -> Diagnostic { + fault(surface, Some(node), Code::ActivationBlocked, detail) +} + /// A v4 UUID from 16 bytes: the version and variant bits are core's, so a minted id is always /// UUID-shaped and dot-free (a result key splits at its last dot). fn uuid(ids: &mut dyn IdSource) -> String { @@ -236,9 +244,10 @@ impl Commands { /// The one commit primitive: the user acted on `act.node` of `tree`. Every path calls it. It /// mints one invocation, or nothing. A refusal (a node that is not a command source for this kind, a - /// node nobody laid, a change the input does not take, a command waiting on confirmation) answers with - /// a `Code::ActivationRefused` diagnostic. A disabled or busy button is not a refusal: the user sees - /// it, so it stays silent. + /// node nobody laid, a change the input does not take) answers with a `Code::ActivationRefused` + /// diagnostic; a change a user state stops (a command waiting on confirmation, a disabled or busy + /// control) answers with `Code::ActivationBlocked`. A disabled or busy button press is neither: the + /// user sees it, so it stays silent. #[allow(clippy::too_many_arguments)] pub fn activate( &mut self, @@ -290,7 +299,7 @@ impl Commands { self.begin(prepared, act.node, decl.confirm.as_ref(), now, ids, port, ledger) } - /// Why `node` takes no change now, said as a refusal: a command waits for confirmation, or the + /// Why `node` takes no change now, said as `Code::ActivationBlocked`: a command waits for confirmation, or the /// control is disabled, or its own invocation waits for a result. A change that is refused writes /// no draft, so a control that looks disabled never holds a value that was not sent. A press on /// such a control stays silent (`activate`); a change is an edit the user made and is told. @@ -299,11 +308,11 @@ impl Commands { if let Some(waiting) = self.confirming_refusal(&surface, node) { return Some(waiting); } - self.holds(tree, node).then(|| refused(&surface, node, "the control is disabled or waiting for a result")) + self.holds(tree, node).then(|| blocked(&surface, node, "the control is disabled or waiting for a result")) } fn confirming_refusal(&self, surface: &str, node: &NodeId) -> Option { - self.confirming.is_some().then(|| refused(surface, node, "a command is waiting for confirmation")) + self.confirming.is_some().then(|| blocked(surface, node, "a command is waiting for confirmation")) } /// Whether `node` is a disabled Button or has an invocation waiting for its result. @@ -433,7 +442,7 @@ impl Commands { return Vec::new(); }; if self.confirming.is_some() { - return vec![refused(&prepared.surface, &node, "another command is waiting for confirmation")]; + return vec![blocked(&prepared.surface, &node, "another command is waiting for confirmation")]; } self.confirming = Some(Confirming { surface: prepared.surface.clone(), node, command: prepared.command.clone(), text: text.clone(), prepared }); Vec::new() diff --git a/crates/thing-core/src/diagnostic.rs b/crates/thing-core/src/diagnostic.rs index e03c5a4..e5f5f96 100644 --- a/crates/thing-core/src/diagnostic.rs +++ b/crates/thing-core/src/diagnostic.rs @@ -59,10 +59,14 @@ pub enum Code { CaptureUnavailable, /// A command capture naming no node, or a node that holds no input value. CaptureUndeclared, - /// An activation core refused to act on: a kind the node does not take, a node nobody laid, a change - /// value outside what the input allows, a command blocked by a confirmation, or a resume that can no - /// longer run. Nothing was minted; the detail says which. + /// An activation core refused to act on because the caller was wrong: a kind the node does not take, a + /// node nobody laid, a change value outside what the input allows, no surface shown, or a resume that + /// can no longer run. Nothing was minted; the detail says which. ActivationRefused, + /// An otherwise valid activation a user state stopped: a command waits for confirmation, or the + /// control is disabled or waits for its own result. Nothing was minted and no draft was written; a + /// host may show or drop it, and it is never a bug. + ActivationBlocked, } impl Code { diff --git a/crates/thing-core/src/input/tests.rs b/crates/thing-core/src/input/tests.rs index a70a023..86b2e2a 100644 --- a/crates/thing-core/src/input/tests.rs +++ b/crates/thing-core/src/input/tests.rs @@ -669,7 +669,7 @@ fn a_toggle_flips_its_draft_and_fires_on_change_once_per_press() { // A second press is a change to a control with an invocation waiting: it is refused and says so, it // fires nothing more, and it leaves the draft that was sent (a busy control holds no unsent value). let said = rig.click(flag); - assert_eq!(said.iter().map(|d| (d.code, d.node.as_ref().map(NodeId::as_str))).collect::>(), vec![(Code::ActivationRefused, Some("flag"))], "{mode:?}"); + assert_eq!(said.iter().map(|d| (d.code, d.node.as_ref().map(NodeId::as_str))).collect::>(), vec![(Code::ActivationBlocked, Some("flag"))], "{mode:?}"); assert_eq!(rig.minted(), vec![], "{mode:?}"); assert_eq!(rig.draft("flag"), Some(InputValue::Bool(BoolValue { value: true })), "{mode:?}"); } @@ -750,7 +750,7 @@ fn a_click_while_a_command_waits_for_confirmation_is_a_refusal_the_event_returns assert_eq!(rig.click(inside(rig.rect("a"))), vec![]); assert!(rig.commands.confirming().is_some() && rig.minted().is_empty(), "{mode:?}"); let said = rig.click(inside(rig.rect("b"))); - assert_eq!(said.iter().map(|d| d.code).collect::>(), vec![Code::ActivationRefused], "{mode:?}"); + assert_eq!(said.iter().map(|d| d.code).collect::>(), vec![Code::ActivationBlocked], "{mode:?}"); assert_eq!(said[0].node.as_ref().map(NodeId::as_str), Some("b")); } } @@ -779,7 +779,7 @@ fn a_slider_that_waits_for_its_result_takes_no_press_or_drag_and_a_completion_le let sent = rig.minted().remove(0); assert_eq!(rig.draft("level"), value(30.0), "{mode:?}"); // The slider waits: a second press and its drag are refused, say so, and write nothing. - assert_eq!(refusals(&rig.send(down(along(0.8)))), vec![(Code::ActivationRefused, Some("level"))], "{mode:?}"); + assert_eq!(refusals(&rig.send(down(along(0.8)))), vec![(Code::ActivationBlocked, Some("level"))], "{mode:?}"); assert_eq!(rig.draft("level"), value(30.0), "{mode:?}: the press wrote nothing"); rig.send(mv(along(0.9))); assert_eq!(rig.draft("level"), value(30.0), "{mode:?}: a refused press starts no drag"); @@ -799,7 +799,7 @@ fn a_toggle_pressed_while_it_waits_is_refused_and_a_completion_leaves_the_provid let flag = inside(rig.rect("flag")); rig.click(flag); let sent = rig.minted().remove(0); - assert_eq!(refusals(&rig.click(flag)), vec![(Code::ActivationRefused, Some("flag"))], "{mode:?}"); + assert_eq!(refusals(&rig.click(flag)), vec![(Code::ActivationBlocked, Some("flag"))], "{mode:?}"); let tree = &rig.tree; rig.commands.apply(&result_change(&sent, true), Timestamp(5), &|_| Some(tree), &mut rig.drafts, &mut rig.state, &mut rig.ledger); assert_eq!(rig.draft("flag"), None, "{mode:?}: nothing survives to show a checked box the provider does not hold"); @@ -816,7 +816,7 @@ fn a_slider_press_while_a_command_waits_for_confirmation_writes_no_draft() { assert!(rig.commands.confirming().is_some(), "{mode:?}"); let track = rig.rect("level"); let said = rig.send(down((track.x + 0.5 * track.w, track.y + 0.5))); - assert_eq!(refusals(&said), vec![(Code::ActivationRefused, Some("level"))], "{mode:?}"); + assert_eq!(refusals(&said), vec![(Code::ActivationBlocked, Some("level"))], "{mode:?}"); assert_eq!((rig.draft("level"), rig.drafts.is_empty()), (None, true), "{mode:?}"); } } diff --git a/crates/thing-core/tests/command.rs b/crates/thing-core/tests/command.rs index aa23642..d131ec9 100644 --- a/crates/thing-core/tests/command.rs +++ b/crates/thing-core/tests/command.rs @@ -1205,7 +1205,7 @@ fn a_change_to_a_node_that_waits_is_refused_writes_no_draft_and_the_completion_c let first = rig.commands.take_outbound().pop().expect("minted"); // The node waits for its result: this edit is refused and mints nothing, and it is not a draft. let said = rig.act(&nid("t"), ActivationKind::Change(bool_value(false)), at(10), &mut ids); - assert_eq!(said.iter().map(|d| d.code).collect::>(), vec![Code::ActivationRefused]); + assert_eq!(said.iter().map(|d| d.code).collect::>(), vec![Code::ActivationBlocked]); assert!(rig.commands.take_outbound().is_empty()); assert_eq!(rig.draft(&nid("t")), Some(bool_value(true))); rig.feed(&completed(&first, 1, true, None), at(20)); @@ -1283,7 +1283,7 @@ fn every_refusal_is_a_diagnostic_naming_the_surface_and_node() { // Waiting on a confirmation blocks every other activation, and says so. assert!(rig.press("after", PINNED_NOW, &mut ids).is_empty()); let blocked = rig.press("go", at(1), &mut ids); - assert_eq!(codes(&blocked), vec![Code::ActivationRefused]); + assert_eq!(codes(&blocked), vec![Code::ActivationBlocked]); assert!(rig.commands.take_outbound().is_empty()); // A busy button stays silent: it is a state the user sees, not a fault. let mut rig = Rig::new(MemState::new(), &go_surface()); @@ -1291,6 +1291,50 @@ fn every_refusal_is_a_diagnostic_naming_the_surface_and_node() { assert!(rig.press("go", at(1), &mut ids).is_empty()); } +#[test] +fn each_refusal_site_says_its_code_a_user_state_is_blocked_a_caller_bug_is_refused() { + // Caller bugs: a node nobody laid, a kind the node does not take, a change value the input rejects. + let mut rig = Rig::new(MemState::new(), &range_surface()); + let mut ids = SeqIds::new(); + for (node, kind, site) in [ + ("no-such-node", ActivationKind::Press, "not in the surface"), + ("vol", ActivationKind::Submit, "no command for this kind"), + ("vol", ActivationKind::Change(number_value(f64::NAN)), "bad change value"), + ] { + assert_eq!(codes(&rig.act(&nid(node), kind, PINNED_NOW, &mut ids)), vec![Code::ActivationRefused], "{site}"); + } + + // User states: a control that waits for its own result. + let mut rig = Rig::new(MemState::new(), &tg_surface()); + rig.act(&nid("t"), ActivationKind::Change(bool_value(true)), PINNED_NOW, &mut ids); + assert_eq!(codes(&rig.act(&nid("t"), ActivationKind::Change(bool_value(false)), at(1), &mut ids)), vec![Code::ActivationBlocked], "busy control"); + + // User states: a command waits for confirmation, and another one that would ask waits behind it. + let mut document = go_surface(); + document.commands[1] = decl("after", &[], Some("sure?")); + let mut rig = Rig::new(MemState::new(), &document); + assert!(rig.press("after", PINNED_NOW, &mut ids).is_empty()); + assert_eq!(codes(&rig.press("go", at(1), &mut ids)), vec![Code::ActivationBlocked], "confirmation waiting"); + let resume = Resume { surface_key: rig.surface.clone(), command: CommandId::new("after"), source: nid("after"), items: vec![] }; + let tree = rig.binder.tree(&rig.surface.clone()).unwrap(); + let behind = rig.commands.resume(&resume, tree, &rig.drafts, at(2), &mut ids, &mut rig.state, &mut rig.ledger); + assert_eq!(codes(&behind), vec![Code::ActivationBlocked], "another command waiting"); + + // Caller bugs at the host: no surface shown, a held resume dropped. + let provider = ProviderId::new(PROVIDER); + let document = go_surface(); + let mut state = MemState::new(); + state.put(&provider, &document); + let mut core = core(); + core.activate(press("go"), PINNED_NOW, Ports { state: &mut state, ids: &mut SeqIds::new() }); + assert_eq!(codes(&frame_at(&mut core, &mut state, at(1)).diagnostics), vec![Code::ActivationRefused], "no surface shown"); + core.show(provider, RecordKey::new(document.record_key())); + let held = Resume { surface_key: document.record_key(), command: CommandId::new("after"), source: nid("go"), items: vec![] }; + core.resume(&held, at(2), Ports { state: &mut state, ids: &mut SeqIds::new() }); + core.show(ProviderId::new(PROVIDER), RecordKey::new("thing:surface:provider.cmd.elsewhere")); + assert_eq!(codes(&frame_at(&mut core, &mut state, at(3)).diagnostics), vec![Code::ActivationRefused], "dropped resume"); +} + #[test] fn a_command_param_outside_a_composition_leaves_no_tree_to_activate() { let mut document = go_surface(); @@ -1339,7 +1383,7 @@ fn a_resumed_command_that_asks_for_confirmation_waits_for_it() { // One command waits at a time: a second resume that asks is refused, and the first still waits. let tree = rig.binder.tree(&rig.surface.clone()).unwrap(); let blocked = rig.commands.resume(&resume, tree, &rig.drafts, at(1), &mut ids, &mut rig.state, &mut rig.ledger); - assert_eq!(codes(&blocked), vec![Code::ActivationRefused]); + assert_eq!(codes(&blocked), vec![Code::ActivationBlocked]); rig.commands.confirm(true, at(1), &mut ids, &mut rig.state, &mut rig.ledger); assert_eq!(rig.commands.take_outbound()[0].command, CommandId::new("after")); } -- 2.47.3 From ce16dfe2ca0d9791bcd5aa34faf55d2e95de60dd Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 07:58:56 +0100 Subject: [PATCH 2/3] Pin caller bugs while a confirmation or a result waits (red) Co-Authored-By: Claude Opus 5.5 --- crates/thing-core/tests/command.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/thing-core/tests/command.rs b/crates/thing-core/tests/command.rs index d131ec9..2933c32 100644 --- a/crates/thing-core/tests/command.rs +++ b/crates/thing-core/tests/command.rs @@ -1335,6 +1335,35 @@ fn each_refusal_site_says_its_code_a_user_state_is_blocked_a_caller_bug_is_refus assert_eq!(codes(&frame_at(&mut core, &mut state, at(3)).diagnostics), vec![Code::ActivationRefused], "dropped resume"); } +#[test] +fn a_caller_bug_is_refused_even_while_a_command_waits_for_confirmation_or_for_a_result() { + let bugs = || { + [ + ("no-such-node", ActivationKind::Press, "not in the surface"), + ("go", ActivationKind::Submit, "no command for this kind"), + ("name", ActivationKind::Change(number_value(1.0)), "bad change value"), + ] + }; + let mut ids = SeqIds::new(); + + // Another command waits for confirmation. + let mut document = go_surface(); + document.commands[1] = decl("after", &[], Some("sure?")); + let mut rig = Rig::new(MemState::new(), &document); + assert!(rig.press("after", PINNED_NOW, &mut ids).is_empty()); + for (node, kind, site) in bugs() { + assert_eq!(codes(&rig.act(&nid(node), kind, at(1), &mut ids)), vec![Code::ActivationRefused], "confirming: {site}"); + } + assert_eq!(rig.draft(&nid("name")), None); + + // A command waits for its result. + let mut rig = Rig::new(MemState::new(), &go_surface()); + rig.press("go", PINNED_NOW, &mut ids); + for (node, kind, site) in bugs() { + assert_eq!(codes(&rig.act(&nid(node), kind, at(1), &mut ids)), vec![Code::ActivationRefused], "waiting: {site}"); + } +} + #[test] fn a_command_param_outside_a_composition_leaves_no_tree_to_activate() { let mut document = go_surface(); -- 2.47.3 From d927227ec90fe68c0dfd56670573189a030a90bf Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 07:59:11 +0100 Subject: [PATCH 3/3] Tell caller bugs before user states; trim Blocked docs to reachable states An activation is checked for a missing node, a kind with no command and a bad change value before the confirmation and busy gates, so a malformed activation is Refused whatever the user is doing. The Code docs name the other caller-bug codes of the activation path and only the states Blocked can say. Co-Authored-By: Claude Opus 5.5 --- crates/thing-core/src/command/mod.rs | 41 +++++++++++++++------------- crates/thing-core/src/diagnostic.rs | 10 ++++--- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/crates/thing-core/src/command/mod.rs b/crates/thing-core/src/command/mod.rs index 606e507..0959cbc 100644 --- a/crates/thing-core/src/command/mod.rs +++ b/crates/thing-core/src/command/mod.rs @@ -245,9 +245,9 @@ impl Commands { /// The one commit primitive: the user acted on `act.node` of `tree`. Every path calls it. It /// mints one invocation, or nothing. A refusal (a node that is not a command source for this kind, a /// node nobody laid, a change the input does not take) answers with a `Code::ActivationRefused` - /// diagnostic; a change a user state stops (a command waiting on confirmation, a disabled or busy - /// control) answers with `Code::ActivationBlocked`. A disabled or busy button press is neither: the - /// user sees it, so it stays silent. + /// diagnostic, whatever the user is doing; a well-formed activation a user state stops (a command + /// waiting on confirmation, a change to a busy control) answers with `Code::ActivationBlocked`. A press + /// on a disabled or busy button is neither: the user sees it, so it stays silent. #[allow(clippy::too_many_arguments)] pub fn activate( &mut self, @@ -260,9 +260,6 @@ impl Commands { ledger: &mut Ledger, ) -> Vec { let surface = tree.resolved().document().record_key(); - if let Some(waiting) = self.confirming_refusal(&surface, &act.node) { - return vec![waiting]; - } let Some(located) = tree.locate(&act.node) else { return vec![refused(&surface, &act.node, "the node is not in the surface")]; }; @@ -270,15 +267,21 @@ impl Commands { let Some(CommandRef::Id(command)) = command_of(located.node, &act.kind) else { return vec![refused(&surface, &act.node, "the node fires no command for this activation")]; }; - if let ActivationKind::Change(value) = &act.kind { - // A control that takes no change holds no value the user did not send: the gate is before the draft. - if let Some(held) = self.refuses_change(tree, &act.node) { - return vec![held]; - } - match capture::change(tree, &act.node, located.node, value) { - Ok(taken) => drafts.set(&surface, &act.node, taken), + // Caller bugs are told before user states: a malformed activation is a bug whatever the user is doing. + let taken = match &act.kind { + ActivationKind::Change(value) => match capture::change(tree, &act.node, located.node, value) { + Ok(taken) => Some(taken), Err(detail) => return vec![refused(&surface, &act.node, detail)], - } + }, + _ => None, + }; + // A control that takes no change holds no value the user did not send: the gate is before the draft. + let stopped = if taken.is_some() { self.refuses_change(tree, &act.node) } else { self.confirming_refusal(&surface, &act.node) }; + if let Some(stopped) = stopped { + return vec![stopped]; + } + if let Some(taken) = taken { + drafts.set(&surface, &act.node, taken); } if self.holds(tree, &act.node) { return Vec::new(); @@ -299,16 +302,16 @@ impl Commands { self.begin(prepared, act.node, decl.confirm.as_ref(), now, ids, port, ledger) } - /// Why `node` takes no change now, said as `Code::ActivationBlocked`: a command waits for confirmation, or the - /// control is disabled, or its own invocation waits for a result. A change that is refused writes - /// no draft, so a control that looks disabled never holds a value that was not sent. A press on - /// such a control stays silent (`activate`); a change is an edit the user made and is told. + /// Why `node` takes no change now, said as `Code::ActivationBlocked`: a command waits for confirmation, + /// or its own invocation waits for a result. A change that is blocked writes no draft, so a busy + /// control never holds a value that was not sent. A press on a disabled or busy button stays silent + /// (`activate`); a change is an edit the user made and is told. pub(crate) fn refuses_change(&self, tree: &BoundTree, node: &NodeId) -> Option { let surface = tree.resolved().document().record_key(); if let Some(waiting) = self.confirming_refusal(&surface, node) { return Some(waiting); } - self.holds(tree, node).then(|| blocked(&surface, node, "the control is disabled or waiting for a result")) + self.holds(tree, node).then(|| blocked(&surface, node, "the control is waiting for a result")) } fn confirming_refusal(&self, surface: &str, node: &NodeId) -> Option { diff --git a/crates/thing-core/src/diagnostic.rs b/crates/thing-core/src/diagnostic.rs index e5f5f96..bc95fb0 100644 --- a/crates/thing-core/src/diagnostic.rs +++ b/crates/thing-core/src/diagnostic.rs @@ -61,11 +61,13 @@ pub enum Code { CaptureUndeclared, /// An activation core refused to act on because the caller was wrong: a kind the node does not take, a /// node nobody laid, a change value outside what the input allows, no surface shown, or a resume that - /// can no longer run. Nothing was minted; the detail says which. + /// can no longer run. Nothing was minted; the detail says which. A host logs it as a caller bug, as + /// it logs the other caller bugs of the activation path: `UndeclaredCommand` and `CaptureUnavailable`. ActivationRefused, - /// An otherwise valid activation a user state stopped: a command waits for confirmation, or the - /// control is disabled or waits for its own result. Nothing was minted and no draft was written; a - /// host may show or drop it, and it is never a bug. + /// A well-formed activation a user state stopped: a command waits for confirmation (this one or + /// another), or a change reached a control that waits for its own result. Nothing was minted and no + /// draft was written; a host may show or drop it, and it is never a bug. A press on a disabled or busy + /// button says nothing at all. ActivationBlocked, } -- 2.47.3