Repository navigation
improve: batch memory admission and prepare pinned skill resources - #167254
Conversation
Keep memory exclusion decisions synchronous at their final authority boundary while batching exact metadata reads. Retain the physical corpus source through preparation, and pass immutable worker-prepared skill entries directly into awaited tool construction.
Carry the two unused-export cleanups from 858d31d so the focused branch passes the current dead-code gate. Co-authored-by: Patrick Erichsen <[email protected]>
Resolve the harness abort-signal helper overlap while preserving prepared library authority and publication checks.
|
🦞👀 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: needs maintainer review before merge. Reviewed October 8, 2026, 1:19 PM ET / 17:19 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch batches memory admission metadata reads and carries immutable, worker-prepared pinned skill resources through asynchronous tool construction. Example: Backfill prepares a session while its database file is replaced
Review scores
ProductKind: Performance · Worth it: Yes Merge readiness✅ Ready for maintainer review Keep open: this remains useful performance work on current main, with no actionable correctness or security finding. Focused behavior evidence exercises production owners in process; the ordinary Gateway measurements do not exercise the changed paths. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherMemory dreaming and backfill select trusted session content for durable memory. Agent tool construction also makes resources from the session’s selected skill revisions readable, using host-held run and database authority. flowchart TD
A[Session transcripts] --> B[Corpus discovery with captured file identity]
B --> C[Bounded memory admission checks]
C --> D[Eligible memory candidates]
E[Selected skill revisions] --> F[Existing database reader worker]
F --> G[Immutable prepared resources]
G --> H[Tool publication with current authority]
Technical reviewBest possible solution: Use the existing reader owners for preparation while retaining the live final memory guard and released synchronous SDK contracts. Do we have a high-confidence way to reproduce the issue? Not applicable as a performance proposal; source confirms the existing repeated memory reads and synchronous skill fallback, and supplied paired owner runs measure the changed paths. Is this the best way to solve the issue? Yes: the patch extends existing owners, preserves the synchronous final exclusion decision, and explicitly carries prepared resources instead of relying on cache residency. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3be885108e5e. Provenance checked
TestingProof path: in-process harness. Added test files: 5. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +195, Tests +415, Docs +15. Total +625 across 19 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: LabelsLabel changes: No label 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 History |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…penclaw#167254) * perf: batch memory admission and prepare pinned skill resources Keep memory exclusion decisions synchronous at their final authority boundary while batching exact metadata reads. Retain the physical corpus source through preparation, and pass immutable worker-prepared skill entries directly into awaited tool construction. * chore: keep catalog and cold-turn helpers internal Carry the two unused-export cleanups from 9ae69dd so the focused branch passes the current dead-code gate. Co-authored-by: Patrick Erichsen <[email protected]> * test: use disposal-only bindings in skill pin regressions --------- Co-authored-by: Patrick Erichsen <[email protected]>
What Problem This Solves
Memory dreaming and backfill repeated admission metadata reads for each candidate. Awaited harness tool construction could also fall back to synchronous skill-library SQLite reads after a cold cache or cache eviction.
User Impact
Memory exclusions and pinned skill resources retain their existing behavior. The memory admission guard reads candidates in bounded batches, and awaited tool construction carries immutable prepared resources across worker waits. Deleting or replacing a memory source during preparation now refuses ingestion before diary publication. No schema, stored-data, durability, retention, permission, configuration, or released synchronous SDK contract changes are required.
Why This Change Was Made
The existing session-history owner serves corpus preparation under captured physical-source custody. The final exclusion decision remains synchronous after corpus and forgotten-session preparation: raw SDK and foreign writers do not yet publish complete revocation facts, so making that last guard asynchronous would introduce an authority gap. Candidates are grouped by agent and physical store, then selected in batches of at most 128 through the existing canonical transcript-instance owner. Forgotten sources and disabled policy avoid metadata queries. Canonical validation precedes the batched window query, preventing cold admission from replaying it.
The awaited harness path uses the existing shared-state reader to prepare selected library entries and passes the frozen entries explicitly into resource discovery. Cache eviction cannot reactivate the synchronous fallback. Run authority, database admission, and physical file identity remain live through publication. Released synchronous adapters remain available, and incognito ownership is unchanged.
Cold skill preparation adds one worker read request and one reader-close request; it does not reduce all-thread SQL. The measured saving is in memory admission, as detailed below.
The change is 19 files, +846/-221 lines: net +195 production, +415 tests, and +15 docs. Most growth is regression coverage for the actual entry points, authority loss, and physical replacement; shared fixtures and workspace-agent selection are extracted into existing owners to keep the runtime cutover coherent.
Evidence
Final-head proof on AWS, Node 24.21.0 / pnpm 12.5.1, base
78ade2d7253f2e2db1794337dad14a22d6747f91versus candidate15bb6602d3d13ad4ea7493c3f95279bc31f02759:node scripts/check-changed.mjs --base 78ade2d7253f2e2db1794337dad14a22d6747f91 --timed: exit 0, 2,566.12 s.pnpm check:madge-import-cycles: exit 0, 18.19 s;pnpm deadcode:full: exit 0, 99.50 s.pnpm check:database-worker-ratchet --base 78ade2d7253f2e2db1794337dad14a22d6747f91: exit 0, 3.04 s.pnpm plugin-sdk:api:diff --base <base> --head <candidate>: exit 0, 600.90 s; compatibility assessment below.Focused test command and cost
pnpm test \ extensions/memory-core/src/session-ingestion.test.ts \ extensions/memory-core/src/session-backfill.test.ts \ extensions/memory-core/src/dreaming-phases.test.ts \ src/plugin-sdk/memory-core-host-engine-sessions.test.ts \ packages/memory-host-sdk/src/host/session-transcript-corpus.test.ts \ src/config/sessions/session-accessor.sqlite-data-version.test.ts \ src/config/sessions/session-entry-read.worker.test.ts \ src/agents/harness/host-capability.skill-pins.test.ts \ src/agents/harness/host-capability.test.ts \ src/agents/harness/host-skills.test.ts \ src/skills/library/selection-authority.test.ts \ src/skills/runtime/embedded-run-entries.library-read.test.ts \ --maxWorkers=1AWS wall time: 221.68 s; reported test-runner time: 221.20 s. GitHub CI seconds are not yet measured.
Integrated-base source census (
node scripts/database-worker-inventory.mjs --jsonon each revision): T1 799 → 799, with 2,483 calls across 625 files on both sides. Independent remote CLI inventories passed comparison. The async bundled reachability edge atsrc/skills/library/selection-read.kernel.ts:35:16is retired; the lexical site remains for the released synchronous SDK. The memory census sitesrc/config/sessions/session-accessor.sqlite-entry.ts:207:18remains a documented, batched final-authority guard. Its retirement requires complete committed revocation publication after raw synchronous writers are removed in a future SDK major.SDK diff completed successfully: no entrypoints were added or removed, and no direct export declaration changed. The report flags 131 reachable declarations because four internal/optional declarations changed: bounded session ID selection, optional entry projection, optional physical-source capture, and the internal corpus preparation callback. The callback is reached through a private bridge; the released two-argument corpus reader and single-source synchronous metadata method retain their signatures. Reachable declaration digest:
a09916e582fb66968362ee2244aded03d97d0fbb7c7acc106bee9c75c69cb749.Ordinary Gateway measurement
Six complete runs in alternating M,C,M,C,M,C order on one AWS host. Each run completed 13 turns, 37 RPCs, delegated-child settlement, cron, compaction, and clean shutdown. Entries are medians [min–max] across the three runs per side; warmed values average the ten warmed turns within each run before taking the median. All-thread counts include every SQLite execution on every thread; MAIN is shown separately. Requests count logical worker sends.
The target memory/skill preparation paths have no ordinary-harness executions, so no ordinary decrease is credited as a saving from this PR. Connect's +8 median is unchanged startup timing: exactly one media-retention snapshot request and nine statements occur across connect+first-turn in every run, with its phase placement changing. The non-turn absolute +10 tolerance applies with that unchanged-owner attribution; no custom exception is needed.
There are no candidate-only ordinary request types or nonzero SQL deltas attributed to changed caller files. Per-pair normalized SQL/request group deltas conserve every phase total. Group medians are not added together. Both touched shared native-stack sites have identical per-run counts; the new memory batch and skill preparation paths are absent from this fixture.
Ordinary diagnostic retained: candidate pair 3 had one contended
BEGIN IMMEDIATEin the unchanged audit writer. That owner returned a retry result; all user-flow and shutdown checks passed. The failed execution is preserved separately and receives no savings credit. Each run also retained the same two unresolved-target startup sends; all warmed requests had matching completions.Focused owner measurement
The memory preview comparison uses the actual
runSessionBackfillentry and four durable candidate sessions. Three complete M,C pairs use identical fixtures. Full invocation counts include fixture setup, test hooks, calibration inside the test, and cleanup. HOST is the actual Vitest execution process, not the launcher. Compiler requests remain recorded separately from runtime worker requests.Memory removes 16 attributable statements per four-candidate admission in every pair, with no request change. The raw median reduction is 19: the extra three statements occur during unchanged fixture seeding before corpus discovery and receive no optimization credit.
data_versionreadsRaw all-thread deltas are −19, −16, −19. Pairs 1 and 3 additionally avoid two busy-timeout reads in fixture write admission and one canonical-key read in fixture transcript append; all occur before the first corpus request. SQL literal changes for timeout values and fixture timestamps cancel and are not savings. Metadata worker requests remain 0 → 0; the full runtime count remains 32 → 32. The startup observation phase contains 0 SQL and 239 total sends (238 compiler, one runtime) on each side; the test/hooks phase contains all reported SQL and 566 total sends (535 compiler, 31 runtime) on each side.
The skill path has zero net statement saving and costs two additional logical requests in the cold-plus-warm fixture: one
skills.library.descriptionstask and onecloseResourceduring teardown. All seven runtime requests complete. Its 238 compiler requests are unchanged. Six existing statements move from HOST to the existing reader:data_version,schema_version,user_version, the schema inventory query, the machine-config query, and the pinned-revision description query. Each has HOST −1 / worker +1 in every pair. Moving these statements is not credited as an optimization; it retires the bundled async fallback without increasing total SQLite executions.The skill startup phase is unchanged at 1662 ALL/HOST statements and 239 sends (238 compiler, one runtime). The test/hooks phase is unchanged at 601 ALL statements, with HOST 16 → 10 and runtime sends 4 → 6. Both cold and warm resource reads complete before the baseline's late host-SQL assertion fails; all candidate cases pass. The combined test records only one description request, so the warm call adds no further description request. It does not provide separate latency totals for cold and warm calls.
Published driver × candidate update
The canonical build passed in 352.04 s and package creation in 91.42 s. The Linux Docker update cell passed in 474.46 s using published
[email protected]against candidate commit15bb6602d3d13ad4ea7493c3f95279bc31f02759. The repository cell relabeled the candidate package version to2026.9.9; it verified the candidate commit, finished update state, readiness 200, running version, durable-session checks, and incognito checks. Candidate input tarball SHA-256:f1238d2f59d2cbf0ea42c3c50f97ae0c5b6a2c15c56d2acffa65b4c4ec12b296. Driver registry integrity/provenance and individual step exits were retained.Scope and remaining gaps
The memory final-authority guard and released synchronous skill adapter remain intentional native routes. Incognito ownership, schemas, stored bytes, retention, durability, permissions, and configuration are unchanged. The ordinary harness does not exercise these selected memory/pin flows and remains above the campaign's eventual 500-statements-per-warmed-turn objective. Focused cost evidence covers cold memory preview and a combined cold/warm skill test; dreaming, disabled policy, forgotten sources, source replacement, and cancellation are covered functionally rather than by separate paired cost measurements.
Proof ran on AWS after a Testbox admission stall exceeded 15 minutes and campaign fleet/slot waits. Earlier tmpfs/memory-pressure failures were diagnosed and resolved by moving task storage to the work filesystem; all final-head code gates subsequently passed. Incomplete focused samples were discarded for missing worker observation or incomplete endpoint correlation. The corrected private invocation adapter preserves the shared observer bytes, requires worker coverage and conserved request/SQL accounting, and rejects ambiguous or incomplete observations. A separate update-wrapper JSON parsing failure was corrected without rebuilding or altering the verified candidate package.
The task-owned AWS lease has been released and its host removed. No production Gateway or live user state was changed.
Landing review and inherited CI disposition
Landing review retains head
15bb6602d3d13ad4ea7493c3f95279bc31f02759, the coordinator approval, the completed clean P2 review, and the valid alternating-pair proof above. ClawSweeper completed this head at 2026-10-08T13:57:52Z with no actionable findings. No SQL remeasurement or source change is required for landing.CI run 37786872278, attempt 1 has two independently unrelated failures. The native admin exception is authorized for these unchanged inputs; failed CI is not represented as green:
build-artifacts: compilation completed, then generated-artifact validation found stale Workboard JS/CSS paths inextensions/workboard/openclaw.plugin.json. The PR does not touch Workboard or its asset generator. Main repaired that manifest ind7b523ece4fdf1a9bd637675e993c50cce25fbf0.checks-node-changed-extensions-bundle-4:extensions/codex/src/app-server/side-question.test.tsexpected the final cancellation error within its existing 200ms wait. Its synthetic host and mocked tool factory bypass the changed harness skill preparation; it does not reach memory ingestion or corpus admission. The test, fixture, and cancellation implementation are unchanged by this PR. This is qualified through causal independence, not a claim that a matching failure was reproduced on main.Recent main CI 37813206648 at
95baa6d9510c6b4d242c1734c9d3cb675f5e887fpassed. This is current-main context, not matching-failure proof. The exception uses the explicitly authorized untouched-and-unrelated classification. Required security checks passed; optional cancelled auto-response checks are outside this exception's required-check scope.The released SDK source was inspected at
v2026.10.1-beta.1andv2026.9.9: the two-argument corpus facade and synchronous metadata reader keep their released signatures. The changed artifact-preparation callback is internal and is not re-exported through an SDK/runtime contract. Existing reader-signature type coverage and the completed SDK report above remain applicable.