Skip to content

perf: reduce repeated memory and quarantine database reads - #169898

Merged
steipete merged 5 commits into
mainfrom
dbasync/memrecheck
Oct 12, 2026
Merged

steipete merged 5 commits into
mainfrom
dbasync/memrecheck

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Ordinary memory indexing and database admission repeat revision, session-tombstone, and quarantine-decision reads although the Gateway owns their writers. This removes those repeated reads while retaining the full-index replacement conflict check and the forgotten-session predicate at publication.

User Impact

Memory indexing and database opens avoid repeated SQLite reads while preserving forgotten-session filtering and corruption refusal.

Why This Change Was Made

Memory tombstones load once per admitted physical database. The forget writer publishes the committed session/agent set through the existing transaction-aware database-fact transport; rollback and schema recreation preserve the correct view. The entry-origin reader filters its bounded reply from those facts. Embedding cache keys identify content, so unrelated index revision changes no longer reject cache writes or clears. Incremental source publication returns its existing post-write facts without an extra pre-write revision read.

Quarantine guards retain each pathname's decision, including absence. Record and clear publish committed postimages through the same existing transport. Recorded damage still checks the target file generation, and explicit Doctor inspection still reads disk. No schema, durability, retention, SDK, update, or public configuration change.

Removed checks and accepted edges

  • Embedding-cache revision recheck: unrelated source updates may overlap reusable content-addressed cache writes; dimension-conflict invalidation and forgotten-session filtering remain.
  • Incremental source pre-write revision read: its revision was used only to reject later disposable cache writes; the committed source facts remain authoritative.
  • Per-session tombstone SQL and batched EXISTS query: all production writes use the forget owner; unsupported direct DML must go through that owner or restart the process. Schema recreation invalidates admitted facts.
  • Per-guard quarantine SELECT: out-of-process writes while the Gateway owns the store are unsupported; restart or explicit fresh Doctor inspection observes them. In-process record/clear is immediately published.

Evidence

Measurement

One baseline/candidate live pair under the campaign CPU gate, ten warmed turns each: base a583e3085be3, candidate f8e4df889ae3. Final-head CI covers the subsequent main integration and documentation conflict resolution; memory/quarantine implementation source is unchanged. Both runs passed all turns, control-plane RPCs, cron, compaction and clean shutdown, with complete request attribution.

Warmed metric Base median [min–max] Candidate median [min–max] Base → candidate mean
All-thread SQL statements 392 [385–446] 392.5 [387–436] 403.7 → 401.3
Worker requests 91 [90–104] 91 [89–101] 94.5 → 93.2
MAIN SQL statements 0 [0–0] 0 [0–0] 0 → 0

Whole-workload statements: 10,871 → 10,750; requests: 1,861 → 1,844; MAIN statements: 1,982 → 1,976. The warm median's +0.5-statement movement is within timer noise; both means fall and no touched/shared read family rises. This is one live pair under RELAXED TESTING v6, not a three-pair confidence claim.

Exact read families per warmed turn (non-overlapping target rows):

Owner/read family Base Candidate
Memory revision recheck 0.6 0
Memory per-session tombstone lookup 0.6 0
Origin tombstone predicate 0.3 0
Quarantine decision lookup 0.3 0
Exact-entry facts 7.9 7.1
Actor hydration 6.6 6.4
Entry-cache snapshot primary reads 0.3 0.3
Row facts (inclusive) 4.6 4.4
Shared row facts (inclusive) 3.3 2.9
Transcript watermark reads 5.6 5.4

The four target families fall by 1.8 SQL/turn on this base; the earlier ≈5 target came from a different census. Snapshot participant reads are also unchanged (all snapshot SELECTs: 0.6 → 0.6). Hydration and quarantine use the current named call stacks because their SQL shapes changed since sqlmeasure14; other exact-family shapes use that census. Inclusive shared cohorts overlap and are not summed as independent savings.

Memory domain operations retain their request counts: cache.write.inline 0.3 → 0.3 requests/turn, SQL 2.8 → 2.3; source.replace.inline 0.3 → 0.3 requests/turn, SQL 6.0 → 5.9. Other memory read, source-state, hash/chunk and cache-prune operations are unchanged. There is no request increase attributed to this owner.

Harness adaptation: the shared harness is untouched. The task copy adds count-only request instrumentation, suppresses duplicate archives, and sets the existing OPENCLAW_HANDSHAKE_TIMEOUT_MS=75000 equally for both isolated Gateways. An initial baseline attempt expired the default 15-second handshake under host load before any turns; it is excluded. This pair proves SQL behavior, not default-handshake timing. No workload RPC, turn or assertion was removed.

T1 and validation

Memory SQL remains in its existing workers. Seven quarantine inventory callsites are boot/lease admission/clean-close primitives, now classified individually as the permitted T2 exception with direct caller evidence; this reclassification is not claimed as a runtime SQL saving. The hot quarantine decision read itself is removed from the warm path. Lane T1 callsites: 7 → 0; existing memory callsites remain W. On the paired measurement base, regenerated whole-tree T1 totals are 496 → 487 (seven reclassifications here and two stale inventory entries corrected by regeneration), not nine runtime optimizations.

