Repository navigation
feat(knowledge): agents can no longer grow pages past a read-sized budget, and can extract sections instead - #186270
Conversation
Page bodies now have a write-time size budget derived from one default knowledge_record read: hub pages (top link-degree percentile, default 90, with a 20-page and 10-link floor) get 12,000 characters, other pages twice that. Every page-body write is checked once at acceptance; growth past the budget returns a rejected receipt with section sizes and connected candidates, while same-size and shrinking edits always succeed. Claims are never gated. knowledge_extract_section moves one heading section to a new or connected page in one fenced publication, carrying links, quoted evidence and claim subjects, and leaving a summary line and link on the source. Co-authored-by: jalehman <[email protected]>
…dget, and can extract sections instead Worked on by: - @jalehman Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 34deb92f-04b7-44f3-bc8f-1a8eef59f5eb
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR limits Knowledge page-body growth and adds an atomic tool for extracting sections into other pages. Example: An agent appends 100 characters to a non-hub page containing 24,000 characters.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep open: this maintainer-directed feature remains useful and absent from main, but section extraction has three content-preservation defects that need repair. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe optional Knowledge memory plugin resolves callers to authorized store partitions, runs mutations in its storage worker, and publishes Markdown records through a SQLite-backed journal. flowchart LR
A[Agent tools] --> B[Scoped Knowledge service]
B --> C[Storage worker]
C --> D[Section preparation]
D --> E[Publication budget check]
E --> F[Journal and Markdown vault]
Technical reviewBest possible solution: Keep the centralized budget check, use the existing Markdown parser to preserve document context and exact non-link text, and leave semantic subject changes to explicit agent annotations. Do we have a high-confidence way to reproduce the issue? Current-main body edits have the existing record-byte ceiling but no read-sized page budget; the extraction failures are directly traceable through the introduced code, without executing target code. Is this the best way to solve the issue? The existing publication owner is the right enforcement boundary, but extraction should preserve parsed Markdown and established claim subjects rather than reconstructing their meaning through string matching. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9a0458cf6952. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +871, Tests +480, Docs +432, Generated 0. Total +1783 across 46 files. Added test files: 2. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 27, 2026, 4:23 PM ET / 20:23 UTC. |
…ge-budgets # Conflicts: # docs/.generated/config-baseline.sha256
Replace the untyped extract destination with ExtractSectionInput, drop assertions on static constants and unit cases the write-path tests already cover, and fold the extract failure paths into the round-trip test. Co-authored-by: jalehman <[email protected]>
Worked on by: - @jalehman Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 933115de-dfd9-4753-9ba8-39e84b852cb5
…ge-budgets # Conflicts: # docs/.generated/config-baseline.counts.json # docs/.generated/config-baseline.sha256 # docs/plugins/knowledge.md # extensions/knowledge/skills/knowledge-unlinked-claims/SKILL.md # extensions/knowledge/src/mutation-contract.ts # extensions/knowledge/src/storage-host.ts # extensions/knowledge/src/storage-publication.ts # extensions/knowledge/src/storage-types.ts
Main had 248 lines of slack at the merged commit; the page budget and section extraction tests add a net 338 lines. Co-authored-by: jalehman <[email protected]>
Worked on by: - @jalehman Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: b73fa91a-3541-49e2-828b-03f8372d914a
…ge-budgets # Conflicts: # config/test-lines-baseline.txt # docs/.generated/config-baseline.sha256
Worked on by: - @jalehman Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 21d5a543-8d39-43a4-a3cd-414c7708da1c
…88556) ## What Problem This Solves Knowledge currently walks valid store keys twice and makes an extra array copy before three explorer projections. Let the existing schema validator own key validation, and let filter/toSorted/toReversed provide the arrays they already allocate. ## User Impact No user-visible behavior change. The malformed-membership path still makes affected agents unavailable. Store-key syntax, membership/authority checks, sorting, rendering, pagination, and source-array ownership stay unchanged. No SQL, schema, SDK, or provider-request change. ## Why This Change Was Made The validated schema owns key syntax; the native array methods own the required copies. Keep those owners and delete the redundant work. ## Evidence ### Acceptance and counts This is a four-site cleanup, using the final-small-batch exception; production +4/-5 lines (net -1), net test lines unchanged. Count acceptance: one redundant key scan and its regex allocation removed; three explicit array copies removed. No wall-clock, CPU, SQL, or Gateway latency claim; no timing experiment. Existing nonmutating methods remain, with no new lint suppression. - Focused existing stores-config suite: 4/4 passed, including malformed-key invalidation, revision stability, policy rejection, and conversation grants. - Changed-file oxfmt, oxlint, and git diff --check passed. - Two isolated Codex P0–P2 reviews of the full four-file diff against 8f1ef6c: both scoped-clean; no findings. Initial temporary-directory preflight refusals were corrected before either reviewer executed. - Initial exact-head CI run 41097808042 exposed a storage-schema replacement-fixture failure (expected three indexes, got two). The unchanged file passes 10/10 on both base and candidate; inode reuse was not reproduced locally. Earlier fixture cleanup can leave freed inode IDs in the module admission set. The replacement test now uses a freshly imported owner, preserves both warm-file/replacement index assertions, and passes 10/10 locally. Net test lines remain zero. - One additional isolated Codex P0–P2 delta review found no actionable issue in the fixture repair; the final import alias also passes no-shadow lint. - Final exact-head CI 41099978168 at 31f0f63: all applicable test, type, lint, source-contract, architecture, extension-boundary and baseline-ratchet gates passed, including the previously failing extensions-config shard. Security/dependency review passed. GitHub status requests intermittently returned 502/504; no test rerun or bypass was used. Open-PR overlap comparison used base and candidate merge-tree output against #186270 (2a8f1cc) and #184755 (e1a7985). Conflict blocks are identical: 51→51 and 1→1 respectively; no new conflict. Final shared-index refresh also checked the test file and found no further peers. #186270 is now merged; the remaining open #184755 still has the identical single unrelated generated-baseline conflict. Broader scan candidates needing mutable-sort lint exceptions, uncertain input contracts, or another owner were retained rather than included here. Release-note context: reduce redundant Knowledge config validation and explorer array copying without changing user-visible behavior.
…enclaw#188556) ## What Problem This Solves Knowledge currently walks valid store keys twice and makes an extra array copy before three explorer projections. Let the existing schema validator own key validation, and let filter/toSorted/toReversed provide the arrays they already allocate. ## User Impact No user-visible behavior change. The malformed-membership path still makes affected agents unavailable. Store-key syntax, membership/authority checks, sorting, rendering, pagination, and source-array ownership stay unchanged. No SQL, schema, SDK, or provider-request change. ## Why This Change Was Made The validated schema owns key syntax; the native array methods own the required copies. Keep those owners and delete the redundant work. ## Evidence ### Acceptance and counts This is a four-site cleanup, using the final-small-batch exception; production +4/-5 lines (net -1), net test lines unchanged. Count acceptance: one redundant key scan and its regex allocation removed; three explicit array copies removed. No wall-clock, CPU, SQL, or Gateway latency claim; no timing experiment. Existing nonmutating methods remain, with no new lint suppression. - Focused existing stores-config suite: 4/4 passed, including malformed-key invalidation, revision stability, policy rejection, and conversation grants. - Changed-file oxfmt, oxlint, and git diff --check passed. - Two isolated Codex P0–P2 reviews of the full four-file diff against 5fe865c: both scoped-clean; no findings. Initial temporary-directory preflight refusals were corrected before either reviewer executed. - Initial exact-head CI run 41097808042 exposed a storage-schema replacement-fixture failure (expected three indexes, got two). The unchanged file passes 10/10 on both base and candidate; inode reuse was not reproduced locally. Earlier fixture cleanup can leave freed inode IDs in the module admission set. The replacement test now uses a freshly imported owner, preserves both warm-file/replacement index assertions, and passes 10/10 locally. Net test lines remain zero. - One additional isolated Codex P0–P2 delta review found no actionable issue in the fixture repair; the final import alias also passes no-shadow lint. - Final exact-head CI 41099978168 at 31f0f63: all applicable test, type, lint, source-contract, architecture, extension-boundary and baseline-ratchet gates passed, including the previously failing extensions-config shard. Security/dependency review passed. GitHub status requests intermittently returned 502/504; no test rerun or bypass was used. Open-PR overlap comparison used base and candidate merge-tree output against openclaw#186270 (2a8f1cc) and openclaw#184755 (e1a7985). Conflict blocks are identical: 51→51 and 1→1 respectively; no new conflict. Final shared-index refresh also checked the test file and found no further peers. openclaw#186270 is now merged; the remaining open openclaw#184755 still has the identical single unrelated generated-baseline conflict. Broader scan candidates needing mutable-sort lint exceptions, uncertain input contracts, or another owner were retained rather than included here. Release-note context: reduce redundant Knowledge config validation and explorer array copying without changing user-visible behavior.
…88556) ## What Problem This Solves Knowledge currently walks valid store keys twice and makes an extra array copy before three explorer projections. Let the existing schema validator own key validation, and let filter/toSorted/toReversed provide the arrays they already allocate. ## User Impact No user-visible behavior change. The malformed-membership path still makes affected agents unavailable. Store-key syntax, membership/authority checks, sorting, rendering, pagination, and source-array ownership stay unchanged. No SQL, schema, SDK, or provider-request change. ## Why This Change Was Made The validated schema owns key syntax; the native array methods own the required copies. Keep those owners and delete the redundant work. ## Evidence ### Acceptance and counts This is a four-site cleanup, using the final-small-batch exception; production +4/-5 lines (net -1), net test lines unchanged. Count acceptance: one redundant key scan and its regex allocation removed; three explicit array copies removed. No wall-clock, CPU, SQL, or Gateway latency claim; no timing experiment. Existing nonmutating methods remain, with no new lint suppression. - Focused existing stores-config suite: 4/4 passed, including malformed-key invalidation, revision stability, policy rejection, and conversation grants. - Changed-file oxfmt, oxlint, and git diff --check passed. - Two isolated Codex P0–P2 reviews of the full four-file diff against 8f1ef6c: both scoped-clean; no findings. Initial temporary-directory preflight refusals were corrected before either reviewer executed. - Initial exact-head CI run 41097808042 exposed a storage-schema replacement-fixture failure (expected three indexes, got two). The unchanged file passes 10/10 on both base and candidate; inode reuse was not reproduced locally. Earlier fixture cleanup can leave freed inode IDs in the module admission set. The replacement test now uses a freshly imported owner, preserves both warm-file/replacement index assertions, and passes 10/10 locally. Net test lines remain zero. - One additional isolated Codex P0–P2 delta review found no actionable issue in the fixture repair; the final import alias also passes no-shadow lint. - Final exact-head CI 41099978168 at 31f0f63: all applicable test, type, lint, source-contract, architecture, extension-boundary and baseline-ratchet gates passed, including the previously failing extensions-config shard. Security/dependency review passed. GitHub status requests intermittently returned 502/504; no test rerun or bypass was used. Open-PR overlap comparison used base and candidate merge-tree output against #186270 (2a8f1cc) and #184755 (e1a7985). Conflict blocks are identical: 51→51 and 1→1 respectively; no new conflict. Final shared-index refresh also checked the test file and found no further peers. #186270 is now merged; the remaining open #184755 still has the identical single unrelated generated-baseline conflict. Broader scan candidates needing mutable-sort lint exceptions, uncertain input contracts, or another owner were retained rather than included here. Release-note context: reduce redundant Knowledge config validation and explorer array copying without changing user-visible behavior. (cherry picked from commit cd8290c) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Knowledge page bodies grow without limit when agents append to a page instead of integrating or splitting it. In the Team vault the OpenClaw project page reached 135,706 characters (about 95k in State across 37 subsections), more than eleven default
knowledge_recordreads, even though the knowledge-capture skill already asks agents not to do this.User Impact
User impact: agents can no longer grow a page past its body budget: 12,000 characters for hub pages (one default record read) and 24,000 for other pages. Such a write saves nothing and returns a receipt with
state: "rejected"that names the page's size, budget, hub degree, largest sections and connected pages the content could move to. Edits that keep a body the same size or smaller always succeed, including on pages that are already over budget, so existing large pages need no migration and can only shrink. Facts can always be saved as claims; claims are never limited.A new
knowledge_extract_sectiontool moves one heading section to a new or connected page in one revision-fenced publication.New optional config:
plugins.entries.knowledge.config.pageBudgets.hubPercentile(default 90), which josh asked to be configurable. This raises the plugin config-surface count from 4,887 to 4,889 (pageBudgetsandpageBudgets.hubPercentile);docs/.generated/config-baseline.counts.jsonis updated for that.This PR does not change the test-line ceiling: main has since raised it to 6,300,000, and the merged tree is under it (see Evidence).
Why This Change Was Made
Every page-body write already reaches
StoragePublication.acceptas a prepared record plus its previous revision, so the budget is enforced there once, against the same vault snapshot the publication is fenced on. That one check coversknowledge_save_pagecreates and edits,knowledge_edit_body,knowledge_publish_batchpage items (and the ingest, scribe and memory-flush flows that use them),knowledge_mergewith a combinedbody, and the destination ofknowledge_extract_section. The rule is: reject when the body would be larger than before and larger than its budget. Corrections cannot replace pages (claims and relationships only), and withdraw, unmerge, annotate, recall, evidence reconciliation andknowledge_supersedenever change a body. Markdown edited directly on disk is observed rather than gated; that is the one deliberate exception.Budget, hub classification and extraction details
TEXT_PAGE_DEFAULT_CHARS(12,000): hubs get one read, other pages two (24,000). Sizes are body UTF-16 code units, as record windows count them.hubPercentile(default 90), the partition has at least 20 current pages, and the degree is at least 10. The top decile keeps hubs to a small set of routing pages. Below 20 pages one page spans five or more percentile points, and the degree floor keeps small or sparsely linked vaults from naming hubs.id/path/revision/hashdescribe the unchanged target (empty for a create).budget.pages[]has current and attempted sizes, the budget, hub status (degree,percentile,hubPercentile,minPages,minDegree), the six largest heading sections with offsets and subsection counts, and up to three connected pages per section that the section links to or names, with their remaining headroom. The message points to extraction andknowledge_remember, and says not to truncate.sectionStart, a destination (fences of an existing page connected to the source by a link either way or a typed relationship, or{title, type}for a new page), a one-line summary and a reason. The section moves verbatim. Relative Markdown links are rewritten for the destination directory, and any other link that would resolve differently rejects the request. Source evidence whose quote, path or filename appears in the section is copied, and the source keeps all its evidence. The source keeps the heading line plus the summary and a[[id|title]]link. Claims the section links to that name the source as an entity get the destination as first entity, and keep the source only when the claim names it. The destination, the shrunk source and the relinked claims are validated together in a preview scan, and the destination's link targets and evidence are verified, before one publication is accepted, so a failure changes no file. The receipt hasoperation: "extract"and history keeps the old revisions. The destination's own budget applies.publish.md/publication.mdsynced into each skill, plus knowledge-capture, knowledge-claim-consolidation step 5, knowledge-entities and knowledge-ingest) and the Knowledge docs describe the budget and the extract tool. The docs tool count is 38: main's 37 registered tools (includingknowledge_supersede) plusknowledge_extract_section.Evidence
node scripts/run-vitest.mjs run extensions/knowledgeon the tree merged with main at3bcca4f: 56 of 57 files passed. The exception,live-state.test.ts, fails locally on this shared host because the user's inotify instance limit is exhausted (fs.watchreturnsEMFILEeven in a fresh process). The file is unchanged by this PR, and PR CI runs it.page-budget.test.ts(pure contracts): hub percentile with the vault-size and degree floors and backlink degree; hub budget, nested sections outside code fences, connected candidates a section names; same-size rewrites and claims are never budgeted.page-budget-writes.test.ts(isolated test vaults through the tool handlers and storage worker):edit_body,save_pageedit and create,publish_batchandmerge, with the full payload checked on one, no file change and no stored receipt;knowledge_rememberandknowledge_create_claimstill publish against an oversized page;body-edit.test.tslarge-page edits now replace at the same size;publication.test.tsfixture body 28,672 → 23,800 characters) and the policy default instores-config.test.ts.3bcca4fraised its own ceiling to 6,300,000 and totals 6,296,883 lines (3,117 of slack). This PR adds a net 338 test lines, so the merged tree totals 6,297,221, still 2,779 under main's ceiling, and this PR leavesconfig/test-lines-baseline.txtat main's value. The 338 lines are the two new budget test files above (332 lines) plus small edits to three existing tests. They prove the six budget and extraction rules end to end through the storage worker, which no cheaper layer covers. I trimmed them from 474 lines by dropping assertions on static constants and merging overlapping cases.pnpm tsgo:extensions,pnpm check:test-lines-ratchet,pnpm config:docs:checkand skill reference sync--checkon the3bcca4fmerge; earlier on this branch alsopnpm tsgo:extensions:test, oxlint onextensions/knowledge/src,test/scripts/type-suppression-inventory.test.ts,pnpm check:assertion-safety, docs format and markdownlint,git diff --check: clean.origin/main, P1 threshold): no actionable findings.Work sessions
Worked on by