fix(agents): defer bootstrap context-engine maintenance to background#90199
fix(agents): defer bootstrap context-engine maintenance to background#90199dripsmvcp wants to merge 1 commit into
Conversation
Bootstrap/reconcile context-engine maintenance runs foreground, where deferred compaction debt cannot execute (allowDeferredCompactionExecution is background-only) and no background follow-up is scheduled — only turns defer. So debt created when bootstrap imports tail messages past the leaf trigger is stranded, leaving sessions repeating "deferred compaction still needed" (issue openclaw#67716, Case 1). Extend the deferred-maintenance gate so reason="bootstrap" also schedules the existing background debt consumer for engines that opt into background maintenance (turnMaintenanceMode === "background"). Foreground bootstrap is unchanged for engines without background maintenance, and the plugin-owned hot-cache sticky-debt path (Case 2) is intentionally left out of scope. Closes openclaw#67716
|
Codex review: needs real behavior proof before merge. Reviewed June 4, 2026, 8:00 AM ET / 12:00 UTC. Summary PR surface: Source +4, Tests +61. Total +65 across 2 files. Reproducibility: yes. from source: current main runs bootstrap maintenance in foreground while only background execution sets Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the narrow bootstrap deferral only after redacted live bootstrap/reconcile logs or an explicit maintainer proof override confirms the background worker consumes the stranded debt; keep the plugin-owned hot-cache policy case out of this PR. Do we have a high-confidence way to reproduce the issue? Yes from source: current main runs bootstrap maintenance in foreground while only background execution sets Is this the best way to solve the issue? Yes for the code shape: reusing the existing deferred background maintenance lane for engines that already opt into background maintenance is the narrowest core fix I found. The merge-readiness gap is proof of the real bootstrap/reconcile scenario, not an alternate code repair. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 5ab430fa11ee. Label changesLabel justifications:
Evidence reviewedPR surface: Source +4, Tests +61. Total +65 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Summary
allowDeferredCompactionExecutionis background-only) and no background follow-up is scheduled (only turns defer). So debt created when bootstrap imports tail messages past the leaf trigger is stranded, leaving sessions repeatingdeferred compaction still needed(issue [Bug]: bootstrap/reconcile and hot-cache policy can leave deferred compaction debt stranded #67716, Case 1).reason="bootstrap"schedule the same background debt consumer turns already use, for engines that opt into background maintenance (turnMaintenanceMode === "background").Linked context
Closes #67716
Related #66820 — deferred-maintenance token budget (a different aspect of the same subsystem; not this scheduling gap).
Not maintainer-requested; selected from the
clawsweeper:queueable-fixbacklog. ClawSweeper's review of #67716 recommended exactly this OpenClaw-scoped fix: "extend the existing deferred-maintenance lifecycle so bootstrap/reconcile can schedule a valid background debt consumer," keeping plugin hot-cache/dedup policy out.Real behavior proof (required for external PRs)
runContextEngineMaintenancelifecycle — the deferred background worker, the task registry/queue, and the session lane — not mocked.node scripts/run-vitest.mjs src/agents/embedded-agent-runner/context-engine-maintenance.test.tsmain(bootstrap ran foreground and returned a maintenance result) and passes after the fix (bootstrap defers and the background worker runs):context_engine_turn_maintenancetask instead of running inline, and the deferred worker runsmaintain()withallowDeferredCompactionExecution: true(the debt can now be paid).crabbox check:changedgate). A maintainer with a live setup can confirm end-to-end, or applyproof: overridefor this logic-scoped scheduling fix.expected { ... } to be undefined) is the before-state from unfixedmain, where bootstrap ran foreground.How to capture live behavior proof on a real setup (for a maintainer or the reporter)
This needs the background-maintenance context engine (the Lossless-Claw / "LCM" engine from the issue, which sets
turnMaintenanceMode: "background"and emits theLCM compaction leaf passlines) plus a real provider — neither of which I can run in CI/sandbox. Steps:pnpm install && pnpm build; run the gateway with the LCM-configured agent and tail logs (./scripts/clawlog.sh).rawTokensOutsideTailpast the leaf trigger (issue [Bug]: bootstrap/reconcile and hot-cache policy can leave deferred compaction debt stranded #67716 Case 1).Before this fix the bootstrap window shows
deferred compaction debt pending ... allowDeferredCompactionExecution is disabled→deferred compaction skipped ... reason=deferred compaction still needed(stranded). After this fix it shows the core line[context-engine] deferred turn maintenance queued ... lane=context-engine-turn-maintenance:<key>during bootstrap (emitted atcontext-engine-maintenance.ts:619; previously only on turns) followed bycompactLeafAsync start→LCM compaction leaf pass→deferred compaction completed ... reason=compacted(paid). I will paste the redacted excerpt here once it is captured.Tests and validation
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/context-engine-maintenance.test.ts-> 23 passed (1 new).embedded-agent-runnerrename):attempt.spawn-workspace.context-engine.test.ts-> 56 passed;extensions/codex/src/app-server/run-attempt.context-engine.test.ts-> 24 passed;src/agents/harness/context-engine-lifecycle.test.ts-> 9 passed.tsgo -p tsconfig.core.jsonand core test types: no errors in the changed files (two unrelated pre-existing errors insrc/config/io.tsandsrc/secrets/config-io.tsare present onmain).Risk checklist
Current review state
status: 📣 needs proof).proof: overridefor this logic-scoped core scheduling fix in the meantime — ClawSweeper offered that path for exactly this case.