fix(agent-runtime): never wipe chat history on compaction - #1167
Closed
nordicnode wants to merge 9050 commits into
Closed
fix(agent-runtime): never wipe chat history on compaction#1167nordicnode wants to merge 9050 commits into
nordicnode wants to merge 9050 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
/compactwith an empty model response — the replacement summary was built fromfullResponsewithout 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.isConversationSummary, sofindLastpicked 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 aCONVERSATION_SUMMARYtag 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)/compacttest fails without the guard by stashingrun-agent-step.tsbun test packages/agent-runtime(only the 2 pre-existingprompts-schema-handlingfailures and 2 pre-existingagents-graveyardmodule-not-found errors remain — same onmain)bunx tsc --noEmit -p agents/tsconfig.jsoncleanFixes #1166