Skip to content

improve: reduce Gateway stalls during session indexing - #147234

Merged
steipete merged 4 commits into
mainfrom
codex/session-transcript-workers
Sep 13, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/session-transcript-workers

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #138042

What Problem This Solves

Preparing large session transcripts for background indexing keeps the Gateway event loop busy with SQLite reads, redaction, text processing, and hashing.

User Impact

Background session preparation leaves substantially more time for the Gateway to handle other requests. The existing foreground context queue stays separate from background work. Reset recall boundaries also survive index publication, preventing chunks from spanning a conversation reset.

This trades worker startup and memory for main-thread availability; complete warm indexing time and the longest remaining pause stay essentially unchanged. The existing chunking revision triggers a one-time derived-index rebuild so previously indexed reset chunks are repaired too; unchanged chunks can reuse cached embeddings. No configuration, transcript format, or database schema migration is required.

Why This Change Was Made

Generalize the existing model-context worker into the session-transcript worker, with separate bounded foreground and background queues. Export text, statistics, and classification come from one read-only SQLite snapshot; preparation carries the current exact-secret redaction policy and returns reset metadata explicitly. Archives, incognito state, and caller-owned observers retain their existing local paths.

The actual indexer proof exposed an existing copy that discarded non-enumerable reset metadata. Preserve the prepared entry through that handoff. Operational worker failures now reject the rebuild so its existing failure path retains the published index and retry state.

Evidence

Three alternating baseline/candidate process pairs on the same Linux Blacksmith Testbox, each forcing five rebuilds of 10,000 synthetic messages with 512-character payloads. Across all 30 pre-reset rebuilds, content, line maps, timestamps, provenance, and indexed fingerprints match exactly. The baseline fails the reset-boundary assertion; all three candidate reset checks pass. The added overload regression preserves source/chunk/FTS rows under 128 held worker admissions and recovers after capacity drains. An unchanged legacy-index regression fails before the private chunking revision advances, then repairs through ordinary sync without force.

Warm measurement (12 samples per revision) Baseline Candidate
Main event-loop utilization, median 95.6% 31.3%
Full indexing time, median 869 ms 867 ms
Process CPU, median 899 ms 897 ms
Maximum event-loop delay per sample, median 253 ms 252 ms
Whole-process lifetime RSS high-water mark, median 1,324 MiB 1,715 MiB

These preparation measurements execute TypeScript source. First sync includes source/module and worker startup: 1.29 s baseline versus 4.51 s candidate. RSS includes fixture setup, imported source, and all workers; it is not a packaged-runtime memory measurement. A separate warm-sync CPU profile locates the remaining main-thread work in synchronous index population and final index publication. Those write owners remain unchanged by this read/preparation cutover.

Focused storage/redaction/context coverage passed (321 tests), followed by sibling checks and the complete manager race suite. The final recovery/upgrade run passes 52 tests across the 24-case manager file and existing upgrade suites. The new reset regression fails before the fix and passes afterward. All selected changed checks passed, including all four typecheck lanes, lint, dead exports, import cycles, and storage guards. Independent review found no actionable P0–P2 findings. CI exposed an outdated generic-error expectation in the source-deletion review test; the exact domain-error assertion was updated, and all 22 cases in that file, its changed checks, and review pass. The unrelated Workboard lint failure was already fixed on main.

Both Linux builds completed. The untouched baseline already exceeded the Control UI startup gzip budget by 35 bytes; the candidate exceeded it by 64 bytes. UI module/request counts and CSS totals match; build identity is not pinned between those builds.

Remote proof: https://github.com/openclaw/openclaw/actions/runs/34775319507 . The paired run and the two-process upgrade of the same saved database both passed; the owned Testbox lease is stopped. The upgrade verifies closed-state bytes before the candidate opens them, then repairs the reset chunks through ordinary sync while preserving transcript rows and source hash/mtime/size.

Measurements were captured at a59f01c361d1bc27338dc1a630230e0d0d9c7d75. The touched production files remain byte-identical after refreshing onto current main; package/dependency metadata was refreshed, and exact-head CI passed for that integration before native merge. A separate one-line CI follow-up updates the exact QA Profile routing expectation for a test newly added upstream; its full 602-case suite and scoped review/checks pass.

@clawsweeper

clawsweeper Bot commented Sep 13, 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 marked this pull request as ready for review September 13, 2026 17:44
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 13, 2026, 3:21 PM ET / 19:21 UTC (Revision 5).

ClawSweeper review

What this changes

Moves session transcript preparation into background workers, preserves redaction and reset boundaries, and rebuilds older memory indexes through existing recovery paths.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: this remains useful work beyond fetched main and the latest release. The previous worker-failure blocker is resolved, and the reviewed head preserves the production code used for the supplied performance and upgrade evidence. No actionable patch defects remain.

