Skip to content

fix: reduce session inventory counting work - #148445

Merged
steipete merged 1 commit into
mainfrom
codex/session-inventory-count
Sep 14, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/session-inventory-count

Conversation

@steipete

@steipete steipete commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated session maintenance counts were scanning wide session rows twice even when all entries had already been validated by the writer.

User Impact

Session inventory counts spend less time blocking maintenance and its callers. Counts preserve the existing archive filtering and handling of malformed, raw, and retained entries; no operator action is required.

Why This Change Was Made

Count physical rows through the existing compact indexes, then subtract unreadable entries using the same parser projection. Both parts remain in one SQLite statement, preserving the snapshot and prepared-query cache. The existing storage owner, schema, indexes, and write behavior stay unchanged.

Evidence

  • 155 existing storage and lifecycle tests passed across four files, including mixed validated/raw entries, archived entries, malformed and deep JSON, encoding boundaries, and maintenance protection of active work.
  • Matched ABBA proof ran 240 real maintenance plans on identical synthetic databases with 3,550 rich session entries and eight active admissions. Mean duration fell from 1.572 ms to 0.947 ms (39.8%); process CPU per plan fell from 1.666 ms to 1.055 ms (36.7%). Canonical database contents remained identical before and after every cell.
  • Independent P2 review found no actionable issues. Formatting and diff checks passed.
  • The complete changed-source gate passed on the combined candidates with verified matching source hashes, including production types, all 18 test-type graphs, lint, and runtime guards. The CI prerequisite was repaired in test(ci): deduplicate database worker registry #148425 after fix(ui): restore Custodian wizard session recovery coverage #148444; the patch-identical refreshed head passed its complete CI run. These operation measurements do not establish whole-Gateway or production latency.

@steipete steipete self-assigned this Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review blocked

Automated review did not run, so no review verdict was produced.

Reason: The input-safety check could not safely complete for this revision.

ClawSweeper will not retry this unchanged revision.

Next step: No contributor action is requested. Maintainers should inspect the linked workflow run.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 14, 2026 18:19
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 14, 2026
@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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 3:12 PM ET / 19:12 UTC (Revision 3).

ClawSweeper review

What this changes

The PR speeds up session inventory counts by counting physical rows through existing indexes and subtracting unreadable entries while preserving archive filtering.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful and is not present on current main. No actionable correctness or security defects were found; the prior merged optimization addresses allocations rather than this remaining counting work.

Priority: P2
Reviewed head: c6f92c64aa2c99824e0458b067f6016e4b8648f5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with relevant maintenance-path measurements, existing semantic coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports matched before/after runs through the real maintenance planner that calls the changed inventory owner, with reduced operation time and unchanged database contents on synthetic populated databases; this review did not rerun those measurements.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports matched before/after runs through the real maintenance planner that calls the changed inventory owner, with reduced operation time and unchanged database contents on synthetic populated databases; this review did not rerun those measurements.
Evidence reviewed 9 items Introduced query preserves count semantics: The pinned parent-to-head diff changes only the count calculation. The archive-filtered total and unreadable-row subtraction remain within one SQL statement; the existing parser and connection-keyed compiled-query cache remain in use.
Schema supports the subtraction invariant: entry_json and entry_valid are NOT NULL, validity is restricted to -1, 0, or 1, and existing indexes cover physical and archived rows. Raw entry and identity writes invalidate the writer-owned validity projection. The PR changes no schema, writer, retention, or authorization contract.
Existing behavioral coverage: Existing tests assert empty counts, mixed validated/raw entries, both archive modes, malformed JSON, deep JSON, and invalidated retained placeholders. These tests were inspected, not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

Session inventory reads OpenClaw’s per-agent SQLite session records. Its counts feed maintenance planning and lifecycle reporting.

flowchart TD
  A[Per-agent session database] --> B[Count stored rows]
  C[Include archived setting] --> B
  C --> D[Select unvalidated rows]
  A --> D
  D --> E[Parse existing entry projection]
  B --> F[Subtract unreadable entries]
  E --> F
  F --> G[Maintenance and lifecycle counts]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5. Total +5 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 12 7 +5
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 12 7 +5

Review metrics

None.

Technical review

Best possible solution:

Keep inventory counting inside the existing SQLite owner, using compact indexes without changing readable-entry semantics or persisted state.

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

Not applicable as a correctness-bug reproduction: this is a performance optimization supported by source inspection and reported matched maintenance measurements.

Is this the best way to solve the issue?

Yes. The patch reuses the existing query, parser, indexes, and cache lifecycle, avoiding a new counter or persisted projection.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded performance improvement to repeated session maintenance counts, with no demonstrated urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports matched before/after runs through the real maintenance planner that calls the changed inventory owner, with reduced operation time and unchanged database contents on synthetic populated databases; this review did not rerun those measurements.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports matched before/after runs through the real maintenance planner that calls the changed inventory owner, with reduced operation time and unchanged database contents on synthetic populated databases; this review did not rerun those measurements.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-14T18:26:11.390Z sha 568e401cc7cb8562a3246d91a3a7dd8150fcc954 :: blocked before merge. :: none
  • reviewed 2026-09-14T18:50:07.348Z sha 568e401cc7cb8562a3246d91a3a7dd8150fcc954 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/session-inventory-count branch from 568e401 to c6f92c6 Compare September 14, 2026 19:06
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 14, 2026
@steipete
steipete merged commit 9714d48 into main Sep 14, 2026
199 checks passed
@steipete
steipete deleted the codex/session-inventory-count branch September 14, 2026 19:34
@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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