Skip to content

fix(openshell): remote workspace is never seeded when the gateway restarts before first exec - #129809

Merged
steipete merged 1 commit into
mainfrom
steipete/jovial-driscoll-609a6f
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/jovial-driscoll-609a6f

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators using the OpenShell sandbox backend in mode: "remote" would end up with a silently empty remote-canonical workspace when the Gateway restarted (crash, deploy, host reboot) between sandbox create and the first exec. The one-time seed obligation lived only in process memory (remoteSeedPending): the next process's sandbox get succeeded, the flag was false, and the seed never ran — the agent then operated in an unseeded workspace with no visible failure.

Why This Change Was Made

The seed obligation must survive restarts, so adopted remote sandboxes now probe the managed roots (remoteWorkspaceDir, remoteAgentWorkspaceDir) once per process at the ensure boundary — the same self-healing pattern the generic SSH backend uses. The probe arms the seed only when every managed root is missing or empty, so the wipe step of seeding is provably a no-op and recovery can never destroy operator content: the seed guard shipped in stable v2026.7.1, so legacy seeded sandboxes with no marker exist in production, and /sandbox//agent are OpenShell-managed roots that may pre-exist — a plain existence probe or marker-absence check would risk wiping remote-canonical data. Ambiguous probe output fails toward "seeded". The probe also heals a sibling hole: a sandbox create that times out client-side after the sandbox actually came up was previously adopted unseeded with no restart involved.

Accepted tradeoffs (noted in code comments): an operator who deliberately empties both managed roots gets re-seeded from local after a restart (nothing is destroyed), and a mid-seed crash that left partial content is treated as seeded — the same weakness the SSH backend has. Mirror mode is untouched (it syncs every exec).

User Impact

Remote-mode OpenShell sandboxes now reliably get their one-time workspace seed even when the Gateway restarts before the first exec, eliminating a silent-failure class. Already-seeded workspaces are never re-seeded or wiped. Docs updated to state the recovery behavior.

Evidence

  • New regression test extensions/openshell/src/backend.remote-seed.test.ts simulates create → process restart → first exec (fresh backend, sandbox get succeeds, probe reports empty roots) and asserts the seed upload runs. Verified it fails on pre-fix code for exactly that reason (no seed upload) by running it against the HEAD version of backend.ts.
  • Sibling test locks the safety invariant: probe reports content → zero seed uploads, zero wipe (rm -rf) commands.
  • Full openshell extension suite green: 5 files, 87 tests. check-changed, tsgo:extensions, and tsgo:extensions:test all pass.
  • Codex autoreview (gpt-5.6-sol, high reasoning) on the exact diff: clean, no accepted/actionable findings.
  • Live OpenShell proof not run: no OpenShell gateway credentials in this environment; the OPENCLAW_E2E_OPENSHELL=1 e2e lane covers the real CLI path where one exists.

Production LOC: +26/-0 in backend.ts (~16 non-comment) | Tests: +155 | Docs: +6/-4. Growth is the new restart-surviving probe at the lifecycle owner; no existing structure could absorb it.

…tarts between sandbox create and first exec

The remote-mode seed obligation lived only in process memory
(remoteSeedPending), so a gateway restart between sandbox create and the
first exec adopted the sandbox via 'sandbox get' and silently skipped the
one-time seed, leaving an empty remote-canonical workspace with no visible
failure.

Adopted remote sandboxes now probe the managed roots once per process at
the ensure boundary and arm the seed only when every root is missing or
empty, so recovery can never wipe operator content in an already-seeded
workspace (the seed guard shipped in v2026.7.1, so legacy seeded sandboxes
without any marker exist). The probe also heals a create that timed out
client-side after the sandbox actually came up.

Regression test simulates create -> restart -> first exec and fails
pre-fix; a sibling test locks the never-reseed-non-empty-roots invariant.
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 26, 2026 03:11
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: openshell size: S maintainer Maintainer-authored PR labels Aug 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 11:18 PM ET / August 26, 2026, 03:18 UTC.

ClawSweeper review

What this changes

The PR makes OpenShell remote-mode adoption probe its managed workspace roots so an empty sandbox is seeded after a Gateway restart before first use.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. Current main still returns immediately after adopting an existing OpenShell sandbox, while this focused lifecycle-owner patch restores the missing seed path and preserves non-empty remote workspaces; the protected maintainer PR needs normal exact-head validation.

Priority: P1
Reviewed head: 013d40958c2333bb16ee5a98798e67a8f216911e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) This is a focused owner-boundary repair with meaningful safety regressions, pending normal exact-head CI and real-gateway confirmation.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied context identifies a maintainer-authored PR, so the external-contributor proof gate does not apply; a credentialed real OpenShell restart run remains the useful pre-merge validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied context identifies a maintainer-authored PR, so the external-contributor proof gate does not apply; a credentialed real OpenShell restart run remains the useful pre-merge validation.
Evidence reviewed 8 items Current main has the reported gap: On a successful sandbox lookup, current main completes legacy checks and returns without restoring the process-local seed obligation; only a newly created sandbox sets the flag.
Lifecycle-owner repair: The PR probes at the successful adoption boundary and reuses the existing pending-seed flow rather than adding a second upload path.
Caller and owner boundary: The plugin entry registers this backend factory as the OpenShell sandbox implementation, placing creation, adoption, and workspace preparation in the changed owner.
Findings None None.
Security None None.

How this fits together

OpenShell is a bundled sandbox plugin used by the Gateway for remote agent workspaces. The backend adopts or creates a sandbox, prepares its workspace, then hands execution and filesystem operations to the agent runtime.

flowchart LR
  A[Gateway restart] --> B[OpenShell backend]
  B --> C[Adopt remote sandbox]
  C --> D[Probe managed workspace roots]
  D --> E{All roots empty?}
  E -->|Yes| F[Seed remote workspace]
  E -->|No| G[Preserve remote workspace]
  F --> H[Agent exec and file tools]
  G --> H
Loading

Before merge

  • Resolve merge risk (P1) - A credentialed OpenShell restart run has not been shown for this head; the new adoption-time SSH probe should be confirmed on a real configured gateway before landing.
  • Complete next step (P2) - No repair job is needed: the branch already contains a coherent fix, with ordinary exact-head validation remaining.
Agent review details

Security

None.

PR surface

Source +26, Tests +152, Docs +2. Total +180 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 26 0 +26
Tests 1 152 0 +152
Docs 1 6 4 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 184 4 +180

Review metrics

Metric Value Why it matters
Production versus regression coverage production +26/-0; tests +152/-0; docs +6/-4 The production increase is confined to the existing lifecycle owner and is paired with restart and no-reseed regressions.

Merge-risk options

Maintainer options:

  1. Verify the real remote restart path (recommended)
    Run the credentialed OpenShell E2E restart scenario against this exact head and retain redacted after-fix output before merge.

Technical review

Best possible solution:

Retain the adoption-boundary probe and its non-destructive regression coverage, then confirm the restart path on the exact head with the existing OpenShell E2E environment.

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

Yes, by source: a successful adopted-sandbox lookup leaves the old in-memory seed flag false, so first use skips the canonical seed flow. The added regression models that path, though it was not executed in this read-only review.

Is this the best way to solve the issue?

Yes. The repair records the missing lifecycle fact where adoption occurs and delegates to the existing canonical seed operation; a downstream exec-only workaround would leave other remote operations inconsistent.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6b02b00e23fa.

Labels

Label changes:

  • add P1: The current behavior can silently leave a remote-canonical workspace unseeded after a Gateway restart.
  • add merge-risk: 🚨 availability: Adopted remote sandboxes gain a new SSH shell probe before their first operation, which lacks real-gateway confirmation on this head.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied context identifies a maintainer-authored PR, so the external-contributor proof gate does not apply; a credentialed real OpenShell restart run remains the useful pre-merge validation.

Label justifications:

  • P1: The current behavior can silently leave a remote-canonical workspace unseeded after a Gateway restart.
  • merge-risk: 🚨 availability: Adopted remote sandboxes gain a new SSH shell probe before their first operation, which lacks real-gateway confirmation on this head.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied context identifies a maintainer-authored PR, so the external-contributor proof gate does not apply; a credentialed real OpenShell restart run remains the useful pre-merge validation.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current patch and the immediately preceding OpenShell sandbox cleanup and workspace-sync repair in the affected backend history. (role: recent OpenShell lifecycle contributor; confidence: high; commits: 013d40958c23, 3d0df74b0fd1; files: extensions/openshell/src/backend.ts, extensions/openshell/src/backend.remote-seed.test.ts)
  • Vincent Koc: Prior history includes OpenShell sandbox-creation and workspace-upload repairs in the same backend. (role: earlier OpenShell backend contributor; confidence: medium; commits: ac157b3af0cd, d9034da0a606; files: extensions/openshell/src/backend.ts)

Rank-up moves

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

  • Run the credentialed OpenShell restart scenario on the exact head and attach redacted after-fix output.

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

Addressing the ClawSweeper "Before merge" items:

  • P1 credentialed OpenShell restart run: skipped — no OpenShell gateway credentials are available in this environment (stated in the PR body). The strongest available substitutes are in place: the regression test simulates the exact create → restart → first-exec sequence and fails on pre-fix code; the sibling test locks the never-reseed-non-empty-roots invariant; the OPENCLAW_E2E_OPENSHELL=1 e2e lane covers the real CLI path where credentials exist. This is a bounded deterministic owner defect in adoption-time control flow, not new external-API surface.
  • P2 exact-head validation: complete — exact-head CI is green on 013d40958c2333bb16ee5a98798e67a8f216911e.

@steipete
steipete merged commit 9ab6df9 into main Aug 26, 2026
208 of 209 checks passed
@steipete
steipete deleted the steipete/jovial-driscoll-609a6f branch August 26, 2026 03:32
@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 26, 2026
…tarts between sandbox create and first exec (openclaw#129809)

The remote-mode seed obligation lived only in process memory
(remoteSeedPending), so a gateway restart between sandbox create and the
first exec adopted the sandbox via 'sandbox get' and silently skipped the
one-time seed, leaving an empty remote-canonical workspace with no visible
failure.

Adopted remote sandboxes now probe the managed roots once per process at
the ensure boundary and arm the seed only when every root is missing or
empty, so recovery can never wipe operator content in an already-seeded
workspace (the seed guard shipped in v2026.7.1, so legacy seeded sandboxes
without any marker exist). The probe also heals a create that timed out
client-side after the sandbox actually came up.

Regression test simulates create -> restart -> first exec and fails
pre-fix; a sibling test locks the never-reseed-non-empty-roots invariant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: openshell gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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