fix(agents): reorder workspace AGENTS.md template to put load-bearing rules first#75248
fix(agents): reorder workspace AGENTS.md template to put load-bearing rules first#75248lonexreb wants to merge 4 commits intoopenclaw:mainfrom
Conversation
|
Codex review: needs changes before merge. Summary Reproducibility: yes. Current main reproduces by stripping docs/reference/templates/AGENTS.md front matter and applying the current maxChars=1500 bootstrap trim: the 1044-char head drops Tools, Red Lines, and External vs Internal. Next step before merge Security Review findings
Review detailsBest possible solution: Land this narrow template-ordering fix after adding the required changelog bullet, leaving broader tiered or priority-aware bootstrap loading to #22438 and #22439. Do we have a high-confidence way to reproduce the issue? Yes. Current main reproduces by stripping docs/reference/templates/AGENTS.md front matter and applying the current maxChars=1500 bootstrap trim: the 1044-char head drops Tools, Red Lines, and External vs Internal. Is this the best way to solve the issue? No, not as currently submitted. The template reorder plus body-text regression test is the narrow maintainable fix for #75187, but the PR still needs the required Unreleased changelog entry before merge. Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against d583662fd905. |
…t head window Codex review on PR openclaw#75248 noted that the prior reorder still left `## Tools` starting at char ~1110 in the stripped template, outside the bootstrap trimmer's effective ~1044-char head window at agents.defaults.bootstrapMaxChars=1500 (0.75 head ratio of contentBudget after marker reservation). The injected content kept `Red Lines` and `External vs Internal` but dropped `Tools` along with the tool-dispatch guidance, so the issue's small-model failure mode would persist. Restructure the workspace AGENTS.md template: - Move `## Tools` directly after `## Session Startup` so its body appears in the head window. Add an explicit `Tool dispatch:` rule (emit real structured tool calls, fix args on error rather than repeating). - Condense `## Session Startup` from a multi-list block into a single paragraph, freeing room before `## Tools` without losing semantics. - Split the secondary `Voice Storytelling` and `Platform Formatting` bullets out into a new `## Tool Notes` section lower in the file. They remain available in the full file but no longer crowd the head budget. Section starts (post-frontmatter): First Run @72, Session Startup @220, Tools @555, Red Lines @846, External vs Internal @1021. All four load-bearing sections now sit inside the 1044-char head budget. Add a regression in pi-embedded-helpers.buildbootstrapcontextfiles.test.ts that runs the actual stripped template through buildBootstrapContextFiles with maxChars=1500 and asserts the truncation marker fires and the injected content contains `## Tools`, `Tool dispatch:`, `## Red Lines`, and `## External vs Internal`. This covers the real bootstrap injection path the prior section-order tests did not exercise. Refs openclaw#75187
|
Thanks for the review — that was the bug. Force-pushed 205e83e which addresses the trimmer head-budget gap directly. What changed:
New section starts (post-frontmatter): First Run @72, Session Startup @220, Tools @555, Red Lines @846, External vs Internal @1021. All four load-bearing sections now sit inside the 1044-char head budget. New regression test in
Acceptance criteria checked locally:
PTAL. |
…head window Codex round-2 review on PR openclaw#75248 noted that even after moving `## Tools` into the head, `## External vs Internal` heading landed at char 1018 but its safe/ask body bullets started at char 1067 — outside the trimmer's ~1044-char head window at `bootstrapMaxChars: 1500`. The injected content kept the heading but lost the safe/ask policy bullets the issue explicitly needs preserved, and the regression test only checked headings. Restructure further: - Reorder so `## External vs Internal` comes immediately after `## Tools` (before `## Red Lines`). With its smaller body, External vs Internal now sits entirely below the head boundary. - Condense External vs Internal from per-bullet lists to inline paragraphs. The "safe / ask first" semantics are unchanged but the section is ~100 chars shorter. - Condense `## Session Startup` and the lead-in for `## Tools` so the cumulative chars before Red Lines drop low enough to keep its first rule ("Don't exfiltrate private data") in head as well. New section starts (post-frontmatter): First Run @72, Session Startup @220, Tools @477, External vs Internal @742 (Safe body @767, Ask body @879), Red Lines @1003 (first bullet @1017). Tools dispatch rule, External vs Internal safe + ask bullets, and the first Red Lines rule all fit inside the 1044-char head window. Tighten the regression in pi-embedded-helpers.buildbootstrapcontextfiles test from heading-only assertions to body-text assertions: `structured tool calls`, `Safe to do freely:`, `search the web`, `Ask first:`, `anything that leaves the machine`, and `exfiltrate private data` must all survive injection at `maxChars: 1500`. This catches the exact failure mode the round-2 review highlighted. Refs openclaw#75187
|
Round-2 review addressed in 1e5fc71. The bot was right — Changes:
New section starts (post-frontmatter):
Tightened the regression in
All must survive Acceptance criteria checked locally:
PTAL. |
… rules first The auto-generated AGENTS.md template wrote less critical content (Memory, Group Chats, Heartbeats) ahead of the load-bearing safety and tool-use guidance (Red Lines, External vs Internal, Tools). Users lowering agents.defaults.bootstrapMaxChars to fit small/mid model context budgets got head-truncation that stripped exactly the rules small models need to reliably emit structured tool calls. Reorder so First Run -> Session Startup -> Red Lines -> External vs Internal -> Tools come ahead of Memory/Group Chats/Heartbeats. The post-compaction config already names 'Session Startup' and 'Red Lines' as the priority sections to re-inject, so this reordering aligns the freshly seeded workspace template with the existing post-compaction priority contract. Refs openclaw#75187
…t head window Codex review on PR openclaw#75248 noted that the prior reorder still left `## Tools` starting at char ~1110 in the stripped template, outside the bootstrap trimmer's effective ~1044-char head window at agents.defaults.bootstrapMaxChars=1500 (0.75 head ratio of contentBudget after marker reservation). The injected content kept `Red Lines` and `External vs Internal` but dropped `Tools` along with the tool-dispatch guidance, so the issue's small-model failure mode would persist. Restructure the workspace AGENTS.md template: - Move `## Tools` directly after `## Session Startup` so its body appears in the head window. Add an explicit `Tool dispatch:` rule (emit real structured tool calls, fix args on error rather than repeating). - Condense `## Session Startup` from a multi-list block into a single paragraph, freeing room before `## Tools` without losing semantics. - Split the secondary `Voice Storytelling` and `Platform Formatting` bullets out into a new `## Tool Notes` section lower in the file. They remain available in the full file but no longer crowd the head budget. Section starts (post-frontmatter): First Run @72, Session Startup @220, Tools @555, Red Lines @846, External vs Internal @1021. All four load-bearing sections now sit inside the 1044-char head budget. Add a regression in pi-embedded-helpers.buildbootstrapcontextfiles.test.ts that runs the actual stripped template through buildBootstrapContextFiles with maxChars=1500 and asserts the truncation marker fires and the injected content contains `## Tools`, `Tool dispatch:`, `## Red Lines`, and `## External vs Internal`. This covers the real bootstrap injection path the prior section-order tests did not exercise. Refs openclaw#75187
…head window Codex round-2 review on PR openclaw#75248 noted that even after moving `## Tools` into the head, `## External vs Internal` heading landed at char 1018 but its safe/ask body bullets started at char 1067 — outside the trimmer's ~1044-char head window at `bootstrapMaxChars: 1500`. The injected content kept the heading but lost the safe/ask policy bullets the issue explicitly needs preserved, and the regression test only checked headings. Restructure further: - Reorder so `## External vs Internal` comes immediately after `## Tools` (before `## Red Lines`). With its smaller body, External vs Internal now sits entirely below the head boundary. - Condense External vs Internal from per-bullet lists to inline paragraphs. The "safe / ask first" semantics are unchanged but the section is ~100 chars shorter. - Condense `## Session Startup` and the lead-in for `## Tools` so the cumulative chars before Red Lines drop low enough to keep its first rule ("Don't exfiltrate private data") in head as well. New section starts (post-frontmatter): First Run @72, Session Startup @220, Tools @477, External vs Internal @742 (Safe body @767, Ask body @879), Red Lines @1003 (first bullet @1017). Tools dispatch rule, External vs Internal safe + ask bullets, and the first Red Lines rule all fit inside the 1044-char head window. Tighten the regression in pi-embedded-helpers.buildbootstrapcontextfiles test from heading-only assertions to body-text assertions: `structured tool calls`, `Safe to do freely:`, `search the web`, `Ask first:`, `anything that leaves the machine`, and `exfiltrate private data` must all survive injection at `maxChars: 1500`. This catches the exact failure mode the round-2 review highlighted. Refs openclaw#75187
…template H2 parser
1e5fc71 to
913398a
Compare
Bug being fixed
Closes #75187
The auto-generated
docs/reference/templates/AGENTS.md(used by the workspace bootstrap to seed~/.openclaw/workspace/AGENTS.md) ordered content with personality/onboarding guidance at the top and the load-bearing## Red Lines,## External vs Internal, and## Toolsguidance at the bottom.When a user lowers
agents.defaults.bootstrapMaxChars(typical for small/mid local models — Hermes-3 8B, Qwen3 8B — to fit a tight context budget), bootstrap-budget head-truncates the file. With the old order, that stripped exactly the safety + tool-dispatch rules the model needed, while preserving the less operationally-critical Memory/Group Chats/Heartbeats sections. The reporter's vLLM repro showed 0 structuredtool_callevents vs. 1 successful structured tool call after manually rewritingAGENTS.mdto put tool-use guidance at the top — same model, same parser, samebootstrapMaxChars, content order was the only difference.Fix
Reorder
docs/reference/templates/AGENTS.mdso the section sequence is:Section content is unchanged byte-for-byte — only the H2 ordering moves. Path #1 ("Quickest win — reorder the auto-generated AGENTS.md template content") in the issue's recommended resolution order.
This aligns the seeded workspace template with the existing post-compaction priority contract:
agents.defaults.compactionAgentsMdReinjectionSectionsalready namesSession StartupandRed Linesas the priority sections to re-inject after compaction. Putting them at the top of the seeded file means head-truncation now matches that same priority instead of fighting it.Why this is the best fix
AGENTS.mdfiles are not rewritten; this only affects newly-seeded workspaces (andopenclaw doctor --fix --regenerate-bootstrap-filesflows when applicable).bootstrapMaxChars=20000+ verbose auto-generated bootstrap content degrades tool dispatch on small/mid models #75189 (verbose default content) and feat: Tiered bootstrap file loading for progressive context control #22438 / feat(workspace): add tiered bootstrap loading with configurable bootstrapTier #22439 (tiered bootstrap loading); paths Login fails with 'WebSocket Error (socket hang up)' ECONNRESET #2 and WA business, groups & office hours #3 in the issue's recommended order remain valid future work on top of this base fix.agents.defaults.compactionAgentsMdReinjectionSections.Test plan
pnpm test src/agents/workspace-templates.test.ts— 4 new regression tests pass (Red Lines / External vs Internal / Tools all assert ahead of Memory + Group Chats; First Run / Session Startup stay at the top).pnpm test src/agents/workspace.test.ts src/agents/system-prompt-stability.test.ts— 25 + 4 existing tests pass.pnpm exec oxfmt --check— clean.pnpm tsgo:core+pnpm tsgo:core:test— clean.pnpm lint:core) failure onoxlintconfig is pre-existing onorigin/main(Rule 'no-underscore-dangle' not found in plugin 'eslint'), unrelated to this PR.#75187