diff --git a/core/continuum-cognition/src/cognition/act_observe/apply.rs b/core/continuum-cognition/src/cognition/act_observe/apply.rs index 49b3a77b9e..9869ec7553 100644 --- a/core/continuum-cognition/src/cognition/act_observe/apply.rs +++ b/core/continuum-cognition/src/cognition/act_observe/apply.rs @@ -449,6 +449,43 @@ pub async fn apply_act( append_dispatched_observations(&mut acts, &dispatched_calls); let call_order: std::collections::HashMap<_, _> = calls.iter() .enumerate().map(|(ordinal, call)| (call.id.as_str(), ordinal)).collect(); + // Loop-awareness filtering: if multiple calls share a fingerprint and produce + // identical result content, keep only RESPONSE_LOOP_THRESHOLD + 1 of them — + // beyond that the mind is looping on unchanged evidence. + const RESPONSE_LOOP_THRESHOLD: usize = 3; + + let mut groups: std::collections::HashMap> = std::collections::HashMap::new(); + for (i, act) in acts.iter().enumerate() { + let fp = format!( + "{}|{}", + act.call.name, + serde_json::to_string(&act.call.input).unwrap_or_default() + ); + groups.entry(fp).or_default().push(i); + } + + let mut keep: Vec = vec![true; acts.len()]; + for (_fp, indices) in groups { + if indices.len() <= RESPONSE_LOOP_THRESHOLD + 1 { + continue; + } + + // Check if all results are identical within this group + let result_content = acts[indices[0]].output.result.content.clone(); + let all_identical = indices.iter().skip(1).all(|&idx| + acts[idx].output.result.content == result_content + ); + + if all_identical { + // Keep only the first RESPONSE_LOOP_THRESHOLD + 1, drop the rest + for &idx in indices.iter().skip(RESPONSE_LOOP_THRESHOLD + 1) { + keep[idx] = false; + } + } + } + + let mut keep_iter = keep.into_iter(); + acts.retain(|_| keep_iter.next().unwrap()); acts.sort_by_key(|observation| call_order.get(observation.call.id.as_str()).copied()); // #243 RECEIPT RADIATION: every executed act reaches the room's transcript // as a collapsed receipt ("Ran 4 commands ›", the Claude-iOS pattern) — diff --git a/core/continuum-cognition/src/cognition/act_observe/settle/settle_step.rs b/core/continuum-cognition/src/cognition/act_observe/settle/settle_step.rs index 997fc5882b..08724f8099 100644 --- a/core/continuum-cognition/src/cognition/act_observe/settle/settle_step.rs +++ b/core/continuum-cognition/src/cognition/act_observe/settle/settle_step.rs @@ -147,12 +147,33 @@ pub async fn settle_step( // re-perceive next step; `NoHands`/`ExecutorError` → unfulfilled. Behavior // identical to the old `Some`/`None`, but `ExecutorError` is now // distinguishable for a future backstop. - if apply_act(cycle, &calls, &intent, ws.activity_room_id, chain, hands, ws.decision_generation()) - .await - .produced_an_act() - { + let act_outcome = apply_act(cycle, &calls, &intent, ws.activity_room_id, chain, hands, ws.decision_generation()) + .await; + if act_outcome.produced_an_act() { SettleStep::Acted { calls, intent } } else { + // Proprioception backstop for failed acts: the persona decided to + // run tools but nothing executed — without this fact they have no + // internal signal that their action was unfulfilled, so the next + // tick starts with identical cognition and repeats (the "six times + // the substrate told a party that could not act" loop). + if let Some(body) = cycle.acting() { + body.working_memory.record_fact( + "[unfulfilled] I decided to run tools but nothing executed \ + this concern — the tool calls were not carried out. Nothing \ + exists in the workspace until a tool call actually executes \ + it. If I named a tool, that name may not exist: `list_commands` \ + shows the tools that are real.", + ); + continuum_base::probe!( + class = "persona.act.unfulfilled_proprioception", + persona = %body.persona_name, + room_id = %room_id, + calls_count = calls.len(), + intent = %intent, + "ActUnfulfilled: recorded unfulfilled-promise proprioception for failed act" + ); + } SettleStep::ActUnfulfilled { calls, intent } } }