fix: prevent fallback truncation summaries in compaction#79
Open
cryptomaltese wants to merge 1 commit intoMartian-Engineering:mainfrom
Open
fix: prevent fallback truncation summaries in compaction#79cryptomaltese wants to merge 1 commit intoMartian-Engineering:mainfrom
cryptomaltese wants to merge 1 commit intoMartian-Engineering:mainfrom
Conversation
|
I've run into this a few time, makes it hard to judge if lcm is working at all. |
832133c to
6ac7145
Compare
Replace the three-level summarization escalation (normal → aggressive → deterministic truncation) with a two-level approach that returns null on failure instead of creating garbage summaries. When both normal and aggressive summarization fail to compress below the input token count, the compaction engine now bails and retries on the next turn. This prevents useless '[Truncated from N tokens]' summaries from polluting the DAG — particularly for media-only messages where the stored text content is just a file path (~28 tokens) that no LLM can compress further. Changes: - Remove truncation fallback in summarizeWithEscalation() — return null on compression failure (callers already handle null since upstream) - Wrap summarizer calls in try/catch to handle LLM errors gracefully - Add 'level' column to summaries table (normal/aggressive/fallback) with migration and backfill from compaction event metadata - Add SummaryRecord.level to store types - Add lcm_repair tool to scan/re-summarize existing fallback summaries - Register repair tool in plugin entry point
6ac7145 to
e468037
Compare
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.
Lossless-Claw PR: Fallback Summarization Fix
Overview
This PR addresses a critical bug in the lossless-claw plugin where the LLM summarizer failures (403 errors, timeouts, etc.) trigger a "fallback truncation" that creates useless ~909-token garbage summaries. These summaries pollute the context DB and provide no value for future turns.
The fix: Instead of truncating to garbage, skip compaction entirely and retry on the next turn. This forces the system to maintain meaningful context while waiting for the summarizer to recover.
Problem
Current (Broken) Behavior
When
CompactionEngine.summarizeWithEscalation()encounters:...it falls back to:
This creates:
[Truncated from N tokens]) that flags the garbageImpact
Solution
1. Add
levelColumn tosummariesTableFile:
src/db/migration.tsValues:
'normal'(default) — summary created with normal mode (good compression)'aggressive'— summary created with aggressive mode (aggressive but good compression)'fallback'— deprecated escalation — should never be set by new codeBackfill:
message_partswithpart_type='compaction'forlevel='fallback'eventscreatedSummaryIdsfrom metadata JSONlevel='fallback'in the DB[Truncated fromcanary and flag as fallback (future work)Migration flow:
2. Fix Fallback Behavior in
compaction.tsFile:
src/compaction.tsNew
summarizeWithEscalation()signature:Behavior changes:
Phase 1: Normal mode
summarize(sourceText, false, options){ failed: true, error: "..." }immediatelyPhase 2: Aggressive mode (only if normal didn't compress well)
summarize(sourceText, true, options){ failed: true, error: "..." }immediately{ failed: true, error: "..." }No Phase 3 (no fallback truncation)
Caller changes:
Both
leafPass()andcondensedPass()must handle null returns:In
compactLeaf()andcompactFullSweep():3. Migration Script
File:
src/db/migration.ts→function backfillSummaryLevels()4.
lcm repairCommandFile:
src/tools/lcm-repair-command.ts→LcmRepairEngineResponsibility:
level='fallback'or truncation canarysummarize.ts)level='normal'Public interface:
Input:
Output:
Algorithm:
Find Phase:
summaries WHERE level = 'fallback'summaries WHERE content LIKE '%[Truncated from%'summary_idRepair Phase (if mode='repair'):
summarieswith new content, setlevel='normal'message_partsCascade Phase (future):
condensedPass()logic)Integration:
Register as a tool in
engine.ts:Testing Checklist
Unit Tests
summarizeWithEscalation()returns{ failed: true }on summarizer exceptionsummarizeWithEscalation()returns{ failed: true }when aggressive mode failsleafPass()returnsnullwhen summarization failscondensedPass()returnsnullwhen summarization failscompactLeaf()returnsactionTaken: falsewhen leafPass is nullcompactFullSweep()skips compaction on leafPass/condensedPass failuresIntegration Tests
levelcolumn with CHECK constraintmessage_parts.metadatalevel='fallback'on identified summarieslevel='normal'on fixed summariesManual Testing
Create test scenario:
Run repair in scan mode:
Expected: finds 1+ summaries
Run repair in repair mode:
Expected: re-summarizes and updates DB
Verify DB:
Expected:
level='normal', shorter content, lower token countImplementation Notes
Why Not "Lazy Fallback"?
Some might suggest: "Just mark it fallback and move on, repair later."
Problems:
Our approach:
Token Accounting
FALLBACK_MAX_CHARS = 512 * 4 = 2048 chars2048 / 4 = 512 tokensMigration Safety
ensureSummaryLevelColumn()checks for existing column → idempotentRepair Cascading
Future work: after re-summarizing leaves, check parent condensed summaries:
condensedPass()logicCurrently stubbed as
cascadeDepth: 0placeholder.Files Changed
src/db/migration.ts
levelcolumn with CHECK constraintensureSummaryLevelColumn()backfillSummaryLevels()runLcmMigrations()src/compaction.ts
SummarizationAttempttypesummarizeWithEscalation()with error handlingleafPass()to returnnullon failurecondensedPass()to returnnullon failuresrc/tools/lcm-repair-command.ts (NEW)
LcmRepairEngineclassfindFallbackSummaries()findTruncationCanaries()resummarizeLeaf()resummarizeCondensed()repair()main flowsrc/engine.ts
lcm_repairtool (one-liner)Backcompat & Migration
levelcolumn via down-migration (or just ignore it)Performance Impact
message_parts(fast)Future Work
Status: Draft PR for review
Target: lossless-claw v0.3.1+
Reviewer: @maltese
Related: GitHub issue #334-fallback-summaries