cynarAI ea7892baa3
Compact chat history automatically before it outgrows the model (#225)
* Push agents to act when they end a turn announcing work

A local model often ends a turn with "let me set that up now" and no tool
call. Nothing runs after a turn ends, so the user waits on work that never
happens. A text-only turn that announces unfinished work now gets up to two
follow-ups that ask the agent to do it or report what is open.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011VfFvSskgrByEU75QLyreE

* Summarize project conversations and retry contended handoffs

Group threads, which hold every project's main conversation, were never
compacted. Runs there saw only the last 200 raw messages, so the original
brief and earlier decisions fell out of context. The lead bot now
summarizes them like a bot thread; the summary stays local.

A group handoff now retries when its transaction hits a deadlock, so a
specialist that finished its work no longer fails at the hand-back.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011VfFvSskgrByEU75QLyreE

* Compact chat history automatically before it outgrows the model

Long chats lost their brief and open work. The Pi runtime passed only the
last 25 history entries, and the compacted summary and recalled memory sat
in front of them, so both were cut whenever a chat had more than 24
uncompacted messages. Context pruning then dropped the summary first,
because it was the oldest history entry. Compaction itself only started
after 100 uncompacted messages and ignored tokens.

- History entries can be pinned. The executor pins the summary and recalled
  memory, the runtime always keeps them ahead of the recent window, and
  context pruning never drops them.
- Compaction is driven by messages and tokens: it keeps the newest ten
  messages verbatim and folds the rest into the summary once 20 messages
  are uncompacted or the history exceeds 40% of the model's input budget.
- Before a run whose history would not reach the model in full, the
  executor compacts inline for up to 90 seconds, then runs with what it has.
- The summarizer writes a structured summary: goal and brief, decisions,
  done, open, preferences.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QAiXRe1FLMAJT9jkvwFZFq

* Record runtime failures again instead of leaving the run running

A runtime error closes the stream through withRuntimeCleanup, which aborts
the run's own controller. The catch treated that as an outside stop and
returned without finalizing, so a failed run stayed running and the web
never showed its error. Same fix as on the main-green branch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QAiXRe1FLMAJT9jkvwFZFq

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-23 04:18:21 +02:00
..