Skip to content

perf(sessions): aggregate validated inventory counts - #146158

Merged
steipete merged 1 commit into
mainfrom
codex/memory20-inventory-08
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/memory20-inventory-08

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session inventory counting materializes one JavaScript row per stored session even when the writer has already validated the entry. Maintenance and lifecycle counts repeat this work on populated Gateways.

Why This Change Was Made

Aggregate writer-validated rows in SQLite and stream the remaining raw rows through the existing JSON parser. Both branches share one SQL statement and the same archive filter. Cache the two compiled query shapes weakly by connection; the existing iterator still owns each private native statement. No session data, schema, writer, transaction, retention, or recovery behavior changes.

User Impact

Counting a large session store allocates substantially less temporary memory. Empty stores, archived entries, raw writes, malformed JSON, and retained placeholders keep their existing count semantics.

Evidence

The actual count owner was measured on parent6d0c1c9fcf5a and the candidate using synthetic owner-written sessions, 1,000 reads per case, and identical expected counts:

  • 1,000 sessions: 298.72 MB to0.99 MB sampled allocations (99.67% lower).
  • 1,000 sessions excluding archived rows:243.23 MB to1.16 MB (99.52% lower).
  • 100 sessions:32.53 MB to1.13 MB; empty store:2.66 MB to1.18 MB. Archive-filtered variants also improve.

These are bounded allocation samples. Instrumented wall times varied, including a slower empty-store sample; they do not establish a general latency or retained-memory improvement.

All219 tests passed across session accessors, cache/data-version behavior and raw-row/exclusion contracts. The added mixed validated/raw/archive case also passes the original implementation. During development, these tests caught and rejected an incorrect UNION column order; the final query selects the same columns in both branches. Fresh independent P0-P2 review is scoped-clean. Formatting and whitespace pass; changed-lane planning selects core and core tests. Aggregate local checks remain unrun after host resource exhaustion; exact-head hosted CI 34703977545 passed all required checks.

Connection-lifetime proof exercised both compiled modes on 30 actual owned database connections, closed their owners, and observed zero retained connections after garbage collection. This verifies cache lifetime without claiming a retained-memory size reduction.

@clawsweeper

clawsweeper Bot commented Sep 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 size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 16:01
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 12:08 PM ET / 16:08 UTC.

ClawSweeper review

What this changes

The PR reduces temporary allocations when counting stored sessions by aggregating validated entries in SQLite while preserving parsing and archive filtering for raw entries.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful: current main and the latest release still count validated sessions row by row. No introduced correctness or security defect was found, and the protected maintainer PR should remain in the normal landing workflow.

Priority: P2
Reviewed head: 23ec1dd8f803b04f52a8a5639c3157f2669ac5be

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with sound query semantics, useful compatibility coverage, and appropriately bounded performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies this as a maintainer PR, so the external-contributor proof gate does not apply. Its body reports production count-owner measurements with synthetic SQLite sessions and preserved counts; no authority-changing behavior requires additional proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies this as a maintainer PR, so the external-contributor proof gate does not apply. Its body reports production count-owner measurements with synthetic SQLite sessions and preserved counts; no authority-changing behavior requires additional proof.
Evidence reviewed 9 items Introduced query preserves the counting contract: The aggregate and raw-row branches use identical archive filtering and matching column order in one UNION ALL statement. Only compiled query shapes are cached; each call executes against current database contents.
Validation partition is exhaustive: The existing validity column is NOT NULL and constrained to -1, 0, or 1. Insert, JSON-update, and identity-update triggers clear validation; canonical writes subsequently set it to 1. Thus the two query branches retain the previous validated-versus-parser distinction.
Native statement ownership remains unchanged: The iterator prepares a private statement for each invocation and consumes the supplied compiled query synchronously. The new weak cache does not retain native statements or count results.
Findings None None.
Security None None.

How this fits together

Session inventory reads OpenClaw’s per-agent SQLite database and supplies counts to maintenance planning and lifecycle reporting. Validated entries can be counted directly; raw entries still require the existing JSON parser.

flowchart TD
  A[Per-agent session database] --> B[Archive filter]
  B --> C[Validated entries]
  B --> D[Raw entries]
  C --> E[SQLite aggregate]
  D --> F[Existing JSON parser]
  E --> G[Combined session count]
  F --> G
  G --> H[Maintenance and lifecycle reporting]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +35, Tests +35. Total +70 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 42 7 +35
Tests 1 35 0 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 77 7 +70

Review metrics

Metric Value Why it matters
Reported allocation reduction 298.72 MB → 0.99 MB across 1,000 count reads of 1,000 sessions The bounded production-owner measurement supports the optimization’s purpose without claiming a general latency improvement.

Technical review

Best possible solution:

Keep counting inside the existing inventory owner, using SQLite aggregation for validated rows and the established parser for everything else.

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

Not applicable as a correctness-bug reproduction: this is a performance optimization, and source confirms the existing per-session materialization. The PR supplies bounded before/after allocation measurements.

Is this the best way to solve the issue?

Yes. Aggregating the existing validated partition preserves one-statement consistency and raw-parser behavior without adding persistence or another counting owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 28c97ff7b97a.

Labels

Label changes:

  • add P2: This is a focused performance improvement for populated session stores without evidence of an urgent user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies this as a maintainer PR, so the external-contributor proof gate does not apply. Its body reports production count-owner measurements with synthetic SQLite sessions and preserved counts; no authority-changing behavior requires additional proof.

Label justifications:

  • P2: This is a focused performance improvement for populated session stores without evidence of an urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies this as a maintainer PR, so the external-contributor proof gate does not apply. Its body reports production count-owner measurements with synthetic SQLite sessions and preserved counts; no authority-changing behavior requires additional proof.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit d11e744 into main Sep 12, 2026
268 checks passed
@steipete
steipete deleted the codex/memory20-inventory-08 branch September 12, 2026 16:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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