Final-head PR CI passed: changed owner tests, type-aware lint/types, source contracts, Madge, database-worker and dialect ratchets. The extension test shard initially failed before tests when the pinned Bun download returned HTTP 504; its rerun passed. All three final-head Knip export scans passed with zero unused exports (production, full-tree and scripts). Codex autoreview: two completed rounds, scoped-clean through P2 for implementation and through P1 for the test cleanup; no actionable findings. Basic changed-file oxfmt/oxlint and git diff --check passed. Broad test proof uses PR CI under the campaign testing rules; the memory worker shard passed 10 files in 183.51 seconds. No separate local Vitest suite was run under v6. Focused coverage includes forgotten-session commit/rollback/schema recreation and quarantine add/clear/failed-write visibility. No update cell is needed because update, Doctor, schema/migrations, plugin loading, and service lifecycle implementations are unchanged.

Size

Current diff: 364 additions / 402 deletions across 20 files, including regression tests, documentation, and generated inventory. No dependency or public API changes.

@clawsweeper

clawsweeper Bot commented Oct 12, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core scripts Repository scripts size: L labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses committed memory tombstone and quarantine decisions and removes revision checks from content-addressed embedding-cache operations.

Example: An existing healthy agent database passes three additional quarantine guards after its first lookup.

  • Before: Each guard queries the persisted quarantine decision.
  • After: The guards reuse the cached absence, while committed record and clear operations update that decision.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent source changes with no identified defect; current runtime evidence is limited and CI remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied owner regressions cover committed facts and rollback, while the live baseline/candidate measurement remains pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Ordinary indexing and database opens spend work rereading decisions already owned by the Gateway.
Reason: The maintainer-directed change reuses existing infrastructure without new configuration, public APIs, or persisted formats.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it contains useful maintainer-directed performance work absent from current main, with no actionable code findings.

Priority: P2
Reviewed head: 5423b47ccb97c89b14c592725a3b6d4798a1c342

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not yet include the planned production Gateway comparison showing reduced reads with forgetting and quarantine behavior preserved.
Agent review details

How this fits together

Memory workers publish index and cache writes, while database admission consumes quarantine decisions; existing transaction-aware facts carry committed changes between their owners and readers.

flowchart TD
  A[Memory indexing] --> B[Publication worker]
  C[Forget owner] --> D[Committed database facts]
  D --> B
  E[Quarantine owner] --> D
  D --> F[Database admission guards]
  B --> G[Agent SQLite database]
Loading

Technical review

Best possible solution:

Retain the existing writer owners and committed-fact transport while validating the resulting reduction in repeated reads.

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

Current-main source shows repeated quarantine lookups and revision/tombstone reads; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change follows the existing single-writer contract, removes superseded checks, and preserves full-reindex conflicts, dimension-conflict invalidation, and forgotten-session publication guards.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1ec7b42 adds extensions/memory-core/src/memory/manager-embedding-cache-ops.ts:140 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1ec7b42f3cfe; files: extensions/memory-core/src/memory/manager-embedding-cache-ops.ts)
  • Vincent Koc: Raw commit f288589 adds src/state/openclaw-quarantine-store.ts:174 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: f288589166e0; files: src/state/openclaw-quarantine-store.ts)

PR surface

Source +31, Tests -94, Docs +9, Other +16. Total -38 across 20 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 10 164 133 +31
Tests 6 129 223 -94
Docs 3 54 45 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 1 17 1 +16
Total 20 364 402 -38

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 focused runtime performance improvement without evidence of an urgent user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Publish the planned baseline/candidate Gateway trace, including repeated-read reductions and preserved Forget and quarantine outcomes.

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 (2 earlier review cycles)
  • reviewed 2026-10-12T12:59:13.298Z sha c2e5b6b :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T13:16:25.609Z sha 120a5c7 :: needs changes before merge. :: none

Reviewed October 12, 2026, 10:20 AM ET / 14:20 UTC (Revision 3).

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@steipete
steipete merged commit 4dea824 into main Oct 12, 2026
215 of 217 checks passed
@steipete
steipete deleted the dbasync/memrecheck branch October 12, 2026 15:20
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…169898)

Keep memory tombstones and quarantine decisions in owner-held facts, publish committed changes through existing database admission transport, and remove disposable embedding-cache revision rechecks. Preserve full-index replacement conflicts, forgotten-session publication checks, quarantine generation checks, and fresh Doctor inspection.

The live ten-turn pair removed all four targeted warm read families (1.8 statements/turn on this base). Mean warmed SQL fell from 403.7 to 401.3 and requests from 94.5 to 93.2; warm MAIN SQL remained zero. Lane T1 inventory entries fall from seven to zero by classifying existing boot/lease/close primitives, not by claiming seven removed runtime calls.

Validation: final-head PR CI, three Knip export scans, two Codex review rounds, and isolated baseline/candidate live runs. No schema, dependency, SDK, or public configuration change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L 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