Skip to content

fix(gateway): reduce worker overhead with large session stores - #149700

Merged
vincentkoc merged 15 commits into
mainfrom
perf/worker-session-lookup-20260916
Sep 18, 2026
Merged

vincentkoc merged 15 commits into
mainfrom
perf/worker-session-lookup-20260916

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Worker transcript commits spend CPU reading unrelated saved prompts when resolving a session in a large inventory.

User Impact

Worker commits use less CPU with large session stores. Session selection, full selected prompt/auth fields, and transcript durability are preserved. No operator action is required.

Why This Change Was Made

Use the existing exact lookup for the selected full session entry. Global candidate discovery retains its list projection; exactRead: true preserves cross-store alias checks and duplicate/freshness selection without adding a cache, schema, or configuration surface. The benchmark exercises the real queue, ledger, target resolution, transaction, and publication, with replay and durability assertions outside the measured batch.

The integrated CI fixtures follow current planner and session-lineage contracts, join canonical startup metadata before measuring streaming, and use the existing serialized session-patching owner. Streaming assertions still exercise 240 deltas against the original render ceilings. These test repairs do not change production UI behavior.

Evidence

Current head: 3b7e9bae6a6d99c949adbf68d3d53df1003937ea. Fresh exact-head hosted CI and native landing qualification remain required.

  • Preserved worker proof: the original source returned 530,807 text bytes against a limit below 65,536; the repair passed 95 target-selection, session-ID, store-lookup, real transcript-commit, and inference tests. Runtime and benchmark bytes retain their accepted source-bound proof. The integrated regression checks zero unrelated prompt decoding through the existing read-only key reader.
  • Fixture qualification: 61 selected session/browser cases pass, together with the coercion guard, affected UI/test compilers, targeted typed/style lint, formatting, line-cap and whitespace checks. Earlier meaningful negative fixtures cover lineage, pagination and the unchanged rendering budget. The interrupted broad local check remains partial, not a full aggregate pass.
  • Current outbox timeout diagnostic: the real browser case passes locally; an isolated forced timeout emits exactly one bounded stage receipt through Vitest's timeout signal. Assertions, await order and timeout budgets are unchanged. Fresh scoped review and independent source/runtime review are clear.
  • The preceding hosted run timed out in the inactive-agent outbox case after 120 seconds, with 214 sibling tests passing. Its awaited operation was not reported. Main subsequently landed fix(ui): stop global chat freezes after reconnect #151567: an independently reproduced cold-roster navigation loop and its owning comparison fix. This integration preserves that fix and its deterministic deferred-roster regression, with stage diagnostics around the new waits. Fresh integrated-head CI remains required; the earlier log alone does not establish the cause of that particular timeout.
  • Shared graph-capacity repair is included from fix(ci): rebalance the messaging tsgo shard below its root cap #151564; its prior 701-root failure is separate from the outbox timeout.

Preserved matched committer measurement: one Blacksmith Testbox, Node 24.19.0/pnpm 12.3.4, four guest-visible AMD EPYC CPUs, three interleaved pairs A/B/B/A/A/B. Each sample used 1,000 session rows with 16 KiB saved prompts, 1,000 active transcript messages, and 12 fresh commits. Every sample completed 12 commits, appended 48 messages and emitted 48 updates; deterministic seed/batch hashes matched. Seeding and replay checks were outside timing.

Mean commit cost per sample Baseline Repair
Pair 1 40.560 ms 23.156 ms
Pair 2 39.325 ms 17.355 ms
Pair 3 39.045 ms 17.880 ms

Median paired wall-time reduction: 54.2% (42.9–55.9%). Median paired process-CPU reduction: 52.3% (42.4–54.7%). Source, tracked blobs, frozen install inputs and harness bytes were verified; original source was restored and the one-shot Testbox stopped.

This scoped measurement does not establish cloud transport, normal embedded Gateway throughput, or deployment speedup. Matched Hetzner/AWS shared-vCPU, dedicated-vCPU and bare-metal stack measurements remain unrun. Benchmark qualification merged separately in #149702.

Punchcard-Session: ember-river-harbor-t4

@vincentkoc vincentkoc self-assigned this Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 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 gateway Gateway runtime scripts Repository scripts size: L maintainer Maintainer-authored PR labels Sep 16, 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 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 4:21 AM ET / 08:21 UTC (Revision 16).

ClawSweeper review

What this changes

The PR avoids loading unrelated saved prompts during worker session lookup, adds a transcript-commit benchmark, and updates supporting Gateway and browser test fixtures.

Merge readiness

✅ Ready for maintainer review

The optimization remains absent from current main and the latest release. The introduced changes have no actionable correctness findings, and the preserved measurements support the scoped performance claim.

Priority: P2
Reviewed head: 3b7e9bae6a6d99c949adbf68d3d53df1003937ea

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused runtime repair with useful paired measurements and meaningful regression coverage; no actionable patch defect remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The preserved Testbox measurements exercise the actual transcript committer through session resolution, ledger, persistence, and publication, with successful commits and replay checks after the fix. They support the scoped lookup optimization, not cloud transport or deployment-wide throughput; browser fixture checks are supplemental.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The preserved Testbox measurements exercise the actual transcript committer through session resolution, ledger, persistence, and publication, with successful commits and replay checks after the fix. They support the scoped lookup optimization, not cloud transport or deployment-wide throughput; browser fixture checks are supplemental.
Evidence reviewed 10 items Introduced production change: The pinned merge-base-to-head delta adds exactRead at the existing lookup call; identity selection, logical agent ownership, and the final session-ID check remain unchanged.
Still necessary on main: Fetched main still omits exactRead at the worker target lookup, causing the selected-store loader to materialize full entries.
Latest release comparison: The same worker lookup in v2026.9.4 also omits exactRead; the central optimization is not already shipped there.
Findings None None.
Security None None.

How this fits together

The Gateway resolves worker session identities before committing transcript messages or preparing inference. This change retains metadata-based selection while loading the full saved payload only for the selected session.

flowchart TD
  A[Worker request] --> B[Session metadata discovery]
  B --> C[Resolve identity and freshness]
  C --> D[Read selected full session]
  D --> E[Transcript commit]
  D --> F[Inference preparation]
  E --> G[Durable history and updates]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +460, Config +1, Other +387. Total +849 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 10 596 136 +460
Docs 0 0 0 0
Config 1 1 0 +1
Generated 0 0 0 0
Other 1 387 0 +387
Total 13 985 136 +849

Review metrics

Metric Value Why it matters
Runtime versus validation growth Production +1/-0; tooling +388/-0; tests and support +596/-136 The branch size primarily reflects measurement and validation; runtime growth is one justified use of an existing reader.

Technical review

Best possible solution:

Keep metadata-only discovery and use the existing exact reader for the selected full session, preserving selection and durability contracts.

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

Yes, from source: worker resolution on current main reaches the full-entry store loader after metadata selection, decoding unrelated saved prompts. The supplied benchmark and regression results corroborate this; this review did not execute them.

Is this the best way to solve the issue?

Yes. Reusing the established exact-entry reader removes unnecessary hydration without adding a cache, changing selection policy, or migrating stored state.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded performance improvement for worker operations against large session inventories.
  • 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 (live_output): The preserved Testbox measurements exercise the actual transcript committer through session resolution, ledger, persistence, and publication, with successful commits and replay checks after the fix. They support the scoped lookup optimization, not cloud transport or deployment-wide throughput; browser fixture checks are supplemental.
  • proof: sufficient: Contributor real behavior proof is sufficient. The preserved Testbox measurements exercise the actual transcript committer through session resolution, ledger, persistence, and publication, with successful commits and replay checks after the fix. They support the scoped lookup optimization, not cloud transport or deployment-wide throughput; browser fixture checks are supplemental.

Evidence

What I checked:

  • Introduced production change: The pinned merge-base-to-head delta adds exactRead at the existing lookup call; identity selection, logical agent ownership, and the final session-ID check remain unchanged. (src/gateway/worker-environments/session-target.ts:47, 3b7e9bae6a6d)
  • Still necessary on main: Fetched main still omits exactRead at the worker target lookup, causing the selected-store loader to materialize full entries. (src/gateway/worker-environments/session-target.ts:42, ea6ad975a511)
  • Latest release comparison: The same worker lookup in v2026.9.4 also omits exactRead; the central optimization is not already shipped there. (src/gateway/worker-environments/session-target.ts:42, 3a9d69db306c)
  • Existing exact-reader contract: Exact reads reuse candidate discovery and canonical alias validation, then load requested keys with the full projection by default. The changed path uses OpenClaw-owned session accessors and introduces no dependency on the Codex runtime contract. (src/gateway/session-utils-store-read.ts:133, 3b7e9bae6a6d)
  • Payload and selection coverage: The regressions preserve selected prompt/auth fields, duplicate freshness, ambiguity, sentinel ownership, and warm-read freshness. The existing projection regression now requires zero unrelated prompt decodes. (src/gateway/sessions-resolve-projection.test.ts:374, 3b7e9bae6a6d)
  • Preserved production-owner measurement: Captured body sourceRevision 66a25830344f6fa0cd3a2320a288cd0ab4c70f88640e0bbf3e9af8a1380a5f6f reports three interleaved baseline/repair pairs on one Blacksmith Testbox with 1,000 sessions and 16 KiB prompts: median paired wall-time reduction 54.2% and CPU reduction 52.3%. Each sample completed 12 commits, appended 48 messages, and emitted 48 updates. The inspected harness exercises the real committer, ledger, SQLite persistence, and publication with synthetic admission; it also checks replay and retained transcript contents. These are contributor-recorded observations, not executions performed during this review. (scripts/bench-worker-transcript-commit.ts:198, 3b7e9bae6a6d)

