Skip to content

fix(gateway): unbreak cloud session creation — stale chat metadata, unbounded tunnel hangs, swallowed dispatch errors - #120926

Merged
steipete merged 3 commits into
mainfrom
steipete/cloud-feature-stress-test-41089b
Aug 9, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/cloud-feature-stress-test-41089b

Conversation

@steipete

@steipete steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Live stress-testing the cloud-workers feature (Control UI → New Session → Cloud target, qa-lab static-ssh provider against a real sshd, real dispatch/bootstrap) surfaced three severe, independently reproducible gateway bugs:

  1. "No models available" forever after a gateway restart. chat.metadata builds its prepared generation while the runtime auth-profile store snapshot is not yet published, silently substituting an empty store, and generationFactsMatch never compared auth-store state — so the wrong projection (every model available: false) was cached until an unrelated config edit forced a rebuild. The Control UI new-session page and chat composer read chat.metadata, so the operator could not create any session (cloud or local) from any tab. Reproduced live: models.list said available: true while chat.metadata said false for the same model, across restarts and fresh tabs.
  2. Dispatch failures hide the recorded, actionable reason. sessions.dispatch returned bare Worker provider rejected profile / Worker bootstrap failed while the real cause (e.g. Worker bootstrap requires Node.js on the leased host; install Node in the provider setup phase and retry) was written only to the worker_environments.last_error DB column. docs/gateway/cloud-workers.md's Troubleshooting section explicitly quotes those detailed messages as operator-visible, so shipped behavior contradicted the docs.
  3. sessions.dispatch hangs unbounded when the worker SSH tunnel cannot connect. Observed live: placement stuck in syncing for 12+ minutes (returned only after a manual environments.destroy), UI spinner forever, leaked worker + placement, navigation unable to cancel. Mechanisms (traced and now regression-tested): the ssh child's exited promise settles only on close (a spawn error never settles it, parking the reconnect loop forever), no readiness deadline on the tunnel child or on startTunnel, the abort signal was never wired into spawn, the poisoned entry.ready promise was re-handed to every later dispatch on the same owner epoch, and every connect failure was swallowed by a bare catch {} with no logger in the file.

Why This Change Was Made

Cloud session creation is a default operator path; all three defects end in silent failure or an operator dead end (worst bug class per repo doctrine). Fixes are at the owning boundaries:

  • chat-metadata-runtime.ts: per-agent auth-store snapshot revision captured into generation facts and compared in generationFactsMatch; server-chat-metadata-lifecycle.ts additionally subscribes to runtime auth-store mutations and performs one revision-aware catch-up refresh after listener registration (publications that precede registration were otherwise never observed).
  • worker-environments/service.ts: the five dispatch-visible error messages now append the already-computed boundedWorkerError detail (redacted, 1 KiB cap) instead of discarding it.
  • worker-environments/tunnel-ssh-runner.ts / tunnel.ts / service.ts: exited settles on spawn error and after a bounded post-SIGKILL wait; the owner abort signal is wired into spawn; each tunnel attempt has a 60s readiness deadline; startTunnel has a 3-minute overall deadline that stops the tunnel entry and fails dispatch with a typed, actionable error; connect failures are logged (bounded) via a gateway/worker-tunnel subsystem logger.
  1. Worker tunnels can never connect to macOS hosts. Once the new tunnel logging existed, the live failure cause became visible on the first retry: the remote socket setup script runs chmod 700 -- "$directory", and BSD/macOS chmod treats -- as a filename (chmod: --: No such file or directory), so every tunnel attempt to a Mac worker host fails and previously looped silently forever. Fixed by dropping the -- (the path is script-owned and absolute); mkdir --/rm -f -- are BSD-compatible and unchanged.

