Skip to content

improve: reduce session import, compaction, and UI startup overhead - #133446

Merged
steipete merged 3 commits into
mainfrom
codex/importer-performance-pass-six
Aug 30, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/importer-performance-pass-six

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large legacy-session imports spend avoidable CPU time constructing streaming hash objects for JSON strings that are already complete in the migration spool.

Why This Change Was Made

Use Node's one-shot SHA-256 API for both existing-row preload and incoming-row deduplication. The digest stays a Buffer with identical UTF-8 input, and exact JSON bytes still decide equality. Accepted-only acknowledgement, rejected-identity recency, bounded disk staging, cleanup, and all canonical write/transaction boundaries remain unchanged.

The importer change is a three-line substitution with no production LOC growth. There are no dependency, configuration, schema, index, or persistence-semantic changes. Every supported Node range includes the API; the Node contract, Node 22 source, and Node 24 native implementation were inspected. Streaming hashes elsewhere remain unchanged because their inputs are streamed.

User Impact

Median import wall time improved 3.6% for a deep history and 4.3% for many sessions in an isolated Linux Node 24 comparison. Branching and repeated imports were effectively unchanged. Imported data remains identical. The compaction follow-up below removes unnecessary embedding discovery without changing memory eligibility.

Evidence

  • 105 focused tests passed: importer deduplication/rollback/exact handoff and Doctor migration/validation.
  • Full-priority Codex autoreview found no actionable defects. Core typechecking and the completed changed guards passed.
  • The local aggregate test typecheck encounters unrelated shared-install tslog and UI declaration errors; the shared dependency tree was not modified. Clean exact-head CI is required before landing.
  • Isolated Blacksmith Testbox proof at head 1d628793d9e92775050a77a99ae41a97ee8c67e9 against base a39e03cb299f141994ac0f231077b9194acfaa79, using Node 24.19.0 / SQLite 3.53.3. Only the staging owner differs; all other source and dependencies are identical.
  • Five fresh processes per side per shape, with alternating pair order. All 20 paired persisted-data SHA-256 digests match across transcript bytes, identities, window metadata, active positions, projection watermarks, and FTS. Verification is outside the timer. A separate 10k-event trace retains exactly 100,034 SQL calls and the same 34 SQL shapes. Before/after Node CPU profiles completed separately.
Scenario Before median After median Wall reduction CPU reduction
100k events, one history 5958.2 ms 5744.4 ms 3.6% 2.9%
100 sessions × 100 events 633.7 ms 606.3 ms 4.3% 5.6%
100 branching histories 988.7 ms 983.1 ms 0.6% 0.8%
Repeat import, 10k existing events 144.1 ms 142.6 ms 1.1% 0.7%

The branching/replay differences are too small to claim a material gain. Empty, ASCII, Unicode/NUL, lone-surrogate, and 5 MiB input digests also match between APIs.

Packaged stable 2026.7.1-2 to candidate 2026.8.1 at importer head 1d628793d9e92775050a77a99ae41a97ee8c67e9 passed on Blacksmith Testbox: 4,800 sessions, 1,227,946 events, 10,000 cron jobs, and five complete state assertions. Automatic migration was checked after update and before standalone Doctor. Repeat Doctor completed in 39 seconds against a 60-second budget. Eight Gateway history samples across two agents (600 messages) were identical after restart; startup took 11 seconds and health/readiness/status checks took one second each. The synthetic plugin fixture required explicit capability consent; this proves automatic data migration, not unattended update-channel switching. Profiles and proof artifacts were collected before stopping the worker.

Compaction follow-up found during CI

The first CI run failed the unchanged healthy timeout-compaction recovery test at 132.9 seconds. A focused local reproduction failed the same case at 225.1 seconds, with all 29 sibling cases passing. This was a reproducible cold-load defect, not dismissed as runner noise.

Post-compaction sync resolved the complete embedding configuration before discovering whether a memory backend was available. The fixture enables recall through the personal-install defaults but has no memory runtime; the unnecessary OpenAI capability lookup synchronously loaded provider code first. The fix extracts the existing eligibility/source/sync facts into a provider-free resolver shared with full memory configuration. Compaction consumes those facts, and an acquired memory backend owns provider resolution. The built-in manager still performs full provider/multimodal validation before cache reuse or creation; core secret-owner gating remains before any manager acquisition. Custom memory runtimes retain their own provider validation rather than being forced through the built-in adapter's checks.

No test timeout, fixture configuration, assertion, or plugin policy was weakened. The only test-support change points the existing mock at the narrower production resolver. The added 15 production lines establish this shared owner boundary; the importer itself remains net zero. All 242 memory/configuration/recovery/hook tests pass, including the unchanged failing case now completing in 782 ms. Fresh full-priority Codex review is clean. Core typechecking and changed structural guards pass; the local aggregate test typecheck still reports the pre-existing shared-install declarations described above. The full isolated Linux pnpm build passed at head 4da5346952f9d59e7f1b47c1d33e79fdc9b6c51e. The next CI run passed the previously failing compaction shard, but exposed the UI budget issue below. Final CI completed successfully for 27e94db402d56a298dadd56c5f5a8d033cd57948, including both previously failing jobs. The Docker and benchmark evidence above applies to the unchanged importer at the named hash.

