fix(agent): assistant-attributed compaction summaries + hardened failure paths#48
Merged
Conversation
…n failure paths Summaries are model-generated, so both compaction paths now emit a user-request + assistant-summary pair instead of a single user message (the synthetic user turn keeps providers without prefill support happy). Also fixes two issues surfaced while verifying the change live: - Compaction thrash: a previous summary pair no longer counts toward the summarize threshold, and summarization is skipped up front when it cannot shrink history — previously a compacted history sat just below the trigger and re-fired an LLM call on nearly every turn. - Mid-stream failures: both SummarizeCompactor and tree.Compact drained provider streams collecting only text, ignoring ErrorDelta. A rate limit after stream-open could silently replace real history with a truncated or empty summary. The compactor now falls back to full history; tree.Compact returns an error and leaves the branch intact. Verified end to end against live OpenAI (compaction shape, recall across two summary generations, consecutive-assistant acceptance) and a live 429-ing provider (fallbacks hold).
Resolved conflict in agent/tree/compact.go: main moved compaction node creation into a single WAL transaction; the summary request node now joins the summary node in that transaction's newNodes list.
golangci-lint's gocyclo flagged (*Tree).Compact at complexity 33 (> 30). Move shared-node collection and provider summarization into sharedNodesUnlocked and summarizeMessages with no behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
SummarizeCompactorandtree.Compact) now emit a user-request + assistant-summary pair instead of a single user message. The summary text is model-generated, so it belongs on an assistant turn; the synthetic user turn (types.SummaryRequestText) precedes it because some providers reject histories whose first non-system message is from the assistant (no prefill support). Adds atypes.NewAssistantMessageconstructor.1 + 2 + KeepLastmessages) sat just below the trigger and re-fired a summarization LLM call on nearly every turn.ErrorDelta, so a rate limit arriving after stream-open could silently replace real history with a truncated/empty summary.SummarizeCompactornow falls back to full history on mid-stream error or empty summary;tree.Compactreturns an error and leaves the original branch active and intact.Test plan
go build ./...,go vet ./...,go test ./...— all packages greengo test -count=1 ./agent/...— integration tests fresh, no cachejust validate— live validation harness, all 8 scenarios PASS against a real model (report regenerated in this PR)tree.Compacterrors withmainintact