User Impact

  • After a gateway restart (config reload, update), the Control UI reliably regains its model catalog; session creation is no longer blocked by a stale "No models available".
  • Failed cloud dispatches tell the operator what actually went wrong, matching the documented messages.
  • A tunnel that cannot connect now fails the dispatch within minutes with a clear error and a torn-down environment instead of hanging the RPC indefinitely and leaking the worker/lease.

Evidence

  • Live before/after on a real gateway (isolated state dir, qa-lab static-ssh worker on localhost sshd, real Control UI driven in a browser):
    • Before: sessions.dispatch errors were bare (Worker provider rejected profile, Worker bootstrap failed) with the reason only in worker_environments.last_error; a tunnel-connect failure hung the dispatch RPC for 732160ms (12.2 min) until a manual environments.destroy, with the UI spinning and the worker leaked; tunnel retries were completely silent.
    • After: dispatch failures carry the detail (UI showed cloud startup failed: Worker tunnel did not connect within 3 minutes; check worker SSH reachability and retry at 198790ms, the configured deadline); every tunnel attempt logs worker tunnel connect attempt failed with the bounded ssh error — which immediately exposed the macOS chmod bug (chmod: --: No such file or directory). With that fixed, the full happy path completed: sessions.dispatch in 12777ms, placement active, environment attached, first turn executed on the worker with the reply streamed to the Control UI.
    • chat.metadata regression coverage reproduces the live staleness shape (generation built with an unavailable auth store stays cached; a published store with a bumped revision now rebuilds it).
  • Focused tests: node scripts/run-vitest.mjs src/gateway/worker-environments/tunnel-ssh-runner.test.ts src/gateway/worker-environments/tunnel.test.ts src/gateway/worker-environments/service.test.ts src/gateway/server-methods/chat-metadata-runtime.test.ts → 4 files, 109+ tests green (includes new regressions: auth-revision rebuild, retained-cache no-rebuild, provider-error detail in all five messages, spawn-error settles exited, bounded post-SIGKILL stop, abort wiring, marker-less child timeout+retry, startTunnel deadline).
  • node scripts/check-changed.mjs: typecheck core + core tests green; lint green after fixing an unbound-method finding in the new runner test.

This PR also fixes a fifth bug found once reconciliation became reachable: the workspace quiescence script crashed mid-protocol on kill EPERM (only ESRCH was tolerated), aborting reconcile with a raw stack instead of a diagnosable outcome. EPERM no longer crashes cleanup/resume paths; a freeze target that returns EPERM is un-marked so scans keep counting it as live and quiescence fails closed (a still-running unsignalable process is never reported as frozen — reviewer-hardened semantics).

Follow-ups filed separately (found in the same stress run, out of scope here): startup publishes an empty runtime auth-store snapshot that nothing rehydrates until first inference (models.list vs chat.metadata availability divergence); quiescence's uid-wide freeze cannot converge on shared static-ssh dev hosts; UI orphan-cleanup on transient describe failures; ownership-lost silent dead end; terminal failed placement having no redispatch path; un-argumented reconcileActive after environments.destroy; no "Stop cloud worker" menu item for a syncing placement.

@steipete
steipete marked this pull request as ready for review August 9, 2026 05:38
@steipete
steipete requested a review from a team as a code owner August 9, 2026 05:38
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 9, 2026
chat.metadata cached a prepared generation built before the runtime
auth-profile store snapshot was published (empty-store fallback) and
generationFactsMatch never compared auth state, so the Control UI showed
"No models available" after a gateway restart until an unrelated config
edit. Capture per-agent auth snapshot revisions in the generation facts,
subscribe the metadata lifecycle to auth-store mutations, and run one
awaited revision-aware catch-up refresh after listener registration so
publications that precede registration are still observed.
…failure detail

Live stress-testing the Control UI cloud flow found sessions.dispatch
hanging unbounded (observed 12+ min) when the worker SSH tunnel could
not connect: the runner's exited promise settled only on "close" (a
spawn error never settled it), the reconnect loop swallowed every
failure with no logging, the poisoned ready promise was re-handed to
every later dispatch, and dispatch errors dropped the actionable reason
recorded in worker_environments.last_error.

