Forked agents: stop gracefully on context overflow instead of compacting

Subconscious agents (observe, etc.) fork the conscious agent's context
to share the KV cache prefix. When a multi-step agent fills the context
window, compacting blows the KV cache and evicts the step prompts,
leaving the model with no idea what it was doing.

Fix: forked agents set no_compact=true. On overflow, turn() returns the
error immediately (no compact+retry), and run_with_backend catches it
and returns Ok — the output tool has already written results to
Subconscious.state, so collect_results still picks them up.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-08 23:00:12 -04:00
parent 850008ece7
commit 44a0bc376a
2 changed files with 24 additions and 8 deletions

View file

@ -186,8 +186,14 @@ impl AutoAgent {
for _ in 0..max_turns {
self.turn += 1;
let result = Agent::turn(backend.0.clone()).await
.map_err(|e| format!("{}: {}", self.name, e))?;
let result = match Agent::turn(backend.0.clone()).await {
Ok(r) => r,
Err(e) if super::context::is_context_overflow(&e) => {
dbglog!("[auto] {} context full, stopping gracefully", self.name);
return Ok(String::new());
}
Err(e) => return Err(format!("{}: {}", self.name, e)),
};
if result.had_tool_calls {
continue;