Skip to content

fix(agent-runtime): never wipe chat history on compaction - #1167

Closed
nordicnode wants to merge 9050 commits into
CodebuffAI:mainfrom
nordicnode:oss/compaction-wipe-1166
Closed

fix(agent-runtime): never wipe chat history on compaction#1167
nordicnode wants to merge 9050 commits into
CodebuffAI:mainfrom
nordicnode:oss/compaction-wipe-1166

Conversation

@nordicnode

@nordicnode nordicnode commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Two verified paths could replace the model's entire context with nothing (issue #1166, from the "Model losing all chat history instead of compacting" reports):

  • /compact with an empty model response — the replacement summary was built from fullResponse without an emptiness check, and a silent empty stop yields no recovery chunk, so the whole history was replaced by a single message carrying nothing. Now the replacement only happens when the model actually produced a summary; otherwise the history is kept (the forced next step retries) and a warning is logged.
  • Summary identity by content — a user message quoting the summary markers matched isConversationSummary, so findLast picked the quote over the real summary and the real summary was neither re-parsed nor kept: every earlier turn vanished at the next compaction. Summaries are now stamped with a CONVERSATION_SUMMARY tag and recognized by provenance; a legacy fallback requires the full envelope (open+close tag, header, <historical_memory>) so pre-tag summaries still fold in. The context-pruner's inlined copy — which matched the bare tag alone, wiping memory on any message that merely mentioned the tag — gets the same treatment, closing the parity test's second deliberate divergence.

Regression tests for both mechanisms, including the exact steal shape (tag + header quote with no memory block) and the legacy-envelope case. The parity test now asserts BOTH implementations keep a tag-mentioning user message.

Validation

  • bun test packages/agent-runtime/src/__tests__/compact-history.test.ts packages/agent-runtime/src/__tests__/context-pruner-parity.test.ts packages/agent-runtime/src/__tests__/main-prompt.test.ts (55 pass, 7 new/updated)
  • Verified the new /compact test fails without the guard by stashing run-agent-step.ts
  • bun test packages/agent-runtime (only the 2 pre-existing prompts-schema-handling failures and 2 pre-existing agents-graveyard module-not-found errors remain — same on main)
  • bunx tsc --noEmit -p agents/tsconfig.json clean

Fixes #1166

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction paths can wipe the entire chat history instead of compacting it

2 participants