From 8d4412548e8c6a488a7b54f10a282c1c273907b6 Mon Sep 17 00:00:00 2001 From: Mengye Ren Date: Sat, 24 Oct 2026 22:33:36 -0400 Subject: [PATCH 1/2] One artifact-path validator shared by the kernel and the syscall tool (#337) --- src/outerloop/syscall.py | 10 +--------- src/outerloop/syscall_cli.py | 11 ++++++----- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/outerloop/syscall.py b/src/outerloop/syscall.py index 4bca7b8c..70d3e121 100644 --- a/src/outerloop/syscall.py +++ b/src/outerloop/syscall.py @@ -47,6 +47,7 @@ from outerloop.compute import GONE from outerloop.contract import Benchmark, Budgets +from outerloop.syscall_cli import _rel_path_ok log = logging.getLogger(__name__) @@ -254,15 +255,6 @@ def launch_task_ids(launches: Iterable[Launch], job_ids: list[str]) -> list[str] return [] -def _rel_path_ok(path: str) -> bool: - """A declared artifact must stay inside the job's tree: repo-relative, - no traversal, no absolute paths. (Same stance as scope normalization.)""" - if not path or len(path) > 500 or path.startswith(("/", "~")) or "\\" in path: - return False - parts = path.split("/") - return all(p not in ("", ".", "..") for p in parts) - - def read_request(workspace: Path) -> SyscallRequest | None: """Read and CONSUME the author's request. None = no request (the session finished; today's path). Malformed or over per-request bounds -> diff --git a/src/outerloop/syscall_cli.py b/src/outerloop/syscall_cli.py index 2ddfafe8..95453f27 100644 --- a/src/outerloop/syscall_cli.py +++ b/src/outerloop/syscall_cli.py @@ -76,11 +76,12 @@ class ToolError(Exception): def _rel_path_ok(path: str) -> bool: - """MUST match syscall._rel_path_ok exactly — the CLI's fast check has to - accept precisely what the kernel accepts, or the author burns a sleep on a - post-session validation error (the very thing the tool exists to prevent). - Rejects absolute/`~`, backslashes, over-long, and any empty/`.`/`..` - component (so ``, `.`, `out/./x`, `out//x` all fail here as they do there).""" + """The one artifact-path rule: the kernel imports this from here, so the + CLI's fast check accepts precisely what the kernel accepts (otherwise the + author burns a sleep on a post-session validation error — the very thing + the tool exists to prevent). Rejects absolute/`~`, backslashes, over-long, + and any empty/`.`/`..` component (so ``, `.`, `out/./x`, `out//x` all + fail). Stdlib-only, because this file is copied into workspaces verbatim.""" if not path or len(path) > 500 or path.startswith(("/", "~")) or "\\" in path: return False return all(p not in ("", ".", "..") for p in path.split("/")) From 834f587190457221dbeec0cb97eba106fd28fe8b Mon Sep 17 00:00:00 2001 From: Mengye Ren Date: Sat, 24 Oct 2026 22:52:24 -0400 Subject: [PATCH 2/2] Plain docstring for the shared artifact-path rule --- src/outerloop/syscall_cli.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/outerloop/syscall_cli.py b/src/outerloop/syscall_cli.py index 95453f27..08c3014a 100644 --- a/src/outerloop/syscall_cli.py +++ b/src/outerloop/syscall_cli.py @@ -76,12 +76,10 @@ class ToolError(Exception): def _rel_path_ok(path: str) -> bool: - """The one artifact-path rule: the kernel imports this from here, so the - CLI's fast check accepts precisely what the kernel accepts (otherwise the - author burns a sleep on a post-session validation error — the very thing - the tool exists to prevent). Rejects absolute/`~`, backslashes, over-long, - and any empty/`.`/`..` component (so ``, `.`, `out/./x`, `out//x` all - fail). Stdlib-only, because this file is copied into workspaces verbatim.""" + """The kernel's artifact-path rule; the CLI uses the same function for + early feedback. It rejects absolute and home paths, backslashes, paths + over 500 characters, and empty, `.` or `..` path parts. This module uses + only the standard library because it is copied into workspaces.""" if not path or len(path) > 500 or path.startswith(("/", "~")) or "\\" in path: return False return all(p not in ("", ".", "..") for p in path.split("/"))