Skip to content

feat(knowledge): bundle the Knowledge memory plugin - #180139

Merged
jalehman merged 74 commits into
mainfrom
openclaw-ef3/bundle-knowledge
Oct 25, 2026
Merged

jalehman merged 74 commits into
mainfrom
openclaw-ef3/bundle-knowledge

Conversation

@jalehman

@jalehman jalehman commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Knowledge, the evidence-backed memory plugin, ships separately from OpenClaw, so it can drift from core and users have to install and load it themselves.

User Impact

User impact: Knowledge ships with OpenClaw as a bundled plugin, off by default. Setting plugins.slots.memory: "knowledge" turns it on. Existing stores keep working: the bundled build opened a copy of a real standalone-Knowledge store without a migration step.

People who installed the standalone plugin need a manual switch, because an installed copy takes precedence over the bundled one. openclaw plugins uninstall knowledge also clears plugins.entries.knowledge.config, including stores. The Knowledge guide lists a safe save, uninstall, enable and restore order. No vault data is touched.

Why This Change Was Made

The plugin moves into extensions/knowledge and now follows the repository rules for bundled plugins:

  • Its tests run under vitest.
  • It passes repo lint, type and file-size gates. Large files are split; assertions are justified or removed.
  • Workers, the default ontology and the sample vault load from the runtime entry and ship as static assets.
  • SQLite access uses the plugin SDK's worker helpers, Kysely builders and immediate transactions.
  • A new knowledge_attach_file tool attaches a file from the agent's workspace by path, reusing the durable chunked-upload path, so the model no longer copies attachment bytes through its context.

One part needs maintainer review: keyword search keeps its SQLite FTS5 index. scripts/database-dialect-inventory.mts now excludes fts5, temp-schema and rowid in extensions/knowledge/src/retrieval.ts only, through the same mechanism as the existing SQLite-only exclusions. The reasons:

  • The index is a cache rebuilt from the vault.
  • It lives only in each store's private state.sqlite and is never opened through the PostgreSQL-capable database layer.
  • Moving it behind a shared SDK text-index API would need core to own plugin database files, which it doesn't today.

docs/reference/database-schemas/storage-changes.md documents the exclusion. Tests prove that other constructs in that file, and fts5 anywhere else, still fail the ratchet. If this exclusion isn't acceptable, the fallback is scoring search in TypeScript inside Knowledge.

The config-surface baseline grows by 28 entries. They are Knowledge's own config schema (stores, write and read policy, maintenance), now part of the bundled inventory.

The plugin's tests count toward the repository's test-lines ceiling (config/test-lines-baseline.txt). They put the total 3,027 lines over it, so the suite was trimmed by about 2,750 net lines:

  • Tests that repeated what a wider test already proves were deleted or merged. Examples: delegated-access.test.ts (the same denials are proven in real-vault.test.ts and memory-provider.test.ts), search-detail.test.ts (folded into the real grep tool path in retrieval.test.ts), and the document and meeting port tests in workflows.test.ts.
  • Near-identical cases became it.each tables, and repeated hand-built vaults now use the shared fixtures.
  • Some tests were the only proof of low-stakes behavior and were removed: UI URL-state parsing, prompt-section gating, the compact-metadata projection, legacy evidence filename fallbacks, card and UI search-client projections, the old 500-entry cap guard, the cron daylight-saving unit test, and two ingestion summary checks.

Every authority, partition-isolation, path-escape, crash-recovery, integrity and regression test is kept. Main's own test removals have since brought the total under the unchanged ceiling (6,349,139 of 6,362,000), so this PR leaves the ceiling alone.

