Skip to content

fix(gateway): prevent post-ready catalog warmup from stalling RPCs - #119377

Merged
fuller-stack-dev merged 8 commits into
openclaw:mainfrom
fuller-stack-dev:codex/fix-gateway-context-prewarm-starvation-20260804-a1
Aug 5, 2026
Merged

fuller-stack-dev merged 8 commits into
openclaw:mainfrom
fuller-stack-dev:codex/fix-gateway-context-prewarm-starvation-20260804-a1

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

AI-assisted: yes. The implementation, lifecycle ownership, and validation evidence were independently reviewed before publication.

What Problem This Solves

Fixes an issue where Gateways could appear hung after readiness because optional session-catalog prewarming ran provider-owned discovery on the Gateway event loop. On the affected host, sequential per-agent catalog phases took 11-15 seconds and unrelated metadata, branch, health, and readiness RPCs waited 16-70 seconds.

Why This Change Was Made

Session catalogs are request data, not process-stable startup metadata: providers may scan local databases, query nodes, or invoke external CLIs. This removes their speculative post-ready prewarm and the now-unused headless helper while retaining bounded session-list and process-stable plugin warmups. The authoritative sessions.catalog.list handler, its request cache, progress fanout, and concurrency admission remain unchanged.

The context-window cache hypothesis was tested and falsified for this incident. In the representative red run, post-ready.gateway-data.session-catalog.main occupied the Gateway for 114.7 seconds before context prewarm began. The historical recentPhases context label was stale diagnostic history, not causal proof.

User Impact

New Gateway work is no longer blocked for tens of seconds by low-priority session-catalog preparation after readiness. The first explicit session-catalog request remains authoritative and may perform its normal provider work.

Evidence

Red control

Blacksmith Testbox with 100,000 prepared catalog models:

Production logs independently showed six sequential session-catalog phases of 11-15 seconds, active=0, event-loop utilization 1, and unrelated RPC/liveness delays.

Proposed head

Same Gateway fixture and observation point on code commit df38a55e0c5:

The published PR head fe382f639a1 adds only current-main QA Lab commits; they do not touch the Gateway owner, fixture, callers, dependencies, or runtime configuration, so they do not invalidate the proof.

Tests and review

Prior ClawSweeper review

The durable ClawSweeper comment reviewed the superseded context-cache implementation at ce37a8f1eb4a. Its three rank-up moves are intentionally not carried into this incident-owner patch:

  • Preserving configured context values and adding session-default/cron staging coverage apply only to the removed cooperative context-cache implementation; this head does not change context lookup or persistence behavior.
  • Refreshing the ce37a8f1eb4a benchmark is superseded by the red/green Gateway runs above for the selected session-catalog owner and proposed implementation.

The context-cache path remains separate follow-up work because it was falsified as the owner of the August 4 incident.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 4, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Aug 4, 2026
@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. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 4, 2026, 11:11 PM ET / August 5, 2026, 03:11 UTC.

ClawSweeper review

What this changes

This PR batches Gateway context-cache warming and request-time catalog projection, then atomically swaps the completed cache maps to keep the event loop responsive.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open. The updated head fixes the prior request-time starvation finding, but it deliberately returns no configured context value while a large catalog stages; Gateway session defaults can fall back to 200k and cron can persist that fallback instead of the configured value.

Priority: P1
Reviewed head: ce37a8f1eb4ac5faaa6df23fce7226e23429b4b9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The starvation repair is well-targeted and benchmarked, but the introduced configured-value gap is a P1 correctness blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; the body nevertheless supplies linked benchmark evidence that should be refreshed for the exact head.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; the body nevertheless supplies linked benchmark evidence that should be refreshed for the exact head.
Evidence reviewed 6 items Original blocking path on current main: The current request-time loader synchronously primes configured values, projects catalog rows, and copies the staged cache; an admitted large catalog can monopolize the event loop.
Prior finding is addressed: The PR detects large configured catalogs and stages configured and discovered rows in 512-item cooperative turns before publishing complete maps.
Configured lookup regression: For a large configuration the new path records config but does not populate configured cache entries before yielding; its new regression test explicitly expects the lookup to be undefined until completion.
Findings 1 actionable finding [P1] Preserve configured context values while yielding
Security None None.

How this fits together

Gateway startup publishes a prepared model catalog, then warms process-local context-window metadata used by session displays and agent runs. Health/RPC/channel work shares the same event loop, so warming must yield without making configured model limits temporarily unavailable.

flowchart LR
  A[Gateway ready] --> B[Published model catalog]
  B --> C[Context cache warmup]
  C --> D{Large catalog}
  D --> E[Bounded event-loop batches]
  E --> F[Cache generation publish]
  D --> G[Immediate configured lookup]
  F --> H[Gateway sessions and agent runs]
Loading

Before merge

  • Preserve configured context values while yielding (P1) - For large configurations this branch only records configuredConfig, so synchronous reads remain empty until the staged generation finishes; the new test asserts that outcome. Gateway session defaults then fall back to 200k, and cron can persist that fallback. Keep configured limits readable throughout the cooperative projection.
  • Resolve merge risk (P1) - For large configured catalogs, the PR makes configured context values temporarily unavailable instead of immediately readable; session defaults can report 200k and cron can persist it.
  • Resolve merge risk (P1) - The PR body’s explicit before/after benchmark names commit 940ffa2, not the current head ce37a8f; exact-head runtime evidence should be refreshed after the repair.
  • Complete next step (P2) - The concrete blocker should be resolved on this MEMBER-authored, maintainer-labeled PR rather than dispatched as a separate automated repair.

