Skip to content

fix(openshell): preserve file writes during concurrent mirror commands - #130447

Merged
steipete merged 1 commit into
mainfrom
codex/openshell-mirror-file-operation-lock
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/openshell-mirror-file-operation-lock

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #127441 (parallel OpenShell mirror races), follow-up to #130031 (OpenShell execution and workspace integrity).

What Problem This Solves

Fixes an issue where users writing a file through an OpenShell mirror sandbox could receive success but lose the file when a concurrent command published its downloaded workspace. This was reproduced against the earlier integration repair using a real Docker-hosted OpenShell gateway.

Why This Change Was Made

The backend now holds the existing workspace lease across the complete mirror file operation: validation, host read/mutation, and remote synchronization. Previously only the remote transport step acquired it, allowing command publication to overwrite an already-successful host write. Seven file-bridge operations now share the exec lifecycle owner; four transport-only wrappers are removed, with narrow private callbacks avoiding nested locks.

Remote-canonical mode keeps its existing remote-shell bridge. No public SDK, config, protocol, dependency, or persistence contract changes. This is the owner-boundary repair; retrying uploads or guarding missing files downstream would conceal the lost write rather than prevent it.

User Impact

Concurrent commands and file tools sharing a mirror workspace no longer erase successful file writes through this race. Independent backend handles share the same process-local workspace lock, while unrelated workspaces remain independent. Documentation clarifies that external editors and separate Gateway processes are outside this lock.

Release-note context: fix silent file loss during overlapping OpenShell mirror command/file-tool operations.

Evidence

AI-assisted with Codex; source, caller/sibling boundaries, and observed behavior reviewed.

  • Red/green real reproduction: prepare mirror exec, overlap a file write, execute over SSH, finalize the downloaded mirror, then read the file. Before: ENOENT despite a successful write. After: correct file contents locally and in the sandbox. The regression is retained in the live E2E lane.
  • Final Docker live matrix: official OpenShell 0.0.113 gateway/supervisor and verified CLI, Docker 29.4.0, isolated non-default workspaces, real SSH and containers. 5 tests passed: 2 real live cases plus 3 discovery/parser cases. Mirror case 496.120 s; remote case 346.697 s.
  • Stress: 8 waves × 8 submitted workflows per mode, two handles per workspace; 128 workflows, 64 commands, 16 intentional exit-23 failures, 144 exact data-file checks, plus exact counters/ledgers. Read-only remote inventories cannot heal divergence by triggering another mirror upload. Mirror host contents agree; remote-mode writes remain off the host.
  • Recovery/boundaries: custom image, seed behavior, nested writes, protected metadata, network deny/allow, invalid environment rejection, missing and abandoned workdir preparation, prepared-but-unspawned exec finalization, SSH config/staging cleanup, and independent-workspace progress. All task containers, gateway state, credentials, and identified interrupted-run fixtures were cleaned up.
  • Focused proof: 170 tests passed across the OpenShell and core exec/workdir suites. Final targeted lint, extension test typecheck, formatting, docs MDX validation and diff checks passed. Production extension typecheck and repository guards passed across focused gate reruns.
  • Pushed-head sanity: all 170 focused tests passed again after the mechanical rebase. The OpenShell production files and live-test sources are byte-identical to the Docker-tested source. Exact-head CI fallback: run 33018360581, dispatched through scripts/pr ci-dispatch during the initial PR CI attachment delay.
  • Hosted CI: newest normal PR run 33020374727 passed on the exact pushed head. The earlier normal PR run 33018696624 also passed. The manual fallback above suffered runner shutdowns and Android dependency-resolution trouble, and was cancelled as redundant only after the earlier green normal PR run was verified; it is not counted as a passing run.
  • Required supporting workflow: normal PR Workflow Sanity run 33020374744 passed on the exact pushed head, including actionlint and workflow auditing.
  • Harness regression: signal-killed probe processes must not report success; the new regression failed with the old null-exit-code handling and passes with the fix.

Commands:

OPENCLAW_E2E_VERBOSE=1 OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_OPENSHELL=1 \
  node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts \
  extensions/openshell/src/backend.e2e.test.ts

node scripts/run-vitest.mjs \
  extensions/openshell/src/backend.exec-workdir.test.ts \
  extensions/openshell/src/openshell-core.test.ts \
  extensions/openshell/src/backend.remote-seed.test.ts \
  extensions/openshell/src/mirror.test.ts \
  extensions/openshell/src/config.test.ts \
  extensions/openshell/src/backend.e2e.test-support.test.ts \
  src/agents/bash-tools.exec-foreground-failures.test.ts \
  src/agents/bash-tools.exec-workdir.test.ts

The live command used the existing CLI/config override variables for the disposable gateway and GNU coreutils on macOS. A full baseline build passed before source-backed repetitions. This is real gateway/SSH/container/filesystem proof, not a packaged-release, full-model-agent, remote-VM, or long-duration soak claim.

Earlier exploratory runs hit a no-output watchdog or the combined-case time budget; those are not counted as passes. The final matrix separates the modes under the unchanged 12-minute per-case timeout, drains concurrent work, and reports progress without weakening assertions. The earlier combined changed-file gate found typing/lint issues in the test harness; final targeted reruns passed after correction. Exact-head hosted CI is the landing gate.

Production LOC: +53/-40 (net +13); tests/test support: +431/-145 (net +286); docs: +16/-10. Production growth represents whole-operation ownership for seven methods replacing four insufficient remote-step wrappers. Existing helpers were extracted from the E2E file; no test-only production seam was added.

Provenance: the host-before-upload ordering predates the available shallow history boundary. The transport-only lease in #130031, authored and merged by @steipete on 2026-08-26 (c69abc232755c9a4f6e78f279cb05b51392df281), carried the gap forward. This follow-up was found by the requested live stress testing; it is not attributed to an unrelated contributor.

Maintainer review disposition

ClawSweeper's refreshed exact-head review reports no actionable findings and identifies this as the best owner-boundary repair. Its production-growth item is accepted as justified: the net 13 lines move seven complete file operations under the existing lifecycle owner while removing four insufficient transport-only wrappers. The exact-head CI item is satisfied by the newest green normal PR run above.

The bot's earlier partial live-verification failure was an output matcher looking for an individual test name under the default summarized reporter; its captured logs showed the signal-exit regression passing twice. Its refreshed review now reports PASS with the verbose reporter. The actual Docker integration proof remains the two-mode live matrix documented above, not that small process-helper test.

An explicit reporter rerun also passed, with the exact expected name visible:

node scripts/run-vitest.mjs extensions/openshell/src/backend.e2e.test-support.test.ts --reporter=verbose
✓ extensions/openshell/src/backend.e2e.test-support.test.ts > reports a signal-killed probe as failure
Test Files 1 passed (1)
Tests 1 passed (1)
[test] passed 1 Vitest shard in 5.73s

Lease complete mirror file operations through the workspace owner instead of locking only remote transport. Preserve successful writes across exec publication and share serialization across backend handles.

Proven with a real Docker red/green reproduction, 128-workflow mirror/remote stress matrix, exact inventories, failure recovery, 170 focused tests, and updated operator docs. Related: #127441; follow-up to #130031.
@steipete steipete self-assigned this Aug 26, 2026
@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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: openshell size: L maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 22:06
@clawsweeper clawsweeper Bot added 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 26, 2026, 6:36 PM ET / 22:36 UTC.

ClawSweeper review

What this changes

The PR serializes complete OpenShell mirror file-bridge operations with command workspace publication so concurrent commands cannot erase successful file writes.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still permits the reported lost-write interleaving, while this branch moves the lease to the lifecycle owner that spans local mutation and remote synchronization. No blocking patch defect found; this active maintainer-labeled PR needs normal exact-head landing gates.

Priority: P1
Reviewed head: 9bb9d77dccf50bf384e6dbad6b4dbd19a29c7737

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with credible source and regression evidence and no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an after-fix Docker gateway, SSH, container, and filesystem reproduction.
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 PR is exempt from the external-contributor proof gate; its body nevertheless records an after-fix Docker gateway, SSH, container, and filesystem reproduction.
Evidence reviewed 6 items Current-main failure boundary: Current main constructs the mirror bridge with the public handle, whose lease wraps only remote path methods; the bridge writes the host file before calling that wrapped synchronization method, admitting publication between the two steps.
Owner-boundary repair: The branch creates a private mirror bridge whose complete read, mutation, and synchronization methods acquire the shared lease, while its callbacks bypass nested locking.
Regression coverage: The Docker E2E case prepares an overlapping mirror exec, races a file write, then verifies the file locally and through a subsequent sandbox command; the stress helper covers two handles and all bridge operation families.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/openshell/src/backend.e2e.test-support.test.ts --reporter=verbose

Result: PASS (completed)

[test] starting test/vitest/vitest.extension-misc.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130447-0H8HUH/target

 ✓  extension-misc  extensions/openshell/src/backend.e2e.test-support.test.ts › reports a signal-killed probe as failure 115ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  22:37:49
   Duration  1.56s (transform 1.17s, setup 1.04s, import 16ms, tests 118ms, environment 0ms)

[test] passed 1 Vitest shard in 8.13s
[test] starting test/vitest/vitest.extension-misc.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130447-0H8HUH/target

 ✓  extension-misc  extensions/openshell/src/backend.e2e.test-support.test.ts › reports a signal-killed probe as failure 75ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  22:37:58
   Duration  800ms (transform 367ms, setup 465ms, import 6ms, tests 78ms, environment 0ms)

[test] passed 1 Vitest shard in 7.44s

Assertions:

  • PASS expect_output: reports a signal-killed probe as failure

How this fits together

OpenShell mirror mode keeps a local workspace synchronized with a remote sandbox. Commands upload and later publish that workspace, while file tools mutate and synchronize individual paths; both flows must share one workspace lifecycle.

flowchart LR
  A[Agent command or file tool] --> B[OpenShell mirror backend]
  B --> C[Shared workspace lease]
  C --> D[Local file operation]
  C --> E[Remote sandbox synchronization]
  E --> F[Published mirror workspace]
  D --> G[Consistent local and remote files]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by net 13 lines to extend the process-local critical section across seven complete bridge operations; source inspection supports this as necessary owner-boundary work, but exact-head CI remains the landing guard against lease-lifetime regressions.
  • Complete next step (P2) - This active maintainer-labeled PR has no concrete repair finding; it needs ordinary exact-head merge review rather than a ClawSweeper repair job.
Agent review details

Security

None.

PR surface

Source +265, Tests +34, Docs +6. Total +305 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 305 40 +265
Tests 3 179 145 +34
Docs 2 16 10 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 500 195 +305

Review metrics

Metric Value Why it matters
Production versus test delta production +53/-40 (net +13); tests/test support +431/-145 (net +286); docs +16/-10 The small production increase is justified by moving seven full operations under the existing workspace owner while replacing four transport-only wrappers.

Root-cause cluster

Relationship: canonical
Canonical: #130447
Summary: This is the active repair for a file-bridge interleaving that remained after the earlier broader mirror-command lifecycle work.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one lease at the mirror lifecycle owner across local validation or mutation and remote synchronization; no net-neutral alternative can preserve that atomic operation boundary without reintroducing transport-only locking.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one lease at the mirror lifecycle owner across local validation or mutation and remote synchronization; no net-neutral alternative can preserve that atomic operation boundary without reintroducing transport-only locking.

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

Yes: current main writes the host path before acquiring the transport-only synchronization lease, and the branch’s E2E test recreates that prepared-exec/file-write order. This review did not execute the Docker lane because the checkout is read-only.

Is this the best way to solve the issue?

Yes: the lease must begin before the host operation, not only for remote transport; private callbacks avoid nested locks while preserving the existing shared workspace queue.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The repaired race can silently erase a successful OpenShell mirror file write during normal concurrent command use.
  • 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: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records an after-fix Docker gateway, SSH, container, and filesystem reproduction.

Evidence

What I checked:

  • Current-main failure boundary: Current main constructs the mirror bridge with the public handle, whose lease wraps only remote path methods; the bridge writes the host file before calling that wrapped synchronization method, admitting publication between the two steps. (extensions/openshell/src/backend.ts:362, d27b0e96204a)
  • Owner-boundary repair: The branch creates a private mirror bridge whose complete read, mutation, and synchronization methods acquire the shared lease, while its callbacks bypass nested locking. (extensions/openshell/src/backend.ts:371, 9bb9d77dccf5)
  • Regression coverage: The Docker E2E case prepares an overlapping mirror exec, races a file write, then verifies the file locally and through a subsequent sandbox command; the stress helper covers two handles and all bridge operation families. (extensions/openshell/src/backend.e2e.test.ts:697, 9bb9d77dccf5)
  • History provenance: Blame ties the current-main transport-only wrapper to Peter Steinberger's 2026-08-26 carried-forward implementation; local history also identifies the earlier backend-ownership refactor. (extensions/openshell/src/backend.ts:362, 0e054de54fa2)
  • Release/current-main status: The branch head is not contained by a release tag, and current main is the supplied d27b0e commit whose source retains the transport-only wrapper; this remains an unmerged repair. (extensions/openshell/src/backend.ts:362, d27b0e96204a)
  • Codex dependency boundary: The changed runtime imports OpenClaw Plugin SDK and local OpenShell modules only; the PR does not depend on the sibling Codex harness, runtime, or protocol, so the Codex-specific dependency gate is not applicable. (extensions/openshell/src/backend.ts:1, 9bb9d77dccf5)

Likely related people:

  • steipete: Current-main blame attributes the transport-only wrapper to Peter Steinberger, and supplied history identifies the same person as author of the earlier merged workspace-integrity repair. (role: recent lifecycle owner; confidence: high; commits: 0e054de54fa2, c69abc232755, 9bb9d77dccf5; files: extensions/openshell/src/backend.ts, extensions/openshell/src/backend.e2e.test.ts)
  • Vincent Koc: Recent OpenShell history includes filesystem-bridge and mirror-sync fixes in the same ownership neighborhood. (role: adjacent OpenShell filesystem contributor; confidence: medium; commits: d9034da0a606, ce32697250d5, 30346f97883c; files: extensions/openshell/src/fs-bridge.ts, extensions/openshell/src/backend.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-26T22:12:13.615Z sha 9bb9d77 :: needs maintainer review before merge. :: none

@steipete steipete closed this Aug 26, 2026
@steipete steipete reopened this Aug 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Pre-land proof for 9bb9d77dccf50bf384e6dbad6b4dbd19a29c7737:

  • Newest exact-head normal PR CI run 33020374727 and Workflow Sanity run 33020374744 completed successfully. Native stamped review artifacts are validated; fresh Codex blocking review has no actionable findings.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 130447 completed successfully with hosted CI/Testbox gates, retaining the same reviewed head. No source change or additional push was needed.
  • The real Docker before/after reproduction changed from a successful write followed by ENOENT to preserved host/sandbox contents. The final two-mode matrix passed 128 workflows, 64 commands, 16 deliberate command failures, and 144 exact data-file checks, plus counters, ledgers, recovery, policy, and cleanup assertions.
  • All 170 focused tests passed again after rebase. The three production files and live-test sources are byte-identical to the Docker-tested version. Commands are in the PR description.
  • ClawSweeper's exact-head review has no actionable code findings. Its net+13 production-line item is explicitly accepted: seven complete bridge operations need the existing lifecycle owner, replacing four insufficient transport-only wrappers. The exact-head CI item is satisfied by the green normal PR run.
  • The bot's earlier partial probe failure was only a reporter-output expectation. node scripts/run-vitest.mjs extensions/openshell/src/backend.e2e.test-support.test.ts --reporter=verbose passed and printed reports a signal-killed probe as failure; the output is in the PR body and the refreshed ClawSweeper review now reports PASS. No test assertion or behavior was weakened.

CI recovery note: the initial PR CI attachment was delayed. The native manual fallback run33018360581 exercised the broad matrix but encountered repeated runner shutdowns during core lint and an Android dependency-resolution failure. It was stopped as redundant only after the successful normal PR run on the same SHA was verified; those fallback attempts are not being represented as passing runs.

Maintainer-tooling follow-up, separate from this repair: the PR-event watcher currently selects only pull_request runs and cannot attach to the native manual fallback; the fallback also keeps a monolithic core lint graph on small hosted runners. Preserve these observations for a focused CI routing/watch improvement rather than adding CI changes to this OpenShell fix.

The repair keeps one process-local workspace ownership path; no SDK/config/protocol/storage change. Docs describe the lock boundary and external-editor limitation. Disposable Docker resources and test credentials were removed. No packaged-release, full model-agent conversation, or soak-test claim is made.

@steipete
steipete merged commit dcb2065 into main Aug 26, 2026
608 of 616 checks passed
@steipete
steipete deleted the codex/openshell-mirror-file-operation-lock branch August 26, 2026 22:59
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (26 commits)
  fix(plugins): preserve registry epoch on activation rollback (#129232)
  refactor(plugins): make discovery invocation-owned (#130486)
  feat(ui): save appearance preferences per user profile (#130340)
  fix: Buzz bots recover relay stalls and reject revoked senders (#130467)
  fix(code-mode): serialize catalog handles nested in final values (#130276)
  fix(webchat): CLI skill and harness-injected turns render as operator-sent messages (#130427)
  fix(agents): read the published model catalog owner from session_status (#130277)
  fix(channels): preserve long presentation text (#130368)
  fix(agents): route CLI bootstrap truncation notice into the system prompt (#130325)
  refactor(plugins): unify setup registration and artifact selection (#130474)
  fix(memory): prevent forgotten session content from returning (#130451)
  refactor(outbound): consolidate transport completion (#130460)
  fix(workers): protect in-flight workspace manifests from concurrent retention (#130449)
  fix(portals): keep worker previews reachable and owned by the active environment (#130434)
  fix(config): keep core channels keys in the generated config schema (#120736)
  chore(deps): refresh dependencies after seven-day cooldown (#130296)
  fix(agents): remind exec models to quote shell metacharacters (#125485)
  fix(auth): honor shared-store ownership in temp-state exec and agent deletion (#130437)
  fix(openshell): preserve file writes during concurrent mirror commands (#130447)
  fix(workers): report full nodes as at capacity, not offline (#130445)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
openclaw#130447)

Lease complete mirror file operations through the workspace owner instead of locking only remote transport. Preserve successful writes across exec publication and share serialization across backend handles.

Proven with a real Docker red/green reproduction, 128-workflow mirror/remote stress matrix, exact inventories, failure recovery, 170 focused tests, and updated operator docs. Related: openclaw#127441; follow-up to openclaw#130031.
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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