Likely related people:

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

History

Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-16T19:02:41.110Z sha 6e2f7d7 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T03:58:26.579Z sha 6e2f7d7 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T04:23:59.666Z sha 4a7e75d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T04:34:54.495Z sha f04bd23 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T05:38:24.457Z sha cdf3e69 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T06:17:35.293Z sha f5627e4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T07:17:55.440Z sha 127c985 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-18T07:48:32.857Z sha 7e1b2f0 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 16, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review September 16, 2026 07:10
Punchcard-Session: brisk-summit-brook-mr
Use current-main list discovery and register the real worker commit benchmark through the supported source runner.

Punchcard-Session: clear-workshop-brook-w2
@vincentkoc
vincentkoc force-pushed the perf/worker-session-lookup-20260916 branch from a71e4b7 to 3a273a9 Compare September 16, 2026 14:16
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 16, 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:

@clawsweeper clawsweeper Bot added 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. and removed 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 16, 2026
Punchcard-Session: clear-workshop-brook-w2
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

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

@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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 16, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 18, 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:

Punchcard-Session: ember-river-harbor-t4
Keep the seeded session-count assertion outside measured commit work after the runtime count API retirement.

Punchcard-Session: ember-river-harbor-t4
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Sep 18, 2026
Punchcard-Session: ember-river-harbor-t4
Punchcard-Session: ember-river-harbor-t4
Punchcard-Session: ember-river-harbor-t4
Punchcard-Session: ember-river-harbor-t4
Punchcard-Session: ember-river-harbor-t4
Punchcard-Session: ember-river-harbor-t4
Punchcard-Session: ember-river-harbor-t4
Punchcard-Session: ember-river-harbor-t4
@vincentkoc
vincentkoc merged commit 73775cb into main Sep 18, 2026
228 of 230 checks passed
@vincentkoc
vincentkoc deleted the perf/worker-session-lookup-20260916 branch September 18, 2026 08:38
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 18, 2026
Punchcard-Session: ember-river-harbor-t4

* commit 'fdbb2455ac991202051904501438f690d22a0701': (21 commits)
  fix(qa): restore Telegram skill integration checks (#151632)
  test(e2e): follow published plugin convergence restarts (#151607)
  perf(tasks): skip unnecessary maintenance record copies (#151578)
  refactor: simplify Gateway session-name precedence (#147984)
  fix(ui): keep suggested task launches in the background (#151611)
  fix(agents): preserve subagent progress across repeated restarts (#151450)
  fix(diagnostics): scale memory growth pressure to the heap limit (#151355)
  fix(ui): release reply previews when connections retire (#145907)
  fix(ui): disable skeleton shimmers when motion is reduced (#151314)
  fix(gateway): reduce worker overhead with large session stores (#149700)
  improve: defer unused work during Gateway startup (#151547)
  improve: reduce transcript freshness-check overhead (#151606)
  fix(ui): keep Home from appearing twice in the sidebar (#151401)
  improve(gateway): reduce allocations during large session refreshes (#151565)
  improve: reduce temporary allocations for long provider requests (#151603)
  fix: keep Gateway responsive and preserve completions during SQLite contention (#151594)
  fix(models): renew successful empty provider catalogs (#151580)
  fix: reveal preserved chat branches after rewind and resend (#151598)
  perf(outbound): skip inert plain-text preparation scans (#149829)
  improve(ui): make toast feedback compact and recovery readable (#151575)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…law#149700)

* fix(gateway): avoid full-store hydration for worker session lookup

Punchcard-Session: brisk-summit-brook-mr

* improve(bench): measure worker transcript commit scaling

Punchcard-Session: brisk-summit-brook-mr

* fix(gateway): avoid unrelated prompt reads in worker target lookup

Use current-main list discovery and register the real worker commit benchmark through the supported source runner.

Punchcard-Session: clear-workshop-brook-w2

* test(gateway): verify worker lookups skip unrelated prompts

Punchcard-Session: clear-workshop-brook-w2

* fix(bench): use retained session key reader for fixture counts

Keep the seeded session-count assertion outside measured commit work after the runtime count API retirement.

Punchcard-Session: ember-river-harbor-t4

* fix(ci): settle streaming fixtures and update native test expectations

Punchcard-Session: ember-river-harbor-t4

* fix(test): keep child pagination and dashboard state coherent

Punchcard-Session: ember-river-harbor-t4

* test(ui): split session fixtures and child-query cases

Punchcard-Session: ember-river-harbor-t4

* test(ui): reuse serialized record predicate

Punchcard-Session: ember-river-harbor-t4

* test(ui): report stalled inactive-agent outbox stage

Punchcard-Session: ember-river-harbor-t4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime 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. scripts Repository scripts 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