Findings

  • [P1] Preserve configured context values while yielding — src/agents/context.ts:426-430
Agent review details

Security

None.

PR surface

Source +265, Tests +405. Total +670 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 371 106 +265
Tests 3 422 17 +405
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 793 123 +670

Review metrics

Metric Value Why it matters
Production versus test delta production +371/-106, tests +422/-17 The added lifecycle/cache machinery is justified by cooperative warmup, but its larger surface needs the configured-value invariant preserved.

Stored data model

Persistent data-model change detected: persistent cache schema: src/agents/context-cache.ts, persistent cache schema: src/agents/context.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119375
Summary: This PR is the candidate repair for the linked Gateway event-loop starvation report, but needs one additional compatibility repair before it is landable.

Members:

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

Merge-risk options

Maintainer options:

  1. Retain configured context during staging (recommended)
    Repair the large-catalog path so configured limits remain readable while discovered metadata yields, with session-default and cron-persistence regression coverage.
  2. Accept temporary fallback values
    Merge with the known window where session metadata and cron state may use the 200k fallback instead of a configured model limit.

Technical review

Best possible solution:

Keep a synchronous configured-context source valid throughout cooperative staging, while continuing to batch only the optional discovered-cache work; add coverage for Gateway session defaults and cron session persistence during that window.

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

Yes: a 1,025-model request-time load reaches the changed branch, and the exact-head tests show the configured lookup returns undefined until the cooperative work finishes.

Is this the best way to solve the issue?

No: yielding catalog projection is the right owner-level fix for starvation, but withholding configured values during that work breaks existing synchronous consumers; preserve the configured source while staging.

Full review comments:

  • [P1] Preserve configured context values while yielding — src/agents/context.ts:426-430
    For large configurations this branch only records configuredConfig, so synchronous reads remain empty until the staged generation finishes; the new test asserts that outcome. Gateway session defaults then fall back to 200k, and cron can persist that fallback. Keep configured limits readable throughout the cooperative projection.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The patch can silently replace configured model context limits with a fallback during the exact large-catalog scenario it targets.
  • merge-risk: 🚨 compatibility: Existing large model configurations temporarily lose their configured context-window behavior while the new cache generation stages.
  • merge-risk: 🚨 session-state: Cron finalization can persist the fallback context value to session state when the configured cache is temporarily empty.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; the body nevertheless supplies linked benchmark evidence that should be refreshed for the exact head.

Evidence

What I checked:

  • Original blocking path on current main: The current request-time loader synchronously primes configured values, projects catalog rows, and copies the staged cache; an admitted large catalog can monopolize the event loop. (src/agents/context.ts:198, 866dade2462f)
  • Prior finding is addressed: The PR detects large configured catalogs and stages configured and discovered rows in 512-item cooperative turns before publishing complete maps. (src/agents/context.ts:393, ce37a8f1eb4a)
  • Configured lookup regression: For a large configuration the new path records config but does not populate configured cache entries before yielding; its new regression test explicitly expects the lookup to be undefined until completion. (src/agents/context.ts:426, ce37a8f1eb4a)
  • Affected synchronous consumers: Gateway session defaults use a raw read-only lookup and fall back to DEFAULT_CONTEXT_TOKENS; cron finalization can write that fallback to a session entry. (src/gateway/session-utils-model.ts:267, 866dade2462f)
  • Current-main status: Neither PR commit is an ancestor of current main, so this remains an unmerged and unshipped candidate fix. (src/agents/context.ts:411, ce37a8f1eb4a)
  • Feature provenance: The current post-ready warmup behavior dates to this Gateway startup commit, with Peter Steinberger shown by blame across the scheduler implementation. (src/gateway/server-startup-context-cache-prewarm.ts:16, 941e18d4d1d0)

Likely related people:

  • Peter Steinberger: Blame attributes the current Gateway post-ready cache-warmup scheduler to this commit; it owns the lifecycle entry point affected by the repair. (role: current prewarm-path author; confidence: high; commits: 941e18d4d1d0; files: src/gateway/server-startup-context-cache-prewarm.ts, src/agents/context.ts)

Rank-up moves

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

  • Keep configured context values readable during the cooperative load.
  • Add Gateway session-default and cron session-state coverage for the staging window.
  • Refresh the linked runtime benchmark for commit ce37a8f.

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 (1 earlier review cycle)
  • reviewed 2026-08-05T00:07:25.230Z sha 940ffa2 :: found issues before merge. :: [P1] Yield before priming a large request-time config

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed agents Agent runtime and tooling size: L labels Aug 5, 2026
@fuller-stack-dev fuller-stack-dev changed the title fix(gateway): keep post-ready context cache warming responsive fix(gateway): prevent post-ready catalog warmup from stalling RPCs Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): prevent post-ready catalog warmup from stalling RPCs This is item 1/1 in the current shard. Shard 13/44.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@fuller-stack-dev
fuller-stack-dev merged commit 287da89 into openclaw:main Aug 5, 2026
135 of 140 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the codex/fix-gateway-context-prewarm-starvation-20260804-a1 branch August 5, 2026 08:10
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
…penclaw#119377)

* fix(gateway): keep context cache warmup responsive

* fix(gateway): yield request-time context projection

* Revert "fix(gateway): yield request-time context projection"

This reverts commit ce37a8f.

* Revert "fix(gateway): keep context cache warmup responsive"

This reverts commit 940ffa2.

* fix(gateway): stop prewarming session catalogs
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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant