fix(post-compaction): support H1 headings in extractSections#67090
fix(post-compaction): support H1 headings in extractSections#67090xiaoyu-157 wants to merge 1 commit into
Conversation
Greptile SummaryThis PR fixes a silent failure in Confidence Score: 5/5Safe to merge — minimal, targeted regex fix with correct boundary logic and good test coverage. The change is a single-character quantifier adjustment that is fully additive. The default template uses H2 headings, so no existing deployment is broken. The boundary termination logic was already generalized, and all four new test cases correctly exercise the H1/H4 paths including nesting and termination. No P0 or P1 findings. No files require special attention. Reviews (1): Last reviewed commit: "fix(post-compaction): support H1 heading..." | Re-trigger Greptile |
|
@xiaoyu-157 Thanks for the fix attempt. Looking through the current code and docs, my reading is that the H2/H3 behavior here was intentional rather than an accidental omission. Right now this path is documented as extracting H2/H3 section names from AGENTS.md, and the shipped templates also use # for the document title with ## Session Startup / ## Red Lines as the extractable sections. So before we widen this parser, I want to understand the concrete case you’re trying to support. What AGENTS.md shape are you seeing in practice that needs H1 here? Was this from a real generated workspace / user workspace that broke after compaction, or is this based on a hypothetical Markdown layout? And separately, why expand to H4 as well instead of making the narrowest change needed? |
|
Codex review: needs real behavior proof before merge. Latest ClawSweeper review: 2026-05-19 22:39 UTC / May 19, 2026, 6:39 PM ET. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. for source-level parser behavior: current main matches only H2/H3, so H1/H4 headings are skipped. No for a high-confidence product bug, because the docs/help/template define H2/H3 and no real H1 workspace was supplied. PR rating Rank-up moves:
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. Real behavior proof Risk before merge
Maintainer options:
Next step before merge Security Review findings
Review detailsBest possible solution: End with a maintainer-approved heading-level contract where parser behavior, regression tests, config comments, generated help/schema text, and public docs agree; if a real H1 case is accepted, keep the accepted levels narrow and prove the runtime compaction path. Do we have a high-confidence way to reproduce the issue? Yes for source-level parser behavior: current main matches only H2/H3, so H1/H4 headings are skipped. No for a high-confidence product bug, because the docs/help/template define H2/H3 and no real H1 workspace was supplied. Is this the best way to solve the issue? No as proposed. The diff broadens shared runtime behavior to H1-H4 without settling the heading-level policy or updating all contract surfaces, so the safer path is maintainer approval followed by aligned code, docs, and proof. Label justifications:
Full review comments:
Overall correctness: patch is incorrect What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against ecb6da9289b1. |
|
Codex review: needs maintainer review before merge. What this changes: This PR widens post-compaction AGENTS.md section extraction from H2/H3 headings to H1-H4 headings and adds regression tests for H1/H4 matching plus H1 section boundaries and nested headings. Maintainer follow-up before merge: This is an open implementation PR with a small code diff, but the remaining blocker is maintainer judgment on whether to broaden the documented H2/H3 parser contract to H1 and possibly H4; an automated replacement PR should not decide that contract. Review detailsBest possible solution: End with a maintainer-approved heading-level contract where parser behavior, regression tests, config comments, generated help/schema text, and public docs agree. If a real H1 workspace case is accepted, narrow the implementation to the intended levels and update those surfaces together; otherwise retain the documented H2/H3 behavior and close manually as not planned. Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against acae48b790fa. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
Maintainer note: this overlaps the same post-compaction AGENTS.md surface as #45488, but it does not resolve the default-policy/session-bloat part of the report. Broadening heading extraction would keep the reinjection behavior enabled by default. I opened #85960 as the replacement path: post-compaction AGENTS.md reinjection becomes explicit opt-in, while configured users keep section extraction and the legacy fallback behavior. Treating this PR as superseded/not aligned once #85960 lands; not marking it as an exact duplicate of the implementation because the fix direction is different. |
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes #45488. Fixes #45649. Supersedes #67090.
|
Closing this as superseded by #85960, which landed the maintainer-approved policy fix: post-compaction AGENTS.md reinjection is now explicit opt-in, and configured users keep section extraction/legacy fallback behavior. This PR is not an exact duplicate because it broadens heading extraction, but it does not resolve the default-policy/session-bloat concern from #45488 and would keep reinjection enabled by default. New evidence for broader heading support can come back as a separate, explicitly scoped proposal with docs/config help aligned. |
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes openclaw#45488. Fixes openclaw#45649. Supersedes openclaw#67090.
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes openclaw#45488. Fixes openclaw#45649. Supersedes openclaw#67090.
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes openclaw#45488. Fixes openclaw#45649. Supersedes openclaw#67090.
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes openclaw#45488. Fixes openclaw#45649. Supersedes openclaw#67090.
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes openclaw#45488. Fixes openclaw#45649. Supersedes openclaw#67090.
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes openclaw#45488. Fixes openclaw#45649. Supersedes openclaw#67090.
Summary: - Make post-compaction AGENTS.md reinjection explicit opt-in for configured sections. - Carry the run workspace into compaction-safeguard AGENTS.md reads. - Improve collapsed Control UI tool rows while preserving raw expanded tool details. Verification: - CI green on PR head 9610166. - pnpm exec oxfmt --check --threads=1 <changed files> - OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs <changed ts/mjs files> - node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo - git diff --check origin/main...HEAD && git diff --check - node scripts/run-vitest.mjs src/agents/pi-hooks/compaction-safeguard.test.ts src/agents/pi-embedded-runner/extensions.test.ts -t "workspace" - node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts -t "reads opted-in post-compaction context" - node scripts/run-vitest.mjs test/scripts/test-projects.test.ts -t "allows explicit split Vitest config targets" - node scripts/run-vitest.mjs ui/src/ui/chat/tool-cards.test.ts ui/src/ui/chat/tool-cards.node.test.ts ui/src/ui/chat/grouped-render.test.ts ui/src/styles/chat/tool-cards.test.ts - AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode branch Fixes openclaw#45488. Fixes openclaw#45649. Supersedes openclaw#67090.
Summary
extractSectionsinpost-compaction-context.tsused the regex/^(#{2,3})\s+(.+?)\s*$/which only matched H2 (##) and H3 (###)headings. When a user writes their AGENTS.md with top-level H1 sections —
a very natural choice, e.g.
# Session Startup— the function silentlyreturns
[]andreadPostCompactionContextreturnsnull.The result: after every compaction, the agent loses all injected critical
instructions with zero warning to the user. The bug is particularly
insidious because the AGENTS.md template and docs do not enforce a
specific heading level.
Fix
Change the regex quantifier from
{2,3}to{1,4}to accept H1through H4 headings. The boundary termination logic (
level <= sectionLevel)already handles nesting correctly for any level — no further changes needed.
Testing
Added four new test cases:
# Session Startupis now extracted#### Session Startupis extractedAll existing tests continue to pass.
Impact
headings in AGENTS.md to lose post-compaction context injection