Repository navigation
perf(memory): batch indexing after agent idle periods - #170404
Conversation
|
🦞👀 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 changes before merge. What this changesThis PR delays transcript indexing until an agent is idle and batches preparation, embedding-cache reads, and index publication. Example: Agent main receives ten transcript updates one second apart.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep this PR open: the performance change has maintainer-backed value, but the previously reported mixed-source interruption bug remains on the reviewed head. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherMemory Core consumes transcript notifications, agent execution activity, and memory files; its background workers prepare embeddings and publish searchable rows into the existing agent database. flowchart TD
A[Transcript updates] --> C[Memory Core quiet timer]
B[Agent execution registry] --> C
C --> D[Transcript preparation worker]
D --> E[Embedding provider and cache]
F[Memory files] --> E
E --> G[Publication worker]
G --> H[Published memory search]
Technical reviewBest possible solution: Preserve the existing full-source continuation flag when interrupted work includes memory files, so the next quiet-period pass publishes both sources. Do we have a high-confidence way to reproduce the issue? Source establishes the remaining defect: interrupt a startup catch-up with a valid index, both sources enabled, and source-wide batching before dirty memory files publish; the next targeted session pass skips those memory files. Is this the best way to solve the issue? Reusing the existing timer, execution registry, workers, and publication owner is appropriate, but continuation must retain broad work when a mixed-source pass yields. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ec3c485e8f21. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +525, Tests +340, Docs +13. Total +878 across 43 files. Added test files: 2. View PR surface stats
Review metrics
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 HistoryReview history (5 earlier review cycles)
Reviewed October 12, 2026, 10:33 PM ET / October 13, 2026, 02:33 UTC (Revision 6). |
|
Recorded follow-ups from the completed review of
The two requested isolated review rounds are complete. These findings do not demonstrate source-data loss, a security boundary failure, or money risk and remain follow-ups under the requested relaxed landing scope. The paired live measurement and final CI evidence are being added to the PR body before merge. |
# Conflicts: # extensions/memory-core/src/memory/manager-embedding-ops.ts
Coalesce transcript indexing per agent after a 30-second quiet period, with a five-minute idle deferral bound and existing run ownership giving foreground turns priority. Batch transcript preparation, embedding-cache reads, and bounded source publication; retain incremental rewrite and compaction handling. Search and graceful shutdown do not force a flush. One ten-turn baseline/candidate pair reduces warmed SQL from 217.5 to 194 statements and requests from 57.5 to 49 per turn (medians), with MAIN SQL remaining zero. Indexing performs zero passes during the active window and publishes after settling. Final integrated-head CI and both required gates passed.
What Problem This Solves
Session indexing previously coalesced transcript notifications for only five seconds. Active conversations therefore paid transcript preparation, embedding-cache lookup, and index-publication overhead roughly once per turn even after #170302 batched individual sources.
Memory Core now waits for a 30-second per-agent quiet period, with a five-minute maximum deferral under continuous transcript activity. Existing agent-run execution ownership (including queued turns) gates background passes; active turns always take precedence. A turn that starts during indexing lets the current bounded publication finish, then pending sessions resume after the next quiet period. Rejected passes restore the consumed queue, retaining later updates, and retry through the same quiet-period timer. Ordinary groups share transcript-worker preparation, source-state/cache reads, and one publication transaction. Groups are bounded to eight sources, 128 publication rows, and the existing transfer budget; an oversized single source retains its atomic streamed replacement.
The existing background transcript-worker pool keeps this work separate from foreground model-context reads. No new scheduler, persistent queue, configuration option, database schema, or synchronous fallback is added. The queued-run registry now emits the existing runtime notification for the first/last execution lease even when display metadata remains retained.
Freshness and accepted edges
New transcript content becomes searchable after the quiet period. While the agent is idle, continuous transcript changes defer indexing for at most about five minutes, plus embedding time. Running or back-to-back turns can defer it longer: each return to idle starts a fresh quiet period because foreground work wins. The current turn already has its content in context.
memory_searchserves the published index and does not flush pending transcript changes. Shutdown does not flush the pending timer; startup catches up incrementally. Rewrites and compaction retain the existing reset-generation path.Removed repeated work/checks:
Forget/tombstone checks remain because they protect user-requested deletion. The scoped memory publication receipt remains unchanged so memory writes do not evict unrelated session caches.
Measurement
Pinned harness v2.1.0 pair: base
5cf2615e65ecand candidate9240cb4ffd08, ten warmed turns each, identical 35-second post-turn quiet window. Both full workloads passed (including subagent, cron, compaction, and shutdown). The campaign's current proof policy permits one pair. Runs used the shared CPU gate; host 1-minute load was 88.1 before baseline and 96.3 before candidate.The warmed-window reduction is 312 statements and 89 requests; indexing does no work during these active turns (−100% versus the baseline window), and overall background SQL/min falls 66.3%. The timing figures use
agent.wait's start/end timestamps, with linearly interpolated percentiles. Host load makes these timings unsuitable for evaluating a latency change; reliable latency remains unmeasured. The candidate's deferred pass began in the 35-second settle phase (20 statements / 2 requests), then yielded when subsequent foreground phases started. A separate live probe with ten warmed turns and a 90-second quiet window completed successfully: zero warm indexing passes, then one source publication during settle; the stopped Gateway database contains the indexed transcript and all three chunks. The probe logged 44 memory-index statements during settle. Its generic postprocessor retained the original 13-turn assertion and rejected this intentionally shortened 11-turn workload; direct evidence verification passed all eleven turns, shutdown, and durable index publication. Incremental/full-reindex search parity passes in the dedicated regression.Within baseline warm indexing: transcript-preparation requests 6→0; source-state/hash SELECTs 12→0; embedding-cache lookup SELECTs 6→0; source/chunk/recall/provenance publication INSERTs 24→0. Those operations move into bounded quiet-period batches, not the foreground.
Shared-read attribution per turn (whole warmed window; turn-caused count in parentheses): exact-entry facts 4.8 (4.2) → 4.1 (4.1); actor hydration 1.1 (1.1) → 1.1 (1.1); entry-cache snapshots 1.6 (0) → 0.2 (0); selected row-fact SELECTs 11.1 (11.1) → 11.1 (11.1); watermarks 1 (1) → 1 (1). No shared family or warm MAIN count rises.
T1 in memory indexing: 0 → 0. CI's database-worker and dialect ratchets passed on both measured head
9240cb4ffd08and integrated head7607f460ca621.Evidence
git diff --checkpass.This does not change schema, migration, update, or plugin/service lifecycle contracts; no published-driver update cell applies.
Timer ownership: this replaces the existing memory transcript coalescing timer; other idle/background owners remain unchanged.
Diff: 43 files, +1,525 / -643 lines (including regressions and deleted obsolete coverage).
Measured-head CI (
9240cb4ffd08): run 38327575283 completed. All 25 static jobs passed, including production/test types, type-aware lint, source contracts, Madge/architecture, docs, and T1/dialect ratchets. The three memory bundles passed 56 files / 629 tests; wall times were 318, 280, and 250 seconds (test steps 256, 217, and 213 seconds). All changed tests and six affected SDK mock consumers were explicitly present in passing logs. Core activity (3 tests), session reset/batched exports (10), and SDK contract (1) also passed.The earlier CI failure in
server.sessions.create.durability.test.tsexpected separately staged idle input after refused transcript commit. Main fixed that stale expectation in3c63da22f046b(atomic admission accepts neither pending input nor transcript when rejected); this fix is included by the main merge. The baseline diagnostic timed out in Gateway setup before reaching its assertion, so it is not claimed as inherited-failure reproduction. The redundant head diagnostic targeting the removed test name was stopped; final CI runs the replacement test. The previous dashboard-abort failure passed on the measured head.Follow-up from the completed review of
5c299ee6834b(P2; retained under the requested two-round/relaxed-landing scope): requeue a handled provider-fallback failure that resolves normally while retaining dirty source state. This can delay retry until later transcript activity or startup; the authoritative transcript remains durable. It is not a security issue or loss of source data. The other P2 finding, retaining completed vectors in the source-wide embedding array, was fixed on main and that cleanup is preserved in this integration.Final integration: removed the two obsolete batch-source summary helpers reported by Knip, then merged current main (
5e1752da6a78e) to include its UI export cleanup and memory WAL-reader ownership. Final source head is7607f460ca621. Integrated-head CI 38331920780 completed: all hosted static checks and all three memory bundles passed. Two unrelated test jobs failed, with attribution below.SDK API comparison: two additive exports,
observeAgentRunActivity(agentId, listener): () => voidandbuildSessionEntries(inputs): Promise<(SessionFileEntry | null)[]>, with no removed exports or changed existing signatures. The latter is on the private local-only memory session surface and its memory-host barrel. The source-derived API diff was reviewed; full SDK surface check, runtime guardrails, production types, and test types passed. Two attempts at native semantic-closure rendering stalled on the baseline and were stopped; a completed native render is not claimed.Earlier integrated-head failure attribution:
src/worker/worker.chat-abort.test.tsalso fail on scheduled main run 38331230273, job 115081407653, head2dd42a977aa9. Seven preview cases have the same unexpected history-save warning; the no-preview case on main reaches the later event-count assertion (four events instead of three). This PR does not change that file. The existing red-main owner is tracking these failures.src/plugins/install.npm-spec.e2e.test.tstimed out in thenpm-packlifecycle-successor case after 120 seconds. A focused run on baseline5cf2615e65ecreproduced that exact test and timeout (122.307 seconds elapsed). The suite owns its npm package fixtures and ran in its supportedOPENCLAW_E2E_SKIP_BUILD=1mode after ordinary preparation refused to rewrite potentially shared Gateway artifacts. Remaining baseline tests and the redundant candidate replay were stopped after the exact match; candidate CI is the head-side evidence. No passing whole-file replay is claimed.literal,hasProviderRequestSizeCeiling,getResolvedSpeechProviderConfig,OpenClawApp,ApplicationShell, andShellLayoutController. Both combined and standalone full-tree scans timed out at the unchanged 600-second budget under local load. A completed local full-tree result is not claimed. The two newly obsolete memory helpers were removed. The later main cleanup fix(ci): repair worker entry roots and retired exports #170499 is now integrated; its dedicated Knip proof 38334569481 passed. The integration adds no exports beyond the already-scanned patch; no new local full-tree scan was run under compute conservation.The coordinator removed the Phase E merge hold at 22:06 local. This branch then merged current main
3f1175be9d5einto heada7fb093803e9. The single conflict preserves main's disabled-batch fallback together with the pass's prepared embedding cache. Main's provider-lifetime simplification and completed-vector cleanup are retained. Changed-file oxfmt/oxlint andgit diff --checkpassed. Final integrated-head CI 38350353218 passed ona7fb093803e9, including all three memory bundles, production/test types, type-aware lint, source contracts, architecture, and T1/dialect/worker ratchets. Both required CI/security gate statuses are green; no inherited-failure override is needed for this head. No additional SQL pair or broad local suite was run under the compute-conservation rule.