Priority: P2
Reviewed head: db829a1fd818436e144c7f8b2719b905833d7774

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound, bounded implementation with strong paired performance and upgrade evidence, resolved prior feedback, and clearly stated measurement limits.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The captured Linux Testbox evidence exercises the production indexer and worker preparation path, demonstrates reduced event-loop utilization with matching exports, and verifies reset repair across a saved-database upgrade. All touched production files match the measured revision; blocked raw-log access is a reviewer limitation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The captured Linux Testbox evidence exercises the production indexer and worker preparation path, demonstrates reduced event-loop utilization with matching exports, and verifies reset repair across a saved-database upgrade. All touched production files match the measured revision; blocked raw-log access is a reviewer limitation.
Evidence reviewed 9 items Pinned change ownership: Reviewed the merge-base-to-head delta supplied by the host and verified locally; unrelated base-only UI, channel, and update changes were excluded.
Separate worker queues and preserved error handling: Foreground context reads and background exports use separate bounded pools. Worker admission and transport errors propagate out of preparation into the existing failed-rebuild recovery, resolving the earlier finding.
Redaction, snapshot, and local-state boundaries: Exports read events, statistics, and classification within one read-only transaction. The caller checks the redaction registry revision before accepting worker output; incognito state and observer callbacks retain local execution. Model-context acceptance retains its existing admission, version, and anchor validation.
Findings None None.
Security None None.

How this fits together

Memory Core turns stored conversations into searchable text and embeddings. This change moves transcript reading and preparation off the Gateway thread while leaving index publication with the existing memory manager.

flowchart TD
  A[Stored conversations] --> B[Read-only SQLite snapshot]
  C[Current redaction snapshot] --> D[Background transcript worker]
  B --> D
  D --> E[Prepared text and reset boundaries]
  E --> F[Memory index publication]
  G[Foreground context requests] --> H[Separate context worker]
Loading

Before merge

  • Resolve merge risk (P1) - Source-mode benchmarks do not establish packaged-runtime memory or cold-start costs on smaller hosts.
  • Resolve merge risk (P1) - Raw Testbox logs could not be independently inspected because their storage host is blocked; the captured measurements and upgrade results remain contributor-supplied evidence.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +306, Tests +431, Docs +15. Total +752 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 16 444 138 +306
Tests 5 440 9 +431
Docs 1 15 0 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 899 147 +752

Review metrics

Metric Value Why it matters
Measured responsiveness Median event-loop utilization: 95.6% → 31.3% The supplied paired runs demonstrate more Gateway-thread availability while total indexing time and maximum pause remain essentially unchanged.
Measured resource tradeoff Source-mode peak RSS: 1,324 → 1,715 MiB; first sync: 1.29 → 4.51 s Worker startup and memory costs are explicitly documented alongside the responsiveness benefit.
Production versus tests Production +306 net lines; tests +431 net lines Production growth supports worker transport, coherent snapshots, and redaction transfer; regression coverage exercises recovery and existing-index repair.

Stored data model

Persistent data-model change detected: unknown-data-model-change: packages/memory-host-sdk/src/host/session-files.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-source-sync-ops.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/openclaw-runtime-session.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/session-files.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep transcript preparation on the bounded worker path, preserve existing publication and recovery owners, and track remaining synchronous indexing pauses separately.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep transcript preparation on the bounded worker path, preserve existing publication and recovery owners, and track remaining synchronous indexing pauses separately.

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

Yes for synchronous indexing preparation and lost reset metadata: the source paths are clear and the supplied paired runs exercise them. This read-only review did not execute tests or reproduce the broader multi-minute Gateway incidents.

Is this the best way to solve the issue?

Yes. The patch extends the existing worker mechanism, keeps foreground work separate, and reuses the established index invalidation and atomic publication paths without adding public configuration or schema changes.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Gateway responsiveness and memory-index correctness improvement with useful measured evidence.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The captured Linux Testbox evidence exercises the production indexer and worker preparation path, demonstrates reduced event-loop utilization with matching exports, and verifies reset repair across a saved-database upgrade. All touched production files match the measured revision; blocked raw-log access is a reviewer limitation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux Testbox evidence exercises the production indexer and worker preparation path, demonstrates reduced event-loop utilization with matching exports, and verifies reset repair across a saved-database upgrade. All touched production files match the measured revision; blocked raw-log access is a reviewer limitation.

Evidence