ClawSweeper's final-head review found no actionable code issues. Its rank-up move—green exact-head CI—is satisfied. The remaining production growth (net +9) establishes the shared provider-free indexing boundary; the unchanged compaction recovery case and final CI verify that it removes the cold load. The review's stored-data heuristic does not describe a data-model change: this diff changes no SQL, schema, tables, indexes, retention, persistent shape, or configuration, and preserves all store/vector values.

Startup cleanup required by the final integration build

The combined tree with newer main (5ce50c5cf5ba7454cced0be8079f5c2f7833c46e) exceeded the unchanged UI startup gzip limit by seven bytes: 346,768 B against 346,761 B. This was not dismissed as a flaky result: main had 77 intervening UI/protocol file changes, while the PR head alone built at 346,677 B. Startup source maps excluded the importer and memory changes.

The UI's localized duration functions called the core formatter and discarded its result on every valid input. Removing those calls preserves their existing invalid-input returns and all localized rounding/Intl output, while removing the only startup import of the core duration helpers, pretty-ms, and parse-ms. The Linux preview built at 345,419 B, 1,258 B smaller than the preceding head build; all four dependency sources disappeared (402 mapped sources to 398). Build identity differs between the two snapshots, so the exact byte delta includes that small variation. No budget, markup, stylesheet, or translation text changed.

All 58 formatter tests pass before and after, including invalid values, zero versus positive fractions, rounding boundaries, and French output. These tests protect output equivalence; there is no visual change to illustrate. Final full-priority Codex review found no actionable issues across all six files. Production is +50/-41 (net +9), with +33/-1 test/test-support lines. The added core indexing boundary accounts for the remaining production growth; the UI cleanup deletes six production lines. All Testbox workers have been stopped after proof collection.

@steipete steipete self-assigned this Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 30, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 3:24 PM ET / 19:24 UTC.

ClawSweeper review

What this changes

This PR replaces per-row streaming hashes during legacy session import, avoids unnecessary embedding-provider discovery after compaction, and removes unused duration-formatting imports from the Control UI boot path.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for normal maintainer handling: the final head contains unique performance work, source review found no actionable regression, and required exact-head checks are still in progress.

Priority: P3
Reviewed head: 27e94db402d56a298dadd56c5f5a8d033cd57948

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving performance patch with strong source coverage and no actionable review finding; exact-head CI remains the final merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to the maintainer-authored PR proof gate; the supplied Testbox and focused-test evidence is supplemental, and the final UI change preserves output rather than introducing a visual interaction.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to the maintainer-authored PR proof gate; the supplied Testbox and focused-test evidence is supplemental, and the final UI change preserves output rather than introducing a visual interaction.
Evidence reviewed 8 items Verified introduced scope: The pinned merge-base-to-head diff introduces only the six reviewed import, compaction, and Control UI files; git diff --check reported no whitespace errors.
Session deduplication preserves its comparison boundary: Both preload and incoming-event paths now bind the same SHA-256 Buffer, while SQLite still checks the complete event JSON after the hash lookup.
Supported runtime range: The repository requires Node 22.22.3+, 24.15.0+, or 25.9.0+, covering the Node crypto API used by the import stage.
Findings None None.
Security None None.

How this fits together

Legacy session migration stages transcript JSON before importing it into SQLite, while embedded-session compaction may request a memory sync afterward. The Control UI formats elapsed durations during its booted views; this PR reduces work around all three paths without changing their intended outputs.

flowchart LR
  A[Legacy session data] --> B[SQLite import staging]
  B --> C[One-shot row hash]
  C --> D[Deduplicated transcript import]
  E[Session compaction] --> F[Memory indexing eligibility]
  F --> G[Available memory manager]
  G --> H[Post-compaction sync]
  I[Control UI boot] --> J[Localized duration output]
Loading

Before merge

  • Resolve merge risk (P1) - Required checks for the exact final head are still in progress, so merge readiness is not yet established.
  • Resolve merge risk (P1) - The PR has a net nine production-line increase; the shared provider-free eligibility boundary is justified only if exact-head validation continues to demonstrate that it prevents the unnecessary compaction cold load.
  • Complete next step (P2) - No repair is queued because source review found no discrete defect; normal exact-head CI and maintainer review are the remaining actions.
Agent review details

Security

None.

PR surface

Source +9, Tests +32. Total +41 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 51 42 +9
Tests 1 32 0 +32
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 83 42 +41

Review metrics

