Skip to content

fix: project memory misses its budget on large Knowledge vaults - #198441

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-project-memory-recall-budget-20260919
Nov 13, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-project-memory-recall-budget-20260919

Conversation

@steipete

@steipete steipete commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes avoidable project-memory omissions when a large Knowledge vault exhausts the one-second recall budget.

User Impact

Warm recall does less repeated work while preserving successful prompt bytes. If the budget still expires, the existing diagnostics stream records an explicit skipped outcome, including its reason and budget, for the existing tracing exporter. Cold index loading and queued work can still exceed the unchanged deadline. No configuration or schema migration is required.

Why This Change Was Made

The scanner statted every entry twice and candidate selection revalidated approval metadata already validated by the scan. Reuse the observed stat and the validated facts owned by the existing, file-stamp-invalidated scan snapshot. This adds no independent cache or invalidation policy.

Production code grows by 23 lines: 11 for the skip event and 12 for the scan-owned approval facts and stat reuse.

Evidence

Regression tests fail on the exact parent and pass on this head: repeated approval validation is removed, unchanged records receive one stat, eligible candidates remain identical, and budget omissions emit the trusted diagnostic event. Focused Knowledge vault/link/provider/save-cost tests and 43 core/audience/prefix/compact tests pass. Runtime build and Codex autoreview pass. An isolated Gateway with a real model returned a random phrase available only in approved project memory.

Controlled native Linux/btrfs A,A,B,A,B,B,A,B,A,B runs (50 warm samples per arm) on 62,000 memories / 2,000 projects, a separate 62,000-file / 1.1 GB workspace, and a synthetic 35.7 GiB agent DB with 5,001 sessions:

Measurement Before After
Warm wall p50 / p95 776 / 892 ms 280 / 314 ms
Process CPU p50 / p95 929 / 1,369 ms 303 / 343 ms
Sampled storage allocations per call 793 MB 219 MB
File stats per warm call 124,022 62,022

All 100 successful native prompts have the same SHA-256. The initial A/A medians differ by 0.42%; the full baseline median range is 676–810 ms versus 261–306 ms after the fix. Allocation sampling ran separately in A,B,A,B processes (10 calls each); repeat averages differ by 0.69% before and 0.13% after. These direct-storage allocation samples exclude transport and caller allocation. Native timings use the default writes-enabled provider path; the attribution probe uses writes-disabled storage. Queue wait p95 stays below 0.03 ms, and main-thread CPU p95 stays below 2.6 ms.

Cold reopen settlement remains about 27 seconds in both arms, so this does not solve initial index loading. All five fixed cold skips emit the new diagnostic, versus none before. No warm sample skipped. A separate oversized-import fixture exposed an existing Git change-batch string-size limit; that setup failure is excluded from the results.

Measured production bytes are at 53c8b90 against parent cda1842. The subsequent CI repair only binds benchmark instrumentation to its instances; production is unchanged. Initial CI rejected benchmark lint suppressions; all three are removed, and the failed policy test, script typecheck, and script lint pass locally. The probe also snapshots cold phase counters before explicit warmup; reported warm statistics and cold wall/CPU measurements are unaffected.

pnpm check:changed passes its selected checks except inherited dead-export failures, independently reproduced on the exact parent cda1842. These are main regressions, not passing checks:

The same first CI run also failed the audience integration test's first case (4.98 s; subsequent cases ~0.2 s). That test now preloads the runtime before checking real lineage semantics, keeping cold module loading outside this audience assertion. The fixed test passes under Bun with a fresh transpiler cache. The exact-parent replay passed too, so this is not claimed as a proven inherited failure or an admin-merge exception. Fresh CI is required.

Reuse the scan owner’s file stats and validated approval facts instead of repeating that work on every recall. Preserve successful prompt bytes and the one-second deadline; record a skipped diagnostic outcome when the deadline expires. Add synthetic owner measurements and regression coverage.
@clawsweeper

clawsweeper Bot commented Nov 13, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T20:50:05.360794Z 287e9fc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling plugin: knowledge size: M labels Nov 13, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Reuse scan-owned approval facts and file metadata, and emit a diagnostic event when project recall exceeds its budget.

Example: Warm project recall over 62,000 Knowledge memories across 2,000 projects.

  • Before: Reported median preparation was 776 ms, with 124,022 file stats per call.
  • After: Reported median preparation is 280 ms, with 62,022 file stats and identical successful prompt bytes.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused owner-level optimization with supplied runtime results and no open finding; full current-head CI is still pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Public discussion supplies Linux/btrfs native-provider measurements over 62,000 memories, matching successful prompt hashes, and observed cold-timeout diagnostic events; a separate isolated real-model Gateway result confirms approved project memory reaches the answer. The subsequent repair changes instrumentation and test preload only.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large Knowledge vaults can consume the project-recall budget and omit approved context from an agent turn.
Reason: The maintainer-authored direction has concrete measured value and preserves existing successful recall behavior.

Merge readiness

✅ Ready for maintainer review

This PR makes a useful, focused improvement to large-vault recall. The prior suppression finding is fixed, and no actionable introduced defect was found; current-head CI remains pending.

Priority: P2
Reviewed head: 287e9fc3dda957a5693feb4cb9dee24505ea8eea

Before merge

None.

Findings

None.

Agent review details

How this fits together

Agent prompt preparation requests project candidates from the selected memory provider; Knowledge scans the authorized vault and returns approved summaries, while the host bounds preparation to one second.

flowchart TD
A[Agent prompt preparation] --> B[Project recall budget]
B --> C[Knowledge memory provider]
C --> D[Authorized storage operation]
D --> E[Validated vault scan]
E --> F[Approved project summaries]
F --> A
B --> G[Skipped recall diagnostic]
Loading

Technical review

Best possible solution:

Keep the optimization within the existing scan owner and preserve the deadline, eligibility rules, and explicit skipped outcome.

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

Base source shows two stats per catalog entry and repeated approval validation during candidate selection; supplied controlled measurements exercise this work, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch removes repeated work at its existing owner without introducing another invalidation policy; cold index loading remains an explicitly documented limitation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Vault stamps and scan reuse keeps the original intent (93f9678: Reduce repeated whole-vault save work while retaining stamp-based invalidation and guarded reads.)
  • Approval validation and candidate selection keeps the original intent (65ad180: Bundle Knowledge with validated, scoped automatic-recall projections; the patch carries the existing validator's result rather than changing approval rules.)
  • Project recall deadline keeps the original intent (8cb658e: Continue turns after one second while retaining the original read authority and eventual cleanup.)
  • Performance measurement keeps the original intent (cff0957: Attribute native recall preparation costs while separating cold startup, warm retrieval, and cleanup.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 8cb658e adds src/agents/project-memory-bootstrap.ts:204 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8cb658e39b6d; files: src/agents/project-memory-bootstrap.ts)
  • Josh Lehman: Raw commit 65ad180 adds extensions/knowledge/src/vault-scan.ts:111 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 65ad18005286; files: extensions/knowledge/src/vault-scan.ts)

PR surface

Source +23, Tests +79, Docs +8, Other +223. Total +333 across 14 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 35 12 +23
Tests 5 85 6 +79
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 3 227 4 +223
Total 14 355 22 +333

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Large Knowledge vaults benefit from less recall work; the existing deadline already allows affected turns to continue.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 (1 earlier review cycle)
  • reviewed 2026-11-13T20:39:49.128Z sha 53c8b90 :: needs changes before merge. :: [P2] Reconcile the new suppressions with the checked inventory

Reviewed November 13, 2026, 3:53 PM ET / 20:53 UTC (Revision 2).

Remove benchmark lint suppressions by binding instance methods, snapshot cold phase counters before warmup, and keep cold module loading outside the audience contract test. Production recall behavior is unchanged.
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed item 1 on 287e9fc3dda957a5693feb4cb9dee24505ea8eea:

  1. New lint suppressions: removed all three directives. The storage probe binds the identity-store method at storage-measure.ts:53 and the operation's vault scanner at line 77. The native probe binds each opened runtime's queue at bootstrap-measure.ts:289. The failing inventory test, script typecheck, and targeted lint now pass; no allowlist expansion. Codex autoreview of the complete repair is scoped-clean through P2.

The additional audience-test CI failure is also addressed: audience.test.ts:17 preloads the runtime before the real lineage assertions. The initial CI case took 4.98 seconds versus ~0.2 seconds for subsequent cases. Fixed Bun proof passes all three cases with a fresh transpiler cache. The exact-parent replay passed, so this is not being claimed as proven inherited or used for an admin exception; fresh CI must pass.

The PR body now contains the completed synthetic large-store controls. Selected measured output (production sources unchanged by this test-only repair):

{
  "nativeWarmSamplesPerArm": 50,
  "wallMs": {"before": {"p50": 776.04, "p95": 891.63}, "after": {"p50": 279.60, "p95": 314.09}},
  "processCpuMs": {"before": {"p50": 929.38, "p95": 1369.31}, "after": {"p50": 302.50, "p95": 343.35}},
  "sampledStorageBytesPerCall": {"before": 793081391, "after": 219026805},
  "statsPerWarmCall": {"before": 124022, "after": 62022},
  "successfulPromptSha256": "2aec53284a444ed9d14f7ff82d25a0c955e0a92a021f128b344b66b6c7595ac2",
  "coldSkippedCalls": {"before": 5, "after": 5},
  "coldSkippedDiagnosticEvents": {"before": 0, "after": 5}
}

Cold reopen remains ~27 seconds; no claim that this fixes initial loading. The native cold-path probe observes the real trusted diagnostic event; a separate isolated real-model Gateway proof verifies successful project-memory use. Its inspected result is {"status":"ok","markerReturned":true,"assistantFinalTextVerified":true,"assistantTextCount":1}. The marker existed only in approved memory. This separates the two proof boundaries rather than claiming the Gateway run itself exercised a timeout.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@steipete
steipete enabled auto-merge (squash) November 13, 2026 20:59
@steipete
steipete merged commit 7925bbd into main Nov 13, 2026
150 of 152 checks passed
@steipete
steipete deleted the steipete/perf-micro-project-memory-recall-budget-20260919 branch November 13, 2026 21:02
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…claw#198441)

* fix(knowledge): reduce project recall budget misses

Reuse the scan owner’s file stats and validated approval facts instead of repeating that work on every recall. Preserve successful prompt bytes and the one-second deadline; record a skipped diagnostic outcome when the deadline expires. Add synthetic owner measurements and regression coverage.

* test(memory): bind recall probes and preload audience runtime

Remove benchmark lint suppressions by binding instance methods, snapshot cold phase counters before warmup, and keep cold module loading outside the audience contract test. Production recall behavior is unchanged.
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
Release adaptation: extract only fragment-before-decode repair and focused scan/backlink regression from openclaw#191791; retain baseline parser and unrelated test cleanup. Later openclaw#195027, openclaw#196767 and openclaw#198441 changes are unrelated and already represented by baseline parser structure; no later PR-number follow-up.

(cherry picked from commit 2563438)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 7fdc9ad3b334ac08cb9a76604cfbb78ec56ef479)
(cherry picked from commit af609748bca14f61086ecfa82a961787701bdfcd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. plugin: knowledge 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: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant