Run context-engine turn maintenance as idle-aware background work#65233
Merged
jalehman merged 11 commits intoApr 13, 2026
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
Closes #65220.
This teaches context engines to opt into background turn maintenance and moves turn-triggered maintenance off the foreground session lane when
turnMaintenanceMode === "background". Forlossless-claw, that means proactive post-turn maintenance can be queued as a hidden task instead of blocking the next user turn.Why
afterTurn()andmaintain(... reason: "turn")inline on the session path.What Changed
turnMaintenanceMode?: "foreground" | "background"to context-engine info.allowDeferredCompactionExecution?: booleanto runtime context.runContextEngineMaintenance(... reason: "turn")now:allowDeferredCompactionExecution: trueGuarantees
Validation
pnpm test -- --run src/agents/pi-embedded-runner/context-engine-maintenance.test.ts src/infra/backoff.test.tspassedNODE_OPTIONS=--max-old-space-size=8192 pnpm exec tsc -p tsconfig.json --noEmitstill reports preexisting unrelated AbortSignal type errors in unchangedextensions/telegram/src/bot.tsCompanion Plugin Work
lossless-clawissue: Proactive threshold compaction can stall foreground turns and hide maintenance state Martian-Engineering/lossless-claw#407lossless-clawPR: Defer proactive compaction debt and surface LCM maintenance state Martian-Engineering/lossless-claw#408