Skip to content

perf: count large histories before Gateway prewarm - #117118

Merged
steipete merged 5 commits into
mainfrom
codex/skip-large-sidebar-prewarm
Aug 1, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/skip-large-sidebar-prewarm

Conversation

@steipete

@steipete steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Completes the large-history Gateway recovery from #117108. Live deployment showed the event loop still blocked before catalog prewarming, while the sidebar session-list prewarm materialized a 15k-row store. Two consecutive starts reported ready and then timed out /healthz and RPC while consuming one CPU core for more than eight minutes.

Root Cause

PR #115710 (14ad80481ae1, 2026-07-29) added unconditional post-ready sidebar prewarming. Its 60-session output limit applied only after every configured, custom/discovered, fixed-owner, and open-incognito store had been synchronously projected. PR #117108 skipped the later catalog prewarm but still paid this earlier full-store cost.

The first version of this PR had two important gaps: its count path still ran cold-handle canonical JSON validation, and it counted only default durable stores while projection could load custom/discovered and open-incognito stores. The current head fixes both at their shared combined-store owner.

Why This Change Was Made

The combined-store owner now resolves one target policy for both admission and projection. A raw count-only SQLite query checks every physical store the optional prewarm may load, including custom/discovered, fixed-owner, and open-incognito databases. Above 2,000 rows, sidebar-session and catalog prewarming are skipped while plugin metadata still warms. Request-time session and catalog handlers remain authoritative, and startup records the intentional skip without exposing paths or session data.

User Impact

Gateways with large histories remain responsive after restart instead of blocking health and update verification behind optional dashboard cache population. Normal-size stores retain the existing prewarm order.

Evidence

  • Original live reproduction: a 15,395-row Hetzner store made two Gateway starts CPU-bound for more than eight minutes after readiness, with HTTP and RPC unavailable during sidebar materialization.
  • Exact head 2a893066d499b9799de39bef81d24d1704322ed4: 127 focused tests passed across Gateway prewarm, combined/custom/incognito store selection, and the session accessor.
  • The cold-handle regression corrupts entry_valid through a separate SQLite connection and proves the admission count returns without parsing or validating entry JSON.
  • Custom-store and open-incognito regressions prove the admission budget covers the same targets the Gateway projection can load.
  • A multi-agent fixed-store regression proves one shared physical database is budgeted once for each per-agent projection the scheduler will actually perform.
  • Blacksmith Testbox run 30680167318: 36 exact-head integration tests passed, including multi-agent fixed-store accounting plus a real Gateway sessions harness that seeded 2,001 rows, recorded the optional-prewarm skip without materializing the store, and completed the authoritative sessions.list request in 424 ms.
  • Blacksmith Testbox changed gate 30680540357: exact-head formatting, dependency/boundary guards, dead-code scans, core/core-test types, lint, database-first guards, and runtime import checks all passed.
  • Autoreview: clean, no accepted/actionable findings.

Exact-head CI is in progress. Production-shaped sustained health/RPC proof will run immediately after merge through the supported updater before the remaining fleet advances.

@steipete steipete self-assigned this Aug 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 1, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 10:55 PM ET / August 1, 2026, 02:55 UTC.

ClawSweeper review

What this changes

This PR counts the SQLite session rows for every Gateway sidebar projection before startup prewarming, skipping optional session-list and catalog cache warming above 2,000 rows while retaining request-time handlers.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for explicit maintainer review: current main still unconditionally materializes each configured session store before applying its catalog-only limit, while this branch moves the admission decision ahead of both optional dashboard projections. The branch shares one resolved target policy between counting and projection, addresses the two prior review findings, has source-backed regression coverage, and is clean against the checked-out current main; the remaining decision is whether to land the intentional cold-cache tradeoff for histories above 2,000 rows.

Priority: P1
Reviewed head: 2a893066d499b9799de39bef81d24d1704322ed4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, owner-boundary repair with real Gateway harness proof and regression coverage; the remaining blocker is normal protected maintainer review and exact-head merge gating, not a patch defect.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body provides exact-head Testbox evidence for a real Gateway sessions harness: an oversized store skips optional prewarm and request-time sessions.list remains available. The proof is supported by the corresponding branch regression test.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body provides exact-head Testbox evidence for a real Gateway sessions harness: an oversized store skips optional prewarm and request-time sessions.list remains available. The proof is supported by the corresponding branch regression test.
Evidence reviewed 8 items Current-main behavior remains unguarded: Current main loads and projects each agent’s combined session store before summing its entries, then uses that total only to skip later catalog warming; it therefore does not solve the reported sidebar-materialization stall.
Shared target owner preserves the admission invariant: The branch resolves durable and incognito targets once for both counting and projection, then counts each selected target per scheduled agent projection. This directly addresses the prior open-incognito and repeated shared-store review findings.
Count path avoids session JSON materialization: The new read-only accessor issues a Kysely count over session_nodes and returns it without reading entry JSON, preserving the intended cheap admission check.
Findings None None.
Security None None.

