Skip to content

fix(agents): resolve auto runtime before lease key to prevent livelock - #153326

Closed
SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/runtime-auto-livelock-153313
Closed

SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/runtime-auto-livelock-153313

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #153313

What Problem This Solves

On 2026.9.5 the Gateway main thread livelocks (100% CPU, /healthz timeout, Docker healthcheck failure, only SIGKILL recovers) when an agent run's runtime plugin selection carries runtime: "auto" and no config-pinned agentRuntime exists for that model. normalizePreparedModelRuntimeInput discards selection.agentId after resolving the runtime. When runtime resolves to "auto" (no policy), the next normalization loses the agent scope and resolveModelRuntimePolicy falls back to the compatibility agent, resolving a different runtime. This produces two different owner keys for the same input — the loop's key vs prepareSnapshot's key — so published.snapshot !== snapshot fires every iteration with no state change, spinning forever on already-resolved promises.

  • Problem: Gateway hangs at 100% CPU when a model has no pinned agentRuntime and the selection is runtime: "auto".
  • Solution: Pass input.agentId as a fallback to resolveSelectedAgentHarnessRuntime so every normalization uses the same agent scope, making normalization idempotent across all callers.
  • What changed: src/agents/prepared-model-runtime.owner.ts — one-line fallback in normalizePreparedModelRuntimeInput. Two regression tests.
  • What did NOT change: 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 calls resolveSelectedAgentHarnessRuntime(selection, input.config) which passes selection.agentId to resolveAgentHarnessPolicy. But the function then discards agentId from the normalized entry. When runtime: "auto" is unresolved (agent has no agentRuntime policy), the normalized selection loses its agent scope. A subsequent normalization (inside prepareSnapshot → projectPublishedModelRuntimeOwner) calls resolveModelRuntimePolicy without agentId, falling back to tryResolveLegacyCompatibilityAgentId — a different agent scope that may resolve a different runtime. This creates a key mismatch between the loop's ownerKey(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 agentRuntime pin (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.agentId as a fallback when selection.agentId is absent, so resolveSelectedAgentHarnessRuntime always receives a consistent agent scope. Verified with pre-fix fail / post-fix pass:

Pre-fix (fails): normalizePreparedModelRuntimeInput discards selection.agentId after the first normalization. The second call to resolveSelectedAgentHarnessRuntime receives agentId: undefined instead of "cipher-pilot", resolving a different runtime and producing a different owner key.

expected undefined to be 'cipher-pilot' // Object.is equality

Post-fix (passes): Both normalization calls receive agentId: "cipher-pilot" (from input.agentId fallback), resolving the same runtime and producing the same owner key.

Tests  1 passed

Regression tests: prepared-model-runtime.normalize-idempotency.test.ts (mock-based, verifies agent scope is passed on every normalization) and prepared-model-runtime.gateway-leases.test.ts (integration, verifies auto runtime acquires configured snapshot without hanging). All 6 tests pass; 41 existing tests in prepared-model-runtime.test.ts also 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 deriveRuntimePluginSelections path and missed ordinary agent runs. I traced the root cause to normalizePreparedModelRuntimeInput discarding selection.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.

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Sep 20, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

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 review

What this changes

The 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
Reviewed head: 7ff09fa668f583843ca034b134c1c20c7ee47282

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The narrow production repair is sound on source review, but mocked validation cannot establish recovery from the reported Gateway hang.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Needs real behavior proof before merge: the changed normalization owner has mocked scope-forwarding coverage, but no after-fix execution shows the affected unpinned agent turn completing while Gateway health remains responsive. The linked inspector trace and configuration workaround establish only the original failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Needs real behavior proof before merge: the changed normalization owner has mocked scope-forwarding coverage, but no after-fix execution shows the affected unpinned agent turn completing while Gateway health remains responsive. The linked inspector trace and configuration workaround establish only the original failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Introduced production change: The pinned merge-base-to-head patch adds the enclosing agentId fallback in the shared normalization owner. Explicit selection identities retain precedence; the lease loop, publication lifecycle, configuration schema, and dependency graph are unchanged.
Current main still needs the repair: Fetched main still resolves each selection without input.agentId and then removes selection.agentId. The current lease and model-policy implementations match the reviewed checkout.
Latest release also lacks the fallback: The owner source at the supplied v2026.9.5 release commit contains the same unscoped resolver call. No implemented-on-main or shipped-fix closure is supported.
Findings None None.
Security None None.

How this fits together

OpenClaw 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]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Needs real behavior proof before merge: the changed normalization owner has mocked scope-forwarding coverage, but no after-fix execution shows the affected unpinned agent turn completing while Gateway health remains responsive. The linked inspector trace and configuration workaround establish only the original failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step (P2) - Supply after-fix evidence from the affected unpinned configuration showing turn completion and responsive Gateway health, and correct the stale Gateway-test claim in the PR body. Redacted terminal output or logs are sufficient; screenshots or recordings are welcome when useful. Remove credentials, IP addresses, phone numbers, private endpoints, and user data. Updating the body should trigger a fresh review; otherwise ask a maintainer to comment @clawsweeper re-review.
Agent review details

Security

None.

PR surface

Source +3, Tests +50. Total +53 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 50 0 +50
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 54 1 +53

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #153313
Summary: This PR is the candidate repair for the linked runtime-normalization livelock report; the issue should remain open until a fix lands.

Members:

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

Technical review

Best 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.

Labels

Label justifications:

  • P0: The linked official-release report describes an event-loop livelock that makes Gateway health and WebSocket requests unresponsive and can recur during restart recovery.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Needs real behavior proof before merge: the changed normalization owner has mocked scope-forwarding coverage, but no after-fix execution shows the affected unpinned agent turn completing while Gateway health remains responsive. The linked inspector trace and configuration workaround establish only the original failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Introduced production change: The pinned merge-base-to-head patch adds the enclosing agentId fallback in the shared normalization owner. Explicit selection identities retain precedence; the lease loop, publication lifecycle, configuration schema, and dependency graph are unchanged. (src/agents/prepared-model-runtime.owner.ts:241, 7ff09fa668f5)
  • Current main still needs the repair: Fetched main still resolves each selection without input.agentId and then removes selection.agentId. The current lease and model-policy implementations match the reviewed checkout. (src/agents/prepared-model-runtime.owner.ts:241, 066a93fbdacf)
  • Latest release also lacks the fallback: The owner source at the supplied v2026.9.5 release commit contains the same unscoped resolver call. No implemented-on-main or shipped-fix closure is supported. (src/agents/prepared-model-runtime.owner.ts, ec9c1a13db89)
  • Owned policy and caller boundary: The ordinary run orchestrator supplies the selected agent identity. The target-owned runtime resolver forwards that identity to target-owned model policy; absent identity permits compatibility-agent fallback. This repair concerns OpenClaw configuration normalization and does not depend on the Codex runtime or protocol. (src/agents/harness/runtime-plugin-load-plan.ts:293, 7ff09fa668f5)
  • Prior review continuity: The earlier Gateway fixture has been removed. Its replacement uses an agent-sensitive resolver mock and checks that both normalization calls receive the enclosing identity, addressing the prior fixture’s inability to detect missing scope forwarding. This is bounded unit coverage, not proof that the real Gateway lease completes. (src/agents/prepared-model-runtime.normalize-idempotency.test.ts:3, 7ff09fa668f5)
  • Proof and description mismatch: The supplied PR-body snapshot reports a mocked pre-fix assertion failure and post-fix test pass. It also claims an added auto-runtime Gateway lease regression that is absent from the current patch and current Gateway test file. The latest human comment only requests re-review; no after-fix runtime trace was supplied. (src/agents/prepared-model-runtime.gateway-leases.test.ts, 7ff09fa668f5)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

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

  • Add redacted after-fix terminal output or logs showing the affected unpinned agent turn completes and Gateway health remains responsive.
  • Update the PR body to describe the regression coverage actually present at the current head.

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 (2 earlier review cycles)
  • reviewed 2026-09-20T01:31:39.862Z sha 156d1ce75b3631dc91441fc5e0ca2d8cd16448be :: needs real behavior proof before merge. :: [P1] [P1] Normalize selections on the ordinary agent-run path | [P2] [P2] Release the admission claim before throwing | [P2] [P2] Track actual progress before declaring a livelock
  • reviewed 2026-09-20T02:50:04.921Z sha 071826a045c458d4e2367aea73c73ef3ea0d754c :: needs real behavior proof before merge. :: [P2] [P2] Exercise agent-scope drift in the regression fixture

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 20, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/runtime-auto-livelock-153313 branch from 071826a to f8385a6 Compare September 20, 2026 02:52
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
@SunnyShu0925
SunnyShu0925 force-pushed the fix/runtime-auto-livelock-153313 branch from f8385a6 to 7ff09fa Compare September 20, 2026 02:59
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

Thanks @steipete for confirming the root cause and for the more complete fix in #153386. Glad the mechanism analysis aligned — your approach of resolving auto to a concrete runtime before keying, plus the lease loop publication-progress guard, goes beyond what this PR covered. Closing this in favor of #153386.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

Closing in favor of #153386 which includes a more complete fix (concrete runtime resolution + lease loop guard).

steipete added a commit that referenced this pull request Sep 20, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

1 participant