- settle exited on the real "exit" event, wire the owner abort signal
  into spawn, bound stop()'s post-SIGKILL wait, and fail stop honestly
  when termination is unconfirmed instead of fabricating an exit
- add a 60s per-attempt readiness deadline and log each failed connect
  attempt (bounded, redacted); keep an unconfirmed child tracked and
  wait for its real exit before retrying
- add a 3-minute epoch-fenced startTunnel deadline with a typed,
  actionable error; detach its cleanup so the deadline holds
- append the bounded recorded reason to the five dispatch-visible
  worker environment error messages (docs already promise these)
- remote socket setup: drop "--" from chmod (BSD/macOS chmod treats it
  as a filename), which blocked every tunnel to a macOS worker host
- workspace quiescence: tolerate EPERM without crashing the protocol
  while keeping unsignalable freeze targets counted as live so
  quiescence fails closed
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 9, 2026
@steipete
steipete force-pushed the steipete/cloud-feature-stress-test-41089b branch from 911272d to 48385ff Compare August 9, 2026 05:46
@steipete
steipete merged commit 3bfe821 into main Aug 9, 2026
120 checks passed
@steipete
steipete deleted the steipete/cloud-feature-stress-test-41089b branch August 9, 2026 06:28
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 9, 2026
A gateway startup stall (#120926, awaited chat-metadata refresh in minimal
mode) shipped with green CI and first surfaced by hanging every checks-ui-e2e
suite that boots a minimal test gateway: no gateway-lane test booted one with
bundled plugins enabled (gateway.test.ts disables them, which masked the
stall), and the changed-scope classifier only selects the ui-e2e lane for
ui-touching diffs.

Add a minimal-gateway boot smoke in src/gateway that mirrors the ui-e2e boot
environment (bundled plugins enabled, minimal skips, strict time budget).
Selection is automatic: the smoke imports the gateway server, so the changed
node test plan picks it up through the import graph for any diff that can
affect startup, and full-suite plans run it in the
agentic-control-plane-startup-core shard. Reintroducing the #120926 hunk makes
the smoke fail (watchdog kill) in the gateway lane; healthy code boots in ~10s.

A planner regression test keeps the smoke classified as a gateway-server test
file and import-graph-reachable from gateway startup sources, so a rename or
graph-invisible import shape cannot silently drop the coverage again.
steipete added a commit that referenced this pull request Aug 9, 2026
* test(gateway): boot a minimal test gateway in the gateway lane

A gateway startup stall (#120926, awaited chat-metadata refresh in minimal
mode) shipped with green CI and first surfaced by hanging every checks-ui-e2e
suite that boots a minimal test gateway: no gateway-lane test booted one with
bundled plugins enabled (gateway.test.ts disables them, which masked the
stall), and the changed-scope classifier only selects the ui-e2e lane for
ui-touching diffs.

Add a minimal-gateway boot smoke in src/gateway that mirrors the ui-e2e boot
environment (bundled plugins enabled, minimal skips, strict time budget).
Selection is automatic: the smoke imports the gateway server, so the changed
node test plan picks it up through the import graph for any diff that can
affect startup, and full-suite plans run it in the
agentic-control-plane-startup-core shard. Reintroducing the #120926 hunk makes
the smoke fail (watchdog kill) in the gateway lane; healthy code boots in ~10s.

A planner regression test keeps the smoke classified as a gateway-server test
file and import-graph-reachable from gateway startup sources, so a rename or
graph-invisible import shape cannot silently drop the coverage again.

* test(ui): resolve labs rows by registry id, not positional index