How this fits together

After Gateway reports ready, a background scheduler prewarms dashboard session, plugin, and catalog caches. This PR makes the scheduler inspect the session-store work first so a large history does not synchronously block health or RPC traffic behind optional cache population.

flowchart LR
  A[Gateway reports ready] --> B[Dashboard prewarm scheduler]
  B --> C[Resolve per-agent session-store targets]
  C --> D[Read-only SQLite row counts]
  D --> E{Within 2,000-row budget?}
  E -->|Yes| F[Warm session and catalog caches]
  E -->|No| G[Skip optional caches and log reason]
  G --> H[Authoritative request-time handlers]
  F --> H
Loading

Before merge

  • Resolve merge risk (P1) - For histories above 2,000 rows, Gateway intentionally leaves dashboard session and catalog caches cold; the first corresponding request can still perform that work at request time, even though startup health and RPC are no longer blocked.
  • Resolve merge risk (P1) - The PR is marked maintainer and GitHub reports it behind current main with a Windows check queued, so a maintainer should complete the normal exact-head merge gate before landing.
  • Complete next step (P2) - The protected maintainer label and intentional availability tradeoff require a Gateway owner to make the final landing decision; there is no discrete automated repair remaining.
Agent review details

Security

None.

PR surface

Source +102, Tests +112. Total +214 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 179 77 +102
Tests 4 130 18 +112
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 309 95 +214

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/combined-store-gateway.ts, serialized state: src/config/sessions/session-accessor.sqlite-entry.ts, serialized state: src/config/sessions/session-accessor.test.ts, serialized state: src/gateway/session-utils.subagent.test.ts, unknown-data-model-change: src/config/sessions/combined-store-gateway.ts, unknown-data-model-change: src/gateway/session-utils.subagent.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #117118
Summary: This PR is the remaining candidate fix for the large-history Gateway prewarm path after the earlier catalog-only mitigation merged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Land with the bounded cold-cache tradeoff (recommended)
    Accept skipping only optional dashboard session and catalog prewarming above 2,000 scheduled rows after the final exact-head checks confirm the clean merge result.
  2. Adjust the admission policy first
    Keep the PR open if maintainers want a different large-history threshold or a different startup-versus-first-request latency tradeoff.

Technical review

Best possible solution:

Land the shared count-before-projection guard if the Gateway owner accepts the bounded cold-cache tradeoff, preserving plugin metadata warming and authoritative request-time session/catalog handling for oversized histories.

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

Yes, from source: current main synchronously loads each agent’s combined session store before applying its catalog-only entry limit. The branch’s focused 2,001-row Gateway test also establishes the intended repaired behavior, although this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Resolving one target set at the combined-store owner and using a raw read-only row count is a narrower, safer fix than counting after projection or adding a separate Gateway-only interpretation of custom, incognito, and shared stores.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: This repair targets a Gateway restart regression that can make health and RPC unavailable for minutes while optional dashboard work runs.
  • merge-risk: 🚨 availability: The PR deliberately changes Gateway startup behavior by deferring session and catalog cache population for oversized histories.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body provides exact-head Testbox evidence for a real Gateway sessions harness: an oversized store skips optional prewarm and request-time sessions.list remains available. The proof is supported by the corresponding branch regression test.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head Testbox evidence for a real Gateway sessions harness: an oversized store skips optional prewarm and request-time sessions.list remains available. The proof is supported by the corresponding branch regression test.

Evidence

What I checked:

  • Current-main behavior remains unguarded: Current main loads and projects each agent’s combined session store before summing its entries, then uses that total only to skip later catalog warming; it therefore does not solve the reported sidebar-materialization stall. (src/gateway/server-startup-handler-prewarm.ts:52, 87e900bb6409)
  • Shared target owner preserves the admission invariant: The branch resolves durable and incognito targets once for both counting and projection, then counts each selected target per scheduled agent projection. This directly addresses the prior open-incognito and repeated shared-store review findings. (src/config/sessions/combined-store-gateway.ts:155, 2a893066d499)
  • Count path avoids session JSON materialization: The new read-only accessor issues a Kysely count over session_nodes and returns it without reading entry JSON, preserving the intended cheap admission check. (src/config/sessions/session-accessor.sqlite-entry.ts:284, 2a893066d499)
  • Startup gate covers both optional cache paths: The scheduler calls the admission check before every session-list and catalog prewarm, continues plugin metadata warming, and logs an intentional skip when the budget is exceeded. (src/gateway/server-startup-handler-prewarm.ts:48, 2a893066d499)
  • Regression proof exercises the observable fallback: The branch test seeds 2,001 session rows, verifies that startup does not materialize the store, observes the skip log, and then successfully serves sessions.list through the normal request-time path. (src/gateway/server.sessions.list-store-materialization.test.ts:178, 2a893066d499)
  • Feature provenance: The prewarm behavior dates to the merged dashboard-cache prewarm commit, and the catalog-only large-history mitigation was later merged without preventing the earlier session-list projection. This branch is the follow-up candidate for that remaining path. (src/gateway/server-startup-handler-prewarm.ts:52, 14ad80481ae1)

Likely related people:

  • steipete: The merged dashboard prewarm and catalog-only mitigation both list this person as author, and this PR’s five commits continue the same Gateway/session-store owner boundary. (role: feature introducer and recent area contributor; confidence: high; commits: 14ad80481ae1, 2f875c5ad726, 2a893066d499; files: src/gateway/server-startup-handler-prewarm.ts, src/config/sessions/combined-store-gateway.ts)

Rank-up moves

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

  • Complete the queued platform check and refresh the normal merge gate on the final head.

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 (3 earlier review cycles)
  • reviewed 2026-08-01T00:50:52.288Z sha f57a588 :: needs real behavior proof before merge. :: [P1] Include open incognito stores in the prewarm admission count
  • reviewed 2026-08-01T02:24:11.787Z sha 1f42783 :: found issues before merge. :: [P1] Count each scheduled shared-store projection
  • reviewed 2026-08-01T02:38:11.617Z sha 2a89306 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 1, 2026
@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 1, 2026
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Applied every move from the latest ClawSweeper review at exact head 2a893066d499b9799de39bef81d24d1704322ed4:

  • Count each scheduled shared-store projection: fixed in 2a893066d49; admission now deduplicates within one agent projection but counts a fixed shared database again for every per-agent projection startup schedules.
  • Availability merge risk: the 2,000-row budget now represents actual synchronous projection work, not unique physical databases.
  • Exact-head CI: no failures; the only remaining hosted job is waiting for Windows runner capacity. The complete exact-head changed gate passed on Testbox run 30680540357.
  • Maintainer-owned review: kept in the maintainer lane; no automated repair was dispatched.
  • Multi-agent fixed-store regression: added and green.
  • Focused Gateway harness: Testbox run 30680167318 passed 36 exact-head integration tests, including the shared-store regression and the 2,001-row skip plus authoritative request-time listing.

No move was skipped.

@steipete
steipete merged commit c50237e into main Aug 1, 2026
415 of 433 checks passed
@steipete
steipete deleted the codex/skip-large-sidebar-prewarm branch August 1, 2026 03:36
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to chenyangjun-xy/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  test(google): cover live transcript overflow
  fix(google): bound live transcript accumulation
sunlit-deng pushed a commit to sunlit-deng/openclaw that referenced this pull request Aug 1, 2026
* commit '441d6ab254df14fb6939a8a261f474904ff9c500': (388 commits)
  fix(qqbot): ignore blank app id fallbacks (openclaw#109460)
  fix(feishu): consume implicit reply targets across media delivery (openclaw#117196)
  fix(exec): preserve approved command output when sessions resume (openclaw#117177)
  fix(qa): use public subagent fanout evidence (openclaw#116832)
  fix(googlechat): cancel unread auth response bodies before release (openclaw#115873)
  fix(queue): prevent cron saturation from starving hook dispatch (openclaw#116666)
  fix(gateway): sessions.steer retry no longer interrupts an active run when replaying a cached idempotency key (openclaw#116969)
  fix(irc): config validation rejects documented channels.irc.configWrites key (openclaw#112392)
  fix(mistral): keep terminal error branch lint-clean
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* perf(gateway): count before sidebar prewarm

* fix(sessions): narrow count row before normalization

* fix(gateway): align sidebar prewarm admission targets

* test(gateway): prove large prewarm stays optional

* fix(gateway): budget repeated shared-store prewarm
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  test(google): cover live transcript overflow
  fix(google): bound live transcript accumulation
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* commit 'ae4e662145b6aa162777cdb1c011b3f04ddd230d': (388 commits)
  fix(qqbot): ignore blank app id fallbacks (openclaw#109460)
  fix(feishu): consume implicit reply targets across media delivery (openclaw#117196)
  fix(exec): preserve approved command output when sessions resume (openclaw#117177)
  fix(qa): use public subagent fanout evidence (openclaw#116832)
  fix(googlechat): cancel unread auth response bodies before release (openclaw#115873)
  fix(queue): prevent cron saturation from starving hook dispatch (openclaw#116666)
  fix(gateway): sessions.steer retry no longer interrupts an active run when replaying a cached idempotency key (openclaw#116969)
  fix(irc): config validation rejects documented channels.irc.configWrites key (openclaw#112392)
  fix(mistral): keep terminal error branch lint-clean
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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