Skip to content

perf(sessions): speed up archived session searches - #156665

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-sessions-list-filtersetup-regression-20260919
Sep 23, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-sessions-list-filtersetup-regression-20260919

Conversation

@steipete

@steipete steipete commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Searching archived sessions repeats synchronous SQLite reads for every cold row. A 5,000-session fixture reproduced 56,700 Gateway-thread reads per sessions.list call and roughly 0.8 seconds in filtering.

User Impact

Cold archived searches use about 54% less handler-thread CPU in the measured fixture and execute no main-thread SQL. Results are unchanged. No configuration or migration is required; archived display rows and transcript backfills remain bounded by the existing projection owner.

Why This Change Was Made

Retain ACP metadata and board membership from the existing worker batch instead of falling back to synchronous reads when an archived row has no materialized display data. Exact durable publications and config/store changes refresh the facts under the existing row/database revision checks. Catalog-only demotion preserves them, and lifecycle replacement drops the previous ACP binding.

The tradeoff is one worker metadata pass over cold rows at admission and after config/store invalidation. This does not materialize archived display rows. Net production growth: 13 lines.

Stored-data compatibility: preparedAcpMeta is an in-memory property of the resident Row, not a field added to persisted SessionEntry or a write payload. The patch changes no SQLite schema, schema version, migration, serialization format, config format, or persistence writer. The existing read-only worker acquires the same stored ACP/board facts; the acceptance owner retains them in memory. Upgrade and rollback therefore read the same database bytes with no migration or backfill. Hydration, archive demotion, exact publications, and lifecycle replacement are exercised by the passing tests below; the native state schema guard passed at unchanged version 18. The automated migration/backfill/repair path classification does not describe a persisted-data change in this diff.

Evidence

Synthetic rig: 5,000 sessions, including 2,700 cold archives; registered sessions.list handler; three warmups and ten timed calls. Before/after ran on the same Blacksmith Testbox against base a1107a5217b67fbb2e4ecb27d7bc458cc3713a9c. Timings exclude the SQLite counting hook; statement counts come from a separate call. A fixed clock and normalized fixture paths make complete response hashes comparable.

Cold archived search Before After
filterSetup median 811 ms 371 ms
RPC median 813.1 ms 373.0 ms
Handler-thread CPU median 809.1 ms 371.8 ms
Main-thread read statements/call 56,700 0
acp_sessions reads/call 16,200 0
config_machine_state reads/call 8,100 0
board_tabs / participant reads/call 0 / 0 0 / 0

Normal-list and people-list RPC medians were 5.0 → 3.9 ms and 7.1 → 5.0 ms. Active-only was 32.8 → 40.0 ms in this sample; this change targets archived search. Complete result hashes match for all four request shapes.

The RPC regression covers matching runtime searches, full result equality after catalog demotion, config refresh, ACP publications, board filtering, and lifecycle replacement. It fails on the original base with 12 ACP and six config-state reads over two cold rows. Its native board write requires the existing gateway-database-workers group; no new pool, serial configuration, or worker limit is introduced.

Validation uses provider blacksmith-testbox, profile openclaw-check, lease tbx_01m37dwe677tdfke8853asgxgh (run):

  • pnpm test src/gateway/session-row-projection.search-facts.test.ts --maxWorkers=1: passed; 3.80 s test time, 51.97 s wrapper wall including cold worker compilation.
  • pnpm test src/gateway/session-row-projection.archived.test.ts --maxWorkers=1: eight passed; 15.16 s test time, 44.80 s wrapper wall.
  • node scripts/run-vitest.mjs src/gateway/session-row-projection.archived.test.ts src/gateway/session-row-projection.accepted-facts.test.ts src/gateway/session-row-projection.worker-read.test.ts: 46 sibling tests passed in the combined run.
  • Temporary 5,000-row rig via node scripts/run-vitest.mjs: nine historical snapshots and the candidate passed; benchmark scratch was removed from the deliverable.
  • node scripts/check-changed.mjs --base HEAD -- <changed files>: core typechecking, all 25 test-type shards, formatting, boundaries, and earlier guards passed. The dead-export guard identified the retired board helper export; it is now private and its test counts actual SQL. Affected type/runtime checks and the remaining planned gate components passed separately, reusing the passing proof. The earlier moving-origin/main comparison reported unrelated Zalo line-cap growth already present in this task's base; no ratchet exemption was added.
  • Final cleanup proof on blacksmith-testbox/openclaw-check, lease tbx_01m37k0rqvf0hyph7w00n2mgzf (run): nine affected runtime tests passed (new RPC case 2.31 s; archived cases 11.15 s; combined wrapper wall 58.10 s). Core and both affected Gateway test-type graphs, dead-export scans, task-file lint, script lint, schema/storage/media/sidecar/import-cycle/webhook/pairing guards passed.
  • Full pnpm lint:core found two unmodified baseline violations, also byte-identical on current main: src/cron/service/timer.test.ts (1,022 counted lines; limit 1,000) and src/gateway/server-methods/sessions.abort-agent-scope.test.ts (1,002; limit 1,000). All other stripes passed; direct lint of every changed TypeScript file passed with zero warnings/errors. These failures were not suppressed.
  • Codex autoreview: final pre-commit pass clean, with no actionable P0–P2 findings.
