Repository navigation
fix(agents): Gateway livelocks at 100% CPU when an unpinned agent starts a run on a shared default model - #153389
stackingrockss wants to merge 1 commit into
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 real behavior proof before merge. Reviewed September 19, 2026, 11:33 PM ET / September 20, 2026, 03:33 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR preserves each agent’s runtime-selection scope and stops repeated snapshot mismatches from freezing the Gateway. Regression provenancePossible regression — suspected (failure trace). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 2 items remain Keep open: the defect remains on current main, and the same-author issue remains unresolved. No blocking patch defect was found, but the earlier request for after-fix runtime proof remains unmet. Priority: P0 Review scores
Verification
How this fits togetherPrepared model runtimes combine an agent’s configuration, model selection, and published runtime snapshot. Lease admission supplies that snapshot to an agent turn while coordinating runtime publication and replacement. flowchart TD
A[Agent turn] --> B[Agent configuration and model]
B --> C[Normalize runtime selection]
C --> D[Find prepared runtime owner]
D --> E{Snapshot matches owner}
E -->|Yes| F[Admit agent turn]
E -->|Repeated settled mismatch| G[Return explicit error]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +38, Tests +133. Total +171 across 4 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep runtime identity stable from agent-scoped selection through lease admission, with bounded failure for settled mismatches and normal waits for genuine publication progress. Do we have a high-confidence way to reproduce the issue? Yes, from source: an unpinned agent sharing a model with a pinned compatibility agent can change runtime selection on repeated normalization, while lease acquisition retries the resulting snapshot mismatch. This read-only review did not execute that flow. Is this the best way to solve the issue? Yes, the patch repairs agent scope at the existing normalization owner and bounds the reported mismatch without adding configuration or changing persisted state; runtime validation remains necessary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0537b888cd7d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
normalizePreparedModelRuntimeInput resolved each runtime plugin selection under the selection's agentId, then dropped that agentId from the stored selection. Every later normalization of the same input therefore resolved without an agent scope, fell back to the legacy compatibility agent, and could pick up that agent's model runtime pin. For an agent inheriting a default model with no pin of its own the runtime flipped between "auto" and the system agent's pinned runtime, which changed the owner key. acquirePreparedModelRuntimeLeaseFromOwners keys the owner off the first normalization but prepareSnapshot re-normalizes, so the prepared snapshot came from a different owner and `published.snapshot !== snapshot` held on every iteration. Each await in that path was already resolved, so the loop spun on the microtask queue and starved the Gateway event loop: 100% CPU, no HTTP or WebSocket responses, healthcheck failure, SIGKILL only. - Resolve the selection runtime under the input's agentId when the selection has none, so re-normalization is a no-op. - Fail the lease acquisition when a settled, unchanged owner mismatches the prepared snapshot twice in a row, instead of retrying forever. Closes openclaw#153313
271fb91 to
04e6bf8
Compare
|
Closing as superseded by #153386 (merged as 8720fbf). That change fixes the same #153313 root cause and includes after-fix proof of an unpinned Gateway turn with responsive health checks. This branch was not merged and has no distinct fix to carry forward. — Mote, assisting @stackingrockss |
Closes #153313
What Problem This Solves
Fixes: the Gateway main thread spins at 100% CPU and stops answering
/healthz, WebSocket clients, and the Docker healthcheck when an agent that inheritsagents.defaults.modelwithout a runtime pin starts a run, while the system agent pins a runtime for that same model. On 2026.9.5 this turns into a boot loop, because restart recovery resumes the interrupted session and re-triggers it on every start.User Impact
User impact: agents on a shared default model no longer hang the Gateway on their first turn; if the same owner mismatch ever happens for another reason, the run fails with a clear error instead of livelocking the process. No config change is needed, and the
agentRuntimepin workaround from the issue remains valid but is no longer required.Why This Change Was Made
normalizePreparedModelRuntimeInputresolved each runtime plugin selection under the selection's agent, then dropped that agent id from the stored selection. Re-normalizing the same input later ran the lookup without an agent scope, fell back to the legacy compatibility agent, and could return that agent's pinned runtime instead. The lease loop inacquirePreparedModelRuntimeLeaseFromOwnerskeys the owner off the first normalization whileprepareSnapshotre-normalizes, so the two never agreed and the loop's final checkcontinued forever on already-resolved awaits, starving the event loop.Two changes:
agentIdwhen the selection carries none, so normalization is idempotent and always uses the requesting agent's scope.Evidence
src/agents/prepared-model-runtime.owner.normalize.test.ts: reproduces the defect on unfixed code (second normalization flipsruntime: "auto"→"openclaw"and changes the owner key), passes with the fix.src/agents/prepared-model-runtime-lease.livelock.test.ts: a fake context whoseprepareSnapshotnever matches the owner now rejects withPreparedModelRuntimeOwnerNotPublishedErrorafter exactly two attempts; on the previous loop this test runs out of memory.node scripts/run-vitest.mjs run src/agents/prepared-model-runtime: 25 files, 325 tests pass.node scripts/check-changed.mjs: core typecheck, core test typecheck, lint, boundary guards, and ratchets pass.--inspect: every sample was inside this loop, andDebugger.evaluateOnCallFrameshowed the loop's input selection atruntime: "auto"whilenormalizePreparedModelRuntimeInput(input)returned"openclaw"(owner key changed,prepareSnapshotresolved the other owner's snapshot). Pinning the runtime in config, which makes both normalizations agree, stopped the hang; the same request then completed normally. Full captures are in the issue.