Repository navigation
fix(gateway): reduce resident memory on constrained hosts - #198194
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis PR reduces Gateway memory use by sharing readers, retiring idle workers, loading code on demand, and deferring optional work under memory pressure. Example: Linux ARM64 with a 768 MiB service limit, 1 GiB outer limit, one CPU, and no swap.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this maintainer-backed memory reduction addresses a documented ARM64 failure, but introduces a credential import cycle that blocks the architecture check. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway requests use worker-owned session and credential readers; memory-pressure signals now reclaim idle resources and defer optional maintenance while active requests retain their existing owners. flowchart TD
A[Gateway requests] --> B[Session reader owner]
B --> C[History and search pools]
B --> D[Shared session store pool]
E[Memory pressure] --> B
E --> F[Background schedulers]
A --> G[Direct or broker spawning]
Technical reviewBest possible solution: Keep identity material independent of credential operations by moving result adaptation above that leaf while preserving the measured memory reductions. Do we have a high-confidence way to reproduce the issue? The linked issue supplies a concrete ARM64 OOM profile, and source inspection confirms retained readers and eager imports; this read-only review did not execute the workload. Is this the best way to solve the issue? Consolidating existing owners and removing eager work fits the measured problem; the new credential dependency cycle is avoidable without changing runtime behavior. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8e6768f91235. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfacePR surface statistics unavailable: the file list is incomplete. Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 13, 2026, 6:07 PM ET / 23:07 UTC (Revision 2). |
0747a02 to
0ac22f8
Compare
|
@clawsweeper re-review |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…98194) * fix(sessions): reduce resident readers for constrained gateways * test(sessions): exercise shared reader cleanup with queued writers * fix(workers): retain recently active workers under memory pressure * fix(workers): reclaim idle workers immediately under critical pressure * fix(sessions): skip usage scans for empty stores * fix(models): defer automatic catalog refresh under memory pressure * fix(worktrees): skip empty session owner census * fix(sessions): defer RPC-only history imports * fix(sessions): load history discovery only when needed * fix(logging): load tail redaction only for readers * fix(agents): keep collector runtime out of tool preparation * fix(sessions): retire idle preparation workers under pressure * refactor(agents): isolate memory flush from coding tools * perf(agents): avoid session barrel during chat preparation * perf(runtime): keep session readers independent of delivery imports * perf(cron): isolate read worker runtime chunks * perf(cron): defer state engine in read workers * perf(cron): defer background maintenance under memory pressure * perf(gateway): stop cache warming under memory pressure * perf(gateway): defer update discovery under memory pressure * perf(gateway): defer idle repairs under memory pressure * perf(ai): load Responses WebSocket SDK on demand * perf(gateway): defer unused schema and scope runtimes * fix(state): retire idle SQLite readers under memory pressure * fix(gateway): preserve memory on small hosts * perf(gateway): defer local credential runtimes * perf(cli): load only the current platform service reader * perf(config): isolate physical database inspection * perf(process): defer unused spawn broker host * perf(gateway): defer publication recovery under memory pressure * fix(credentials): keep result types independent of runtime * fix(ci): align memory refactors with source guards * test(gateway): trace guest dictation timeout phases * fix(state): explain incomplete checkpoint close receipts * test(gateway): make concurrent admission retry deterministic * chore(state): identify incomplete checkpoint owners * perf(gateway): skip unobserved terminal session reads * test(gateway): publish real transcript in metadata socket proof * test(gateway): persist blocked placeholders in socket proof * fix(runtime): ignore unbounded process memory limits * test(gateway): report auth timeout phases * test(gateway): prepare guest profile before transport checks * test(gateway): isolate lifecycle fixture dependencies * refactor(agents): remove unused runtime exports * test(agents): release prompt continuity preparations * test(commands): await profile merge in restore fixture * fix(state): defer idle writer retirement during shutdown * refactor(agents): inline single-use compaction values * fix(state): await active executor retirement during shutdown * test: prepare route workers and expose fault errors * test(gateway): retain RPC failure context * test(gateway): await restarted cron readiness * fix(test): honor Gateway worker budget * test(gateway): settle background title before fixture cleanup * test(gateway): await persisted cron repair settlement * test(gateway): use fixture test deadline for child startup * test(gateway): report agent deletion upgrade timeout phase * test(gateway): correlate compressed replies past presence events * test(gateway): let transport outlive agent wait deadline
…PRs (#199882) The interleaved-reply case starts two inbound runs at once and read dispatch.mock.calls[0] as the first run. Each run awaits a session-entry read in a worker before it dispatches. Since #198194 those reads share a two-worker lane, so either run can reach dispatch first and the case failed in 12 of 30 local runs. Find each turn by the message it carries and assert that dispatch ran twice. The session-key, sender, and per-task reply assertions are unchanged, and replies are still delivered in reverse order. Also drop the queuedFinal argument from the two dispatch-result helpers. Every caller passed false, so the values they return are the same.
…PRs (openclaw#199882) The interleaved-reply case starts two inbound runs at once and read dispatch.mock.calls[0] as the first run. Each run awaits a session-entry read in a worker before it dispatches. Since openclaw#198194 those reads share a two-worker lane, so either run can reach dispatch first and the case failed in 12 of 30 local runs. Find each turn by the message it carries and assert that dispatch ran twice. The session-key, sender, and per-task reply assertions are unchanged, and replies are still delivered in reverse order. Also drop the queuedFinal argument from the two dispatch-result helpers. Every caller passed false, so the values they return are the same.
Backport bounded memory-lifecycle repairs onto the retained release owners: probe constrained headroom from startup, distinguish moderate and critical pressure, retire idle read-only workers, and close readers before retained agent executors during shutdown. Keep current dedicated database lanes. Adapted-from: c3b3d56 (#191272) Adapted-from: 67ecf6b (#198194) Co-authored-by: RomneyDa <[email protected]>
Keep existing cron, update/catalog, post-ready maintenance and page-cache owners. Parent reviewed cancellation, explicit-check availability and reader cleanup. Reuse 47 passing targeted tests and ten-file typed lint. Adapted-from: 67ecf6b (#198194) Co-authored-by: RomneyDa <[email protected]>
Bounded OpenClaw2026.11.6 adaptation of #198194. Preserve existing worker custody, native receipt settlement, and independent FIFO lanes. (cherry picked from commit 67ecf6b) Co-authored-by: RomneyDa <[email protected]>
Continue bounded backport of 67ecf6b (#198194): keep optional spawn broker off small hosts, load history and Cron reader dependencies on demand, isolate memory flush from coding tools, and defer API-key Responses WebSocket SDK initialization. Move the intact Cron authority writer to the existing save kernel and migrate all callers. Parent independent review and 28-file canonical typed lint passed. Reused genuine red/green worker boundary and consumer proof (179 passing checks across the recorded suites); format, whitespace and exact patch checks passed. Remaining legacy entry parsing, physical inspection, tail logging and FIFO consolidation are not claimed complete. Constrained-host RSS/boot qualification and full build remain unproved. Co-authored-by: RomneyDa <[email protected]>
Related: #192547
Problem and change
Gateway startup and the first model turn retain unnecessary code and independent readers on memory-constrained ARM64 hosts.
This change shares bounded store readers; retires idle workers under memory pressure; loads optional runtimes on demand; skips empty-store work; and defers optional background work until memory is available. Token-only CLI requests avoid credential database machinery. Hosts with at most 1 GiB of effective memory use the existing direct-spawn path instead of retaining the optional default broker.
Shutdown leaves idle native writers to the existing reader-first drain. The final active borrower still waits for its native handle and lease to close. The memory guard rejects Node 24's unlimited-memory sentinel while retaining finite-limit pressure deferral.
Internal unused exports are removed. No new configuration options, dependencies or persistent formats. Net added test lines: 400/400; no test-line allocation file.
Validation
989f4a6d, preserving its independent compaction lane and bounded readers. All 52 focused reader, compaction and lifecycle checks pass.216ba2e7.523851ff: 916.641 MiB outer peak below 928 MiB, health in 7.345 seconds, a real OpenAIgpt-5.4-minireply in 19.498 seconds, and a 60.382-second healthy soak. Limits: 768 MiB service, 1 GiB outer/client, one CPU, V8 old/young 256/4 MiB. No OOM, restart or swap.CI and limits
Current head:
3ba05113eda4f5c037881badd2f43bb61312384e. CI run 43647908332, attempt 1, completed with 139 successful jobs, six failed test jobs, a downstream failing CI gate and 23 skipped jobs. All PostgreSQL jobs and the build-artifact job passed.Six failed test jobs are attributed to existing baseline behavior; the aggregate gate consequently remains failed:
0740281ereproduces both; upstream moved a recovery test to an isolated owner without removing it from whole-config inventory. All 12 owner inputs remain unchanged through this run's base and merge..activity-empty. A fresh browser build on this run's exact base18a62d6ffails the same case before subscription or event injection. All 22 inspected test, UI, build and dependency inputs match the tested merge.27592cd3(2 failed, 25 passed), with the same Bun-to-Node worker serialization mismatch and missing mocked task operations.27592cd3(1 failed, 11 passed), with the same deserialization error before pending-recovery reporting.27592cd3(3 failed, 13 passed).account-a-onlypresentation was reproduced on baseline2f6061c9; the retained native review records that run, although its raw log was not located. The failing assertion precedes replacement-time dispatch. The inspected owner still returns its retained published list while replacement discovery is pending.All 73 inspected source inputs are unchanged between the current run's exact base and tested merge. Earlier baseline proofs retain their actual revision labels; they are not reported as new runs on the current head.
The automated failure report and the operator's baseline attribution are separate evidence. Failed CI is not described as green. Native landing must verify current review/security requirements and the exact completed attempt.
Earlier runs and revision-specific evidence remain in native review: e1013f37, a28b821e, 8db1930a, 7d758ade, and 88641423. Passing local replays do not explain historical timeouts.
The memory measurement belongs to
523851ff, not the latest head. The physical Cardputer is offline; physical-device operation and a 512 MiB service are not qualified. Shared queues and first-use imports can add latency, and sustained memory pressure can delay optional work.