From d927227ec90fe68c0dfd56670573189a030a90bf Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 07:59:11 +0100 Subject: [PATCH] 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, }