Repository navigation
perf(state): release cached Knowledge evidence buffers - #186100
Conversation
Knowledge verification caches must retain verdicts without keeping request-scoped artifact buffers and decoded text alive through lazy V8 Error stacks. Materialize the stack once before caching the existing Error, preserving negative-cache identity and behavior. Regression: a cached failure must allow its EvidenceInspector to be collected, while unchanged citations still reject and rewritten files invalidate the verdict. Independent subagent review (autoreview route unavailable) found no actionable P0-P2 findings.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR materializes cached evidence-error stacks so completed Knowledge operations can release artifact buffers and decoded text. Example: A Knowledge catalog scans 32 distinct 1 MiB text artifacts whose citation quotes do not match.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a concrete Knowledge memory-retention defect still present on current main, with no actionable introduced bugs found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherKnowledge storage workers scan partition-local records and verify cited artifact files; operation-scoped inspectors read their contents, while the vault's longer-lived cache retains file-stamped verification verdicts. flowchart TD
A[Catalog request] --> B[Knowledge storage worker]
B --> C[Vault scanner]
C --> D[Evidence inspector]
E[Artifact files] --> D
D --> F[File stamped verdict cache]
C --> G[Validated catalog and diagnostics]
Technical reviewBest possible solution: Materialize the existing Error stack at the verdict-cache owner, preserving negative-cache reuse and file-stamp invalidation. Do we have a high-confidence way to reproduce the issue? The unchanged main cache retains Errors created through the request-scoped inspector; the supplied Node worker measurements and reported red-on-base regression establish a concrete reproduction path, which this read-only review did not execute. Is this the best way to solve the issue? This is the smallest complete repair: it removes the lazy-stack retention at the existing cache owner without replacing Errors, changing validation, or adding another lifetime mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c22d6a5c87ba. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +2, Tests +42, Docs +3, Other +58. Total +105 across 4 files. Added test files: 0. View PR surface stats
Review metrics
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, 12:08 PM ET / 16:08 UTC. |
|
Landing at the pinned head
|
…186100) Knowledge verification caches must retain verdicts without keeping request-scoped artifact buffers and decoded text alive through lazy V8 Error stacks. Materialize the stack once before caching the existing Error, preserving negative-cache identity and behavior. Regression: a cached failure must allow its EvidenceInspector to be collected, while unchanged citations still reject and rewritten files invalidate the verdict. Independent subagent review (autoreview route unavailable) found no actionable P0-P2 findings.
What Problem This Solves
Knowledge storage workers retain artifact buffers and decoded text after a citation fails validation, because the cached Error's lazy V8 stack retains the request-scoped EvidenceInspector.
User Impact
Failed evidence verification no longer keeps the operation's artifact contents alive until cache invalidation. Citation errors, negative-cache hits, authority checks, and file-stamp invalidation keep their existing behavior. No schema, configuration, or API changes.
Why This Change Was Made
Materialize the original Error's stack once before retaining it. This preserves the existing Error and cheap negative-cache hit instead of allocating a new Error on each hit. Production delta is +2 lines (one statement and its lifetime comment); preserving negative-cache behavior requires the statement. The existing worker measurement script now supports synthetic failing evidence and aggregate heap evidence.
Evidence
The new regression fails on unchanged main under Node with
cached verdict must not retain the request inspector, and passes with the fix. It keeps the verdict cache live across a GC, then verifies cached rejection and invalidation after a file rewrite. Bun does not exhibit the V8-specific retention, but passes the behavior test.Real storage-worker protocol, Node 26.12.1, synthetic read-only vault with 32 distinct 1 MiB text artifacts and 32 records whose quotes do not match. Every tenth catalog request edits a record. Two counterbalanced A/B then B/A pairs, 2,000 measured requests per arm per pair (4,000 per revision), separate worker isolates; source mode includes equal loader overhead. Acceptance: release the completed inspector/artifact contents, preserve rejection/invalidation/authority behavior, and retain the existing cache-hit path without a material controlled regression. This is an owner retention result, not a whole-Gateway throughput claim.
The deterministic saving is 64 MiB external memory, comprising 32 MiB of buffers and 32 MiB of decoded text. Aggregate-only snapshot census: retained EvidenceInspector 1 → 0, Buffer objects 37 → 5, Buffer retained bytes 33,633,536 → 72,704. Main-thread CPU and sessions.list were not measured; the bounded retention fix uses the campaign's owner-proof fast path rather than a ten-minute Gateway stress run.
Timing/allocation differences are modest and noisy: paired-mean CPU +4.7%, allocation −1.9%, RPC p99 +5.0%; no speedup claimed. An identical-base A/A control varied CPU 13,981 → 15,471 ms (+10.7%), RPC p99 88.08 → 72.06 ms, and process RSS 270.28 → 319.31 MiB. RSS is inconclusive, not a worker-retention metric. GC rose by a paired mean 0.0077 ms/request, well below the campaign's 1 ms/request absolute threshold. Minor GC counts/time: 152/122.89 → 152/124.15 ms and 168/104.54 → 159/112.61 ms. Major counts were 1/1 and 1/7, so major pause statistics are context only. The discarded message-only-cache prototype allocated a new Error per negative hit and was replaced by this smaller fix.
Reproduce with the script header; the measured command is:
For source overlays, add
--baseline-dir <source-tree> --baseline-file extensions/knowledge/src/evidence-files.tsto both sides with their respective source bytes. Snapshots contain synthetic data and remain local; only aggregate counts are reported.Validation:
OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs extensions/knowledge/src/evidence-inspector.test.ts extensions/knowledge/src/storage-worker.test.ts extensions/knowledge/src/source-descriptor-integration.test.ts --maxWorkers=1— 9 tests passed; final harness wall time 105.67 s (compilation/cleanup included), new regression about 0.34 s. Changed-file oxfmt/oxlint, script syntax, andgit diff --checkpassed. The pre-rebase local test-line ratchet passed at 6,284,782 / 6,285,000. Exact-head CI later failed that gate on its merge tree at 6,285,692 / 6,285,000, with this PR adding 42 lines; the merge base was already 650 lines over. The ceiling is unchanged. This is an unresolved test-budget gate, not a passing/inherited-only CI claim. No new test file, production export, or module.Review: independent subagent review (autoreview route unavailable), complete four-file diff through P2, no actionable findings. Autoreview refused provider/configuration mismatch before inference; no configuration was changed. The reviewed patch is unchanged after rebasing onto main; CI supplies broad exact-head validation. Merge is reserved for the coordinating maintainer.
Exact-head CI: run 40535170508 completed with only
checks-fast-baseline-ratchetsfailing (test-lines), propagating toopenclaw/ci-gate. All other substantive checks passed. No rerun was requested. A read-only audit found the nearby evidence tests protect distinct contracts; they were not deleted to offset this regression. A smaller in-process GC experiment passed but was discarded because the subprocess avoids shared-constructor and stack-formatter retention. Shared test-headroom cleanup is needed before this PR is green. Not merged.