Repository navigation
fix(gateway): prevent chat metadata from blocking concurrent RPCs - #119369
fuller-stack-dev merged 13 commits into
Conversation
|
Codex review: found issues before merge. Reviewed August 5, 2026, 1:08 AM ET / 05:08 UTC. ClawSweeper reviewWhat this changesThe PR moves Gateway chat metadata from request-time model, auth, plugin, and skill discovery into a lifecycle-prepared snapshot shared by concurrent chat requests. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked by patch quality or review findings - 10 items remain Keep open: the lifecycle-owned snapshot is the right direction, but this head introduces three P1 regressions in startup availability, persisted-profile visibility, and invalidation coherence. Priority: P1 Review scores
Verification
How this fits togetherGateway chat metadata feeds chat startup and metadata RPC responses with available models and commands. The new lifecycle prepares that response from model/auth publication plus skill and plugin state, then serves cached projections to clients. flowchart LR
A[Gateway client] --> B[Chat metadata request]
B --> C[Prepared metadata lifecycle]
D[Model and auth publication] --> C
E[Skill and plugin changes] --> C
C --> F[Shared metadata generation]
F --> G[Chat startup and metadata response]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +573, Tests +460. Total +1033 across 26 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep a single lifecycle-owned metadata generation, but publish its effective auth facts before use, preserve the startup RPC contract without restoring request-time discovery, and retry any projection superseded during its await. Do we have a high-confidence way to reproduce the issue? Yes, source establishes three focused paths: call chat.metadata after HTTP bind before post-attach sidecars, start with a persisted auth profile but no runtime snapshot, or invalidate during a deferred session-profile projection. Is this the best way to solve the issue? No. The lifecycle owner is appropriate, but this head must preserve the startup contract, publish authoritative auth facts, and recheck the generation after an awaited lazy projection. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 75ef5aebecb8. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
…anonical-snapshot
…anonical-snapshot
…anonical-snapshot
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…anonical-snapshot
…anonical-snapshot
|
Exact-head update for
Proof:
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
…enclaw#119369) * fix(gateway): serve chat metadata from prepared snapshots * fix(gateway): make chat metadata replacement atomic * fix(gateway): keep metadata contract cycle-free * fix(gateway): settle coalesced metadata replacement * fix(gateway): retry invalidated metadata projections * fix(gateway): terminate unowned metadata invalidation
Related: #118846
What Problem This Solves
Fixes an issue where users opening chat with a large model/skill configuration could see
chat.metadatatake tens of seconds, duplicate that work across concurrent requests, and delay unrelated Gateway RPCs during the same interval.Why This Change Was Made
Review findings and root-cause judgment
The independent review compared four credible causes: request-time model discovery, command/skill scanning, duplicate concurrent amplification, and broader process-wide event-loop starvation. Current canonical main still constructs model and command metadata on the RPC path; deterministic instrumentation proved equivalent concurrent requests duplicate that work, while user-shaped Gateway runs showed
worktrees.branchesdelayed in the same request window.The best-fit fix is therefore the lifecycle owner, not another request cache: one prepared chat metadata generation derived from the published config/catalog/auth/plugin/skills facts, with projections shared by equivalent callers. The prepared model runtime already owns catalog and auth publication; auth mutations invalidate and republish that owner. Skill and plugin lifecycle signals invalidate the same metadata generation.
models.listremains the explicit discovery/freshness API.A final review found a separate lifecycle deadlock in the first implementation: a worker scheduled for epoch 1 could absorb a second invalidation, commit epoch 2, then leave the replacement gate unresolved because completion still checked epoch 1. The final patch makes gate settlement belong to the generation actually committed and prevents stale/non-owning workers from settling it.
This does not claim to solve every process-wide event-loop starvation source in #118846. It removes the proven request-time metadata work at its canonical owner. It adds no config, protocol, storage, or compatibility fallback, and does not modify Control UI model-control behavior.
Evidence map
chat.metadataand chat startup metadata.models.listretains explicit fresh discovery behavior.AI-assisted implementation and review.
User Impact
Chat startup and metadata reads use a prepared snapshot, equivalent concurrent callers share one projection, warm reads are effectively constant-time, and unrelated Gateway RPCs are not held behind request-time metadata discovery/scanning.
Evidence
Final head:
c32625d732b006cba081a48f53049e4088c98c76Canonical base:
75ef5aebecb8e808eaa8a0503fb4b466703c5306Root-cause regression and local/static proof
003cc7e06e48: Blacksmith Testbox leasetbx_01kz83cz960zfq2sbayqwabcmp, run https://github.com/openclaw/openclaw/actions/runs/30975684559, commandpnpm test src/gateway/server-methods/chat-metadata-runtime.test.ts -- -t 'resolves the replacement gate after a coalesced second invalidation'. Both coalesced refreshes completed, but the following read remained blocked past 100 ms. The same proof passed after the repair.tbx_01kz83n6q0j1rbnjj1a4966jsa, run https://github.com/openclaw/openclaw/actions/runs/30975893921.chat-metadata-runtime.test.ts(9),prepared-model-runtime.lifecycle.test.ts(40), andserver-lifetime-sidecars.test.ts(1): 50 tests passed.pnpm check:changed: exit 0. Core and core-test tsgo, both changed-file lint passes, formatting, dead exports, plugin/dependency boundaries, database guards, and runtime import cycles all passed.0.98; TruffleHog clean.Final Crabbox/Testbox user-shaped Gateway proof
Provider:
blacksmith-testboxthrough the Crabbox wrapperLease:
tbx_01kz84b3kw4cq2pw111hswhcfg(violet-krill)Run: https://github.com/openclaw/openclaw/actions/runs/30976475675
Environment: Linux x86_64, Node
24.19.0, pnpm11.15.1, 41 configured models, 1,000 workspace skill manifestsScenario script SHA-256:
268539eb0f094808b89c27137c80a95fbdbfa68fd2f4a0ea54e3c57d9bf66320Exact remote command:
CHAT_METADATA_BOOTSTRAPPED=1 bash /tmp/chat-metadata-crabbox-scenario.sh 75ef5aebecb8e808eaa8a0503fb4b466703c5306 c32625d732b006cba081a48f53049e4088c98c76 "$PWD"The same run started a real Gateway for base and head, issued two concurrent
chat.metadatacalls together withworktrees.branchesandhealth, then issued a warm metadata call, invalid input, and a recovered valid call.chat.metadata.achat.metadata.bworktrees.brancheshealthchat.metadataINVALID_REQUEST, 1.955 msINVALID_REQUEST, 1.905 msBoth cases returned 41 models and 267 commands. Concurrent payloads were identical. Model fingerprint was
4453a94a585073ce2315e6440a5304759f8f27845c371ca9a8ddfad5e5a0ffa8; command fingerprint was73bf1d7e0a88e50d12961c5244fd062266a097d5308c13acdd07a173d71a1acd. File tracing was available but recorded zero request-window lines for both cases, so no implementation inference is drawn from it.Source-blind behavior validation passed all seven clauses: equivalent concurrent snapshots, 41-model result, unrelated-RPC liveness, warm reuse, invalid-input rejection, recovery, and base/head catalog equivalence.
Direct AWS supporting proof
Earlier direct AWS proof used lease
cbx_d593332898f7(crimson-krill), AWSc7a.8xlarge, Linux x86_64, Node24.18.1, pnpm11.15.1, public networking, and no Tailscale:30164.635/30167.606ms and branches30535.481ms; prepared-snapshot head metadata95.204/96.980ms and branches631.760ms.INVALID_REQUESTfailure path, and 3.390 ms recovery.Three later fresh direct-AWS leases could not reach provider SSH and executed no scenario code; final corrected-head proof therefore used the trusted Blacksmith Testbox backend above rather than presenting an infrastructure failure as product evidence.