feat: add idle compaction trigger (idleCompactMinutes)#102
Open
drdotdot wants to merge 1 commit intoMartian-Engineering:mainfrom
Open
feat: add idle compaction trigger (idleCompactMinutes)#102drdotdot wants to merge 1 commit intoMartian-Engineering:mainfrom
drdotdot wants to merge 1 commit intoMartian-Engineering:mainfrom
Conversation
Add time-based compaction that triggers when a session has been idle beyond a configurable threshold. This addresses stale context in sessions that go through periods of inactivity (overnight, between work sessions). When enabled (idleCompactMinutes > 0), the first assemble() call after the idle threshold runs a lightweight leaf pass (15s timeout), followed by a forced full compaction cascade in afterTurn(). Changes: - Config: idleCompactMinutes option (env: LCM_IDLE_COMPACT_MINUTES, default: 0) - ConversationStore: getLastActivityTimestamp() filtering user/assistant roles - CompactionEngine: evaluateIdleTrigger() method - Engine: idle leaf pass in assemble() with 15s timeout + forced cascade in afterTurn() - Plugin schema + UI hints for new config key - Documentation with usage guidance and idle timer policy
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
Adds time-based compaction that triggers when a session has been idle beyond a configurable threshold (
idleCompactMinutes). This addresses stale context in sessions that go through periods of inactivity — overnight, between work sessions, or during long-running background jobs.Motivation
Currently, LCM only compacts when context exceeds the
contextThreshold(turn-based trigger). Sessions that accumulate significant context but never quite hit the threshold — or sessions that go idle for hours/days — can resume with stale, unorganized raw context. This is especially common in agentic workflows with periodic cron/watchdog messages.Idle compaction ensures returning users get lean, organized context instead of a wall of raw messages from hours ago.
Enables practical use of large context windows (1M tokens). With models like Gemini offering 1M-token context at no pricing premium, the turn-based threshold trigger alone isn't sufficient — sessions can accumulate hundreds of thousands of tokens of raw conversation over hours without ever hitting the 75% threshold. Idle compaction provides the missing time-based dimension: after periods of inactivity, context is proactively organized into the summary DAG regardless of size, keeping large-window sessions navigable and performant over long lifespans.
How it works
idleCompactMinutes(env:LCM_IDLE_COMPACT_MINUTES, default:0= disabled)getLastActivityTimestamp()queries the most recentuserorassistantmessage. Heartbeats (never ingested) don't reset the timer. SystemEvents and sub-agent completions do.compactLeaf()withforce: truebefore assembling context. Protected by a 15-second timeout to bound first-message latency.afterTurn()forces a full compaction sweep regardless of context threshold, ensuring the leaf pass doesn't leave the DAG in a partial state.Changes
src/db/config.tsidleCompactMinutestoLcmConfigtype andresolveLcmConfig()src/store/conversation-store.tsgetLastActivityTimestamp()methodsrc/compaction.tsevaluateIdleTrigger()methodsrc/engine.tsassemble(), forced cascade inafterTurn(), session tracking mapopenclaw.plugin.jsondocs/configuration.mdConfiguration
{ "plugins": { "entries": { "lossless-claw": { "config": { "idleCompactMinutes": 180 } } } } }Or via environment:
LCM_IDLE_COMPACT_MINUTES=180Idle timer policy
Testing
Tested in production OpenClaw deployment with
idleCompactMinutes: 180across multiple concurrent sessions (main, autoresearch, data collection). Gateway restart successful, config persisted, no errors in logs.Breaking changes
None. Default is
0(disabled). Existing behavior unchanged unless explicitly enabled.