Historical phase measurements and attribution

The same instrumented rig was run at both supplied builds and all six proposed candidates. These timings include the statement counter and vary with host load; every historical snapshot executed the same 56,700 reads and returned the same response hashes.

Snapshot Cold-search filterSetup median
a2e79767baf6 (earlier build) 587 ms
b981f930dc2 (#156014) 827 ms
3ab93b4ea59 (#156286) 896 ms
383730e5682 (#156268) 761 ms
7c9f2723d63 (#156338) 738 ms
a9c4ff712b5 (#154965) 988 ms
e77e2791e07 (#156462) 703 ms
4663b6e4041366 (later build) 1,093 ms
a1107a5217b6 (task base) 1,095 ms
Candidate 529 ms; zero reads

The cold modelFacts fallback originated in b3fdf20e631 (#151574). b7f616e4326 (#155740) later prepared ACP metadata only for materialized rows, leaving this path synchronous. Both precede the supplied earlier build. The list/filter callees are unchanged across the supplied interval, so this evidence does not establish a new culprit within that interval.

Initial provisioning needed dependencies installed in the synchronized checkout. Lease tbx_01m37d65vvdrxayam7cs256p8z was stopped after native sync timeouts. Fixture failures uncovered missing prepared plugin metadata, a moving response timestamp, and native board host-thread requirements; these were corrected without relaxing the zero-query or equality assertions. The archived-lineage suite also caught an early candidate's board-fact lifetime error, which is fixed.

No live Gateway deployment or production remeasurement was performed. This proves the cold archived search path; the cause of the reported production jump between the two builds remains unestablished. Exact-head CI passed in 982 seconds elapsed (17:12:39–17:29:01 UTC, including parallel jobs). Per-file CI timing was not collected; the Testbox test budgets above are the measured per-file evidence. GitHub squash auto-merge, enabled through GraphQL, completed as fe5005f85f1065f04b1b0d99ed6fc68b70d59b7d.

Retain ACP metadata and board membership on resident archived rows using
existing worker batch acceptance and row/database revision invalidation.
Keep archived display rows cold and preserve durable facts across catalog
demotion, so repeated searches no longer reread SQLite on the Gateway thread.

Cover RPC result equality, ACP publications, board filtering, and lifecycle
replacement without main-thread session metadata reads.
@clawsweeper

clawsweeper Bot commented Sep 23, 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.

@steipete
steipete enabled auto-merge (squash) September 23, 2026 17:13
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 23, 2026, 1:19 PM ET / 17:19 UTC.

ClawSweeper review

What this changes

The PR retains worker-prepared runtime metadata and board membership for archived sessions, avoiding repeated database reads while preserving search results and bounded display-row caching.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful, focused performance fix: current main still rereads metadata for cold archived searches. No actionable correctness or security defect was found in the introduced changes.

Priority: P2
Reviewed head: 3aea8b8266772fc7f4c779c496871a5d05803306

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with measured boundary evidence, meaningful regression coverage, and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured Testbox comparison exercises the registered session-list handler and actual database-worker path, reporting eliminated main-thread reads and matching results after the fix. This supports the scoped optimization, not deployment-wide performance; raw linked logs were inaccessible to this reviewer. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Testbox comparison exercises the registered session-list handler and actual database-worker path, reporting eliminated main-thread reads and matching results after the fix. This supports the scoped optimization, not deployment-wide performance; raw linked logs were inaccessible to this reviewer. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduced changes: Reviewed the merge-base-to-head delta, including metadata retention, invalidation, lifecycle replacement, RPC regression coverage, and existing worker-test routing. Base-branch drift was not attributed to this PR.
Current main still contains the targeted fallback: Current main supplies prepared ACP metadata only for clean materialized rows. Cold archived rows pass undefined, allowing runtime projection to call the synchronous metadata reader. The related merged performance work does not eliminate this remaining path.
Cache lifetime and worker acceptance: Worker replies retain the existing physical-store, database-revision, row-revision, and generation checks. Catalog demotion preserves accepted search facts; other broad invalidations clear and requeue them, and lifecycle replacement clears the old ACP binding.
Findings None None.
Security None None.

How this fits together

The Gateway session-row projection turns stored session metadata into searchable session lists. Database workers prepare facts, while the Gateway filters and presents rows using current configuration and sharing rules.

flowchart LR
  A[Stored sessions and runtime metadata] --> B[Existing database workers]
  B --> C[Revision and lifecycle checks]
  C --> D[Resident search facts]
  E[Committed changes] --> C
  D --> F[Search and visibility filters]
  F --> G[Selected session results]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +13, Tests +144. Total +157 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 37 24 +13
Tests 3 148 4 +144
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 185 28 +157

Review metrics

Metric Value Why it matters
Measured archived-search work 56,700 → 0 main-thread reads; 809.1 → 371.8 ms median handler CPU The reported same-host fixture quantifies the targeted improvement while checking complete response equality.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/gateway/session-row-projection.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep search facts under the existing projection's revision and lifecycle owner while materializing only selected archived display rows.

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

Yes, source establishes the path: searching cold archived rows on current main omits prepared ACP metadata and reaches synchronous reads. The contributor reports a failing baseline RPC control; this review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing already acquired worker facts within the existing projection avoids a competing cache and preserves archive residency, invalidation, and lifecycle ownership.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This addresses a demonstrated archived-search performance bottleneck with a bounded implementation and no reported emergency outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured Testbox comparison exercises the registered session-list handler and actual database-worker path, reporting eliminated main-thread reads and matching results after the fix. This supports the scoped optimization, not deployment-wide performance; raw linked logs were inaccessible to this reviewer. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This addresses a demonstrated archived-search performance bottleneck with a bounded implementation and no reported emergency outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Testbox comparison exercises the registered session-list handler and actual database-worker path, reporting eliminated main-thread reads and matching results after the fix. This supports the scoped optimization, not deployment-wide performance; raw linked logs were inaccessible to this reviewer. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the merge-base-to-head delta, including metadata retention, invalidation, lifecycle replacement, RPC regression coverage, and existing worker-test routing. Base-branch drift was not attributed to this PR. (src/gateway/session-row-projection-materialize.ts:133, 3aea8b826677)
  • Current main still contains the targeted fallback: Current main supplies prepared ACP metadata only for clean materialized rows. Cold archived rows pass undefined, allowing runtime projection to call the synchronous metadata reader. The related merged performance work does not eliminate this remaining path. (src/gateway/session-row-projection.ts:652, c7bab50e6ed7)
  • Cache lifetime and worker acceptance: Worker replies retain the existing physical-store, database-revision, row-revision, and generation checks. Catalog demotion preserves accepted search facts; other broad invalidations clear and requeue them, and lifecycle replacement clears the old ACP binding. (src/gateway/session-row-projection-archive.ts:119, 3aea8b826677)
  • Production boundary and storage compatibility: The changed cache holds in-memory display/search facts. ACP acquisition uses OpenClaw's existing shared-state reader and lifecycle binding; the patch introduces no persisted format, schema, migration, plugin API, or dependency-runtime contract. (src/acp/runtime/session-meta-readonly.ts:22, 3aea8b826677)
  • Captured after-fix performance evidence: The supplied complete PR body reports a Blacksmith Testbox comparison through the registered sessions.list handler over 5,000 stored sessions, including 2,700 cold archives: main-thread reads fell from 56,700 to zero, handler CPU median from 809.1 to 371.8 ms, and complete response hashes matched across four request shapes. Active-only latency rose from 32.8 to 40.0 ms in that sample; production-wide improvement is expressly unclaimed. The captured context revision is 20b110f4a32c9118baef07ae6c318e147794ea5048e567a8839a0121e70352d5. (3aea8b826677)
  • Behavioral regression coverage: The new test exercises the registered handler with real SQLite-backed session and board owners. It checks runtime search results, response equality after catalog demotion, ACP publications, board filtering, lifecycle replacement, and absence of relevant caller-thread SQL. The body reports a failing baseline control and a final 2.31-second test case; tests were not executed during this read-only review. (src/gateway/session-row-projection.search-facts.test.ts:24, 3aea8b826677)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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 fe5005f into main Sep 23, 2026
219 of 220 checks passed
@steipete
steipete deleted the steipete/perf-micro-sessions-list-filtersetup-regression-20260919 branch September 23, 2026 17:30
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
Retain ACP metadata and board membership on cold resident rows through the existing worker batch and revision lifecycle. Preserve cold display-row retention, catalog demotion, and lifecycle replacement semantics.

A 5,000-session Testbox fixture reduced filterSetup from 811 ms to 371 ms and main-thread read statements from 56,700 to zero with identical results. RPC regression, worker/archival coverage, typechecks, scoped lint, and repository guards validated. Full core lint has two documented, unmodified baseline line-cap violations.

Related: openclaw#151574, openclaw#155740.

PR openclaw#156665 contains historical measurements, Testbox evidence, and remaining production-attribution limits.
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant