Skip to content

The agent that grows with you

fix(cron): move cloud-placeholder refusal into _read_referenced_script and cover ~/Library/CloudStorage

Teknium42a96e754327
diff --git a/cron/lifecycle_guard.py b/cron/lifecycle_guard.py
index 9a7dcaf7e09..b6bba136908 100644
--- a/cron/lifecycle_guard.py
+++ b/cron/lifecycle_guard.py
@@ -110,18 +110,27 @@ _MAX_REFERENCED_SCRIPT_DEPTH = 8
_CONTROL_CHARS = frozenset(";&|()")
-def _is_apple_file_provider_path(path: Path) -> bool:
- """Return True for paths inside macOS's cloud-backed document root.
+# Directory names that sit directly under a `Library` path component and
+# mark a FileProvider-backed subtree: `Mobile Documents` is iCloud Drive;
+# `CloudStorage` hosts every third-party FileProvider domain (Dropbox,
+# OneDrive, Google Drive, Box, ...) on modern macOS.
+_CLOUD_PLACEHOLDER_MARKERS = frozenset({"Mobile Documents", "CloudStorage"})
+
+
+def _is_cloud_placeholder_path(path: Path) -> bool:
+ """Return True for paths inside a macOS FileProvider-backed subtree.
``O_NONBLOCK`` does not make regular-file reads non-blocking. Opening an
- evicted FileProvider placeholder below ``~/Library/Mobile Documents`` can
- therefore wait indefinitely for hydration. The lifecycle guard runs
- before a terminal command's timeout starts, so it must identify this
- boundary from path metadata and fail closed without opening the file.
+ evicted FileProvider placeholder below ``~/Library/Mobile Documents``
+ (iCloud Drive) or ``~/Library/CloudStorage`` (Dropbox / OneDrive /
+ Google Drive and other third-party providers) can therefore wait
+ indefinitely for hydration. The lifecycle guard runs before a terminal
+ command's timeout starts, so it must identify this boundary from path
+ metadata and fail closed without opening the file.
"""
parts = path.parts
return any(
- parts[index - 1] == "Library" and part == "Mobile Documents"
+ parts[index - 1] == "Library" and part in _CLOUD_PLACEHOLDER_MARKERS
for index, part in enumerate(parts)
if index
)
@@ -443,7 +452,28 @@ def _resolve_script_directory(script_path: str) -> Optional[str]:
def _read_referenced_script(path: Path) -> tuple[Optional[str], bool]:
- """Return ``(text, unsafe)`` using bounded, regular-file-only reads."""
+ """Return ``(text, unsafe)`` using bounded, regular-file-only reads.
+
+ This is the shared choke point for every local script read the guard
+ performs (the terminal walk in ``_contains_unsafe_gateway_action`` AND
+ the cron-script scan in ``_read_script_for_scanning``), so the
+ cloud-placeholder refusal lives here: a FileProvider path must never be
+ opened — not even to discover whether the file is hydrated — because an
+ evicted placeholder's ``open()`` can hang preflight indefinitely
+ (#88052). The lexical check covers direct cloud paths; the resolved
+ check covers local launchers that are symlinks into a cloud subtree.
+ """
+ if _is_cloud_placeholder_path(path):
+ return None, True
+ try:
+ resolved = path.resolve(strict=False)
+ except (OSError, ValueError):
+ # OSError: unreadable/long paths. ValueError: embedded NUL byte
+ # from a binary's decoded contents tokenized as a path — a
+ # guarded path must never crash the guard (#76762).
+ resolved = path
+ if _is_cloud_placeholder_path(resolved):
+ return None, True
flags = os.O_RDONLY | getattr(os, "O_NONBLOCK", 0)
try:
descriptor = os.open(path, flags)
@@ -549,10 +579,13 @@ def _contains_unsafe_gateway_action(
return True
for script_path in _iter_referenced_shell_scripts(command, cwd=cwd):
- # Do not touch a FileProvider path even to discover whether the file is
- # hydrated. The lexical check covers direct cloud paths; the resolved
- # check below covers local launchers that are symlinks into iCloud.
- if _is_apple_file_provider_path(script_path):
+ # Do not touch a FileProvider path even to discover whether the file
+ # is hydrated. The lexical check covers direct cloud paths; the
+ # resolved check below covers local launchers that are symlinks into
+ # a cloud subtree. _read_referenced_script repeats both checks as the
+ # shared choke point, so every caller stays covered even if this
+ # walk-level short-circuit is bypassed.
+ if _is_cloud_placeholder_path(script_path):
return True
try:
resolved = script_path.resolve(strict=False)
@@ -561,7 +594,7 @@ def _contains_unsafe_gateway_action(
# from a binary's decoded contents tokenized as a path — a
# guarded path must never crash the guard (#76762).
resolved = script_path
- if _is_apple_file_provider_path(resolved):
+ if _is_cloud_placeholder_path(resolved):
return True
if resolved in visited:
continue
diff --git a/tests/hermes_cli/test_gateway_restart_loop.py b/tests/hermes_cli/test_gateway_restart_loop.py
index 96145a36ebe..5043bea08e8 100644
--- a/tests/hermes_cli/test_gateway_restart_loop.py
+++ b/tests/hermes_cli/test_gateway_restart_loop.py
@@ -803,6 +803,61 @@ class TestLifecycleGuardModule:
str(launcher)
) is True
+ def test_third_party_cloudstorage_path_fails_closed_without_opening(
+ self, tmp_path, monkeypatch
+ ):
+ """~/Library/CloudStorage (Dropbox/OneDrive/Google Drive) is the same
+ FileProvider hazard as iCloud's Mobile Documents: an evicted
+ placeholder's open() can hang preflight. The guard must fail closed
+ on the lexical path without opening the file."""
+ import cron.lifecycle_guard as lifecycle_guard
+
+ cloud_dir = (
+ tmp_path
+ / "Library"
+ / "CloudStorage"
+ / "Dropbox-Personal"
+ / "scripts"
+ )
+ cloud_dir.mkdir(parents=True)
+ script = cloud_dir / "helper.sh"
+ script.write_text("#!/bin/sh\necho safe\n", encoding="utf-8")
+
+ real_open = lifecycle_guard.os.open
+
+ def reject_cloud_open(path, flags, *args, **kwargs):
+ if str(path) == str(script):
+ pytest.fail("lifecycle guard opened a CloudStorage path")
+ return real_open(path, flags, *args, **kwargs)
+
+ monkeypatch.setattr(lifecycle_guard.os, "open", reject_cloud_open)
+
+ assert lifecycle_guard.contains_gateway_lifecycle_command_or_referenced_script(
+ str(script)
+ ) is True
+
+ def test_read_referenced_script_choke_point_refuses_cloud_paths(
+ self, tmp_path, monkeypatch
+ ):
+ """The cloud refusal lives in _read_referenced_script itself so EVERY
+ caller (terminal walk AND cron-script scan) is covered — not just the
+ walk-level short-circuit in _contains_unsafe_gateway_action."""
+ import cron.lifecycle_guard as lifecycle_guard
+
+ cloud_dir = tmp_path / "Library" / "CloudStorage" / "OneDrive" / "s"
+ cloud_dir.mkdir(parents=True)
+ script = cloud_dir / "job.sh"
+ script.write_text("#!/bin/sh\necho safe\n", encoding="utf-8")
+
+ def forbid_open(path, flags, *args, **kwargs): # pragma: no cover
+ pytest.fail("choke point opened a cloud placeholder path")
+
+ monkeypatch.setattr(lifecycle_guard.os, "open", forbid_open)
+
+ text, unsafe = lifecycle_guard._read_referenced_script(script)
+ assert text is None
+ assert unsafe is True
+
# -- Whole-class regression tests (tilllt's T1-T4 on PR #79454) --------
def test_tilde_nul_candidate_does_not_crash_terminal_walk(self):