#899

ECW: files.make_dir() on an existing directory returns True (E2B returns False)

OpenRGB-loopopened 1mo ago

Summary

Through the ECW (E2B-compatible) API, files.make_dir() on a directory that already exists returns True ("created"). With E2B the same call returns False. SPACE's pinned Python SDK (e2b==2.21.1) documents the return value as "True if the directory was created, False if the directory already exists".

Where it happens (main 4791af3)

  • crates/libs/data/plane/server/src/ecw_files.rs filesystem_make_dir (L620-656) always sends MkdirRequest { parents: true, exist_ok: true }. It ignores the response, stats the path and returns 200 {entry}.
  • The guest mkdir turns AlreadyExists into Ok when exist_ok is set (crates/libs/spaced/guest/execution/src/filesystem.rs:322). MkdirResponse {} (proto/spaced/operations/v1/operations.proto) has no created/existed field, so the data plane can't tell the two cases apart.
  • In e2b 2.21.1, Filesystem.make_dir returns False only when it gets Code.already_exists; any 200 returns True.

What I ran

  • Guest semantics on real code: cargo test -p pplx-space-spaced-guest-server --test it --locked bridge_guest_mkdir passed 5/5. bridge_guest_mkdir_and_remove_flags_work already asserts that an existing directory with exist_ok: false returns AlreadyExists.
  • Error mapping on real data-plane code: feeding tonic::Code::AlreadyExists through tonic_status_to_ecw_error + EcwProxyError::into_response gives HTTP 409 {"code":409,...}. The real e2b 2.21.1 wheel (sha256 matches uv.lock) maps that body to Code.already_exists.
  • I have not run this against a live SPACE sandbox, and I did not run a data-plane handler test (I didn't find a fixture with a fake WorkerApi). The chain above comes from source plus these component runs.

Why it matters

Code that uses the boolean for first-run setup, "skip if exists" logic or a simple directory lock behaves differently on SPACE than on E2B. Most callers ignore the return value. space_smoke/scenarios/ecw_filesystem_mutations.py also ignores it, which is why the smoke suite doesn't catch this.

Possible approach (for discussion)

Send exist_ok: false from filesystem_make_dir only, and keep exist_ok: true in the parent-ensure helper (~L825). The existing 409 mapping would then make the SDK return False. One tradeoff needs your call: filesystem_make_dir goes through retryable_bounded_node_api_unary. If it can retry after the guest has already applied the mkdir (I haven't checked whether it does), the retry would see AlreadyExists and report False for a directory the call just created. Keeping exist_ok: true avoids that, at the cost of E2B parity. Two other options are adding a created flag to MkdirResponse, or documenting the difference in docs/ecw.md. Related: the node-api sim worker uses create_dir_all for parents: true, so sim-based tests would hide a fix either way.

Severity (self-assessed): low. This is a divergence from the SDK contract. There is no data loss, and most callers don't read the return value.

Happy to send a PR with a regression test once the approach is agreed. This issue was drafted with an AI agent (Claude Code); I checked the references and ran the tests above.

Activity

1
NancyKwongPerplexity1mo ago

Thanks for opening this issue! A SPACE maintainer will take a look.

CONTRIBUTING.md explains how we review outside contributions.