Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix: follow the current Summarize long chats choice for pending summaries

leepokai03a009bb55a2
diff --git a/docs/design/bot-memory.md b/docs/design/bot-memory.md
index 3fa5efab..e9ea8838 100644
--- a/docs/design/bot-memory.md
+++ b/docs/design/bot-memory.md
@@ -446,6 +446,11 @@ in `context.window.<bot>`); before that they offer only the three choices. A cus
reported a window keeps its setting while its agent isn't running. Other agents have no setting (`compaction` is
`null`) and keep the defaults for rollovers.
+Decisions follow the setting in force when they act. A queued compaction runs only if it's still due then (another
+turn may have gone first, or the user changed the setting). When the setting changes, a handoff card it no longer
+calls for is withdrawn (shown as kept, without counting as the user turning the rollover down) and the old
+conversation goes on.
+
The `idleCompaction` setting needs no change. The harness never idle-compacts in SDK/ACP sessions, and setting it
to true "does not turn idle compaction on".
diff --git a/docs/features/context-and-memory.md b/docs/features/context-and-memory.md
index 29b1de8d..e5b2b035 100644
--- a/docs/features/context-and-memory.md
+++ b/docs/features/context-and-memory.md
@@ -167,6 +167,7 @@ Claude Code's own memory; the rules live in the `codync-mem` crate, and `chat/me
It runs as a hidden turn: dreaming first, then the opening rendered again (a Claude session reloads only when
it changed), then `/compact <keep-list>` for Claude, or `/compact` for Codex, whose keep-list is its
`CODEX_CONFIG` `compact_prompt`. Other harnesses compact on their own. The keep-list is also in the opening.
+ A compaction queued behind another turn runs only if it is still due when its turn comes.
- **The user's threshold** (*Summarize long chats* in a Claude Code or Codex bot's settings, the bot's
`compaction`): Early (the default above), Near the limit, Only when full (no compaction or rollover from the
host), or a size from 50k up to the window less 40k (the apps list 100k steps and take any other size typed,
@@ -182,7 +183,8 @@ Claude Code's own memory; the rules live in the `codync-mem` crate, and `chat/me
the user's last four messages and the last reply (each cut at 2,000 characters, so a pasted document doesn't fill
the new conversation), the open plan, and a bookmark for `search_history`. The user can
edit it (`editHandoff`) or keep the conversation (`keepConversation`); otherwise their next message there starts
- a new session that begins with it.
+ a new session that begins with it. A change of the threshold withdraws a card it no longer calls for (shown as
+ kept, not counted as the user turning it down).
- **After every compaction** the host records a notice ("Earlier context was summarized to make room.", its
`compaction` field carrying Claude's summary, which the next handoff starts from). The apps don't show it: the
same conversation goes on.
diff --git a/host/src/agent/bot/compaction.rs b/host/src/agent/bot/compaction.rs
index 04e7a3b5..383799db 100644
--- a/host/src/agent/bot/compaction.rs
+++ b/host/src/agent/bot/compaction.rs
@@ -283,6 +283,18 @@ impl Actor {
c
}
+ /// The user changed when the chat is summarized: a fresh conversation the new setting doesn't call for is
+ /// withdrawn, and the old one goes on.
+ pub(super) fn threshold_changed(&self) {
+ let Some(sid) = &self.session_id else { return };
+ let Some((card, _)) = handoff::pending(&self.hub.store, &self.cfg.id) else { return };
+ let (c, at, now) = (self.conversation(sid), self.threshold(), now_ms());
+ if !rules::rollover_due(&c, at, self.cache_life(), now) && rules::at_turn_end(&c, at, now) != Decision::Rollover
+ {
+ handoff::withdraw(&self.hub, &self.cfg.id, &card);
+ }
+ }
+
fn draft_handoff(&mut self, session: &str, reason: handoff::Reason) {
if handoff::pending(&self.hub.store, &self.cfg.id).is_some() {
return;
@@ -296,7 +308,14 @@ impl Actor {
/// opening is rendered again, so the compaction keeps current memory (render, load, compact).
pub(super) async fn start_compaction(&mut self, idle: bool, done_tx: &tokio::sync::mpsc::UnboundedSender<Done>) {
let (Some(sid), Some(command)) = (self.session_id.clone(), self.compact_command()) else { return };
- crate::analytics::context_compacted(&self.hub, &self.cfg.backend, idle, self.threshold());
+ // Decided when it was queued; another turn or a change of the setting may have come first.
+ let (c, at, now) = (self.conversation(&sid), self.threshold(), now_ms());
+ let due =
+ if idle { rules::while_idle(&c, at, self.cache_life(), now) } else { rules::at_turn_end(&c, at, now) };
+ if due != Decision::Compact {
+ return;
+ }
+ crate::analytics::context_compacted(&self.hub, &self.cfg.backend, idle, at);
let _ = self.dreamer.send(memory::DreamEvent::Flush);
if let Err(error) = context::refresh(&self.hub.store, &self.cfg.id, &sid) {
tracing::warn!(bot = %self.cfg.id, error = format!("{error:#}"), "couldn't refresh the opening");
diff --git a/host/src/agent/bot/queue.rs b/host/src/agent/bot/queue.rs
index 64717539..335f58ae 100644
--- a/host/src/agent/bot/queue.rs
+++ b/host/src/agent/bot/queue.rs
@@ -93,9 +93,13 @@ impl Actor {
// Live sessions switch before their next turn (see `fast_mode`).
let fast_changed = cfg.fast_mode != self.cfg.fast_mode;
let mode_changed = cfg.mode != self.cfg.mode;
+ let threshold_changed = cfg.compaction != self.cfg.compaction;
// Name, description and skill changes reach the agent as a profile update
// on the next message (see `context`).
self.cfg = cfg;
+ if threshold_changed {
+ self.threshold_changed();
+ }
if fast_changed {
self.fast_mode_changed();
}
diff --git a/host/src/chat/handoff.rs b/host/src/chat/handoff.rs
index fff3c284..87a050ff 100644
--- a/host/src/chat/handoff.rs
+++ b/host/src/chat/handoff.rs
@@ -16,6 +16,8 @@ const MAX_CHARS: usize = 20_000;
const REQUESTS: usize = 4;
/// Main-chat entries read to build one.
const READ: i64 = 120;
+/// A card's line once the old conversation goes on.
+const KEPT: &str = "Kept this conversation.";
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
@@ -144,6 +146,13 @@ pub fn sent(hub: &Hub, bot: &str, id: &str) {
let _ = hub.store.kv_delete(&key(bot));
}
+/// The setting that called for the card changed: the old conversation goes on, without counting as the user turning
+/// a fresh one down.
+pub fn withdraw(hub: &Hub, bot: &str, id: &str) {
+ set_status(hub, id, Status::Kept, KEPT);
+ let _ = hub.store.kv_delete(&key(bot));
+}
+
fn set_status(hub: &Hub, id: &str, status: Status, line: &str) -> Option<Entry> {
let mut data = hub.store.entry(id)?.data;
data["handoff"]["status"] = json!(status);
@@ -169,8 +178,36 @@ pub fn call(hub: &Hub, method: &str, b: &Value) -> Result<Value> {
data["handoff"]["text"] = text.into();
hub.set_entry(id, &data)
}
- "keepConversation" => set_status(hub, id, Status::Kept, "Kept this conversation."),
+ "keepConversation" => set_status(hub, id, Status::Kept, KEPT),
_ => bail!("unknown method {method}"),
};
Ok(json!({"entry": entry}))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::remote::identity::Identity;
+
+ #[test]
+ fn a_withdrawn_card_is_not_the_user_keeping_the_conversation() {
+ let dir = std::env::temp_dir().join(format!("codync-handoff-{}", uuid::Uuid::new_v4()));
+ std::fs::create_dir_all(&dir).unwrap();
+ let cfg: BotConfig = serde_json::from_value(json!({"id": "b", "name": "B", "backend": "codex"})).unwrap();
+ let store = Store::open(&dir.join("t.db")).unwrap();
+ store.save_bot(&cfg).unwrap();
+ let hub = Hub::new(store, "test".into(), Identity::load_or_create(&dir).unwrap(), "token".into(), 0);
+
+ let card = draft(&hub, &cfg, "s1", Reason::Cold).unwrap();
+ withdraw(&hub, "b", &card.id);
+ assert_eq!(hub.store.entry(&card.id).unwrap().data["handoff"]["status"], json!(Status::Kept));
+ assert!(pending(&hub.store, "b").is_none());
+ assert!(!kept(&hub.store, "b"), "the setting took it back, not the user");
+
+ let card = draft(&hub, &cfg, "s1", Reason::Cold).unwrap();
+ call(&hub, "keepConversation", &json!({"entryId": card.id})).unwrap();
+ assert!(kept(&hub.store, "b"));
+ drop(hub);
+ std::fs::remove_dir_all(dir).ok();
+ }
+}
diff --git a/host/tests/compaction_e2e.rs b/host/tests/compaction_e2e.rs
index e6e38f52..6a474c8c 100644
--- a/host/tests/compaction_e2e.rs
+++ b/host/tests/compaction_e2e.rs
@@ -1,5 +1,6 @@
//! Compaction and rollover on a real host with disposable data: the host compacting a full conversation at the
-//! end of a turn, its loop guard turning to a rollover, and the handoff card the user edits or turns down.
+//! end of a turn, its loop guard turning to a rollover, the handoff card the user edits or turns down, and a queued
+//! compaction or a card the conversation no longer calls for.
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
@@ -129,3 +130,79 @@ async fn compacting_too_often_turns_into_a_rollover_the_user_can_edit_or_turn_do
assert_eq!(host.requests(&bot, "session/new").len(), 2, "same conversation");
assert!(!host.prompts(&bot).last().unwrap().contains("<handoff>"));
}
+
+#[tokio::test]
+async fn turning_summaries_off_withdraws_a_fresh_conversation_already_drafted() {
+ let host = Host::start().await;
+ let bot = host.fixture_bot("Changed", "instructions_agent.py", "codex").await;
+ host.reply(&bot, "USAGE 210000 SIZE 1000000").await;
+ notice(&host, &bot, "compaction").await;
+ host.reply(&bot, "USAGE 210000 SIZE 1000000").await;
+ let card = notice(&host, &bot, "handoff").await;
+ assert_eq!(card["data"]["handoff"]["status"], "draft");
+
+ host.call("updateBot", json!({"id": bot, "compaction": "off"})).await;
+ common::eventually("the card was withdrawn", Duration::from_secs(10), async || {
+ common::steer::entry(&host, &bot, card["id"].as_str().unwrap()).await["data"]["handoff"]["status"] == "kept"
+ })
+ .await;
+ host.reply(&bot, "carry on").await;
+ assert_eq!(host.requests(&bot, "session/new").len(), 1, "same conversation");
+ assert!(!host.prompts(&bot).last().unwrap().contains("<handoff>"));
+}
+
+/// Holds a turn that fills the conversation, queues "second" (held too) behind it and lets the first end: the
+/// compaction it called for waits in the queue while "second" runs.
+async fn compaction_queued_behind_a_turn(host: &Host, bot: &str) {
+ host.call("send", json!({"botId": bot, "text": "USAGE 210000 SIZE 1000000 HOLD"})).await;
+ prompted(host, bot, 1).await;
+ let second = host.call("send", json!({"botId": bot, "text": "second HOLD"})).await;
+ assert_eq!(second["entry"]["data"]["status"], "queued");
+ release(host, bot);
+ prompted(host, bot, 2).await;
+}
+
+async fn prompted(host: &Host, bot: &str, prompts: usize) {
+ common::eventually("the agent got the prompt", Duration::from_secs(30), async || {
+ host.prompts(bot).len() == prompts
+ })
+ .await;
+}
+
+/// Ends the bot's held turn (`HOLD` in `instructions_agent.py`).
+fn release(host: &Host, bot: &str) {
+ std::fs::write(host.home.join("bots").join(bot).join("workspace").join("release"), "").unwrap();
+}
+
+/// Sends `text` and waits until the agent has it, after everything queued before it.
+async fn reaches_agent(host: &Host, bot: &str, text: &str) {
+ host.call("send", json!({"botId": bot, "text": text})).await;
+ common::eventually("the agent got the message", Duration::from_secs(30), async || {
+ host.prompts(bot).last().is_some_and(|p| p.contains(text))
+ })
+ .await;
+}
+
+fn compactions(host: &Host, bot: &str) -> usize {
+ host.prompts(bot).iter().filter(|p| p.starts_with("/compact")).count()
+}
+
+#[tokio::test]
+async fn a_queued_compaction_runs_only_while_still_due() {
+ let host = Host::start().await;
+ // The second turn queues another compaction, but the first one makes room.
+ let busy = host.fixture_bot("Busy", "instructions_agent.py", "codex").await;
+ compaction_queued_behind_a_turn(&host, &busy).await;
+ release(&host, &busy);
+ notice(&host, &busy, "compaction").await;
+ reaches_agent(&host, &busy, "third").await;
+ assert_eq!(compactions(&host, &busy), 1);
+
+ // Summaries turned off while it waits.
+ let off = host.fixture_bot("Off", "instructions_agent.py", "codex").await;
+ compaction_queued_behind_a_turn(&host, &off).await;
+ host.call("updateBot", json!({"id": off, "compaction": "off"})).await;
+ release(&host, &off);
+ reaches_agent(&host, &off, "third").await;
+ assert_eq!(compactions(&host, &off), 0);
+}
diff --git a/host/tests/fixtures/instructions_agent.py b/host/tests/fixtures/instructions_agent.py
index 3895cf75..60fa11d0 100644
--- a/host/tests/fixtures/instructions_agent.py
+++ b/host/tests/fixtures/instructions_agent.py
@@ -3,15 +3,18 @@
`standard` advertises ACP `systemPrompt`; `reporting` reports compactions with `compaction_update`; `silent` only
shows them in `usage_update`; `flaky` resumes sessions and fails its first prompt ever (across restarts), as a rate limit does; `codex` and `claude` answer `initialize` the way those adapters do, so the host asks
them to compact. A prompt containing COMPACT_NOW, or one that is a `/compact` command, compacts; one containing
-`USAGE <n>` (optionally `SIZE <m>`) reports that much context in use. Every request is appended to
-`requests.jsonl` in the working directory.
+`USAGE <n>` (optionally `SIZE <m>`) reports that much context in use; one containing HOLD ends only once a `release`
+file appears in the working directory (and takes it), or exits with its parent (a background job that quotes the chat
+never gets one). Every request is appended to `requests.jsonl` in the working directory.
"""
import json
import os
import re
import sys
+import time
mode = sys.argv[1] if len(sys.argv) > 1 else "reporting"
+parent = os.getppid()
sessions = 0
compactions = 0
@@ -73,6 +76,12 @@ for line in sys.stdin:
size = re.search(r"SIZE (\d+)", text)
update(session, {"sessionUpdate": "usage_update", "used": int(usage.group(1)),
"size": int(size.group(1)) if size else 200000})
+ if "HOLD" in text:
+ while not os.path.exists("release"):
+ if os.getppid() != parent:
+ sys.exit()
+ time.sleep(0.05)
+ os.remove("release")
update(session, {"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": "ok"}})
result = {"stopReason": "end_turn"}
else:
diff --git a/web/content/docs/conversations.mdx b/web/content/docs/conversations.mdx
index 5a659666..adab1f89 100644
--- a/web/content/docs/conversations.mdx
+++ b/web/content/docs/conversations.mdx
@@ -132,7 +132,7 @@ Before your next message, you can:
Afterwards the card folds into one line that unfolds to what was carried.
-When Codync summarizes, and whether it starts fresh conversations at all, is the bot's [Summarize long chats](/docs/bots#summarize-long-chats) setting.
+When Codync summarizes, and whether it starts fresh conversations at all, is the bot's [Summarize long chats](/docs/bots#summarize-long-chats) setting. Changing it takes back a card the new setting no longer calls for, and the conversation carries on.
## Notifications