Unblocks landing onto red main: 8fdf757 (#120727) added the Cloud Worker
Desktop labs entry with a hardcoded row index that collides with Message audit
metadata, so enabling it toggled the neighboring row and the full-suite lane
failed deterministically (labs-page.test.ts, exposed only on PRs that run the
compact full suite). Derive each table case's row index from LAB_FEATURES by
feature id — the idiom the rest of the suite already uses — so a new labs
entry can no longer silently retarget an existing case.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…nbounded tunnel hangs, swallowed dispatch errors (openclaw#120926)

* fix(gateway): rebuild chat metadata when auth-profile snapshots change

chat.metadata cached a prepared generation built before the runtime
auth-profile store snapshot was published (empty-store fallback) and
generationFactsMatch never compared auth state, so the Control UI showed
"No models available" after a gateway restart until an unrelated config
edit. Capture per-agent auth snapshot revisions in the generation facts,
subscribe the metadata lifecycle to auth-store mutations, and run one
awaited revision-aware catch-up refresh after listener registration so
publications that precede registration are still observed.

* fix(gateway): bound cloud worker tunnel startup and surface dispatch failure detail

Live stress-testing the Control UI cloud flow found sessions.dispatch
hanging unbounded (observed 12+ min) when the worker SSH tunnel could
not connect: the runner's exited promise settled only on "close" (a
spawn error never settled it), the reconnect loop swallowed every
failure with no logging, the poisoned ready promise was re-handed to
every later dispatch, and dispatch errors dropped the actionable reason
recorded in worker_environments.last_error.

- settle exited on the real "exit" event, wire the owner abort signal
  into spawn, bound stop()'s post-SIGKILL wait, and fail stop honestly
  when termination is unconfirmed instead of fabricating an exit
- add a 60s per-attempt readiness deadline and log each failed connect
  attempt (bounded, redacted); keep an unconfirmed child tracked and
  wait for its real exit before retrying
- add a 3-minute epoch-fenced startTunnel deadline with a typed,
  actionable error; detach its cleanup so the deadline holds
- append the bounded recorded reason to the five dispatch-visible
  worker environment error messages (docs already promise these)
- remote socket setup: drop "--" from chmod (BSD/macOS chmod treats it
  as a filename), which blocked every tunnel to a macOS worker host
- workspace quiescence: tolerate EPERM without crashing the protocol
  while keeping unsignalable freeze targets counted as live so
  quiescence fails closed

* test(gateway): type worker child kill mock
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…law#121134)

* test(gateway): boot a minimal test gateway in the gateway lane

A gateway startup stall (openclaw#120926, awaited chat-metadata refresh in minimal
mode) shipped with green CI and first surfaced by hanging every checks-ui-e2e
suite that boots a minimal test gateway: no gateway-lane test booted one with
bundled plugins enabled (gateway.test.ts disables them, which masked the
stall), and the changed-scope classifier only selects the ui-e2e lane for
ui-touching diffs.

Add a minimal-gateway boot smoke in src/gateway that mirrors the ui-e2e boot
environment (bundled plugins enabled, minimal skips, strict time budget).
Selection is automatic: the smoke imports the gateway server, so the changed
node test plan picks it up through the import graph for any diff that can
affect startup, and full-suite plans run it in the
agentic-control-plane-startup-core shard. Reintroducing the openclaw#120926 hunk makes
the smoke fail (watchdog kill) in the gateway lane; healthy code boots in ~10s.

A planner regression test keeps the smoke classified as a gateway-server test
file and import-graph-reachable from gateway startup sources, so a rename or
graph-invisible import shape cannot silently drop the coverage again.

* test(ui): resolve labs rows by registry id, not positional index

Unblocks landing onto red main: e675b67 (openclaw#120727) added the Cloud Worker
Desktop labs entry with a hardcoded row index that collides with Message audit
metadata, so enabling it toggled the neighboring row and the full-suite lane
failed deterministically (labs-page.test.ts, exposed only on PRs that run the
compact full suite). Derive each table case's row index from LAB_FEATURES by
feature id — the idiom the rest of the suite already uses — so a new labs
entry can no longer silently retarget an existing case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant