Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/agents/sandbox/entries/mounts/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ async def _start_rclone_server(
*,
config: RcloneMountConfig,
config_path: Path,
remote_name: str,
nfs_addr: str,
) -> None:
nfs_check = await session.exec(
Expand All @@ -753,7 +754,7 @@ async def _start_rclone_server(
tool="rclone serve nfs",
context={"type": config.mount_type},
)
cmd: list[str] = ["rclone", "serve", "nfs", f"{config.remote_name}:{config.remote_path}"]
cmd: list[str] = ["rclone", "serve", "nfs", f"{remote_name}:{config.remote_path}"]
cmd.extend(["--addr", nfs_addr])
cmd.extend(["--config", sandbox_path_str(config_path)])
if config.read_only:
Expand All @@ -778,13 +779,14 @@ async def _start_rclone_client(
path: Path,
config: RcloneMountConfig,
config_path: Path,
remote_name: str,
nfs_addr: str | None = None,
) -> None:
if self.mode == "fuse":
cmd: list[str] = [
"rclone",
"mount",
f"{config.remote_name}:{config.remote_path}",
f"{remote_name}:{config.remote_path}",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass the resolved remote name into rclone helpers

When any rclone mount is applied, the default fuse path calls _start_rclone_client(), but this helper has no remote_name parameter or local binding, so evaluating this f-string raises NameError before rclone is invoked. The NFS server helper has the same issue, so this change currently breaks rclone mounts instead of just changing name resolution.

Useful? React with 👍 / 👎.

sandbox_path_str(path),
]
if config.read_only:
Expand Down Expand Up @@ -900,12 +902,13 @@ async def apply(
context={"type": rclone_config.mount_type},
)
session_id_str = session_id.hex
remote_name = rclone_config.remote_name
# Keep generated rclone config under the workspace root so `session.mkdir()` /
# `session.write()` can handle it without special-casing absolute paths.
config_dir = posix_path_as_path(
coerce_posix_path(f".sandbox-rclone-config/{session_id_str}")
)
config_path = config_dir / f"{rclone_config.remote_name}.conf"
config_path = config_dir / f"{remote_name}.conf"
await session.mkdir(path, parents=True)
await session.mkdir(config_dir, parents=True)
session.register_persist_workspace_skip_path(config_dir)
Expand All @@ -924,13 +927,15 @@ async def apply(
session,
config=rclone_config,
config_path=command_config_path,
remote_name=remote_name,
nfs_addr=nfs_addr,
)
await self._start_rclone_client(
session,
path=path,
config=rclone_config,
config_path=command_config_path,
remote_name=remote_name,
nfs_addr=nfs_addr,
)
else:
Expand All @@ -940,6 +945,7 @@ async def apply(
path=path,
config=rclone_config,
config_path=command_config_path,
remote_name=remote_name,
)

async def unapply(
Expand All @@ -965,12 +971,22 @@ async def unapply(
shell=False,
)

session_id = getattr(session.state, "session_id", None)
if session_id is None:
remote_name = rclone_config.remote_name
else:
remote_name = self.resolve_remote_name(
session_id=session_id.hex,
remote_kind=rclone_config.remote_kind,
mount_type=rclone_config.mount_type,
)
Comment on lines +978 to +982

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the resolved remote name during teardown

For mounts where the pattern-level or derived name differs from rclone_config.remote_name, teardown computes the resolved remote_name here but the pkill pattern below still matches rclone_config.remote_name. After apply launches rclone under the resolved name, unapply will miss that process and leave the rclone mount/server running.

Useful? React with 👍 / 👎.


await session.exec(
"sh",
"-lc",
(
"pkill -f -- "
f"'rclone (mount|serve nfs) {rclone_config.remote_name}:' >/dev/null 2>&1 || true"
f"'rclone (mount|serve nfs) {remote_name}:' >/dev/null 2>&1 || true"
),
shell=False,
)
Expand Down