openclaw/src/context-engine
Josh Lehman 75e7fc97f8
fix: preserve runtime token budget in deferred context-engine maintenance (#66820)
* fix(context-engine): pass deferred maintenance token budget

Thread tokenBudget through the after-turn runtime context so background context-engine maintenance reuses the real model context window instead of falling back to 128k. Also pass through a best-effort currentTokenCount from the latest call total and make the runtime context type explicit about both fields.

Regeneration-Prompt: |
  OpenClaw already passed the real context token budget into direct context-engine calls like afterTurn and assemble, but deferred maintain() reused only the runtimeContext object and that object did not carry tokenBudget. Lossless Claw therefore fell back to 128k during background maintenance, which made budget-trigger fire much more aggressively than the live model context warranted. Thread the real contextTokenBudget into buildAfterTurnRuntimeContext so deferred maintenance receives the same budget, and pass a straightforward best-effort currentTokenCount from the latest call total while the relevant data is already in scope. Keep the change additive, update the runtime-context type, and cover the background maintenance/runtime-context behavior with focused tests.

* fix(context-engine): use prompt usage for deferred maintenance
2026-04-14 15:30:37 -07:00
..
context-engine.test.ts fix: validate resolved context engine contracts (#63222) 2026-04-13 07:39:34 -07:00
delegate.ts fix: use literal runtime import for compaction 2026-04-12 18:56:27 +01:00
index.ts fix(cycles): bulk extract leaf type surfaces 2026-04-11 13:26:50 +01:00
init.ts fix(cycles): bulk extract leaf type surfaces 2026-04-11 13:26:50 +01:00
legacy.registration.ts fix(context-engine): bundle legacy runtime registration 2026-04-12 00:22:32 +01:00
legacy.ts fix(cycles): bulk extract leaf type surfaces 2026-04-11 13:26:50 +01:00
registry.ts fix: validate resolved context engine contracts (#63222) 2026-04-13 07:39:34 -07:00
types.ts fix: preserve runtime token budget in deferred context-engine maintenance (#66820) 2026-04-14 15:30:37 -07:00