Metric Value Why it matters
Production versus test delta production +50/-41 (net +9); tests/support +33/-1 The only net production growth is the shared indexing-eligibility boundary; the import substitution is neutral and the UI cleanup is net-negative.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/agents/memory-search.ts, vector/embedding metadata: src/agents/memory-search.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    After exact-head checks are green, retain the shared provider-free eligibility resolver and the behavior-preserving UI cleanup, with no new configuration, schema, or compatibility surface.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

After exact-head checks are green, retain the shared provider-free eligibility resolver and the behavior-preserving UI cleanup, with no new configuration, schema, or compatibility surface.

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

Yes—source-reproducible: current main resolves the full memory configuration before learning whether a manager exists, while the final head isolates the provider-free eligibility path. This read-only review did not rerun the reported timeout scenario.

Is this the best way to solve the issue?

Yes. Reusing one eligibility resolver preserves the memory manager as the provider-validation owner, and deleting formatter calls whose values are discarded is the narrowest startup cleanup.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d434b3dbe0b2.

Labels

Label justifications:

  • P3: This is a bounded performance and startup-overhead improvement with no demonstrated user-visible behavior change.
  • 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: Not applicable to the maintainer-authored PR proof gate; the supplied Testbox and focused-test evidence is supplemental, and the final UI change preserves output rather than introducing a visual interaction.

Evidence

What I checked:

  • Verified introduced scope: The pinned merge-base-to-head diff introduces only the six reviewed import, compaction, and Control UI files; git diff --check reported no whitespace errors. (src/agents/memory-search.ts:180, 27e94db402d5)
  • Session deduplication preserves its comparison boundary: Both preload and incoming-event paths now bind the same SHA-256 Buffer, while SQLite still checks the complete event JSON after the hash lookup. (src/config/sessions/session-accessor.sqlite-import-stage.ts:75, 1d628793d9e9)
  • Supported runtime range: The repository requires Node 22.22.3+, 24.15.0+, or 25.9.0+, covering the Node crypto API used by the import stage. (package.json:2174, 27e94db402d5)
  • Provider resolution remains owned by the memory manager: Compaction now reads only enablement, session-source, and sync facts before requesting a manager; the full resolver and built-in manager retain provider and multimodal validation when a backend is used. (src/agents/memory-search.ts:180, 4da5346952f9)
  • Compaction boundary coverage: Existing focused tests cover off, await, and asynchronous post-compaction sync behavior; the introduced harness change maps the mock to the narrower resolver. (src/agents/embedded-agent-runner/compact.hooks.test.ts:2898, 27e94db402d5)
  • UI output path is unchanged: The removed core calls had their results discarded for valid durations; the replacement keeps the same invalid-value branches while preserving the localized formatter and its callers. (ui/src/lib/format.ts:97, 27e94db402d5)

Likely related people:

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

Rank-up moves

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

  • Let required checks complete on the exact final head before merging.

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-08-30T18:31:52.723Z sha 1d62879 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T19:06:24.570Z sha 4da5346 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S and removed size: XS labels Aug 30, 2026
@steipete steipete changed the title improve: reduce hashing overhead during session imports improve: reduce session import and compaction overhead Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Head 4da5346 adds a bounded compaction performance fix found while diagnosing CI: shared provider-free memory indexing eligibility avoids embedding discovery before an unavailable backend. The unchanged timeout recovery reproduction improved from 225 seconds to 782 ms; all 242 memory/recovery/hook tests pass and full-priority Codex review is clean. Importer benchmark and packaged-upgrade evidence are in the updated body. Final exact-head CI remains required.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Aug 30, 2026
@steipete steipete changed the title improve: reduce session import and compaction overhead improve: reduce session import, compaction, and UI startup overhead Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final head 27e94db removes redundant UI duration formatting found while diagnosing the combined-tree startup budget failure. No budget was raised. Linux preview startup gzip fell from 346,677 B to 345,419 B, with all four redundant duration dependencies absent from startup source maps. All 58 formatter cases pass before and after. Full-priority Codex review is clean across the complete final diff; prior importer and compaction proof is retained in the updated body. Final exact-head CI remains required.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit ec3077c into main Aug 30, 2026
262 checks passed
@steipete
steipete deleted the codex/importer-performance-pass-six branch August 30, 2026 19:36
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 31, 2026
Compute authorization metadata for spaced and punctuation-leading bang commands, including genuinely mentioned WhatsApp group messages. Keep ClickClack control-command mention bypass distinct from coarse metadata detection.

Use the actual native command registry in regression fixtures. Align the UI formatter with the identical cleanup already landed in #133446; no additional UI change is claimed.

Proof: native channel boundary RED/GREEN, exact canonical check-stage evidence, full build, fresh independent reviews, and 15 delivered-reply checks through a rebuilt isolated Gateway with real exec targets. Preserve the earlier failed startup attempt and aggregate-check limits in PR evidence.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
…penclaw#133446)

* perf(sessions): hash staged import rows without stream objects

* perf(agents): resolve compaction indexing without embedding discovery

* perf(ui): avoid redundant duration formatting at startup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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