Repository navigation
fix(agents): resolve auto runtime before lease key to prevent livelock - #153326
SunnyShu0925 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:04 PM ET / September 20, 2026, 03:04 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR preserves the enclosing agent’s identity during runtime selection normalization and adds a regression test to prevent inconsistent runtime ownership. Merge readiness⛔ Blocked before merge - 2 items remain Keep open: this focused fix remains necessary on current main. No blocking production-code defect was found, but after-fix real behavior proof is still required. Priority: P0 Review scores
Verification
How this fits togetherOpenClaw prepares model runtimes before executing agent turns. Normalized agent and model selections identify the prepared snapshot that a run must acquire before execution. flowchart TD
A[Agent turn] --> B[Agent and model configuration]
B --> C[Normalize runtime selection]
C --> D[Prepared owner key]
D --> E[Acquire matching snapshot]
E --> F[Execute agent turn]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +3, Tests +50. Total +53 across 2 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 normalization in the shared owner so repeated preparation preserves the selected agent’s runtime policy without requiring configuration pins. Do we have a high-confidence way to reproduce the issue? Yes, the source establishes how removing selection.agentId can change an unresolved runtime on subsequent normalization, and the linked report supplies a concrete release reproduction with inspector observations. No current-main runtime execution was performed in this read-only review. Is this the best way to solve the issue? Yes, supplying the enclosing identity at the shared normalization boundary is narrower than adding retry-loop guards and covers ordinary and derived selections; runtime validation remains outstanding. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 066a93fbdacf. 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 (2 earlier review cycles)
|
156d1ce to
071826a
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
071826a to
f8385a6
Compare
normalizePreparedModelRuntimeInput discards selection.agentId after resolving the runtime. When runtime resolves to "auto" (no configured agentRuntime policy), the next normalization loses the agent scope and resolveModelRuntimePolicy falls back to the compatibility agent, potentially resolving a different runtime. This produces two different owner keys for the same logical input: the loop's key (with the first resolution) vs prepareSnapshot's key (with the fallback resolution), causing published.snapshot !== snapshot to fire every iteration with no state change — an infinite continue that livelocks the event loop. Pass input.agentId as a fallback to resolveSelectedAgentHarnessRuntime so every normalization uses the same agent scope, making the function idempotent across all callers (direct and derived selections). Fixes openclaw#153313
f8385a6 to
7ff09fa
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Thanks @steipete for confirming the root cause and for the more complete fix in #153386. Glad the mechanism analysis aligned — your approach of resolving |
|
Closing in favor of #153386 which includes a more complete fix (concrete runtime resolution + lease loop guard). |
Fix Gateway hangs when an agent inherits a model without a runtime pin. Resolve runtime policy in the requesting agent's scope, make automatic selections concrete before deriving owner keys, and admit leases from the exact keyed owner's snapshot. Reject retries that make no publication progress while preserving typed supersession refusals, cancellation, and publication budgets. Reported by @stackingrockss. This is an independent owner-level repair; no contributor patch was adopted. No new configuration, migration, or workaround is required. Validation: four regressions failed against the original source; 101 focused tests passed; registry-borrow coverage passed 100 executions; changed-file checks and Codex review passed. Isolated Gateway proof returned OK in 190 ms with all 185 health probes successful (maximum 115 ms). The endpoint was synthetic, so this proves Gateway/runtime behavior rather than external provider authentication. Exact-head CI passed. Fixes #153313. Related: #153326.
…#153386) Fix Gateway hangs when an agent inherits a model without a runtime pin. Resolve runtime policy in the requesting agent's scope, make automatic selections concrete before deriving owner keys, and admit leases from the exact keyed owner's snapshot. Reject retries that make no publication progress while preserving typed supersession refusals, cancellation, and publication budgets. Reported by @stackingrockss. This is an independent owner-level repair; no contributor patch was adopted. No new configuration, migration, or workaround is required. Validation: four regressions failed against the original source; 101 focused tests passed; registry-borrow coverage passed 100 executions; changed-file checks and Codex review passed. Isolated Gateway proof returned OK in 190 ms with all 185 health probes successful (maximum 115 ms). The endpoint was synthetic, so this proves Gateway/runtime behavior rather than external provider authentication. Exact-head CI passed. Fixes openclaw#153313. Related: openclaw#153326.
Fixes #153313
What Problem This Solves
On 2026.9.5 the Gateway main thread livelocks (100% CPU,
/healthztimeout, Docker healthcheck failure, only SIGKILL recovers) when an agent run's runtime plugin selection carriesruntime: "auto"and no config-pinnedagentRuntimeexists for that model.normalizePreparedModelRuntimeInputdiscardsselection.agentIdafter resolving the runtime. Whenruntimeresolves to"auto"(no policy), the next normalization loses the agent scope andresolveModelRuntimePolicyfalls back to the compatibility agent, resolving a different runtime. This produces two different owner keys for the same input — the loop's key vsprepareSnapshot's key — sopublished.snapshot !== snapshotfires every iteration with no state change, spinning forever on already-resolved promises.agentRuntimeand the selection isruntime: "auto".input.agentIdas a fallback toresolveSelectedAgentHarnessRuntimeso every normalization uses the same agent scope, making normalization idempotent across all callers.src/agents/prepared-model-runtime.owner.ts— one-line fallback innormalizePreparedModelRuntimeInput. Two regression tests.ownerKey,projectPublishedModelRuntimeOwner, the publish path, the lease loop, or any schema/config.Why This Change Was Made
The root cause is in
normalizePreparedModelRuntimeInput(owner layer), not in the lease loop. The function callsresolveSelectedAgentHarnessRuntime(selection, input.config)which passesselection.agentIdtoresolveAgentHarnessPolicy. But the function then discardsagentIdfrom the normalized entry. Whenruntime: "auto"is unresolved (agent has noagentRuntimepolicy), the normalized selection loses its agent scope. A subsequent normalization (insideprepareSnapshot→projectPublishedModelRuntimeOwner) callsresolveModelRuntimePolicywithoutagentId, falling back totryResolveLegacyCompatibilityAgentId— a different agent scope that may resolve a different runtime. This creates a key mismatch between the loop'sownerKey(input)and the snapshot's resolved owner key. Fixing at the owner layer covers all callers: direct agent runs (run-orchestrator.ts), derived selections (deriveRuntimePluginSelections), and read-only probes.User Impact
Agents that inherit a model without an explicit
agentRuntimepin (common for local/OAuth-proxy models like xai/grok) no longer hang the Gateway. The fix is a single fallback that ensures normalization is idempotent — the same input always produces the same owner key regardless of how many times it is normalized.Evidence
The fix adds
input.agentIdas a fallback whenselection.agentIdis absent, soresolveSelectedAgentHarnessRuntimealways receives a consistent agent scope. Verified with pre-fix fail / post-fix pass:Pre-fix (fails):
normalizePreparedModelRuntimeInputdiscardsselection.agentIdafter the first normalization. The second call toresolveSelectedAgentHarnessRuntimereceivesagentId: undefinedinstead of"cipher-pilot", resolving a different runtime and producing a different owner key.Post-fix (passes): Both normalization calls receive
agentId: "cipher-pilot"(frominput.agentIdfallback), resolving the same runtime and producing the same owner key.Regression tests:
prepared-model-runtime.normalize-idempotency.test.ts(mock-based, verifies agent scope is passed on every normalization) andprepared-model-runtime.gateway-leases.test.ts(integration, verifies auto runtime acquires configured snapshot without hanging). All 6 tests pass; 41 existing tests inprepared-model-runtime.test.tsalso pass.AI Assistance
This PR was AI-assisted using Codex CLI. The issue provided a detailed root-cause analysis with live inspector evidence. ClawSweeper's first review identified that the initial fix only covered the
deriveRuntimePluginSelectionspath and missed ordinary agent runs. I traced the root cause tonormalizePreparedModelRuntimeInputdiscardingselection.agentId, and moved the fix to the owner layer so it covers all callers. I understand the lease admission lifecycle and why normalization must be idempotent.