Evidence

  • Upgrade on real data. I took a consistent copy (SQLite online backup) of a live standalone-Knowledge state directory: 487 MB, 2 stores, about 76k state pages. An isolated Gateway built from this branch opened it on port 19390 with Knowledge as the memory slot:

    • status: the store is ready and live watching is on.
    • Keyword search: the FTS index is ready and returns ranked hits.
    • Record read, exact lookup, records, timeline, history (git committed) and connections all succeed.
    • A temporary, uncommitted test opened the same copied store through createKnowledgeService and saved a claim with remember. The receipt came back published, the claim count went from 1,097 to 1,098, and keyword search found the new claim.
  • Authority at the final effect, bundled Gateway. An isolated Gateway built from this branch, plus the memory-audience fixes (fix(memory): memory tools fail for owner sessions started by sessions_send and cross-agent subagents #181359), with a real model and agents main/fm-know. Probe sessions saved claims with knowledge_remember, and the vault path shows the partition:

    • Owner-private permitted: owner dashboard turn, owner turn started by sessions_send, and owner cross-agent sessions_spawn child all published to stores/<id>/vault/private/claims/….
    • Conversation caller denied private content: a non-admin turn wrote only to vault/conversations/<sessionId>/claims/…. The same knowledge_grep query returned no hits for it and the three private probe claims for the owner. A non-admin knowledge_record on a private claim's exact ID returned not found.
    • Operator surfaces on a Gateway with two people: the Knowledge page (agent_query status) and memory.search refuse operator.read/operator.write and succeed for operator.admin.
    • Revocation before publication (reset, reassignment, retired service) is covered at the worker and publication boundary, not live: storage-worker.test.ts (authority revoked mid-operation publishes nothing), stores.test.ts (the cutover fences old-assignment access), live-state.test.ts (in-flight operations leave no accepted write), session-activity.test.ts (revoked authority fails delivery). Gap: there is no live trace of a reset racing a queued write.
  • knowledge_attach_file through a bundled Gateway. An isolated Gateway ran this branch's dist at 46415c3e63c with Knowledge as the memory slot and openai/gpt-5.6-sol. The turn ran in a direct session created with sessions.create, which the host granted an owner-private memory audience. The agent workspace held proof/notes.md (87 bytes); outside/secret.txt sat next to the workspace, with a symlink to it at proof/link-out.txt. Tool calls and results from the session transcript:

    knowledge_attach_file {"filePath":"../outside/secret.txt"}       -> ERROR Source file must be a readable regular file inside the authorized workspace without aliases.
    knowledge_attach_file {"filePath":"proof/link-out.txt"}          -> ERROR Source file must be a readable regular file inside the authorized workspace without aliases.
    knowledge_attach_file {"filePath":"<proof>/outside/secret.txt"}  -> ERROR Source file must be a readable regular file inside the authorized workspace without aliases.
    knowledge_attach_file {"filePath":"proof/notes.md"}              -> {"state":"complete","receivedBytes":87,"evidence":{"path":"artifacts/e5807468-543e-463c-83aa-184e98ccc4fc/notes.md","sha256":"6efbc2b0345f03f0c62b955a866600d1aa6f3397759f322c2cf316c85c1619d9","size":87}}
    

    The retained vault/private/artifacts/e5807468-…/notes.md is byte-identical to the workspace original (same SHA-256). Neither secret.txt nor its marker text appears anywhere under the Knowledge state directory. The agent's first attempt at the allowed file passed expectedVaultId: "", copied from the status of a store that did not exist yet, and the input schema rejected it; the retry omitted the field.

  • Review fixes, now on head e7c62d534a2 (rebased onto main 93a374a9c95, which includes fix(memory): memory tools fail for owner sessions started by sessions_send and cross-agent subagents #181359; the core commits it carried were dropped as identical to the merged code; the only conflicts were the generated config baseline and worker inventory, regenerated with their generators). Each regression test fails without its fix and passes with it:

    • Live operator policy: plugin session actions get host-owned allowsAgent() and isSharedGateway() checks (fix(memory): memory tools fail for owner sessions started by sessions_send and cross-agent subagents #181359). Knowledge calls them each time it re-resolves the principal. real-vault.test.ts > a role or roster change after admission refuses the operator read before disclosure admits under the old policy and is refused at the recheck before records are returned.
    • Pinned memory index: the rendered index is pinned per agent, session incarnation, store binding and cutoff, while authority is still checked live each turn. memory-index-hook.test.ts > keeps the rendered index byte-stable when a record is renamed mid-session fails without the pin. A Gateway restart re-renders once (accepted).
    • Recycled-inode admission: found while running the full suite. Since 74f001f8ec1, state databases were admitted once per device:inode, so a recreated or restored database on a recycled inode skipped schema creation (no such table). Admitted inodes must now also carry the current schema stamp. storage-schema.test.ts > a legacy database written into an already admitted inode is admitted again reproduces it deterministically by rewriting an admitted file in place.
    • Missing-audience assertions updated to the new diagnostic; flush-plan prompt-wording assertions trimmed.
    • Full extensions/knowledge suite: 51 files, 405 tests pass (49 files, 364 tests after the test trim described above). Plugin contract, host-hook and memory-provider tests pass; tsgo:extensions, tsgo:core, config:docs:check and db:worker-inventory:check pass.
  • Registry sentinel recovery. 2ac79915156 completes an empty registry.id from the verified registry ID before comparing it. Its regression test, stores.test.ts > an interrupted sentinel write is completed; a sentinel naming another registry is refused, fails with the previous store-registry.ts (1 failed / 24) and passes with the fix (24 / 24).

  • Build. pnpm build passes, and Knowledge loads from dist with origin bundled.

  • Rebased onto current main (0843b940a56, which includes fix(plugins): reload edited bundled code without restarting the gateway #180466). Two real conflicts: main added a v31 rowid exclusion to scripts/database-dialect-inventory.mts and its test in the same spots as this PR's FTS5 exclusion, so both exclusions are kept and the test covers both files. The config baseline and worker inventory were regenerated with their generators. On head 64a8959f4cb: the dialect ratchet (against 0843b940a56), its 39 tests, the worker-inventory, config-baseline, plugin-inventory and skill-reference checks, tsgo:extensions, Knowledge oxlint, the import-cycle check and pnpm build all pass.

  • Tests. Under Node (the CI runtime), OPENCLAW_VITEST_RUNTIME=node pnpm test:extension knowledge passed on 3a28571f0ae (the rebase before the attachment commits): 48 files, 385 tests, in 13m7s. On head 64a8959f4cb (49 files, 391 tests), 390 passed. The one failure was publication.test.ts > cross-process publishers fence competing edits and never lose the winner, which saw revision 4 instead of 2 while the winner's hash was correct. It passed 3 of 3 runs alone, and passed in the earlier full run. The attachment commits don't touch publication, so I'm treating it as a rare timing-sensitive failure under load, tracked as a follow-up, not a regression from this head.

    • fix(knowledge): bound Markdown block runs before link lexing fixes the Bun-only slowness in record-capacity.test.ts > near-limit records…: JavaScriptCore gave up on marked's paragraph regexp after ~49K lines and fell back to line-by-line lexing. CI runs Node, so CI wasn't affected.
  • Control UI. Screenshots from an isolated Gateway on this build (origin bundled), seeded with the synthetic sample vault. Knowledge is a new page, so there's no "before".

    Knowledge Recent view
    Knowledge Browse view
    Knowledge record view

  • Gates. pnpm check:changed passes every gate that covers Knowledge, including typecheck, the dialect, worker and assertion ratchets, and import cycles. The dead-export scan flagged two of this PR's re-exports. I removed them, and the scan is now clean. Three gates fail only on files this PR doesn't touch:

    • lint, for line caps in ui/, src/ and extensions/{telegram,crabbox}
    • the max-lines suppression ratchet, for ui/ files
    • the core test-shard root budget
  • Review. Autoreview (Codex gpt-6.1-sol, branch mode, P0 threshold) returned scoped-clean across 5 passes.

  • Simplify. pr-simplify removed a test-only Publisher rename alias and two unused MAX_ENTRIES re-exports. Two things remain by design:

    • The includeMetadata tool input stays, because agents already use it with the published plugin.
    • Raw prepared statements stay where the SDK database rules allow them.

Diff against the merge base: about 53.7k lines added. Roughly 26.5k is production TypeScript and 3.3k CSS. The rest is tests (14.7k), docs (8.1k) and fixtures, ontology and skills.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Dependency graph changes

This maintainer PR changes the dependency graph.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: a5dd508af32b0165037d06c7325b78fa53799923
  • Maintainer: @jalehman
  • Repository role: admin

These dependency graph changes were made:

  • pnpm-lock.yaml
  • extensions/knowledge/package.json

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: XL labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR bundles Knowledge as an optional memory plugin with evidence-backed records, retrieval, shared stores, and a Control UI explorer.

Example: An operator selects plugins.slots.memory: "knowledge".

  • Before: Knowledge requires a separately installed plugin.
  • After: The bundled plugin provides Knowledge tools and its explorer without a separate installation.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful and supported by shipped-entry-point evidence, with no introduced blocking defect identified; exact-head core CI attribution remains unresolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Bundled-Gateway output exercises real-model memory writes, private-versus-conversation isolation, operator denials, and workspace attachment success and escape rejection; the later production-owner harness records reset, reassignment, and operator-revocation rejection before final effects, with the relevant Knowledge paths unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Users must separately install Knowledge, and its independent distribution can drift from OpenClaw.
Reason: Maintainer-authored direction makes this an approved optional integration, with existing memory selection and other providers preserved.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: optional Knowledge bundling has clear value, and the previously reported physical-store pinning defect is fixed.

Priority: P2
Reviewed head: 9f4f07a64002fbe871b95a52d975ad022d666295

Before merge

None.

Findings

None.

Agent review details

How this fits together

Knowledge consumes host-issued agent and operator authority, resolves the authorized store and partition, and serves memory operations through plugin-owned workers and vault files.

flowchart TD
  A[Agent tools] --> C[Knowledge service]
  B[Control UI] --> C
  C --> D[Host authority and store resolution]
  D --> E[Storage worker]
  E --> F[SQLite journal and search index]
  E --> G[Markdown vault and evidence]
Loading

Technical review

Best possible solution:

Bundle Knowledge through the existing plugin owners while preserving live authority checks, existing stores, and the documented standalone transition.

Do we have a high-confidence way to reproduce the issue?

This is a feature import; source inspection confirms that Knowledge is absent from fetched main and registered by this PR.

Is this the best way to solve the issue?

The implementation fits the existing feature-plugin, memory-provider, worker, and config-writer owners without introducing a competing core memory system.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ec3cfa5f72da.

Provenance checked

  • Generic plugin session actions keeps the original intent (1adaa28: [plugin sdk] Add generic plugin host-hook contracts #72287 established generic host hooks so workflow plugins could integrate without product-specific core patches.)
  • Session-action reload and live policy keeps the original intent (4bbb815: The existing handler retries actions across plugin reload; this PR retains that dispatch and adds the request-authority callback needed at configuration publication.)
  • Learning command descriptions keeps the original intent (f8d9d25: feat(learn): /learn can save lessons to the selected memory plugin #181879 already added memory-backed learning; this PR aligns command descriptions and supplies the participating plugin.)
  • SQLite dialect inventory changes intended behavior with a stated reason (a1c1610: The shrink-only inventory exposes SQLite-specific debt; the maintainer explains the narrow exception for Knowledge's rebuildable plugin-private FTS index and adds scope controls.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Plugin configuration inventory +29 baseline entries The generated plugin baseline increases from 4,828 to 4,857 as Knowledge's optional configuration joins the bundled inventory.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a useful optional memory capability with no demonstrated urgent regression.
  • merge-risk: 🚨 compatibility: The PR adds a public session-action authority callback and bundles a previously standalone plugin; its maintainer records the transition, and existing-store compatibility evidence is supplied.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-23T13:19:56.099Z sha 726c134 :: needs real behavior proof before merge. :: [P1] Carry live operator policy into session-action storage checks | [P2] Pin the rendered index across turns in the same session context | [P2] Update the missing-audience assertions for the new diagnostic
  • reviewed 2026-10-23T14:12:40.639Z sha 05285ef :: needs real behavior proof before merge. :: [P1] Revalidate operator authority when committing store assignments | [P2] Replace the assertion chains rejected by the boundary gate | [P2] Let the source-ingest scripts exit naturally after help output
  • reviewed 2026-10-23T17:21:22.513Z sha 1735621 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-23T20:50:22.065Z sha 46415c3 :: needs real behavior proof before merge. :: [P2] [P2] Apply private-read policy to store inventory counts | [P2] [P2] Preserve schema types without a chained assertion | [P2] [P2] Replace unchecked casts in the imported test fixtures
  • reviewed 2026-10-23T23:25:43.408Z sha 4d6e53e :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-25T13:57:10.022Z sha 246d776 :: needs changes before merge. :: [P2] [P2] Include physical vault identity in the pinned-index key
  • reviewed 2026-10-25T14:03:48.811Z sha 246d776 :: needs changes before merge. :: [P2] Include physical vault identity in the pinned-index key
  • reviewed 2026-10-25T15:08:37.087Z sha d574ff8 :: needs changes before merge. :: none

Reviewed October 25, 2026, 1:06 PM ET / 17:06 UTC (Revision 11).

@clawsweeper clawsweeper Bot closed this Oct 22, 2026
@jalehman jalehman added the size: accepted-large Maintainer-accepted large change; exempts ClawSweeper size closure, not review or CI. label Oct 22, 2026
@jalehman jalehman reopened this Oct 22, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 22, 2026
@jalehman
jalehman force-pushed the openclaw-ef3/bundle-knowledge branch 2 times, most recently from d78ac96 to 7e02dc7 Compare October 22, 2026 02:28
@jalehman
jalehman force-pushed the openclaw-ef3/bundle-knowledge branch from 5f50cb4 to 64a8959 Compare October 22, 2026 23:43
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 23, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

Subject inference (subject-infer.ts): keeping as-is.

When the agent passes subject, knowledge_remember resolves it by exact page ID, title or alias and never guesses. Inference runs only when subject is omitted and infer_subject is not false. It links a claim only when the claim text names exactly one current entity page by exact ID, title or alias, and names no other capitalized name. Bare first names that only prefix a title, two resolved entities, or any competing name leave the claim unlinked.

In the example, "Atlas acquired nimbus." links to Atlas, which is the claim's subject. A claim only ever links to a page its text names, and keyword search still finds the claim through "nimbus".

Removing inference means claims saved without subject never appear on entity pages, and the maintenance relink pass links only claims that carry a source_page. That would cut what every entity page shows in order to change how a lowercase second name is handled. Claims the deterministic pass leaves unlinked go to the agent through the knowledge-unlinked-claims skill, which chooses their subject pages with judgment. This is exact-match identity resolution with deterministic rules, not interpretation of meaning, and I couldn't find the contract cited in the finding in the repository's AGENTS.md files or review docs.

@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 23, 2026
This was referenced Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android dependencies-changed PR changes dependency-related files docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: accepted-large Maintainer-accepted large change; exempts ClawSweeper size closure, not review or CI. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant