Skip to content

fix(gateway): keep cloud-managed nodes out of device placement - #128780

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-infrastructure-node-classification
Aug 24, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-infrastructure-node-classification

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #128769

What Problem This Solves

Fixes an issue where cloud-managed node hosts could reappear as ordinary paired-device destinations when their worker owner became orphaned, failed while retaining a durable node binding, or could not be read from the worker store.

Why This Change Was Made

Environment discovery now gathers one worker inventory snapshot and uses that exact snapshot for both node ownership classification and worker projection. A non-device worker that still retains nodeDeviceId remains the infrastructure owner unless its state is destroyed, which is the lifecycle point after enrollment retirement succeeds. Canonical failed teardown already clears the binding; failed rows that still retain it remain fenced.

Worker inventory read failures now fail the environment request closed with a generic redacted unavailable result instead of silently treating every cloud node as an ordinary device. Device-provider workers remain ordinary paired devices by design.

Production LOC: +7/-7 (net 0) | Tests: +252/-85 (net +167)

AI-assisted: yes. I reviewed worker enrollment retirement, provider teardown terminal states, worker inventory projection, node catalog construction, automatic device selection, status/list error handling, and the duplicate inventory-read path and understand the change.

User Impact

Operators no longer see or automatically select infrastructure-owned cloud nodes through the ordinary paired-device path while ownership is unresolved. If the ownership store cannot be read, discovery returns a visible redacted failure instead of a misleading partial inventory.

Evidence

  • Pre-fix regressions: orphaned cloud nodes remained visible as ordinary node environments; failed rows retaining nodeDeviceId were treated as released; worker inventory failures returned a successful partial gateway/node inventory; environments.list read worker ownership twice.
  • Post-fix focused proof: 4 files, 86 tests passed across environment ownership/list/status and automatic/explicit session dispatch surfaces.
  • Full changed-file gate: node scripts/check-changed.mjs passed after rebase, including core/test typechecking, lint, formatting, import-cycle, pairing, database-first, and architecture guards.
  • State matrix proves requested/unbound, ready, draining, destroyed, failed-bound, failed-retired, orphaned, and device-provider behavior.
  • Failure proof verifies both list and node status fail UNAVAILABLE, underlying store details stay redacted, and worker-specific status failures retain their existing redacted response.
  • Fresh P0/P1 autoreview: no accepted/actionable findings (0.96).
  • Live Gateway proof not run for the store-corruption branch because deterministically injecting a worker inventory read failure into a running Gateway would require replacing the owning store. The handler regression exercises the shipped request path and automatic dispatch consumes the same listGatewayEnvironments owner; the campaign's final current-main live matrix will cover normal node/cloud discovery.

Keep durable cloud node bindings out of ordinary device placement until enrollment retirement is proven, and fail closed when worker ownership inventory cannot be read.\n\nRefs #128769
@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 24, 2026
@steipete
steipete marked this pull request as ready for review August 24, 2026 15:34
@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 11:33 AM ET / 15:33 UTC.

ClawSweeper review

What this changes

This PR keeps cloud-worker-bound nodes out of ordinary paired-device discovery until enrollment retirement is proven, and returns an unavailable response if worker inventory cannot be read.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. Source review found no blocking defect: this is a direct ownership-boundary repair, but the maintainer-authored draft is behind main and needs exact-head validation before landing.

Priority: P1
Reviewed head: 2166fa2a94b30bd33c0de455e68ea4ae5af21314

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, net-neutral in production, and aligned with the lifecycle owner; exact-head validation remains before landing.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored draft is exempt from the external-contributor proof gate; its body documents focused after-fix regression coverage and a concrete live-failure-injection limitation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored draft is exempt from the external-contributor proof gate; its body documents focused after-fix regression coverage and a concrete live-failure-injection limitation.
Evidence reviewed 6 items Current-main defect: Current main excludes failed and orphaned worker rows from the managed-node set and converts an inventory-read failure into an empty list, allowing uncertain cloud ownership to appear as an ordinary device.
Canonical repair point: The branch takes one worker snapshot, fences every non-device binding except destroyed rows, and reuses that snapshot when projecting workers into environments.list.
Lifecycle contract: The lifecycle owner marks destruction only after enrollment retirement; its terminal failed teardown path clears nodeDeviceId, so a failed row retaining a binding has not proven release.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/server-methods/environments.node-ownership.test.ts

Result: FAIL (partial) — step 2 expect_output environment node ownership: expected terminal output was not visible within 30 seconds: "environment node ownership"

node scripts/run-vitest.mjs src/gateway/server-methods/environments.node-ownership.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128780-o6aQij/target$ node scripts/run-vitest.mjs src/gateway/server-methods/environments.node-ownership.test.t
s
node scripts/run-vitest.mjs src/gateway/server-methods/environments.node-ownership.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128780-o6aQij/target

 ✓  gateway-methods  ../../src/gateway/server-methods/environments.node-ownership.test.ts (9 tests) 104ms

 Test Files  1 passed (1)
      Tests  9 passed (9)
   Start at  15:34:53
   Duration  2.23s (transform 1.62s, setup 908ms, import 893ms, tests 104ms, environment 0ms)

[test] passed 1 Vitest shard in 7.41s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128780-o6aQij/target$ node scripts/run-vitest.mjs src/gateway/server-methods/environments.node-ownership.test.t
s
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128780-o6aQij/target

 ✓  gateway-methods  ../../src/gateway/server-methods/environments.node-ownership.test.ts (9 tests) 67ms

 Test Files  1 passed (1)
      Tests  9 passed (9)
   Start at  15:35:00
   Duration  1.14s (transform 518ms, setup 408ms, import 468ms, tests 67ms, environment 0ms)

[test] passed 1 Vitest shard in 6.28s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128780-o6aQij/target$




















Assertions:

  • FAIL expect_output: environment node ownership
  • FAIL expect_output: automatic paired-device selection

How this fits together

Gateway environment discovery merges paired-device data, connected-node data, and worker inventory before environment listing and automatic session placement. The worker record’s durable node binding determines whether a node remains cloud-managed or can be offered as an ordinary device.

flowchart LR
  A[Worker inventory] --> C[Ownership classification]
  B[Paired devices and connected nodes] --> C
  C --> D[Environment listing]
  C --> E[Automatic session placement]
  C --> F[Unavailable response on read failure]
Loading

Before merge

  • Resolve merge risk (P1) - Worker-inventory loss now intentionally makes discovery unavailable rather than returning a partial inventory; rebase and rerun the ownership and automatic-placement checks on the exact head before merge.
  • Complete next step (P2) - No mechanical repair is indicated; the remaining action is maintainer readiness, rebase, and exact-head validation for this protected draft.
Agent review details

Security

None.

PR surface

Source 0, Tests +167. Total +167 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 7 0
Tests 2 252 85 +167
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 259 92 +167

Review metrics

Metric Value Why it matters
Production vs test delta production +7/-7 (net 0); tests +252/-85 (net +167) The repair changes one ownership projection without growing production code and adds focused lifecycle/failure coverage.
Worker inventory reads 2 → 1 per environments.list request One snapshot now drives both ownership classification and worker projection, preventing contradictory observations.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128769
Summary: This PR is the focused candidate repair for the linked cloud-node ownership defect.

Members:

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

Merge-risk options

Maintainer options:

  1. Rebase and validate the placement boundary (recommended)
    Rebase onto current main and rerun the focused ownership and automatic device-placement coverage so the fail-closed selection behavior is verified on the merge head.

Technical review

Best possible solution:

Keep the single worker-inventory snapshot as the canonical ownership fact, then land after an exact-head rebase validates both environment discovery and automatic placement.

Do we have a high-confidence way to reproduce the issue?

Yes—current-main source establishes the faulty filtering and empty-on-error path, and the added owner-boundary scenarios express a focused reproduction; no live Gateway run was performed in this read-only review.

Is this the best way to solve the issue?

Yes. The worker environment owns the durable binding, and gathering that fact once before all node projections is safer than downstream placement-specific exclusions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 61bc753da306.

Labels

Label changes:

  • add P1: The change repairs incorrect automatic placement of cloud-managed nodes while their lifecycle ownership is unresolved.
  • add merge-risk: 🚨 session-state: The altered environment inventory directly determines automatic session destination candidates.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P1: The change repairs incorrect automatic placement of cloud-managed nodes while their lifecycle ownership is unresolved.
  • merge-risk: 🚨 session-state: The altered environment inventory directly determines automatic session destination candidates.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

Likely related people:

  • steipete: History and blame attribute the environment projection and related worker lifecycle work to Peter Steinberger, who also authored this focused repair. (role: recent gateway and worker-lifecycle contributor; confidence: high; commits: 0d840c0fce11, 84fd10db2a1b, 2166fa2a94b3; files: src/gateway/server-methods/environments.ts, src/gateway/worker-environments/provider-lifecycle.ts, src/gateway/server-methods/sessions-dispatch.ts)

Rank-up moves

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

  • Rebase onto current main and rerun the focused environment-ownership and automatic device-placement checks on the exact 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.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 2166fa2a94b30bd33c0de455e68ea4ae5af21314:

  • CI run 32745656265: green, including the required openclaw/ci-gate.
  • Pre-fix proof: orphaned and failed-bound cloud nodes were projected as ordinary node environments; worker inventory failure returned a successful partial node inventory; environments.list read ownership twice.
  • Post-fix owner proof: 86 tests passed across four environment ownership/list/status and automatic/explicit dispatch suites.
  • node scripts/check-changed.mjs: passed after rebase.
  • Fresh P0/P1 autoreview: no accepted/actionable findings (0.96).
  • Native review artifacts validate as READY FOR /prepare-pr with zero findings; native prepare-run passed hosted exact-head gates.
  • Production LOC: +7/-7 (net 0); tests +252/-85 (net +167, including the concept-file split required to stay below max-lines).

ClawSweeper reported no code findings. Its optional rank-up move requested another rebase and exact-head rerun because main advanced. I am skipping the extra rebase: repository policy treats behind-main drift as advisory when there is no conflict, this head already has exact-head CI and hosted prepare proof, and native merge-run will re-evaluate mainline overlap before merging. No rank-up move is being skipped silently.

Proof gap: forced worker-store read failure is covered at the shipped handler/automatic-dispatch owner rather than by replacing the store in a live Gateway. Normal node/cloud discovery remains in the campaign's final current-main live matrix.

@steipete
steipete merged commit 4d8bfab into main Aug 24, 2026
294 checks passed
@steipete
steipete deleted the steipete/fix-infrastructure-node-classification branch August 24, 2026 15:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 25, 2026
Keep durable cloud node bindings out of ordinary device placement until enrollment retirement is proven, and fail closed when worker ownership inventory cannot be read.\n\nRefs openclaw#128769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud-managed nodes reappear as paired devices when ownership is uncertain

1 participant