Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
28k only-a-real-no: a step says "You said no" only when the person pressed Deny (#802)
Oleksandr Ivanchenko15f8490877f3
diff --git a/src/drivers/activity.rs b/src/drivers/activity.rsindex 18798ba2..43366b0a 100644--- a/src/drivers/activity.rs+++ b/src/drivers/activity.rs@@ -89,8 +89,13 @@ pub struct ActivityLog {/// itself), sent with that scope's next chunk or when the thinking step ends.held: Vec<(Vec<TurnTag>, String)>,/// Indexes of `declined` approval steps already paired with the tool step they refused (28b),- /// so one Deny ends one tool step `declined`.+ /// so one Deny ends one tool step `declined`, and of `stopped` ones paired with the denied+ /// step whose wait they ended (28k).paired: HashSet<usize>,+ /// Calls kwnt refused on its own this turn, before the engine heard (28k), oldest first: the+ /// tool's name and the words its step shows instead of what the bot was told. Each one is+ /// used by one failed step of that tool.+ refused: Vec<(String, &'static str)>,}fn now() -> String {@@ -207,8 +212,8 @@ impl ActivityLog {if let Some(i) = self.tools.remove(id) {let (status, why) = step_end(result);let card = self.declined_card_for(i, status, why.as_deref());- if let Some(why) = why {- self.steps[i].detail = Some(cut(&self.redact(&why), MAX_DETAIL));+ if let Some(why) = why.as_deref() {+ self.steps[i].detail = Some(cut(&self.redact(why), MAX_DETAIL));}if status == "ok" && self.steps[i].tool.as_deref().is_some_and(opens_page) {self.steps[i].page_title = result["title"]@@ -223,7 +228,12 @@ impl ActivityLog {self.steps[i].detail = Some(crate::mcp::DENIED_STEP_DETAIL.to_string());"declined"}- None => status,+ None => {+ if let Some(words) = self.blocked_detail(i, status, why.as_deref()) {+ self.steps[i].detail = Some(words.to_string());+ }+ status+ }};changed.push(self.end(i, status));}@@ -254,6 +264,46 @@ impl ActivityLog {})}+ /// kwnt refused a call to `tool` on its own, before the engine heard (28k): the next failed+ /// step of that tool shows `words`, not the text the bot was told.+ pub fn refused(&mut self, tool: &str, words: &'static str) {+ self.refused.push((tool.to_string(), words));+ }++ /// What tool step `i`, which [`step_end`] ended `status` with reason `why` and no declined card+ /// of its own, shows instead of the bot's text (28k). Nobody pressed Deny, so it never says the+ /// person did:+ /// - the words of a refusal kwnt noted for its tool ([`refused`](Self::refused)), such as the+ /// pre-push gate's;+ /// - when it failed with the CLI's denial ([`denial_shown`]) and the turn has a `stopped` approval+ /// step of the same tool not yet paired (its card stopped waiting with no answer),+ /// [`crate::mcp::NOBODY_ANSWERED_STEP_DETAIL`], and that card is paired with it;+ /// - else, with that denial, [`crate::mcp::BLOCKED_STEP_DETAIL`] (kwnt's+ /// secret files, a ticket it couldn't store).+ fn blocked_detail(&mut self, i: usize, status: &str, why: Option<&str>) -> Option<&'static str> {+ if status != "failed" {+ return None;+ }+ let tool = self.steps[i].tool.clone();+ if let Some(k) = self.refused.iter().position(|(t, _)| Some(t) == tool.as_ref()) {+ return Some(self.refused.remove(k).1);+ }+ if !why.is_some_and(|w| w.starts_with(denial_shown())) {+ return None;+ }+ let stopped = (0..self.steps.len()).find(|j| {+ let s = &self.steps[*j];+ s.kind == "approval" && s.status == "stopped" && s.tool == tool && !self.paired.contains(j)+ });+ Some(match stopped {+ Some(j) => {+ self.paired.insert(j);+ crate::mcp::NOBODY_ANSWERED_STEP_DETAIL+ }+ None => crate::mcp::BLOCKED_STEP_DETAIL,+ })+ }+/// A note from kwnt itself, such as which engine can't show its thinking.pub fn note(&mut self, title: &str) -> Option<Step> {let i = self.push("note", "ok", title.to_string())?;@@ -1632,8 +1682,9 @@ mod tests {}/// 28b: a denial with no declined card (kwnt refused a call naming its own secret files, or a- /// ticket couldn't be stored) wasn't the person's no: it stays `failed` with the CLI's text.- /// A card for another tool, or one the person allowed, doesn't count either.+ /// ticket couldn't be stored) wasn't the person's no: it stays `failed`, and (28k) its step+ /// says kwant blocked it, not the CLI's "The user denied this tool call.". A card for another+ /// tool, or one the person allowed, doesn't count either.#[test]fn a_denial_without_a_declined_card_stays_failed() {let mut log = ActivityLog::default();@@ -1641,7 +1692,7 @@ mod tests {let ended = log.observe(&denied("a"));assert_eq!((ended[0].status, ended[0].detail.as_deref()),- ("failed", Some("The user denied this tool call."))+ ("failed", Some(crate::mcp::BLOCKED_STEP_DETAIL)));assert_eq!(denial_shown(), "The user denied this tool call.");log.wait("approval", "t1", "Waiting for your approval: Fetching", Some("WebFetch"));@@ -1650,7 +1701,10 @@ mod tests {log.settle("t2", "ok");log.observe(&pending("b", "Bash", json!({"command": "ls"})));let ended = log.observe(&denied("b"));- assert_eq!(ended[0].status, "failed");+ assert_eq!(+ (ended[0].status, ended[0].detail.as_deref()),+ ("failed", Some(crate::mcp::BLOCKED_STEP_DETAIL))+ );// Another failure is never read as a no, even with a declined card for that toollog.wait("approval", "t3", "Waiting for your approval: Running `ls`", Some("Bash"));log.settle("t3", "declined");@@ -1683,7 +1737,7 @@ mod tests {tools,vec![("declined", Some(crate::mcp::DENIED_STEP_DETAIL)),- ("failed", Some(denial_shown())),+ ("failed", Some(crate::mcp::BLOCKED_STEP_DETAIL)),]);// A second Deny pairs with the second call@@ -1692,4 +1746,90 @@ mod tests {log.observe(&pending("c", "Bash", json!({"command": "rm c"})));assert_eq!(log.observe(&denied("c"))[0].status, "declined");}++ /// 28k: a refusal the person never saw doesn't blame them. kwnt's secret files read "kwant+ /// blocked this; nothing ran"; a push the pre-push gate held reads "Blocked before push;+ /// nothing ran", whatever the gate told the bot. Only the saved step changes: the result the+ /// engine got (and so what the bot was told) is the same event, untouched.+ #[test]+ fn a_refusal_the_person_never_saw_says_who_stopped_it() {+ assert_eq!(crate::mcp::BLOCKED_STEP_DETAIL, "kwant blocked this; nothing ran");+ assert_eq!(crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL, "Blocked before push; nothing ran");+ assert_eq!(crate::mcp::NOBODY_ANSWERED_STEP_DETAIL, "Nobody answered in time; nothing ran");++ // kwnt's secret files: the CLI reports kwnt's DENIED_TEXT, and no card was shown+ let mut log = ActivityLog::default();+ log.observe(&pending("a", "Read", json!({"file_path": "/data/vault.json"})));+ let secret = denied("a");+ let ended = log.observe(&secret);+ assert_eq!(+ (ended[0].status, ended[0].detail.as_deref()),+ ("failed", Some("kwant blocked this; nothing ran"))+ );+ // What the engine got back is exactly what kwnt sent+ let RuntimeEvent::ToolCallCompleted { result, .. } = &secret else { unreachable!() };+ assert_eq!(result["error"], crate::mcp::with_no_false_claims(crate::mcp::DENIED_TEXT));++ // The pre-push gate: the bot gets the gate's own text; the step says "Blocked before push"+ let gate = "kwant is checking this push of main before it goes (pre-push card pp1): secrets, new packages, \+ test tampering, the risk rules and a fresh-eyes review by another bot. Nothing was pushed. Run the \+ same push again in a minute or two.";+ let mut log = ActivityLog::default();+ log.observe(&pending("p", "Bash", json!({"command": "git push origin main"})));+ log.refused("Bash", crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL);+ let held = RuntimeEvent::ToolCallCompleted { id: "p".into(), result: json!({"status": "error", "error": gate}) };+ let ended = log.observe(&held);+ assert_eq!(+ (ended[0].status, ended[0].detail.as_deref()),+ ("failed", Some("Blocked before push; nothing ran"))+ );+ let RuntimeEvent::ToolCallCompleted { result, .. } = &held else { unreachable!() };+ assert_eq!(result["error"], gate);+ // The note is used once: the next failure of that tool keeps its own reason+ log.observe(&pending("q", "Bash", json!({"command": "make"})));+ let ended = log.observe(&RuntimeEvent::ToolCallCompleted { id: "q".into(), result: json!({"status": "error", "error": "exit 2"}) });+ assert_eq!(ended[0].detail.as_deref(), Some("exit 2"));++ // A note for another tool, or a call that went fine, leaves the note for its own step+ let mut log = ActivityLog::default();+ log.refused("mcp__github__create_or_update_file", crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL);+ log.observe(&pending("x", "Bash", json!({"command": "ls"})));+ let ended = log.observe(&RuntimeEvent::ToolCallCompleted { id: "x".into(), result: json!({"status": "ok"}) });+ // An ok step keeps its command summary as detail, as on main; the note doesn't touch it+ assert_eq!((ended[0].status, ended[0].detail.as_deref()), ("ok", Some("ls")));+ log.observe(&pending("y", "mcp__github__create_or_update_file", json!({"branch": "lin-x"})));+ let ended = log.observe(&RuntimeEvent::ToolCallCompleted { id: "y".into(), result: json!({"status": "denied", "error": gate}) });+ assert_eq!(ended[0].detail.as_deref(), Some(crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL));+ }++ /// 28k: a denial whose card stopped waiting with no answer (it couldn't stay open, or it was+ /// withdrawn) reads "Nobody answered in time", once per card; a Deny still reads as a no.+ #[test]+ fn a_denial_after_a_card_nobody_answered_says_so() {+ let mut log = ActivityLog::default();+ log.observe(&pending("a", "Bash", json!({"command": "rm a"})));+ log.wait("approval", "t1", "Waiting for your approval: Running `rm a`", Some("Bash"));+ log.settle("t1", "stopped");+ let ended = log.observe(&denied("a"));+ assert_eq!(+ (ended[0].status, ended[0].detail.as_deref()),+ ("failed", Some("Nobody answered in time; nothing ran"))+ );+ // That card is used up: another denial with no card of its own is kwant's block+ log.observe(&pending("b", "Bash", json!({"command": "rm b"})));+ assert_eq!(log.observe(&denied("b"))[0].detail.as_deref(), Some(crate::mcp::BLOCKED_STEP_DETAIL));+ // A stopped card of another tool doesn't count+ log.wait("approval", "t2", "Waiting for your approval: Fetching", Some("WebFetch"));+ log.settle("t2", "stopped");+ log.observe(&pending("c", "Bash", json!({"command": "rm c"})));+ assert_eq!(log.observe(&denied("c"))[0].detail.as_deref(), Some(crate::mcp::BLOCKED_STEP_DETAIL));+ // A Deny is still the person's no, even with a stopped card of the same tool waiting+ log.wait("approval", "t3", "Waiting for your approval: Running `rm d`", Some("Bash"));+ log.settle("t3", "stopped");+ log.wait("approval", "t4", "Waiting for your approval: Running `rm d`", Some("Bash"));+ log.settle("t4", "declined");+ log.observe(&pending("d", "Bash", json!({"command": "rm d"})));+ let ended = log.observe(&denied("d"));+ assert_eq!((ended[0].status, ended[0].detail.as_deref()), ("declined", Some(crate::mcp::DENIED_STEP_DETAIL)));+ }}diff --git a/src/mcp/mod.rs b/src/mcp/mod.rsindex 2ffc08fe..6b7e97fe 100644--- a/src/mcp/mod.rs+++ b/src/mcp/mod.rs@@ -486,6 +486,16 @@ pub const UNANSWERED_STEP_DETAIL: &str = "Waited 5 minutes for your answer; noth/// The step detail of a call the person said no to on its card (28b): the tool step ends/// `declined`, in the person's words. The bot is still told [`DENIED_TEXT`].pub const DENIED_STEP_DETAIL: &str = "You said no; nothing ran";+/// The step detail of a call kwant refused on its own, with no card the person said no on (28k):+/// kwnt's secret files, a ticket it couldn't store, a card withdrawn before anyone answered. The+/// bot is still told [`DENIED_TEXT`]; only the saved step says who stopped it.+pub const BLOCKED_STEP_DETAIL: &str = "kwant blocked this; nothing ran";+/// The step detail of a call whose card stopped waiting with no answer and couldn't stay open+/// for a late one (28k): it didn't run, and it wasn't the person's no.+pub const NOBODY_ANSWERED_STEP_DETAIL: &str = "Nobody answered in time; nothing ran";+/// The step detail of a push or GitHub write the pre-push gate held (28k). The bot still gets+/// the gate's own text, which says what to do next.+pub const PREPUSH_BLOCKED_STEP_DETAIL: &str = "Blocked before push; nothing ran";/// The step detail of a call a Skill Foundry replay recorded instead of running.pub const REHEARSED_STEP_DETAIL: &str = "Dry run: kwant recorded this call instead of running it";diff --git a/src/mcp/session.rs b/src/mcp/session.rsindex 94072d75..6f19f730 100644--- a/src/mcp/session.rs+++ b/src/mcp/session.rs@@ -301,8 +301,14 @@ impl McpToolSession {payment: super::payment_floor::credits_reason(server, server_url, &t.tool.name),};// B2: a write to a GitHub branch waits for its pre-push card before any card or rule+ // 28k: a push the gate holds shows "Blocked before push" on its step; the bot+ // gets the gate's own text+ let held = || crate::server::activity::refused(&caller.turn_id, name, super::PREPUSH_BLOCKED_STEP_DETAIL);match self.ctx.approver.prepush_gate(&req).await {- Err(why) => ("denied", why),+ Err(why) => {+ held();+ ("denied", why)+ }Ok(pass) => {// A push the person's Retry or Override covers skips the ordinary card (0.9.7)let outcome = match &pass.grant {@@ -312,6 +318,7 @@ impl McpToolSession {if !outcome.allowed() {(outcome.record_status(), outcome.refusal_text().to_string())} else if let Some(why) = self.ctx.approver.prepush_use(&pass.overrides).await {+ held();("denied", why)} else {match client.call_tool(&t.tool.name, arguments.clone()).await {diff --git a/src/server/activity.rs b/src/server/activity.rsindex 184aeec4..840abdcf 100644--- a/src/server/activity.rs+++ b/src/server/activity.rs@@ -230,6 +230,15 @@ pub fn approval_waiting(turn_id: &str, ticket: &str, tool_name: &str) {}}+/// kwnt refused a call to `tool_name` in turn `turn_id` on its own, before the engine heard (28k):+/// that tool's next failed step shows `words` (as [`crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL`]),+/// not the text the bot was told. Nobody pressed Deny, so it never reads as the person's no.+pub fn refused(turn_id: &str, tool_name: &str, words: &'static str) {+ if let Some(turn) = TurnActivity::find(turn_id) {+ turn.with_log(|log| log.refused(tool_name, words));+ }+}+/// An approval card for `turn_id` was answered ("ok" allowed, "declined") or stopped waiting.pub fn approval_settled(turn_id: &str, ticket: &str, status: &'static str) {if let Some(turn) = TurnActivity::find(turn_id) {@@ -552,6 +561,25 @@ mod tests {assert_eq!(with_activity(None, Some(json!({"steps": []}))).unwrap()["activity"]["steps"], json!([]));}+ /// 28k: kwnt's pre-push gate notes its refusal on the turn by id, so the tool step it held is+ /// saved as "Blocked before push; nothing ran". A turn that isn't running is left alone.+ #[test]+ fn a_held_push_is_saved_as_blocked_before_push() {+ let (tx, _rx) = broadcast::channel(16);+ let tag = TurnTag { turn_id: "turn-prepush-held".into(), kwant_id: "k".into(), context_id: "c".into(), thread_id: None };+ let turn = TurnActivity::start(tx, tag);+ turn.observe(&RuntimeEvent::ToolCallPending { id: "1".into(), name: "Bash".into(), args: json!({"command": "git push origin lin-x"}) });+ refused("turn-prepush-held", "Bash", crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL);+ refused("no-such-turn", "Bash", crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL);+ turn.observe(&RuntimeEvent::ToolCallCompleted {+ id: "1".into(),+ result: json!({"status": "error", "error": "kwant checks one branch at a time before a push: push the branch by name."}),+ });+ let saved = turn.finish().unwrap();+ assert_eq!(saved["steps"][0]["status"], "failed");+ assert_eq!(saved["steps"][0]["detail"], "Blocked before push; nothing ran");+ }+/// 0.9.8 browser panel: the page title of a bot browser open goes out live, is listed on/// `GET /api/turns` and is kept on the saved reply; a reply saved before it reads as it did.#[test]diff --git a/src/server/mcp_runtime.rs b/src/server/mcp_runtime.rsindex c9e6250c..badd3b58 100644--- a/src/server/mcp_runtime.rs+++ b/src/server/mcp_runtime.rs@@ -557,14 +557,7 @@ impl BrokerApprover {let decision = tokio::time::timeout(self.timeout, rx).await;guard.id = None;super::scheduler::approval_wait(&self.events, &req.kwant_id, &chat_key, None);- let answered = match &decision {- Ok(Ok(ApprovalDecision::AllowOnce | ApprovalDecision::AlwaysAllowSession)) => {- Some("ok")- }- Ok(_) => Some("declined"),- Err(_) => None,- };- if let Some(settled) = answered {+ if let Some(settled) = card_settles(&decision) {super::activity::approval_settled(&req.turn_id, &ticket, settled);}let outcome = match decision {@@ -584,6 +577,8 @@ impl BrokerApprover {self.broker.declined.record(&req.kwant_id, &self.conversation, &families, &ticket);ApprovalOutcome::Denied}+ // The card was withdrawn or its channel dropped (28k): nothing runs, but it wasn't+ // the person's no, so its step settled `stopped` aboveOk(Err(_)) => ApprovalOutcome::Denied,// Nobody answered: the card stays up as `waiting`, and a late Allow resumes the work// (see `resume_late_approval`)@@ -656,6 +651,19 @@ pub async fn home_server_names(db: &Database, servers: &[McpServer]) -> Vec<Strinames}+/// How an approval card's step settles once its wait ends with `decision`: "ok" on an Allow,+/// "declined" only on the person's Deny, and "stopped" when the card was withdrawn or its+/// channel dropped with no answer (28k: nobody pressed Deny, so it isn't the person's no). `None`+/// when the wait ran out: the timeout path settles it (`unanswered` or `stopped`).+fn card_settles<E, T>(decision: &Result<Result<ApprovalDecision, E>, T>) -> Option<&'static str> {+ match decision {+ Ok(Ok(ApprovalDecision::AllowOnce | ApprovalDecision::AlwaysAllowSession)) => Some("ok"),+ Ok(Ok(ApprovalDecision::Deny)) => Some("declined"),+ Ok(Err(_)) => Some("stopped"),+ Err(_) => None,+ }+}+/// 26f: whether `req` acts on a lock, a door, a garage door, a gate or an alarm on a Home/// Assistant server ([`mcp::home_floor`]), so it always asks. What the server is comes from what/// it said on kwnt's last connection to it in this run, else from what its last test stored; one@@ -1525,13 +1533,19 @@ pub async fn permission_endpoint(None => Ok(Default::default()),},};+ // 28k: the gate's refusal is its own text to the bot, and "Blocked before push" on the step+ let held = || super::activity::refused(&session.turn_id, tool_name, mcp::PREPUSH_BLOCKED_STEP_DETAIL);let decision = match prepush {- Err(why) => json!({"behavior": "deny", "message": why}),+ Err(why) => {+ held();+ json!({"behavior": "deny", "message": why})+ }Ok(pass) => {let mut decision = decide(&session, args, smart, pass.grant.as_ref()).await;if decision["behavior"] == "allow" {// The override goes with the push that runs, never one the person declinedif let Some(why) = super::dev::prepush::use_up(&state, &pass).await {+ held();decision = json!({"behavior": "deny", "message": why});} else if let (Some(pinned), Some(input)) = (pass.pinned, decision.get_mut("updatedInput").and_then(Value::as_object_mut)) {// What goes is the commit kwant checked, even if a parallel call commits@@ -2097,3 +2111,52 @@ mod declined_tests {serve.abort();}}++#[cfg(test)]+mod card_settles_tests {+ use super::*;++ /// 28k: only the person's Deny settles a card `declined`. A card that was withdrawn, or whose+ /// channel dropped, settles `stopped`: nobody pressed Deny. The bot's outcome is `Denied`+ /// either way (nothing runs), and it hears the same text.+ #[tokio::test]+ async fn a_withdrawn_card_settles_stopped_and_only_a_deny_settles_declined() {+ let broker = PermissionBroker::new();+ let ask = |id: &str| ApprovalRequest {+ id: id.into(),+ kwant_id: "k1".into(),+ tool_name: "Bash".into(),+ details: Value::Null,+ };+ let wait = |rx: tokio::sync::oneshot::Receiver<ApprovalDecision>| tokio::time::timeout(Duration::from_secs(5), rx);++ // Withdrawn: the broker drops the ticket with no decision+ let rx = broker.request_approval(ask("apr_withdrawn")).await;+ assert!(broker.cancel("apr_withdrawn").await);+ let withdrawn = wait(rx).await;+ assert!(matches!(withdrawn, Ok(Err(_))), "the waiter sees the channel close");+ assert_eq!(card_settles(&withdrawn), Some("stopped"));++ // The person pressed Deny+ let rx = broker.request_approval(ask("apr_deny")).await;+ assert!(broker.resolve("apr_deny", ApprovalDecision::Deny).await);+ assert_eq!(card_settles(&wait(rx).await), Some("declined"));++ // Allow, once or for the session+ for d in [ApprovalDecision::AllowOnce, ApprovalDecision::AlwaysAllowSession] {+ let rx = broker.request_approval(ask("apr_ok")).await;+ assert!(broker.resolve("apr_ok", d).await);+ assert_eq!(card_settles(&wait(rx).await), Some("ok"));+ }++ // The wait ran out: the timeout path settles it, not this+ let rx = broker.request_approval(ask("apr_slow")).await;+ let ran_out = tokio::time::timeout(Duration::from_millis(1), rx).await;+ assert!(ran_out.is_err());+ assert_eq!(card_settles(&ran_out), None);++ // What the bot hears doesn't change: a withdrawn card and a Deny are both `Denied`+ assert_eq!(ApprovalOutcome::Denied.refusal_text(), mcp::DENIED_TEXT);+ assert_eq!(ApprovalOutcome::Denied.record_status(), "denied");+ }+}diff --git a/src/server/scheduler.rs b/src/server/scheduler.rsindex 35e46f2d..2cbe7a87 100644--- a/src/server/scheduler.rs+++ b/src/server/scheduler.rs@@ -734,11 +734,10 @@ pub fn steps_seen(// declined card of the same tool counts for one call. The pre-push gate, kwnt's secret files,// a ticket that couldn't be stored and a wait that ran out record `denied` with no card the// person said no on.- let mut cards_left: Vec<&str> = activity- .iter()- .filter(|s| s["kind"] == "approval" && s["status"] == "declined")- .filter_map(|s| s["tool"].as_str())- .collect();+ let mut cards_left = cards(activity, "declined");+ // 28k: a card that stopped waiting with no answer (the wait ran out and couldn't be kept+ // open, or the card was withdrawn) explains one `denied` call of its tool: nobody answered+ let mut stopped_left = cards(activity, "stopped");let mut seen = Vec::new();for c in tool_calls.and_then(|v| v.as_array()).into_iter().flatten() {let status = match c["status"].as_str().unwrap_or("") {@@ -759,8 +758,10 @@ pub fn steps_seen(if let Some(k) = card {cards_left.remove(k);}+ let unanswered = c["status"] == "denied" && !said && take(&mut stopped_left, &tool);let reason = match c["status"].as_str() {Some("denied") if said => Some(said_no(&tool)),+ Some("denied") if unanswered => Some(nobody_answered(&tool)),Some("denied") => Some(format!("{tool} was denied")),_ => reason.map(|r| {r.replace(crate::mcp::NO_FALSE_CLAIMS_TEXT, "")@@ -803,6 +804,32 @@ fn said_no(tool: &str) -> String {format!("You said no to {tool}; nothing ran")}+/// A routine run's reason when `tool` waited on a card nobody answered and didn't run (28k). It+/// stays a failure, but not the person's no.+fn nobody_answered(tool: &str) -> String {+ format!("Nobody answered in time; {tool} didn't run")+}++/// The tools of `activity`'s approval steps that settled `status`, in order.+fn cards<'a>(activity: &'a [serde_json::Value], status: &str) -> Vec<&'a str> {+ activity+ .iter()+ .filter(|s| s["kind"] == "approval" && s["status"] == status)+ .filter_map(|s| s["tool"].as_str())+ .collect()+}++/// Uses up one entry for `tool` in `left`: whether there was one.+fn take(left: &mut Vec<&str>, tool: &str) -> bool {+ match left.iter().position(|t| *t == tool) {+ Some(k) => {+ left.remove(k);+ true+ }+ None => false,+ }+}+/// The meta key of a routine run's id on each reply of its turn (see `run_routine_turn`).pub(super) const ROUTINE_RUN_KEY: &str = "routine_run";@@ -1399,11 +1426,14 @@ mod run_outcome_tests {// a declined card of another tool, or a card of the same tool that wasn't declinedlet other = cards(json!([{"kind": "approval", "status": "declined", "tool": "Bash"},- {"kind": "approval", "status": "stopped", "tool": "github__push"},{"kind": "approval", "status": "ok", "tool": "github__push"},]));let seen = steps_seen(Some(&calls), Some(&other));assert_eq!(seen[0], step("github__push", "failed", Some("github__push was denied")));+ // a card of the same tool that stopped waiting: nobody answered (28k)+ let stopped = cards(json!([{"kind": "approval", "status": "stopped", "tool": "github__push"}]));+ let seen = steps_seen(Some(&calls), Some(&stopped));+ assert_eq!(seen[0], step("github__push", "failed", Some("Nobody answered in time; github__push didn't run")));// one card, two denied calls of its tool: one no, one plain deniallet twice = json!([denied("github__push"), denied("github__push")]);assert_eq!(@@ -1416,6 +1446,57 @@ mod run_outcome_tests {assert_eq!(steps_seen(Some(&bash), Some(&bash_card))[0], no("Bash"));}+ /// 28k: a routine wait that ran out with no answer reads "Nobody answered in time; X didn't+ /// run", a rose failure (`said_no` false), never the person's no; each stopped card explains+ /// one denied call. The person's real no keeps its words, and a refusal kwnt made on its own+ /// reads as its saved step says.+ #[test]+ fn a_wait_that_ran_out_says_nobody_answered() {+ let denied = |name: &str| json!({"name": name, "status": "denied"});+ let meta = |steps: serde_json::Value| json!({"activity": {"steps": steps}});+ let calls = json!([denied("mail__send"), denied("mail__send")]);+ let one_card = meta(json!([{"kind": "approval", "status": "stopped", "tool": "mail__send"}]));+ let seen = steps_seen(Some(&calls), Some(&one_card));+ assert_eq!(+ seen,+ vec![+ step("mail__send", "failed", Some("Nobody answered in time; mail__send didn't run")),+ step("mail__send", "failed", Some("mail__send was denied")),+ ]+ );+ assert!(!seen[0].said_no);+ assert_eq!(+ run_outcome(&seen[..1]),+ ("incomplete", Some("Nobody answered in time; mail__send didn't run".into()))+ );+ // A Deny on one card and a wait that ran out on another: each call gets its own words+ let both = meta(json!([+ {"kind": "approval", "status": "stopped", "tool": "mail__send"},+ {"kind": "approval", "status": "declined", "tool": "mail__send"},+ ]));+ assert_eq!(+ steps_seen(Some(&calls), Some(&both)),+ vec![no("mail__send"), step("mail__send", "failed", Some("Nobody answered in time; mail__send didn't run"))]+ );+ // The claude CLI's own step for it, as the activity log saves it (28k)+ let cli = meta(json!([+ {"kind": "tool", "status": "failed", "tool": "Bash", "detail": crate::mcp::NOBODY_ANSWERED_STEP_DETAIL},+ {"kind": "approval", "status": "stopped", "tool": "Bash"},+ {"kind": "tool", "status": "failed", "tool": "Bash", "detail": crate::mcp::PREPUSH_BLOCKED_STEP_DETAIL},+ {"kind": "tool", "status": "failed", "tool": "Read", "detail": crate::mcp::BLOCKED_STEP_DETAIL},+ ]));+ let seen = steps_seen(None, Some(&cli));+ assert_eq!(+ seen,+ vec![+ step("Bash", "failed", Some("Nobody answered in time; nothing ran")),+ step("Bash", "failed", Some("Blocked before push; nothing ran")),+ step("Read", "failed", Some("kwant blocked this; nothing ran")),+ ]+ );+ assert!(seen.iter().all(|s| !s.said_no));+ }+/// 28b round 2: a real failure's reason wins over the person's no, whichever came first; the/// no is the reason only when nothing else failed. The run is `incomplete` either way.#[test]