What I checked:

  • Pinned change ownership: Reviewed the merge-base-to-head delta supplied by the host and verified locally; unrelated base-only UI, channel, and update changes were excluded. (db829a1fd818)
  • Separate worker queues and preserved error handling: Foreground context reads and background exports use separate bounded pools. Worker admission and transport errors propagate out of preparation into the existing failed-rebuild recovery, resolving the earlier finding. (src/config/sessions/session-transcript-worker-runtime.ts:18, db829a1fd818)
  • Redaction, snapshot, and local-state boundaries: Exports read events, statistics, and classification within one read-only transaction. The caller checks the redaction registry revision before accepting worker output; incognito state and observer callbacks retain local execution. Model-context acceptance retains its existing admission, version, and anchor validation. (packages/memory-host-sdk/src/host/session-files.ts:650, db829a1fd818)
  • Recovery and existing-index coverage: The manager regressions inspect published source, chunk, and FTS rows during 128 held worker admissions, then verify ordinary retry recovery. Reset coverage includes an unchanged revision-4 index repaired through ordinary sync while transcript rows and source hash remain unchanged. (extensions/memory-core/src/memory/manager-session-update-race.test.ts:84, db829a1fd818)
  • Production identity across the review refresh: GitHub's complete tree for the measured revision matches all 14 surviving introduced production files at the reviewed head; both retired worker files are absent in both revisions. (db829a1fd818)
  • Supplied real indexing and upgrade evidence: The captured PR body reports three alternating Linux baseline/candidate process pairs using the actual indexer with 10,000 synthetic messages, matching output fingerprints, passing candidate reset assertions, and a two-process upgrade of the same saved database. Evidence is tied to a59f01c361d1bc27338dc1a630230e0d0d9c7d75 and https://github.com/openclaw/openclaw/actions/runs/34775319507. The lease workflow is cancelled, consistent with the reported stopped lease; that status alone proves neither scenario success nor failure. Raw job-log retrieval was blocked by the environment's storage-host allowlist. (a59f01c361d1)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-13T17:57:42.452Z sha 51c011a :: blocked before merge. :: [P2] Propagate worker failures instead of skipping existing sessions
  • reviewed 2026-09-13T18:12:39.999Z sha 23a62ad0afd000ecfe0bb78e1186d164de093457 :: blocked before merge. :: [P2] Propagate worker failures instead of skipping existing sessions
  • reviewed 2026-09-13T18:23:39.468Z sha 23a62ad0afd000ecfe0bb78e1186d164de093457 :: blocked before merge. :: [P2] Propagate worker failures instead of skipping existing sessions
  • reviewed 2026-09-13T18:51:31.654Z sha a59f01c361d1bc27338dc1a630230e0d0d9c7d75 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the operational-failure finding in a59f01c361d1bc27338dc1a630230e0d0d9c7d75. Worker admission and transport errors now reach the existing failed-rebuild owner. The real manager regression fills all 128 shared admissions, verifies that published source/chunk/FTS rows survive unchanged with dirty/error state retained, then drains capacity and verifies ordinary retry recovery. It fails before the fix and passes afterward.

I also verified the unchanged-index upgrade path. The existing private chunking revision advances from 4 to 5, so previously indexed reset chunks rebuild once even when source hashes and timestamps match. The legacy-index regression fails before that invalidation and passes afterward; all 52 final manager/upgrade cases and checks pass. There are no database schema, transcript codec, public protocol, or configuration changes. Existing cached embeddings remain reusable.

The PR description now records these repairs. Fresh paired Linux measurements and same-database upgrade proof are running on the current head; I will update the evidence before landing.

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
Use the shared session-transcript worker with separate context and background queues. Preserve exact-secret redaction and reset recall metadata through preparation and index publication.
Propagate operational worker errors through existing shadow-rebuild recovery. Advance the private chunking revision so unchanged reset-bearing indexes rebuild through the existing owner without changing transcript hashes or schemas.
@steipete
steipete force-pushed the codex/session-transcript-workers branch from a59f01c to db829a1 Compare September 13, 2026 19:11
@steipete

Copy link
Copy Markdown
Contributor Author

Reviewed the remaining merge-risk notes. The bounded worker tradeoff is intentional, and the PR explicitly limits the startup/RSS numbers to source execution; it makes no packaged-runtime cost claim. The existing-index compatibility proof is complete: two processes opened the same saved database, verified its bytes before upgrade, and repaired the reset chunks with ordinary sync while preserving transcript and source metadata. Raw-log access being blocked in the review environment does not change the executed results, which were collected and inspected during this task.

The previous operational-failure finding is fixed, the current-head CI run is green, and native prepare has passed. No actionable code findings remain; proceeding with the scoped landing under the requested maintainer authority.

@steipete
steipete merged commit 9d5615c into main Sep 13, 2026
192 checks passed
@steipete
steipete deleted the codex/session-transcript-workers branch September 13, 2026 19:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
* perf(sessions): offload transcript preparation

Use the shared session-transcript worker with separate context and background queues. Preserve exact-secret redaction and reset recall metadata through preparation and index publication.

* test(sessions): expect preserved transcript fence errors

* fix(memory): preserve indexes when transcript preparation fails

Propagate operational worker errors through existing shadow-rebuild recovery. Advance the private chunking revision so unchanged reset-bearing indexes rebuild through the existing owner without changing transcript hashes or schemas.

* test(ci): include QA profile status routing coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: memory-core Extension: memory-core 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: XL 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