feat: triple-layer post-compaction context enforcement#18049
feat: triple-layer post-compaction context enforcement#18049steipete merged 7 commits intoopenclaw:mainfrom
Conversation
- Add readWorkspaceContextForSummary() to extract Session Startup + Red Lines from AGENTS.md - Inject workspace context into compaction summary (limited to 2000 chars) - Export extractSections() from post-compaction-context.ts for reuse - Ensures compaction summary includes core rules needed for recovery Part 1 of post-compaction context injection feature.
Windows path.relative() produces backslashes (e.g., memory\2026-02-16.md)
which fail to match RegExp patterns using forward slashes.
Normalize relative paths to forward slashes before RegExp matching
using rel.split(path.sep).join('/').
Fixes 4 test failures on Windows CI.
|
acciedentially merged this but it's problematic:
will revert |
|
@steipete Hey, thanks for the detailed review on the I actually spotted these bugs shortly after submitting the PR, but I was hit by AI model rate limits at the time and couldn't get my agent system to work on fixes (I work on a strict "AI-only, zero manual coding" principle 😅). When the rate limits finally cleared, I did a full audit:
I'm working on a fix for Bug 1 now and will submit a new PR shortly. On a personal note — this was my very first time using GitHub to submit issues and PRs, so I'm still learning. It's also Chinese New Year right now, which added to the delay. Since then I've set up a full HA multi-model setup with four providers (Claude, Gemini, GPT-5.x, MiniMax) with task-type routing, so I should be able to keep contributing going forward. Thank you for open-sourcing OpenClaw — it got me back into programming after 20+ years away from code. Turns out directing AI workers is a pretty fun way to build things! |
|
Quick follow-up: I've submitted #18914 to fix Bug 1 ( I'm aware that upstream's compaction safeguard in |
Add notifyOnStart and notifyOnStartText fields to AgentCompactionConfig so users receive a message the moment auto-compaction begins, resolving the UX problem where the interface appears frozen or shows red errors with no context. Changes: - src/config/types.agent-defaults.ts: add notifyOnStart (boolean) and notifyOnStartText (string) to AgentCompactionConfig - src/config/zod-schema.agent-defaults.ts: add corresponding Zod fields inside the .strict() compaction object - src/auto-reply/reply/agent-runner-execution.ts: add onCompactionStart optional callback to runAgentTurnWithFallback params; call it when the Pi runtime fires compaction:phase=start - src/auto-reply/reply/agent-runner.ts: build and pass onCompactionStart callback that reads cfg.agents.defaults.compaction.notifyOnStart and delivers via opts.onBlockReply when enabled - src/config/config.compaction-settings.test.ts: 5 new tests covering true/false/undefined and schema rejection of invalid types - src/auto-reply/reply/agent-runner.compaction-notify.test.ts: 5 new agent-runner integration tests (default text, custom text, false, undefined, end-only event) - docs/concepts/compaction.md: document the new config fields - docs/reference/session-management-compaction.md: add implementation reference section Extends openclaw#18049 (triple-layer post-compaction context enforcement). Default: notifyOnStart is false (opt-in, no behaviour change for existing users).
Add notifyOnStart and notifyOnStartText fields to AgentCompactionConfig so users receive a message the moment auto-compaction begins, resolving the UX problem where the interface appears frozen or shows red errors with no context. Changes: - src/config/types.agent-defaults.ts: add notifyOnStart (boolean) and notifyOnStartText (string) to AgentCompactionConfig - src/config/zod-schema.agent-defaults.ts: add corresponding Zod fields inside the .strict() compaction object - src/auto-reply/reply/agent-runner-execution.ts: add onCompactionStart optional callback to runAgentTurnWithFallback params; call it when the Pi runtime fires compaction:phase=start - src/auto-reply/reply/agent-runner.ts: build and pass onCompactionStart callback that reads cfg.agents.defaults.compaction.notifyOnStart and delivers via opts.onBlockReply when enabled - src/config/config.compaction-settings.test.ts: 5 new tests covering true/false/undefined and schema rejection of invalid types - src/auto-reply/reply/agent-runner.compaction-notify.test.ts: 5 new agent-runner integration tests (default text, custom text, false, undefined, end-only event) - docs/concepts/compaction.md: document the new config fields - docs/reference/session-management-compaction.md: add implementation reference section Extends openclaw#18049 (triple-layer post-compaction context enforcement). Default: notifyOnStart is false (opt-in, no behaviour change for existing users).
Add notifyOnStart and notifyOnStartText fields to AgentCompactionConfig so users receive a message the moment auto-compaction begins, resolving the UX problem where the interface appears frozen or shows red errors with no context. Changes: - src/config/types.agent-defaults.ts: add notifyOnStart (boolean) and notifyOnStartText (string) to AgentCompactionConfig - src/config/zod-schema.agent-defaults.ts: add corresponding Zod fields inside the .strict() compaction object - src/auto-reply/reply/agent-runner-execution.ts: add onCompactionStart optional callback to runAgentTurnWithFallback params; call it when the Pi runtime fires compaction:phase=start - src/auto-reply/reply/agent-runner.ts: build and pass onCompactionStart callback that reads cfg.agents.defaults.compaction.notifyOnStart and delivers via opts.onBlockReply when enabled - src/config/config.compaction-settings.test.ts: 5 new tests covering true/false/undefined and schema rejection of invalid types - src/auto-reply/reply/agent-runner.compaction-notify.test.ts: 5 new agent-runner integration tests (default text, custom text, false, undefined, end-only event) - docs/concepts/compaction.md: document the new config fields - docs/reference/session-management-compaction.md: add implementation reference section Extends openclaw#18049 (triple-layer post-compaction context enforcement). Default: notifyOnStart is false (opt-in, no behaviour change for existing users).
Add notifyOnStart and notifyOnStartText fields to AgentCompactionConfig so users receive a message the moment auto-compaction begins, resolving the UX problem where the interface appears frozen or shows red errors with no context. Changes: - src/config/types.agent-defaults.ts: add notifyOnStart (boolean) and notifyOnStartText (string) to AgentCompactionConfig - src/config/zod-schema.agent-defaults.ts: add corresponding Zod fields inside the .strict() compaction object - src/auto-reply/reply/agent-runner-execution.ts: add onCompactionStart optional callback to runAgentTurnWithFallback params; call it when the Pi runtime fires compaction:phase=start - src/auto-reply/reply/agent-runner.ts: build and pass onCompactionStart callback that reads cfg.agents.defaults.compaction.notifyOnStart and delivers via opts.onBlockReply when enabled - src/config/config.compaction-settings.test.ts: 5 new tests covering true/false/undefined and schema rejection of invalid types - src/auto-reply/reply/agent-runner.compaction-notify.test.ts: 5 new agent-runner integration tests (default text, custom text, false, undefined, end-only event) - docs/concepts/compaction.md: document the new config fields - docs/reference/session-management-compaction.md: add implementation reference section Extends openclaw#18049 (triple-layer post-compaction context enforcement). Default: notifyOnStart is false (opt-in, no behaviour change for existing users).
Add notifyOnStart and notifyOnStartText fields to AgentCompactionConfig so users receive a message the moment auto-compaction begins, resolving the UX problem where the interface appears frozen or shows red errors with no context. Changes: - src/config/types.agent-defaults.ts: add notifyOnStart (boolean) and notifyOnStartText (string) to AgentCompactionConfig - src/config/zod-schema.agent-defaults.ts: add corresponding Zod fields inside the .strict() compaction object - src/auto-reply/reply/agent-runner-execution.ts: add onCompactionStart optional callback to runAgentTurnWithFallback params; call it when the Pi runtime fires compaction:phase=start - src/auto-reply/reply/agent-runner.ts: build and pass onCompactionStart callback that reads cfg.agents.defaults.compaction.notifyOnStart and delivers via opts.onBlockReply when enabled - src/config/config.compaction-settings.test.ts: 5 new tests covering true/false/undefined and schema rejection of invalid types - src/auto-reply/reply/agent-runner.compaction-notify.test.ts: 5 new agent-runner integration tests (default text, custom text, false, undefined, end-only event) - docs/concepts/compaction.md: document the new config fields - docs/reference/session-management-compaction.md: add implementation reference section Extends openclaw#18049 (triple-layer post-compaction context enforcement). Default: notifyOnStart is false (opt-in, no behaviour change for existing users).
Add notifyOnStart and notifyOnStartText fields to AgentCompactionConfig so users receive a message the moment auto-compaction begins, resolving the UX problem where the interface appears frozen or shows red errors with no context. Changes: - src/config/types.agent-defaults.ts: add notifyOnStart (boolean) and notifyOnStartText (string) to AgentCompactionConfig - src/config/zod-schema.agent-defaults.ts: add corresponding Zod fields inside the .strict() compaction object - src/auto-reply/reply/agent-runner-execution.ts: add onCompactionStart optional callback to runAgentTurnWithFallback params; call it when the Pi runtime fires compaction:phase=start - src/auto-reply/reply/agent-runner.ts: build and pass onCompactionStart callback that reads cfg.agents.defaults.compaction.notifyOnStart and delivers via opts.onBlockReply when enabled - src/config/config.compaction-settings.test.ts: 5 new tests covering true/false/undefined and schema rejection of invalid types - src/auto-reply/reply/agent-runner.compaction-notify.test.ts: 5 new agent-runner integration tests (default text, custom text, false, undefined, end-only event) - docs/concepts/compaction.md: document the new config fields - docs/reference/session-management-compaction.md: add implementation reference section Extends openclaw#18049 (triple-layer post-compaction context enforcement). Default: notifyOnStart is false (opt-in, no behaviour change for existing users).
After session compaction, agents often skip their configured startup sequence because the compaction summary creates a false 'I already know everything' illusion.
This PR implements triple-layer enforcement to ensure post-compaction recovery:
Layer 1: Summary Append
Append critical workspace rules (AGENTS.md Session Startup + Red Lines) into the compaction summary via
<workspace-critical-rules>tags. 100% reliable — rules are physically in the prompt.Layer 2: System Event
Inject workspace context as a system event for the next agent turn after compaction. Explicit reminder to execute startup sequence.
Layer 3: Post-Turn Audit
After the agent's first post-compaction turn, audit whether required files were actually read. If not, inject a one-time warning listing missing files. Max 1 retry to prevent loops.
Changes
src/agents/pi-extensions/compaction-safeguard.ts— Layer 1: append workspace context to summarysrc/auto-reply/reply/agent-runner.ts— Layer 2 + 3: system event injection + audit integrationsrc/auto-reply/reply/post-compaction-context.ts— reads and formats AGENTS.md sectionssrc/auto-reply/reply/post-compaction-audit.ts— audits post-compaction file readssrc/auto-reply/reply/post-compaction-context.test.ts— tests for context extractionsrc/auto-reply/reply/post-compaction-audit.test.ts— tests for read auditDesign decisions
enqueueSystemEvent()infrastructureextractSectionshandles H2/H3, case-insensitive, code-block awareFixes #18023