From c7b8831294b4275d201a1a27899356157818ffa1 Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 16:16:48 -0500 Subject: [PATCH 1/8] feat/no-ticket(dispatch): deny free OpenCode models on sensitive paths After classification, a declared target in a sensitive class cannot stay on a free OpenCode model. That launch drops Doppler, Supabase, cloud, and GitHub-write tokens and cannot read the sensitive path or a secrets file. A routine path may still use a free model. Any other launch is unchanged. Property tests generate one path for each sensitive class plus a routine path, and a launch check proves the scrub and the read block. --- bin/fm-dispatch-resolve.sh | 9 + bin/fm-free-model-sensitivity.py | 738 ++++++++++++++++++++++++ bin/fm-free-model-sensitivity.sh | 7 + bin/fm-spawn.sh | 37 ++ docs/configuration.md | 4 + tests/fm-dispatch-resolve.test.sh | 57 ++ tests/fm-free-model-sensitivity.test.sh | 327 +++++++++++ tests/fm-spawn-dispatch-profile.test.sh | 41 ++ 8 files changed, 1220 insertions(+) create mode 100755 bin/fm-free-model-sensitivity.py create mode 100755 bin/fm-free-model-sensitivity.sh create mode 100755 tests/fm-free-model-sensitivity.test.sh diff --git a/bin/fm-dispatch-resolve.sh b/bin/fm-dispatch-resolve.sh index 63abefacaf2..306c34b2911 100755 --- a/bin/fm-dispatch-resolve.sh +++ b/bin/fm-dispatch-resolve.sh @@ -31,6 +31,9 @@ # matched path and pattern. Paths come only from that explicit line; prose is # never scanned for path-shaped words. With no such line, no match, or no # rule declaring the field, the Jev path below runs unchanged. +# Free OpenCode deny, after classification: bin/fm-free-model-sensitivity.sh +# owns the sensitive-path classes and drops a free OpenCode candidate when +# a declared target path matches one. Paid models and other harnesses stay. # # What it does when on with at least one rule: one POST to # https://api.typesafe.ai/v1/systemone with the project name and the brief's @@ -685,6 +688,12 @@ RESULT=$(jq -n --arg floor "$CONFIDENCE_FLOOR" --argjson lat "$LAT_MS" --arg non end end') || emit_error "resolution failed" +# The classifier has already chosen. A sensitive target path still cannot +# keep a free OpenCode model, whatever that choice was. +if ! RESULT=$(printf '%s\n' "$RESULT" | "$SCRIPT_DIR/fm-free-model-sensitivity.sh" apply-resolution --brief "$BRIEF"); then + emit_error "free-model sensitivity check failed" +fi + if [ "$JSON_OUTPUT" = 1 ]; then printf '%s\n' "$RESULT" exit 0 diff --git a/bin/fm-free-model-sensitivity.py b/bin/fm-free-model-sensitivity.py new file mode 100755 index 00000000000..588b10874b8 --- /dev/null +++ b/bin/fm-free-model-sensitivity.py @@ -0,0 +1,738 @@ +#!/usr/bin/env python3 +"""Free OpenCode sensitivity boundary. + +This file is the single owner of three facts: which paths are sensitive, +which configured OpenCode model ids are free, and which environment names +carry Doppler, Supabase, cloud, or GitHub-write tokens. + +bin/fm-dispatch-resolve.sh applies the deny after classification. +bin/fm-spawn.sh confines only a launch whose resolved model is free. +A paid OpenCode model and every other harness keep their environment and +their read access. A routine path may still resolve to a free model. + +The read block is a seccomp user notifier in the parent. The child cannot +complete open, stat, or exec of a blocked path, including by a raw syscall. +The parent opens an allowed file itself and installs that fd, so a symlink +swap after the check cannot hand the child a secret inode. +""" + +from __future__ import annotations + +import ctypes +import errno +import json +import os +import platform +import socket +import stat +import struct +import sys +from ctypes import c_uint16, c_uint32, c_uint64, c_ulong + +AT_FDCWD = -100 +SECCOMP_SET_MODE_FILTER = 1 +SECCOMP_FILTER_FLAG_NEW_LISTENER = 8 +SECCOMP_GET_NOTIF_SIZES = 3 +SECCOMP_RET_ALLOW = 0x7FFF0000 +SECCOMP_RET_USER_NOTIF = 0x7FC00000 +SECCOMP_RET_ERRNO = 0x00050000 +SECCOMP_ADDFD_FLAG_SEND = 1 << 1 +SECCOMP_USER_NOTIF_FLAG_CONTINUE = 1 +PR_SET_NO_NEW_PRIVS = 38 +O_CLOEXEC = 0o2000000 +O_CREAT = 0o100 +O_DIRECTORY = 0o200000 + +BPF_LD_W_ABS = 0x20 +BPF_JMP_JEQ_K = 0x15 +BPF_RET_K = 0x06 + +ENV_NAMES = { + "env.local", + "env.development", + "env.production", + "env.staging", + "env.test", +} +DOPPLER_NAMES = { + "doppler.yaml", + "doppler.yml", + ".doppler.yaml", + ".doppler.yml", +} +CI_NAMES = { + ".gitlab-ci.yml", + ".gitlab-ci.yaml", + "jenkinsfile", + "azure-pipelines.yml", + "azure-pipelines.yaml", + "bitbucket-pipelines.yml", +} +SECRET_NAMES = { + "secrets", + ".secrets", + "secrets.json", + "secrets.yaml", + "secrets.yml", + "secrets.env", + "secrets.toml", + "credentials.json", + "service-account.json", + "serviceaccount.json", + ".git-credentials", + ".netrc", +} +# Home-relative token stores that would put a scrubbed token back on disk. +TOKEN_STORES = ( + ".doppler", + ".doppler.yaml", + ".supabase", + ".aws", + ".azure", + ".config/gcloud", + ".config/gh", + ".git-credentials", + ".netrc", + ".config/doppler", +) +SEGMENTS = { + "auth": "auth", + "authentication": "auth", + "oauth": "auth", + "payments": "payments", + "payment": "payments", + "billing": "payments", + "stripe": "payments", + "doppler": "doppler", + ".doppler": "doppler", + "migrations": "migration", + "migrate": "migration", + "migration": "migration", + "alembic": "migration", + "flyway": "migration", + "infra": "infra", + "terraform": "infra", + "k8s": "infra", + "kubernetes": "infra", + "helm": "infra", + "deploy": "infra", + "deployment": "infra", + "argocd": "infra", + "cloudformation": "infra", +} +FILE_STEMS = { + "auth": "auth", + "oauth": "auth", + "payment": "payments", + "payments": "payments", + "billing": "payments", + "stripe": "payments", +} + + +def parts_of(path: str) -> list[str]: + text = path.strip().replace("\\", "/") + while "//" in text: + text = text.replace("//", "/") + if text.startswith("./"): + text = text[2:] + text = os.path.normpath(text) if text else "" + if text in ("", "."): + return [] + text = text.rstrip("/") + return [seg.lower() for seg in text.split("/") if seg not in ("", ".")] + + +def sensitive_class(path: str) -> str | None: + """Return the sensitive class, or None when the path may use a free model.""" + parts = parts_of(path) + if not parts: + return None + base = parts[-1] + if base == ".env" or base.startswith(".env.") or base.endswith(".env") or base in ENV_NAMES: + return "env" + if base in DOPPLER_NAMES: + return "doppler" + if base in CI_NAMES or ".circleci" in parts or ".buildkite" in parts: + return "ci" + for index, seg in enumerate(parts[:-1]): + if seg == ".github" and parts[index + 1] == "workflows": + return "ci" + for seg in parts[:-1]: + kind = SEGMENTS.get(seg) + if kind: + return kind + if base.endswith(".sql") and "migration" in base: + return "migration" + if ( + base.endswith(".tf") + or base.endswith(".tfvars") + or base in {"vercel.json", "dockerfile", "fly.toml", "cdk.json", "chart.yaml", "chart.yml"} + or base in {"serverless.yml", "serverless.yaml", "render.yaml", "render.yml", "pulumi.yaml", "pulumi.yml"} + or (base.startswith("docker-compose") and base.endswith((".yml", ".yaml"))) + or ("deploy" in base and base.endswith(".sh")) + or base in {"values.yaml", "values.yml"} + or (base.startswith("values-") and base.endswith((".yaml", ".yml"))) + or base.endswith((".k8s.yaml", ".k8s.yml")) + or ("deployment" in base and base.endswith((".yaml", ".yml"))) + or ("ingress" in base and base.endswith((".yaml", ".yml"))) + ): + return "infra" + stem = base.split(".", 1)[0] + return FILE_STEMS.get(stem) + + +def _under(path: str, root: str) -> bool: + path = os.path.normpath(path) + root = os.path.normpath(root) + return path == root or path.startswith(root + os.sep) + + +def secrets_path(path: str, home: str) -> bool: + parts = parts_of(path) + if not parts: + return False + if ".secrets" in parts or parts[-1] in SECRET_NAMES: + return True + if not home: + return False + home = os.path.normpath(home) + candidate = path if os.path.isabs(path) else os.path.join(home, path) + for rel in TOKEN_STORES: + if _under(os.path.normpath(candidate), os.path.join(home, rel)): + return True + return _under(os.path.normpath(candidate), os.path.join(home, ".secrets")) + + +def path_blocked(path: str, home: str) -> bool: + return sensitive_class(path) is not None or secrets_path(path, home) + + +def is_free_opencode(harness: str | None, model: str | None) -> bool: + """A free OpenCode model is a configured opencode model whose id marks it free. + + The catalog mark is a final segment that is `free` or ends in `-free`, + as in `opencode/glm-5.3-flash-free`. `big-pickle` and paid provider ids + do not. Another harness stays paid even when its id ends in `-free`. + """ + if harness != "opencode" or not model: + return False + leaf = model.split("/")[-1].lower() + return leaf == "free" or leaf.endswith("-free") + + +def token_name(name: str) -> bool: + """True when the variable is a Doppler, Supabase, cloud, or GitHub-write token.""" + if name == "DOPPLER_TOKEN" or (name.startswith("DOPPLER_") and "TOKEN" in name): + return True + if name.startswith("SUPABASE_") and any(part in name for part in ("KEY", "TOKEN", "SECRET")): + return True + if name in { + "AWS_ACCESS_KEY_ID", + "AWS_SECRET_ACCESS_KEY", + "AWS_SESSION_TOKEN", + "AWS_SECURITY_TOKEN", + "GOOGLE_APPLICATION_CREDENTIALS", + "GOOGLE_OAUTH_ACCESS_TOKEN", + "CLOUDSDK_AUTH_ACCESS_TOKEN", + "AZURE_CLIENT_SECRET", + "AZURE_CLIENT_CERTIFICATE_PASSWORD", + "ARM_CLIENT_SECRET", + "ARM_CLIENT_CERTIFICATE_PASSWORD", + "DIGITALOCEAN_ACCESS_TOKEN", + "DIGITALOCEAN_TOKEN", + "GH_TOKEN", + "GITHUB_TOKEN", + "GH_ENTERPRISE_TOKEN", + "GITHUB_ENTERPRISE_TOKEN", + "GITHUB_PAT", + "GH_PAT", + }: + return True + return False + + +def target_paths(brief: str) -> list[str]: + found = [] + for line in brief.splitlines(): + if line.startswith("Target paths:"): + found.extend(line[len("Target paths:") :].split()) + return found + + +def brief_sensitive(path: str) -> bool: + with open(path, encoding="utf-8") as handle: + text = handle.read() + return any(sensitive_class(item) is not None for item in target_paths(text)) + + +def apply_resolution(brief: str, payload: dict) -> dict: + if not brief_sensitive(brief): + return payload + candidates = payload.get("candidates") or [] + denied = False + for candidate in candidates: + profile = candidate.get("profile") or {} + if is_free_opencode(profile.get("harness"), profile.get("model")): + candidate["eligible"] = False + candidate.pop("unranked", None) + candidate["reason"] = "sensitive target path denies a free OpenCode model" + denied = True + if not denied: + return payload + chosen = payload.get("chosen") or {} + chosen_profile = chosen.get("profile") or {} + if not is_free_opencode(chosen_profile.get("harness"), chosen_profile.get("model")): + return payload + eligible = [ + item + for item in candidates + if item.get("eligible") and not item.get("unranked") and isinstance(item.get("spendPriority"), (int, float)) and not isinstance(item.get("spendPriority"), bool) + ] + if not eligible: + payload["status"] = "escalate" + payload["reason"] = "sensitive target path denies a free OpenCode model and no other rankable candidate remains" + payload.pop("chosen", None) + return payload + best = max(item.get("spendPriority") for item in eligible) + tops = [item for item in eligible if item.get("spendPriority") == best] + if len(tops) > 1: + payload["status"] = "escalate" + payload["reason"] = "genuine spendPriority tie" + payload.pop("chosen", None) + return payload + payload["status"] = "clear" + payload.pop("reason", None) + payload["chosen"] = tops[0] + return payload + + +def arch_tables(): + machine = platform.machine() + if machine in ("aarch64", "arm64"): + return 0xC00000B7, 277, 167, { + "openat": 56, + "openat2": 437, + "execve": 221, + "execveat": 281, + "statx": 291, + "newfstatat": 79, + "faccessat": 48, + "faccessat2": 439, + "readlinkat": 78, + "name_to_handle_at": 264, + }, { + "io_uring_setup": 425, + "io_uring_enter": 426, + "io_uring_register": 427, + }, None + if machine in ("x86_64", "amd64"): + return 0xC000003E, 317, 157, { + "open": 2, + "openat": 257, + "openat2": 437, + "execve": 59, + "execveat": 281, + "statx": 332, + "newfstatat": 262, + "faccessat": 269, + "faccessat2": 439, + "readlinkat": 267, + "name_to_handle_at": 303, + }, { + "io_uring_setup": 425, + "io_uring_enter": 426, + "io_uring_register": 427, + }, 2 + return None + + +def _ioc(direction: int, number: int, size: int) -> int: + return (direction << 30) | (ord("!") << 8) | number | (size << 16) + + +class NotifSizes(ctypes.Structure): + _fields_ = [ + ("seccomp_notif", c_uint16), + ("seccomp_notif_resp", c_uint16), + ("seccomp_data", c_uint16), + ] + + +class SockFilter(ctypes.Structure): + _fields_ = [ + ("code", c_uint16), + ("jt", ctypes.c_uint8), + ("jf", ctypes.c_uint8), + ("k", c_uint32), + ] + + +class SockFprog(ctypes.Structure): + _fields_ = [("len", c_uint16), ("filter", ctypes.POINTER(SockFilter))] + + +class IOVec(ctypes.Structure): + _fields_ = [("base", ctypes.c_void_p), ("len", ctypes.c_size_t)] + + +def build_filter(audit_arch: int, notify: set[int], deny: set[int]) -> bytes: + words = [] + + def stmt(code: int, k: int) -> None: + words.append(struct.pack(" None: + words.append(struct.pack(" int: + libc = ctypes.CDLL(None, use_errno=True) + count = len(blob) // 8 + filters = (SockFilter * count).from_buffer_copy(blob) + prog = SockFprog(count, filters) + if libc.syscall(sys_prctl, PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0: + raise OSError(ctypes.get_errno(), "prctl") + fd = libc.syscall(sys_seccomp, SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_NEW_LISTENER, ctypes.byref(prog)) + if fd < 0: + raise OSError(ctypes.get_errno(), "seccomp") + return fd + + +def send_fd(sock: socket.socket, fd: int) -> None: + sock.sendmsg([b"x"], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, struct.pack("i", fd))]) + + +def recv_fd(sock: socket.socket) -> int: + _, ancdata, _, _ = sock.recvmsg(1, socket.CMSG_LEN(4)) + for level, kind, data in ancdata: + if level == socket.SOL_SOCKET and kind == socket.SCM_RIGHTS: + return struct.unpack("i", data[:4])[0] + raise OSError(errno.EIO, "listener fd missing") + + +def read_cstr(pid: int, address: int) -> str | None: + if not address: + return None + libc = ctypes.CDLL(None, use_errno=True) + buf = ctypes.create_string_buffer(4096) + local = IOVec(ctypes.addressof(buf), 4096) + remote = IOVec(address, 4096) + got = libc.process_vm_readv(pid, ctypes.byref(local), 1, ctypes.byref(remote), 1, 0) + if got < 0: + return None + raw = buf.raw[:got] + end = raw.find(b"\0") + if end < 0: + return None + return raw[:end].decode("utf-8", "surrogateescape") + + +def as_i64(value: int) -> int: + if value >= 2**63: + return value - 2**64 + return value + + +def resolve_path(pid: int, dirfd: int, path: str) -> tuple[str, str]: + if path.startswith("/"): + lexical = path + else: + if dirfd == AT_FDCWD: + base = os.readlink(f"/proc/{pid}/cwd") + else: + base = os.readlink(f"/proc/{pid}/fd/{dirfd}") + lexical = os.path.join(base, path) + lexical = os.path.normpath(lexical) + try: + resolved = os.path.realpath(lexical) + except OSError: + resolved = lexical + return lexical, resolved + + +def ioctl(fd: int, request: int, buffer) -> int: + libc = ctypes.CDLL(None, use_errno=True) + rc = libc.ioctl(fd, c_ulong(request), buffer) + if rc < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) + return rc + + +def supervise(notify_fd: int, child: int, home: str, names: dict[str, int], notif_size: int) -> None: + recv_req = _ioc(3, 0, notif_size) + send_req = _ioc(3, 1, 24) + valid_req = _ioc(1, 2, 8) + addfd_req = _ioc(1, 3, 24) + # glibc opens through openat. openat2 is denied below: its flag argument + # is a struct pointer, so the parent cannot install a checked fd for it. + open_numbers = {names[name] for name in ("openat", "open") if name in names} + path_at = {names[name] for name in ("openat", "openat2", "statx", "newfstatat", "faccessat", "faccessat2", "readlinkat", "name_to_handle_at") if name in names} + while True: + buf = ctypes.create_string_buffer(notif_size) + try: + ioctl(notify_fd, recv_req, buf) + except OSError as exc: + if exc.errno in (errno.ENOENT, errno.EINTR): + if exc.errno == errno.EINTR: + continue + break + raise + ident, pid, _flags = struct.unpack_from("QII", buf.raw, 0) + nr = struct.unpack_from("I", buf.raw, 16)[0] + args = struct.unpack_from("6Q", buf.raw, 32) + try: + ioctl(notify_fd, valid_req, struct.pack("Q", ident)) + except OSError: + continue + allow_fd = None + remote_flags = 0 + error = errno.EACCES + continue_call = False + try: + if nr in path_at or nr == names.get("open") or nr in (names.get("execve"), names.get("execveat")): + if nr == names.get("execve") or nr == names.get("open"): + raw = read_cstr(pid, args[0]) + dirfd = AT_FDCWD + elif nr == names.get("execveat"): + raw = read_cstr(pid, args[1]) + dirfd = as_i64(args[0]) + else: + raw = read_cstr(pid, args[1]) + dirfd = as_i64(args[0]) + if raw is None: + error = errno.EFAULT + else: + lexical, resolved = resolve_path(pid, dirfd, raw) + if nr == names.get("openat2"): + # openat2's flag argument is a struct pointer, so the + # parent cannot install an fd for it. Denying the call + # keeps that path from skipping the inode check. + error = errno.EPERM + elif path_blocked(lexical, home) or path_blocked(resolved, home): + error = errno.EACCES + elif nr in open_numbers: + flags = int(as_i64(args[2])) if nr != names.get("open") else int(as_i64(args[1])) + mode = 0o666 + if flags & O_CREAT: + mode = int(args[3 if nr != names.get("open") else 2]) & 0o7777 + try: + st_mode = os.lstat(resolved).st_mode + special = not (stat.S_ISREG(st_mode) or stat.S_ISDIR(st_mode)) + except FileNotFoundError: + special = False + if special: + continue_call = True + else: + fd = os.open(resolved, flags | O_CLOEXEC, mode) + try: + opened = os.path.realpath(f"/proc/self/fd/{fd}") + if path_blocked(opened, home): + error = errno.EACCES + else: + allow_fd = fd + fd = None + remote_flags = O_CLOEXEC if flags & O_CLOEXEC else 0 + finally: + if fd is not None: + os.close(fd) + else: + continue_call = True + else: + continue_call = True + except OSError as exc: + error = exc.errno or errno.EIO + if allow_fd is not None: + try: + ioctl( + notify_fd, + addfd_req, + struct.pack("QIIII", ident, SECCOMP_ADDFD_FLAG_SEND, allow_fd, 0, remote_flags), + ) + finally: + os.close(allow_fd) + continue + flags_out = SECCOMP_USER_NOTIF_FLAG_CONTINUE if continue_call else 0 + # seccomp_notif_resp.error is 0 or a negative errno. A positive value + # is rejected, and the target would otherwise observe a live fd. + err_out = 0 if continue_call else -int(error or errno.EIO) + resp = ctypes.create_string_buffer(struct.pack("QqiI", ident, 0, err_out, flags_out)) + try: + ioctl(notify_fd, send_req, resp) + except OSError: + continue + + +def confine(home: str, command: list[str]) -> int: + tables = arch_tables() + if tables is None: + print("free-model sensitivity: this architecture cannot confine a free OpenCode model", file=sys.stderr) + return 2 + audit, sys_seccomp, sys_prctl, names, deny_names, _open = tables + for key in list(os.environ): + if token_name(key): + del os.environ[key] + parent, child = socket.socketpair() + pid = os.fork() + if pid == 0: + try: + parent.close() + listener = install_filter(build_filter(audit, set(names.values()), set(deny_names.values())), sys_seccomp, sys_prctl) + send_fd(child, listener) + os.close(listener) + child.close() + os.execvpe(command[0], command, os.environ) + except OSError as exc: + print(f"free-model sensitivity: confine failed: {exc}", file=sys.stderr) + os._exit(127) + child.close() + try: + listener = recv_fd(parent) + except OSError as exc: + print(f"free-model sensitivity: confine failed: {exc}", file=sys.stderr) + os.waitpid(pid, 0) + return 2 + parent.close() + libc = ctypes.CDLL(None, use_errno=True) + sizes = NotifSizes() + if libc.syscall(sys_seccomp, SECCOMP_GET_NOTIF_SIZES, 0, ctypes.byref(sizes)) != 0: + os.close(listener) + os.kill(pid, 9) + os.waitpid(pid, 0) + return 2 + try: + supervise(listener, pid, home, names, sizes.seccomp_notif or 80) + finally: + os.close(listener) + _pid, status = os.waitpid(pid, 0) + if os.WIFEXITED(status): + return os.WEXITSTATUS(status) + if os.WIFSIGNALED(status): + return 128 + os.WTERMSIG(status) + return 1 + + +def usage() -> None: + print( + "usage: fm-free-model-sensitivity.sh class \n" + " fm-free-model-sensitivity.sh free-model --harness --model \n" + " fm-free-model-sensitivity.sh token-name \n" + " fm-free-model-sensitivity.sh brief-sensitive --brief \n" + " fm-free-model-sensitivity.sh apply-resolution --brief \n" + " fm-free-model-sensitivity.sh confine --home -- ...", + file=sys.stderr, + ) + + +def flag_value(argv: list[str], flag: str) -> str: + if flag not in argv: + raise SystemExit(2) + index = argv.index(flag) + if index + 1 >= len(argv): + raise SystemExit(2) + return argv[index + 1] + + +def main(argv: list[str]) -> int: + if len(argv) < 2 or argv[1] in ("-h", "--help"): + usage() + return 0 if len(argv) > 1 and argv[1] in ("-h", "--help") else 2 + cmd = argv[1] + if cmd == "class": + if len(argv) != 3: + usage() + return 2 + kind = sensitive_class(argv[2]) + if kind is None: + return 1 + print(kind) + return 0 + if cmd == "free-model": + try: + harness = flag_value(argv[2:], "--harness") + model = flag_value(argv[2:], "--model") + except SystemExit: + usage() + return 2 + return 0 if is_free_opencode(harness, model) else 1 + if cmd == "token-name": + if len(argv) != 3: + usage() + return 2 + return 0 if token_name(argv[2]) else 1 + if cmd == "brief-sensitive": + try: + brief = flag_value(argv[2:], "--brief") + except SystemExit: + usage() + return 2 + try: + return 0 if brief_sensitive(brief) else 1 + except OSError as exc: + print(f"free-model sensitivity: {exc}", file=sys.stderr) + return 2 + if cmd == "apply-resolution": + try: + brief = flag_value(argv[2:], "--brief") + except SystemExit: + usage() + return 2 + raw = sys.stdin.buffer.read() + try: + if not brief_sensitive(brief): + sys.stdout.buffer.write(raw) + return 0 + payload = json.loads(raw) + updated = apply_resolution(brief, payload) + except (OSError, json.JSONDecodeError) as exc: + print(f"free-model sensitivity: {exc}", file=sys.stderr) + return 2 + if updated is payload and not any( + is_free_opencode((item.get("profile") or {}).get("harness"), (item.get("profile") or {}).get("model")) + for item in (payload.get("candidates") or []) + ): + sys.stdout.buffer.write(raw) + return 0 + json.dump(updated, sys.stdout) + sys.stdout.write("\n") + return 0 + if cmd == "confine": + if "--" not in argv: + usage() + return 2 + split = argv.index("--") + command = argv[split + 1 :] + if not command: + usage() + return 2 + try: + home = flag_value(argv[2:split], "--home") + except SystemExit: + home = os.environ.get("HOME", "") + if not home: + print("free-model sensitivity: confine needs --home", file=sys.stderr) + return 2 + return confine(home, command) + usage() + return 2 + + +if __name__ == "__main__": + try: + sys.exit(main(sys.argv)) + except BrokenPipeError: + sys.exit(0) diff --git a/bin/fm-free-model-sensitivity.sh b/bin/fm-free-model-sensitivity.sh new file mode 100755 index 00000000000..6fa3eb17c42 --- /dev/null +++ b/bin/fm-free-model-sensitivity.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# fm-free-model-sensitivity.sh - public interface for the free OpenCode boundary. +# bin/fm-free-model-sensitivity.py owns the path classes, the free-model mark, +# the token names, the post-classification deny, and the launch confine. +set -euo pipefail +here=$(CDPATH='' cd -- "$(dirname "$0")" && pwd) || exit 1 +exec python3 "$here/fm-free-model-sensitivity.py" "$@" diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index 87c812c54c8..aa2d6538a7a 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -424,6 +424,8 @@ # be POSIX sh compatible under this opt-in; the absent-file path is unchanged. # This is an exec environment boundary, not a sandbox for the pane's startup # shell, credential files, same-user processes, or later shell initialization. +# A free OpenCode model is the exception: bin/fm-free-model-sensitivity.sh +# owns that launch's token scrub, read block, and sensitive-target refusal. # See docs/configuration.md for provider/Git setup and supported limits. # On backend=orca the destination is an Orca terminal whose environment comes # from the Orca app and shell startup, not this home, so a nonempty allowlist @@ -7509,6 +7511,41 @@ if [ "$ORCA_LAUNCH_ENV_ENABLED" = 1 ]; then # before launching the worker, including on a later command failure. LAUNCH="command rm -- $(shell_quote "$LAUNCH_FILE") || { echo 'error: cannot remove private launch file; refusing worker launch' >&2; return 1 2>/dev/null || exit 1; }; $LAUNCH" fi +# Confine only a resolved free OpenCode model. Any other launch, including a +# paid OpenCode model, keeps the command and environment built above. +if [ -n "$MODEL" ] && [ "$MODEL" != default ] && [ -n "$HARNESS" ]; then + fm_free_rc=0 + "$SCRIPT_DIR/fm-free-model-sensitivity.sh" free-model --harness "$HARNESS" --model "$MODEL" || fm_free_rc=$? + case "$fm_free_rc" in + 0) + # Exit 0 means a declared target is sensitive. Start there so a + # successful check is not mistaken for the not-sensitive exit. + fm_brief_rc=0 + if [ -n "${BRIEF:-}" ]; then + "$SCRIPT_DIR/fm-free-model-sensitivity.sh" brief-sensitive --brief "$BRIEF" || fm_brief_rc=$? + else + fm_brief_rc=1 + fi + case "$fm_brief_rc" in + 0) + echo "error: refusing to launch free OpenCode model '$MODEL' because a declared target path is sensitive" >&2 + exit 1 + ;; + 1) ;; + *) + echo "error: free-model sensitivity check failed; refusing launch" >&2 + exit 1 + ;; + esac + LAUNCH="$(shell_quote "$SCRIPT_DIR/fm-free-model-sensitivity.sh") confine --home $(shell_quote "${HOME:-}") -- /bin/sh -c $(shell_quote "$LAUNCH")" + ;; + 1) ;; + *) + echo "error: free-model sensitivity check failed; refusing launch" >&2 + exit 1 + ;; + esac +fi if [ -e "$LAUNCH_FILE" ] || [ -L "$LAUNCH_FILE" ]; then echo "error: task launch file $LAUNCH_FILE already exists; refusing to replace it" >&2 exit 1 diff --git a/docs/configuration.md b/docs/configuration.md index f12aaf79b5a..044a70ac99b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2047,6 +2047,10 @@ A forced result replaces the model, confidence, and probability lines with `deci Everything after the rule choice is identical: the rule's `approval` and `floor`, each candidate's `provider` and `floor`, the same `quota-axi` snapshot, and the same `spendPriority` argmax. Without a rule declaring `path_force` this check is inert, whatever paths a brief declares. A brief with no `Target paths:` line, no matching path, or a home whose rules declare no `path_force` leaves the Jev request and its output unchanged, so only some briefs carry this fact and the rest route exactly as before. +After that classification, a declared target path in a sensitive class cannot resolve to a free OpenCode model. +[`bin/fm-free-model-sensitivity.sh`](../bin/fm-free-model-sensitivity.sh) owns the classes, the free-model mark, the token scrub, and the read block. +A routine path may still resolve to a free OpenCode model, and a paid OpenCode model or any other harness keeps its environment and its read access. + **What the model receives** When on and at least one rule exists, the tool sends the project name and the brief's task-specific text as state and asks one Choice question whose options are every rule's `when` plus the fixed neutral option for no matching rule; the model never sees quota, catalogs, `why`, `use`, approvals, or confidence floors. diff --git a/tests/fm-dispatch-resolve.test.sh b/tests/fm-dispatch-resolve.test.sh index abea57eb7db..afb0efbf277 100755 --- a/tests/fm-dispatch-resolve.test.sh +++ b/tests/fm-dispatch-resolve.test.sh @@ -1470,3 +1470,60 @@ printf 'selected\n' > "$HOME_DIR/config/codex-seat" TYPESAFE_API_KEY=$KEY run code out err "$BRIEF" --codex-alternative --json assert_equals "$TMP_ROOT/codex-seats/selected" "$(cat "$LOG/quota-axi.calls.codex-home")" "dispatch quota reads selected Codex home" pass "dispatch evidence uses the Codex home a new native worker will launch on" + +# A free OpenCode model outranks the paid candidate, then a sensitive target +# path removes it after classification. A routine path keeps the free model. +test_sensitive_target_denies_free_opencode() { + local sens routine profile + sens="$TMP_ROOT/sens-brief.md" + routine="$TMP_ROOT/routine-brief.md" + cat > "$RULES" <<'JSON' +{ + "rules": [ + { + "when": "Any coding task.", + "use": [ + {"harness": "opencode", "model": "opencode/glm-5.3-flash-free", "provider": "codex"}, + {"harness": "claude", "model": "sonnet", "effort": "high"} + ] + } + ], + "default": {"harness": "claude", "model": "opus"} +} +JSON + write_quota "$QUOTA" 0.1 -0.4 + jq '.providers |= map(if .provider == "codex" then .quotaSemantics.effectiveAvailability[0].selection.spendPriority = 0.95 else . end)' \ + "$QUOTA" > "$TMP_ROOT/quota-free.json" + cp "$TMP_ROOT/quota-free.json" "$QUOTA" + cat > "$RESPONSE" <<'JSON' +{ "model": "jev-1.13.0", + "answers": { "rule": { "type": "choice", "choice": "rule_1", "confidence": 0.91, + "probabilities": { "rule_1": 0.99, "default": 0.01 } } }, + "usage": { "input_tokens": 20, "output_tokens": 5 } } +JSON + cat > "$routine" <<'MD' +# Task +Fix the pager. +MD + printf '\nTarget paths: src/app.ts\n' >> "$routine" + cat > "$sens" <<'MD' +# Task +Fix the pager. +MD + printf '\nTarget paths: .env\n' >> "$sens" + reset_log + TYPESAFE_API_KEY=$KEY run code out err "$routine" --project pager + expect_code 0 "$code" "routine target resolution exits 0" + profile=$(printf '%s\n' "$out" | awk '/^ profile:/{print}') + assert_contains "$profile" "--model 'opencode/glm-5.3-flash-free'" "a routine path may resolve to a free OpenCode model" + reset_log + TYPESAFE_API_KEY=$KEY run code out err "$sens" --project pager + expect_code 0 "$code" "sensitive target resolution exits 0" + profile=$(printf '%s\n' "$out" | awk '/^ profile:/{print}') + assert_contains "$profile" "--harness 'claude'" "a sensitive path resolves to the paid candidate" + assert_contains "$profile" "--model 'sonnet'" "a sensitive path keeps the paid model" + assert_not_contains "$profile" "flash-free" "a sensitive path does not resolve to the free OpenCode model" + assert_contains "$out" "not eligible: sensitive target path denies a free OpenCode model" "the free candidate is denied after classification" + pass "a sensitive target path cannot resolve to a free OpenCode model" +} +test_sensitive_target_denies_free_opencode diff --git a/tests/fm-free-model-sensitivity.test.sh b/tests/fm-free-model-sensitivity.test.sh new file mode 100755 index 00000000000..1a2669df754 --- /dev/null +++ b/tests/fm-free-model-sensitivity.test.sh @@ -0,0 +1,327 @@ +#!/usr/bin/env bash +# Property and model checks for the free OpenCode sensitivity boundary. +# Cases are generated from a fixed seed. A failure prints that seed and the +# shrunk path. Dispatch is driven through fm-dispatch-resolve.sh, the launch +# scrub and read block through fm-free-model-sensitivity.sh. +set -u + +# shellcheck source=tests/lib.sh +. "$(dirname "${BASH_SOURCE[0]}")/lib.sh" + +SENS="$ROOT/bin/fm-free-model-sensitivity.sh" +RESOLVE="$ROOT/bin/fm-dispatch-resolve.sh" +TMP_ROOT=$(fm_test_tmproot fm-free-model-sensitivity) +SEED=20261106 +COUNT=4 + +rand() { + SEED=$(( (SEED * 1103515245 + 12345) & 2147483647 )) + echo $(( SEED % $1 )) +} + +shrink_path() { + local path=$1 kind=$2 current segment got + current=$path + while [ "$current" != "${current#*/}" ]; do + segment=${current#*/} + if [ "$kind" = routine ]; then + "$SENS" class "$segment" >/dev/null 2>&1 && break + else + got=$("$SENS" class "$segment" 2>/dev/null || true) + [ "$got" = "$kind" ] || break + fi + current=$segment + done + printf '%s' "$current" +} + +expect_class() { + local path=$1 kind=$2 got + if [ "$kind" = routine ]; then + if "$SENS" class "$path" >/dev/null 2>&1; then + fail "seed=$SEED routine path classified sensitive: $(shrink_path "$path" routine)" + fi + return + fi + got=$("$SENS" class "$path" 2>/dev/null || true) + if [ "$got" != "$kind" ]; then + fail "seed=$SEED expected $kind for $(shrink_path "$path" "$kind") (built as $path, got ${got:-routine})" + fi +} + +# One command of the path model: a constructed path must keep its class. +check_generated_path() { + local kind=$1 n prefix depth path + n=$(rand 1000) + depth=$(rand 3) + prefix='' + while [ "$depth" -gt 0 ]; do + prefix="pkg$(rand 50)/$prefix" + depth=$((depth - 1)) + done + case "$kind" in + ci) path="${prefix}app${n}/.github/workflows/build-${n}.yml" ;; + migration) path="${prefix}db${n}/migrations/${n}_init.sql" ;; + infra) path="${prefix}stack${n}/infra/main.tf" ;; + env) path="${prefix}app${n}/.env" ;; + doppler) path="${prefix}app${n}/doppler.yaml" ;; + auth) path="${prefix}app${n}/auth/session.ts" ;; + payments) path="${prefix}app${n}/payments/charge.ts" ;; + routine) path="${prefix}src/app-${n}.ts" ;; + *) fail "unknown class $kind" ;; + esac + expect_class "$path" "$kind" +} + +echo "free-model sensitivity seed=$SEED count=$COUNT" + +for _ in $(seq 1 "$COUNT"); do + check_generated_path ci + check_generated_path migration + check_generated_path infra + check_generated_path env + check_generated_path doppler + check_generated_path auth + check_generated_path payments + check_generated_path routine +done + +# Fixed shapes that define the boundary, including paths under bin/ and docs/ +# that stay routine. +expect_class '.gitlab-ci.yml' ci +expect_class 'azure-pipelines.yml' ci +expect_class 'src/workflows/job.ts' routine +expect_class 'db/001_migration.sql' migration +expect_class 'docs/migration-notes.md' routine +expect_class 'bin/deploy.sh' infra +expect_class 'bin/fm-spawn.sh' routine +expect_class 'vercel.json' infra +expect_class 'docs/configuration.md' routine +expect_class 'config/.env.local' env +expect_class 'src/env.ts' routine +expect_class 'service/.doppler/config.yaml' doppler +expect_class 'src/auth.ts' auth +expect_class 'src/author.ts' routine +expect_class 'src/billing.ts' payments +expect_class 'src/secrets/helper.ts' routine +pass "generated paths keep their sensitive class, and routine bin and docs paths stay eligible" + +# Token names are a pure rule: a generated mix of token and ordinary names. +token_cases=( + 'DOPPLER_TOKEN scrub' + 'DOPPLER_SERVICE_TOKEN scrub' + 'DOPPLER_PROJECT keep' + 'SUPABASE_SERVICE_ROLE_KEY scrub' + 'SUPABASE_ANON_KEY scrub' + 'SUPABASE_URL keep' + 'AWS_SECRET_ACCESS_KEY scrub' + 'AWS_ACCESS_KEY_ID scrub' + 'AWS_SESSION_TOKEN scrub' + 'AWS_REGION keep' + 'AWS_PROFILE keep' + 'GOOGLE_APPLICATION_CREDENTIALS scrub' + 'AZURE_CLIENT_SECRET scrub' + 'GH_TOKEN scrub' + 'GITHUB_TOKEN scrub' + 'GITHUB_PAT scrub' + 'GH_HOST keep' + 'GITHUB_ACTOR keep' + 'PATH keep' + 'HOME keep' +) +for item in "${token_cases[@]}"; do + name=${item%% *} + want=${item##* } + if [ "$want" = scrub ]; then + "$SENS" token-name "$name" || fail "seed=$SEED $name should be scrubbed" + else + if "$SENS" token-name "$name"; then + fail "seed=$SEED $name should stay in the environment" + fi + fi +done +pass "token names cover Doppler, Supabase, cloud, and GitHub-write, and ordinary names stay" + +# Model: the same ranked rule is offered a path command. A sensitive path never +# resolves to the free OpenCode model. A routine path does, because that model +# has the higher spend priority. +HOME_DIR="$TMP_ROOT/home" +FAKEBIN=$(fm_fakebin "$TMP_ROOT") +LOG="$TMP_ROOT/log" +mkdir -p "$HOME_DIR/config" "$LOG" +cat > "$FAKEBIN/curl" <<'SH' +#!/usr/bin/env bash +set -u +out='' +while [ $# -gt 0 ]; do + case "$1" in + -o) out=$2; shift 2 ;; + *) shift ;; + esac +done +cat >/dev/null +cat /dev/fd/3 >/dev/null 2>&1 || true +cp "${FAKE_CURL_RESPONSE:?}" "$out" +printf '200' +SH +chmod +x "$FAKEBIN/curl" +cat > "$FAKEBIN/quota-axi" <<'SH' +#!/usr/bin/env bash +set -u +[ "${1:-}" = --json ] || exit 2 +cat "${QUOTA_AXI_FIXTURE:?}" +SH +chmod +x "$FAKEBIN/quota-axi" +cat > "$HOME_DIR/config/crew-dispatch.json" <<'JSON' +{ + "rules": [ + { + "when": "Any coding task.", + "use": [ + {"harness": "opencode", "model": "opencode/glm-5.3-flash-free", "provider": "codex"}, + {"harness": "claude", "model": "sonnet", "effort": "high"} + ] + } + ], + "default": {"harness": "claude", "model": "opus"} +} +JSON +cat > "$TMP_ROOT/quota.json" <<'JSON' +{ + "generatedAt": "2030-01-01T00:00:00Z", + "schemaVersion": 5, + "providers": [ + { "provider": "claude", "state": { "status": "fresh" }, "quotaSemantics": { "status": "known", "effectiveAvailability": [ + { "scope": "all_models", "status": "known", "effectivePercentRemaining": 70, "runway": { "status": "projected_exhaustion" }, "selection": { "spendPriority": -0.4 } } ] } }, + { "provider": "codex", "state": { "status": "fresh" }, "quotaSemantics": { "status": "known", "effectiveAvailability": [ + { "scope": "all_models", "status": "known", "effectivePercentRemaining": 80, "runway": { "status": "through_reset" }, "selection": { "spendPriority": 0.95 } } ] } } + ] +} +JSON +cat > "$TMP_ROOT/response.json" <<'JSON' +{ "model": "jev-1.13.0", + "answers": { "rule": { "type": "choice", "choice": "rule_1", "confidence": 0.93, + "probabilities": { "rule_1": 0.99, "default": 0.01 } } }, + "usage": { "input_tokens": 12, "output_tokens": 3 } } +JSON +export FAKE_CURL_RESPONSE="$TMP_ROOT/response.json" QUOTA_AXI_FIXTURE="$TMP_ROOT/quota.json" +export TYPESAFE_API_KEY=test-key-sensitivity + +resolve_profile() { + local path=$1 out profile + cat > "$TMP_ROOT/brief.md" <"$TMP_ROOT/resolve.err") || fail "resolve failed for $path: $(cat "$TMP_ROOT/resolve.err")" + profile=$(printf '%s\n' "$out" | awk '/^ profile:/{print}') + printf '%s' "$profile" +} + +for _ in $(seq 1 "$COUNT"); do + for kind in ci migration infra env doppler auth payments; do + n=$(rand 1000) + case "$kind" in + ci) path="svc${n}/.github/workflows/ci.yml" ;; + migration) path="svc${n}/migrations/001.sql" ;; + infra) path="svc${n}/infra/main.tf" ;; + env) path="svc${n}/.env.local" ;; + doppler) path="svc${n}/doppler.yaml" ;; + auth) path="svc${n}/auth/session.ts" ;; + payments) path="svc${n}/payments/charge.ts" ;; + esac + profile=$(resolve_profile "$path") + case "$profile" in + *flash-free*) fail "seed=$SEED sensitive $kind path resolved to a free model: $path" ;; + *sonnet*) ;; + *) fail "seed=$SEED sensitive $kind path did not resolve to the paid model: $path profile=$profile" ;; + esac + done + path="src/app-$(rand 1000).ts" + profile=$(resolve_profile "$path") + case "$profile" in + *flash-free*) ;; + *) fail "seed=$SEED routine path lost the free model: $path profile=$profile" ;; + esac +done +pass "after classification a sensitive path never resolves to the free OpenCode model" + +# The read block and the scrub are one confined process. The same files are +# readable without that process, which is what every other launch keeps. +TREE="$TMP_ROOT/tree" +mkdir -p "$TREE/home/.secrets" "$TREE/home/.aws" "$TREE/home/.config/gh" \ + "$TREE/work/.github/workflows" "$TREE/work/migrations" "$TREE/work/infra" \ + "$TREE/work/auth" "$TREE/work/payments" "$TREE/work/src/secrets" \ + "$TREE/work/bin" "$TREE/work/docs" +printf 'SECRET\n' > "$TREE/home/.secrets/token" +printf 'AWS\n' > "$TREE/home/.aws/credentials" +printf 'GH\n' > "$TREE/home/.config/gh/hosts.yml" +printf 'ENV\n' > "$TREE/work/.env" +printf 'CI\n' > "$TREE/work/.github/workflows/ci.yml" +printf 'SQL\n' > "$TREE/work/migrations/001.sql" +printf 'TF\n' > "$TREE/work/infra/main.tf" +printf 'DOP\n' > "$TREE/work/doppler.yaml" +printf 'AUTH\n' > "$TREE/work/auth/session.ts" +printf 'PAY\n' > "$TREE/work/payments/charge.ts" +printf 'APP\n' > "$TREE/work/src/app.ts" +printf 'BIN\n' > "$TREE/work/bin/fm-spawn.sh" +printf 'DOC\n' > "$TREE/work/docs/configuration.md" +printf 'CODE\n' > "$TREE/work/src/secrets/helper.ts" +ln -s ../.env "$TREE/work/src/link.env" +unconfined=$(python3 -c 'print(open("'"$TREE/work/.env"'", encoding="utf-8").read().strip())') +[ "$unconfined" = ENV ] || fail "the unconfined process could not read .env, so a denial would prove nothing" +cat > "$TMP_ROOT/probe.py" <<'PY' +import os, sys +for path in sys.argv[1:]: + try: + open(path, "r", encoding="utf-8").read() + print("read\t" + path) + except OSError as exc: + print("deny\t" + path + "\t" + str(exc.errno)) +for name in ("DOPPLER_TOKEN", "SUPABASE_URL", "SUPABASE_SERVICE_ROLE_KEY", "AWS_SECRET_ACCESS_KEY", "AWS_REGION", "GH_TOKEN", "GITHUB_TOKEN", "PATH", "HOME"): + print("env\t" + name + "\t" + ("set" if os.environ.get(name) else "unset")) +PY +( + cd "$TREE/work" || exit 1 + export DOPPLER_TOKEN=d SUPABASE_URL=https://db.example SUPABASE_SERVICE_ROLE_KEY=s \ + AWS_SECRET_ACCESS_KEY=a AWS_REGION=us-east-1 GH_TOKEN=g GITHUB_TOKEN=gt + "$SENS" confine --home "$TREE/home" -- python3 "$TMP_ROOT/probe.py" \ + .env .github/workflows/ci.yml migrations/001.sql infra/main.tf doppler.yaml \ + auth/session.ts payments/charge.ts src/link.env \ + "$TREE/home/.secrets/token" "$TREE/home/.aws/credentials" "$TREE/home/.config/gh/hosts.yml" \ + src/app.ts bin/fm-spawn.sh docs/configuration.md src/secrets/helper.ts +) > "$TMP_ROOT/probe.out" || fail "confine probe failed" +while IFS=$'\t' read -r action path extra; do + case "$action" in + read) + case "$path" in + src/app.ts|bin/fm-spawn.sh|docs/configuration.md|src/secrets/helper.ts) ;; + *) fail "confined process read $path" ;; + esac + ;; + deny) + [ "$extra" = 13 ] || fail "confined denial of $path was errno $extra, not EACCES" + ;; + env) + case "$path:$extra" in + DOPPLER_TOKEN:unset|SUPABASE_SERVICE_ROLE_KEY:unset|AWS_SECRET_ACCESS_KEY:unset|GH_TOKEN:unset|GITHUB_TOKEN:unset) ;; + SUPABASE_URL:set|AWS_REGION:set|PATH:set|HOME:set) ;; + *) fail "confined environment $path is $extra" ;; + esac + ;; + esac +done < "$TMP_ROOT/probe.out" +pass "a free-model process cannot read secrets or sensitive paths, and other launches still can" + +# Paid OpenCode, Grok, Codex, and Claude are not free OpenCode models. +"$SENS" free-model --harness opencode --model opencode/glm-5.3-flash-free +"$SENS" free-model --harness opencode --model opencode/big-pickle && fail "big-pickle is not marked free" +"$SENS" free-model --harness opencode --model anthropic/claude-sonnet-4-5 && fail "a paid OpenCode model was treated as free" +"$SENS" free-model --harness grok --model grok-4-free && fail "a Grok model was treated as a free OpenCode model" +"$SENS" free-model --harness codex --model gpt-5 && fail "Codex was treated as a free OpenCode model" +"$SENS" free-model --harness claude --model claude-sonnet-4-5 && fail "Claude was treated as a free OpenCode model" +pass "only an OpenCode model id marked free is a free OpenCode model" + +echo "# all fm-free-model-sensitivity tests passed" diff --git a/tests/fm-spawn-dispatch-profile.test.sh b/tests/fm-spawn-dispatch-profile.test.sh index 4b41d20b0f8..ada9f64e5b1 100755 --- a/tests/fm-spawn-dispatch-profile.test.sh +++ b/tests/fm-spawn-dispatch-profile.test.sh @@ -2764,6 +2764,47 @@ test_keep_ai_trailers_reaches_secondmate_crew_launches test_claude_secondmate_launch_carries_the_attribution_policy test_active_dispatch_profile_does_not_block_secondmate_launch +test_free_opencode_launch_is_confined() { + local rec id status launch paid + id=profile-opencode-free-z8 + rec=$(make_spawn_case profile-opencode-free opencode "$id") + read_case_record "$rec" + printf '\nTarget paths: src/app.ts\n' >> "$HOME_DIR/data/$id/brief.md" + run_ship_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" --model opencode/glm-5.3-flash-free >/dev/null + status=$? + expect_code 0 "$status" "a routine free OpenCode launch should succeed" + launch=$(cat "$LAUNCH_LOG") + assert_contains "$launch" "fm-free-model-sensitivity.sh" "a free OpenCode launch is confined" + assert_contains "$launch" " confine " "a free OpenCode launch runs the confine command" + assert_contains "$launch" "opencode/glm-5.3-flash-free" "the confined launch still names the free model" + id=profile-opencode-paid-z8b + rec=$(make_spawn_case profile-opencode-paid opencode "$id") + read_case_record "$rec" + run_ship_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" --model anthropic/claude-sonnet-4-5 >/dev/null + status=$? + expect_code 0 "$status" "a paid OpenCode launch should succeed" + paid=$(cat "$LAUNCH_LOG") + assert_not_contains "$paid" "fm-free-model-sensitivity.sh" "a paid OpenCode launch keeps its environment" + pass "only a free OpenCode launch is confined" +} + +test_free_opencode_sensitive_target_refuses_launch() { + local rec id status out + id=profile-opencode-secret-z8c + rec=$(make_spawn_case profile-opencode-secret opencode "$id") + read_case_record "$rec" + printf '\nTarget paths: .github/workflows/ci.yml\n' >> "$HOME_DIR/data/$id/brief.md" + out=$(run_ship_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" --model opencode/glm-5.3-flash-free 2>&1) + status=$? + expect_code 1 "$status" "a sensitive target refuses a free OpenCode launch" + assert_contains "$out" "refusing to launch free OpenCode model" "the refusal names the free model" + [ ! -s "$LAUNCH_LOG" ] || fail "a refused free OpenCode launch must not start" + pass "a sensitive target path does not launch a free OpenCode model" +} + +test_free_opencode_launch_is_confined +test_free_opencode_sensitive_target_refuses_launch + echo "# all fm-spawn-dispatch-profile tests passed" From 99aab496769f77c50a570b678db7e544defa54e4 Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 16:33:40 -0500 Subject: [PATCH 2/8] no-mistakes(review): Confine /proc self-aliases, refuse Orca token forwarding, harden probe --- bin/fm-free-model-sensitivity.py | 45 +++++++++++++-------- bin/fm-spawn.sh | 9 +++++ tests/fm-free-model-sensitivity.test.sh | 53 +++++++++++++++---------- tests/fm-spawn-orca-worktree.test.sh | 50 +++++++++++++++++++++++ 4 files changed, 119 insertions(+), 38 deletions(-) diff --git a/bin/fm-free-model-sensitivity.py b/bin/fm-free-model-sensitivity.py index 588b10874b8..88857d905b6 100755 --- a/bin/fm-free-model-sensitivity.py +++ b/bin/fm-free-model-sensitivity.py @@ -204,8 +204,16 @@ def secrets_path(path: str, home: str) -> bool: return _under(os.path.normpath(candidate), os.path.join(home, ".secrets")) +PROC_PRIVATE = {"environ", "mem"} + + +def proc_private(path: str) -> bool: + parts = os.path.normpath(path).split("/") + return len(parts) > 3 and parts[1] == "proc" and parts[-1] in PROC_PRIVATE + + def path_blocked(path: str, home: str) -> bool: - return sensitive_class(path) is not None or secrets_path(path, home) + return sensitive_class(path) is not None or secrets_path(path, home) or proc_private(path) def is_free_opencode(harness: str | None, model: str | None) -> bool: @@ -266,9 +274,7 @@ def brief_sensitive(path: str) -> bool: return any(sensitive_class(item) is not None for item in target_paths(text)) -def apply_resolution(brief: str, payload: dict) -> dict: - if not brief_sensitive(brief): - return payload +def apply_resolution(payload: dict) -> bool: candidates = payload.get("candidates") or [] denied = False for candidate in candidates: @@ -279,11 +285,11 @@ def apply_resolution(brief: str, payload: dict) -> dict: candidate["reason"] = "sensitive target path denies a free OpenCode model" denied = True if not denied: - return payload + return False chosen = payload.get("chosen") or {} chosen_profile = chosen.get("profile") or {} if not is_free_opencode(chosen_profile.get("harness"), chosen_profile.get("model")): - return payload + return True eligible = [ item for item in candidates @@ -293,18 +299,18 @@ def apply_resolution(brief: str, payload: dict) -> dict: payload["status"] = "escalate" payload["reason"] = "sensitive target path denies a free OpenCode model and no other rankable candidate remains" payload.pop("chosen", None) - return payload + return True best = max(item.get("spendPriority") for item in eligible) tops = [item for item in eligible if item.get("spendPriority") == best] if len(tops) > 1: payload["status"] = "escalate" payload["reason"] = "genuine spendPriority tie" payload.pop("chosen", None) - return payload + return True payload["status"] = "clear" payload.pop("reason", None) payload["chosen"] = tops[0] - return payload + return True def arch_tables(): @@ -457,6 +463,17 @@ def resolve_path(pid: int, dirfd: int, path: str) -> tuple[str, str]: base = os.readlink(f"/proc/{pid}/fd/{dirfd}") lexical = os.path.join(base, path) lexical = os.path.normpath(lexical) + for alias, target in ( + ("/proc/self", f"/proc/{pid}"), + ("/proc/thread-self", f"/proc/{pid}"), + ("/dev/fd", f"/proc/{pid}/fd"), + ("/dev/stdin", f"/proc/{pid}/fd/0"), + ("/dev/stdout", f"/proc/{pid}/fd/1"), + ("/dev/stderr", f"/proc/{pid}/fd/2"), + ): + if lexical == alias or lexical.startswith(alias + "/"): + lexical = target + lexical[len(alias) :] + break try: resolved = os.path.realpath(lexical) except OSError: @@ -531,7 +548,7 @@ def supervise(notify_fd: int, child: int, home: str, names: dict[str, int], noti if flags & O_CREAT: mode = int(args[3 if nr != names.get("open") else 2]) & 0o7777 try: - st_mode = os.lstat(resolved).st_mode + st_mode = os.stat(lexical).st_mode special = not (stat.S_ISREG(st_mode) or stat.S_ISDIR(st_mode)) except FileNotFoundError: special = False @@ -697,17 +714,13 @@ def main(argv: list[str]) -> int: sys.stdout.buffer.write(raw) return 0 payload = json.loads(raw) - updated = apply_resolution(brief, payload) except (OSError, json.JSONDecodeError) as exc: print(f"free-model sensitivity: {exc}", file=sys.stderr) return 2 - if updated is payload and not any( - is_free_opencode((item.get("profile") or {}).get("harness"), (item.get("profile") or {}).get("model")) - for item in (payload.get("candidates") or []) - ): + if not apply_resolution(payload): sys.stdout.buffer.write(raw) return 0 - json.dump(updated, sys.stdout) + json.dump(payload, sys.stdout) sys.stdout.write("\n") return 0 if cmd == "confine": diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index aa2d6538a7a..7519ee3269b 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -7537,6 +7537,15 @@ if [ -n "$MODEL" ] && [ "$MODEL" != default ] && [ -n "$HARNESS" ]; then exit 1 ;; esac + if [ "$ORCA_LAUNCH_ENV_ENABLED" = 1 ]; then + while IFS= read -r fm_env_name; do + [ -n "$fm_env_name" ] || continue + if "$SCRIPT_DIR/fm-free-model-sensitivity.sh" token-name "$fm_env_name"; then + echo "error: refusing to launch free OpenCode model '$MODEL' because config/launch-env-allowlist forwards token $fm_env_name from the Orca source session" >&2 + exit 1 + fi + done <<<"$LAUNCH_ENV_NAMES" + fi LAUNCH="$(shell_quote "$SCRIPT_DIR/fm-free-model-sensitivity.sh") confine --home $(shell_quote "${HOME:-}") -- /bin/sh -c $(shell_quote "$LAUNCH")" ;; 1) ;; diff --git a/tests/fm-free-model-sensitivity.test.sh b/tests/fm-free-model-sensitivity.test.sh index 1a2669df754..f6cd01bd806 100755 --- a/tests/fm-free-model-sensitivity.test.sh +++ b/tests/fm-free-model-sensitivity.test.sh @@ -275,42 +275,51 @@ unconfined=$(python3 -c 'print(open("'"$TREE/work/.env"'", encoding="utf-8").rea cat > "$TMP_ROOT/probe.py" <<'PY' import os, sys for path in sys.argv[1:]: + target = path.replace("@ppid", str(os.getppid())) try: - open(path, "r", encoding="utf-8").read() + open(target, "r", encoding="utf-8", errors="replace").read() print("read\t" + path) except OSError as exc: print("deny\t" + path + "\t" + str(exc.errno)) for name in ("DOPPLER_TOKEN", "SUPABASE_URL", "SUPABASE_SERVICE_ROLE_KEY", "AWS_SECRET_ACCESS_KEY", "AWS_REGION", "GH_TOKEN", "GITHUB_TOKEN", "PATH", "HOME"): print("env\t" + name + "\t" + ("set" if os.environ.get(name) else "unset")) PY +# /proc/@ppid is the supervisor, whose kernel environment block still holds +# the tokens it unset. /dev/fd/3 is a routine file and /dev/fd/4 a pipe, both +# opened by the caller as process substitution would. +denied_paths=( + .env .github/workflows/ci.yml migrations/001.sql infra/main.tf doppler.yaml + auth/session.ts payments/charge.ts src/link.env + "$TREE/home/.secrets/token" "$TREE/home/.aws/credentials" "$TREE/home/.config/gh/hosts.yml" + /proc/self/environ /proc/thread-self/environ /proc/@ppid/environ /proc/self/mem +) +read_paths=(src/app.ts bin/fm-spawn.sh docs/configuration.md src/secrets/helper.ts /dev/fd/3 /dev/fd/4) ( cd "$TREE/work" || exit 1 export DOPPLER_TOKEN=d SUPABASE_URL=https://db.example SUPABASE_SERVICE_ROLE_KEY=s \ AWS_SECRET_ACCESS_KEY=a AWS_REGION=us-east-1 GH_TOKEN=g GITHUB_TOKEN=gt "$SENS" confine --home "$TREE/home" -- python3 "$TMP_ROOT/probe.py" \ - .env .github/workflows/ci.yml migrations/001.sql infra/main.tf doppler.yaml \ - auth/session.ts payments/charge.ts src/link.env \ - "$TREE/home/.secrets/token" "$TREE/home/.aws/credentials" "$TREE/home/.config/gh/hosts.yml" \ - src/app.ts bin/fm-spawn.sh docs/configuration.md src/secrets/helper.ts + "${denied_paths[@]}" "${read_paths[@]}" 3<"$TREE/work/src/app.ts" 4< <(printf 'PIPE\n') ) > "$TMP_ROOT/probe.out" || fail "confine probe failed" +probe_line() { + awk -F'\t' -v p="$1" '$1 != "env" && $2 == p' "$TMP_ROOT/probe.out" +} +for path in "${denied_paths[@]}"; do + got=$(probe_line "$path") + [ "$got" = "deny"$'\t'"$path"$'\t'13 ] || fail "confined process should get EACCES for $path, got: ${got:-nothing}" +done +for path in "${read_paths[@]}"; do + got=$(probe_line "$path") + [ "$got" = "read"$'\t'"$path" ] || fail "confined process should read routine $path, got: ${got:-nothing}" +done +[ "$(grep -vc '^env' "$TMP_ROOT/probe.out")" = $(( ${#denied_paths[@]} + ${#read_paths[@]} )) ] || + fail "confine probe reported unexpected paths: $(cat "$TMP_ROOT/probe.out")" while IFS=$'\t' read -r action path extra; do - case "$action" in - read) - case "$path" in - src/app.ts|bin/fm-spawn.sh|docs/configuration.md|src/secrets/helper.ts) ;; - *) fail "confined process read $path" ;; - esac - ;; - deny) - [ "$extra" = 13 ] || fail "confined denial of $path was errno $extra, not EACCES" - ;; - env) - case "$path:$extra" in - DOPPLER_TOKEN:unset|SUPABASE_SERVICE_ROLE_KEY:unset|AWS_SECRET_ACCESS_KEY:unset|GH_TOKEN:unset|GITHUB_TOKEN:unset) ;; - SUPABASE_URL:set|AWS_REGION:set|PATH:set|HOME:set) ;; - *) fail "confined environment $path is $extra" ;; - esac - ;; + [ "$action" = env ] || continue + case "$path:$extra" in + DOPPLER_TOKEN:unset|SUPABASE_SERVICE_ROLE_KEY:unset|AWS_SECRET_ACCESS_KEY:unset|GH_TOKEN:unset|GITHUB_TOKEN:unset) ;; + SUPABASE_URL:set|AWS_REGION:set|PATH:set|HOME:set) ;; + *) fail "confined environment $path is $extra" ;; esac done < "$TMP_ROOT/probe.out" pass "a free-model process cannot read secrets or sensitive paths, and other launches still can" diff --git a/tests/fm-spawn-orca-worktree.test.sh b/tests/fm-spawn-orca-worktree.test.sh index c9eb7c72a1a..ba12f64a5fe 100755 --- a/tests/fm-spawn-orca-worktree.test.sh +++ b/tests/fm-spawn-orca-worktree.test.sh @@ -922,6 +922,56 @@ PY pass "real tmux preserves absent/C locale values and reported raw bytes, rejects missing/phantom names and excludes the automatic SSH agent" } +# A free OpenCode worker runs after the confine scrub, but an Orca source +# snapshot puts allowlisted values into the launch text as literals that the +# scrub never sees. A free launch that would forward a token must not start. +test_orca_free_opencode_refuses_forwarded_token() { + local case_dir home id=orca-free-token fb out status + case_dir="$TMP_ROOT/$id" + home="$case_dir/home" + mkdir -p "$home/data/$id" "$home/state" "$home/config" "$home/projects" + touch "$home/state/.last-watcher-beat" + printf 'opencode\n' > "$home/config/crew-harness" + printf 'manual\n' > "$home/config/backlog-backend" + printf 'scoped-source\n' > "$home/config/launch-env-tmux-session" + printf 'GH_TOKEN\n' > "$home/config/launch-env-allowlist" + fm_git_init_commit "$case_dir/project" + cat > "$home/data/$id/brief.md" < "$fb/tmux" + chmod +x "$fb/tmux" + out=$(FM_ROOT_OVERRIDE='' FM_HOME="$home" HOME="$case_dir/user-home" \ + FM_STATE_OVERRIDE="$home/state" FM_DATA_OVERRIDE="$home/data" \ + FM_PROJECTS_OVERRIDE="$home/projects" FM_CONFIG_OVERRIDE="$home/config" \ + FM_SPAWN_NO_GUARD=1 FM_TEST_ORCA_DIR="$case_dir" \ + FM_TEST_ORCA_LOG="$case_dir/terminal.log" PATH="$fb:$PATH" \ + "$SPAWN" "$id" "$case_dir/project" --mode no-mistakes --yolo off --ticket no-ticket --commit-type chore \ + --backend orca --model opencode/glm-5.3-flash-free 2>&1) + status=$? + expect_code 1 "$status" "a free OpenCode launch forwarding a token must be refused: $out" + assert_contains "$out" "forwards token GH_TOKEN" "the refusal must name the forwarded token" + if [ -e "$case_dir/terminal.log" ] && grep -q -e 'synthetic-token' -e '/launch\.[^/]*\.sh' "$case_dir/terminal.log"; then + fail "a refused free OpenCode launch reached the Orca terminal: $(cat "$case_dir/terminal.log")" + fi + pass "a free OpenCode launch refuses an Orca source that forwards a token" +} + +test_orca_free_opencode_refuses_forwarded_token test_orca_source_preserves_values_without_utf8_locale test_orca_launch_uses_controlled_tmux_environment test_orca_allowlist_without_source_warns From cd23378f5bd5d67e554a9e330487ade8fbaf656d Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 17:20:15 -0500 Subject: [PATCH 3/8] no-mistakes(review): Scope path classes to worktree; widen free OpenCode detection --- bin/fm-free-model-sensitivity.py | 52 ++++++++++++++++--------- bin/fm-spawn.sh | 8 ++-- docs/configuration.md | 2 + tests/fm-free-model-sensitivity.test.sh | 23 ++++++++--- tests/fm-spawn-dispatch-profile.test.sh | 10 +++++ 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/bin/fm-free-model-sensitivity.py b/bin/fm-free-model-sensitivity.py index 88857d905b6..4c558775b13 100755 --- a/bin/fm-free-model-sensitivity.py +++ b/bin/fm-free-model-sensitivity.py @@ -10,7 +10,9 @@ A paid OpenCode model and every other harness keep their environment and their read access. A routine path may still resolve to a free model. -The read block is a seccomp user notifier in the parent. The child cannot +The read block is a seccomp user notifier in the parent. Path classes apply +inside the task worktree, the directory confine starts in, so toolchain +files elsewhere stay readable. Secrets files and token stores apply anywhere. The child cannot complete open, stat, or exec of a blocked path, including by a raw syscall. The parent opens an allowed file itself and installs that fd, so a symlink swap after the check cannot hand the child a secret inode. @@ -212,21 +214,26 @@ def proc_private(path: str) -> bool: return len(parts) > 3 and parts[1] == "proc" and parts[-1] in PROC_PRIVATE -def path_blocked(path: str, home: str) -> bool: - return sensitive_class(path) is not None or secrets_path(path, home) or proc_private(path) +def path_blocked(path: str, home: str, root: str) -> bool: + if _under(path, root) and sensitive_class(os.path.relpath(path, root)) is not None: + return True + return secrets_path(path, home) or proc_private(path) def is_free_opencode(harness: str | None, model: str | None) -> bool: - """A free OpenCode model is a configured opencode model whose id marks it free. + """A free OpenCode model is an opencode launch on a documented free model. - The catalog mark is a final segment that is `free` or ends in `-free`, - as in `opencode/glm-5.3-flash-free`. `big-pickle` and paid provider ids - do not. Another harness stays paid even when its id ends in `-free`. + That is an id whose final segment is `free` or ends in `-free` or `:free` + (OpenCode Zen and OpenRouter free ids, such as GLM and DeepSeek ones), + `big-pickle`, or no model at all, since opencode's own default may be + free. Another harness stays paid even when its id ends in `-free`. """ - if harness != "opencode" or not model: + if harness != "opencode": return False + if not model or model == "default": + return True leaf = model.split("/")[-1].lower() - return leaf == "free" or leaf.endswith("-free") + return leaf in ("free", "big-pickle") or leaf.endswith(("-free", ":free")) def token_name(name: str) -> bool: @@ -490,7 +497,18 @@ def ioctl(fd: int, request: int, buffer) -> int: return rc -def supervise(notify_fd: int, child: int, home: str, names: dict[str, int], notif_size: int) -> None: +def special_file(*paths: str) -> bool: + for path in paths: + try: + st_mode = os.stat(path).st_mode + except FileNotFoundError: + continue + if not (stat.S_ISREG(st_mode) or stat.S_ISDIR(st_mode)): + return True + return False + + +def supervise(notify_fd: int, child: int, home: str, root: str, names: dict[str, int], notif_size: int) -> None: recv_req = _ioc(3, 0, notif_size) send_req = _ioc(3, 1, 24) valid_req = _ioc(1, 2, 8) @@ -540,25 +558,20 @@ def supervise(notify_fd: int, child: int, home: str, names: dict[str, int], noti # parent cannot install an fd for it. Denying the call # keeps that path from skipping the inode check. error = errno.EPERM - elif path_blocked(lexical, home) or path_blocked(resolved, home): + elif path_blocked(lexical, home, root) or path_blocked(resolved, home, root): error = errno.EACCES elif nr in open_numbers: flags = int(as_i64(args[2])) if nr != names.get("open") else int(as_i64(args[1])) mode = 0o666 if flags & O_CREAT: mode = int(args[3 if nr != names.get("open") else 2]) & 0o7777 - try: - st_mode = os.stat(lexical).st_mode - special = not (stat.S_ISREG(st_mode) or stat.S_ISDIR(st_mode)) - except FileNotFoundError: - special = False - if special: + if special_file(resolved, lexical): continue_call = True else: fd = os.open(resolved, flags | O_CLOEXEC, mode) try: opened = os.path.realpath(f"/proc/self/fd/{fd}") - if path_blocked(opened, home): + if path_blocked(opened, home, root): error = errno.EACCES else: allow_fd = fd @@ -595,6 +608,7 @@ def supervise(notify_fd: int, child: int, home: str, names: dict[str, int], noti def confine(home: str, command: list[str]) -> int: + root = os.path.realpath(os.getcwd()) tables = arch_tables() if tables is None: print("free-model sensitivity: this architecture cannot confine a free OpenCode model", file=sys.stderr) @@ -632,7 +646,7 @@ def confine(home: str, command: list[str]) -> int: os.waitpid(pid, 0) return 2 try: - supervise(listener, pid, home, names, sizes.seccomp_notif or 80) + supervise(listener, pid, home, root, names, sizes.seccomp_notif or 80) finally: os.close(listener) _pid, status = os.waitpid(pid, 0) diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index 7519ee3269b..7879411ca83 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -7513,9 +7513,9 @@ if [ "$ORCA_LAUNCH_ENV_ENABLED" = 1 ]; then fi # Confine only a resolved free OpenCode model. Any other launch, including a # paid OpenCode model, keeps the command and environment built above. -if [ -n "$MODEL" ] && [ "$MODEL" != default ] && [ -n "$HARNESS" ]; then +if [ -n "$HARNESS" ]; then fm_free_rc=0 - "$SCRIPT_DIR/fm-free-model-sensitivity.sh" free-model --harness "$HARNESS" --model "$MODEL" || fm_free_rc=$? + "$SCRIPT_DIR/fm-free-model-sensitivity.sh" free-model --harness "$HARNESS" --model "${MODEL:-}" || fm_free_rc=$? case "$fm_free_rc" in 0) # Exit 0 means a declared target is sensitive. Start there so a @@ -7528,7 +7528,7 @@ if [ -n "$MODEL" ] && [ "$MODEL" != default ] && [ -n "$HARNESS" ]; then fi case "$fm_brief_rc" in 0) - echo "error: refusing to launch free OpenCode model '$MODEL' because a declared target path is sensitive" >&2 + echo "error: refusing to launch free OpenCode model '${MODEL:-default}' because a declared target path is sensitive" >&2 exit 1 ;; 1) ;; @@ -7541,7 +7541,7 @@ if [ -n "$MODEL" ] && [ "$MODEL" != default ] && [ -n "$HARNESS" ]; then while IFS= read -r fm_env_name; do [ -n "$fm_env_name" ] || continue if "$SCRIPT_DIR/fm-free-model-sensitivity.sh" token-name "$fm_env_name"; then - echo "error: refusing to launch free OpenCode model '$MODEL' because config/launch-env-allowlist forwards token $fm_env_name from the Orca source session" >&2 + echo "error: refusing to launch free OpenCode model '${MODEL:-default}' because config/launch-env-allowlist forwards token $fm_env_name from the Orca source session" >&2 exit 1 fi done <<<"$LAUNCH_ENV_NAMES" diff --git a/docs/configuration.md b/docs/configuration.md index 044a70ac99b..a92b8d5c6e9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2049,6 +2049,8 @@ Without a rule declaring `path_force` this check is inert, whatever paths a brie A brief with no `Target paths:` line, no matching path, or a home whose rules declare no `path_force` leaves the Jev request and its output unchanged, so only some briefs carry this fact and the rest route exactly as before. After that classification, a declared target path in a sensitive class cannot resolve to a free OpenCode model. [`bin/fm-free-model-sensitivity.sh`](../bin/fm-free-model-sensitivity.sh) owns the classes, the free-model mark, the token scrub, and the read block. +A free OpenCode model is a `-free` or `:free` id, `big-pickle`, or an OpenCode launch that names no model or `default`. +The read block applies path classes inside the task worktree only, so toolchain files elsewhere stay readable. A routine path may still resolve to a free OpenCode model, and a paid OpenCode model or any other harness keeps its environment and its read access. **What the model receives** diff --git a/tests/fm-free-model-sensitivity.test.sh b/tests/fm-free-model-sensitivity.test.sh index f6cd01bd806..c071286a8f4 100755 --- a/tests/fm-free-model-sensitivity.test.sh +++ b/tests/fm-free-model-sensitivity.test.sh @@ -254,7 +254,10 @@ TREE="$TMP_ROOT/tree" mkdir -p "$TREE/home/.secrets" "$TREE/home/.aws" "$TREE/home/.config/gh" \ "$TREE/work/.github/workflows" "$TREE/work/migrations" "$TREE/work/infra" \ "$TREE/work/auth" "$TREE/work/payments" "$TREE/work/src/secrets" \ - "$TREE/work/bin" "$TREE/work/docs" + "$TREE/work/bin" "$TREE/work/docs" \ + "$TREE/toolchain/site-packages/pip/_internal/network" "$TREE/toolchain/node_modules/pkg/migrations" +printf 'PIP\n' > "$TREE/toolchain/site-packages/pip/_internal/network/auth.py" +printf 'NODE\n' > "$TREE/toolchain/node_modules/pkg/migrations/001.js" printf 'SECRET\n' > "$TREE/home/.secrets/token" printf 'AWS\n' > "$TREE/home/.aws/credentials" printf 'GH\n' > "$TREE/home/.config/gh/hosts.yml" @@ -286,14 +289,18 @@ for name in ("DOPPLER_TOKEN", "SUPABASE_URL", "SUPABASE_SERVICE_ROLE_KEY", "AWS_ PY # /proc/@ppid is the supervisor, whose kernel environment block still holds # the tokens it unset. /dev/fd/3 is a routine file and /dev/fd/4 a pipe, both -# opened by the caller as process substitution would. +# opened by the caller as process substitution would. Path classes cover the +# worktree the confine starts in, so toolchain files outside it stay readable. denied_paths=( .env .github/workflows/ci.yml migrations/001.sql infra/main.tf doppler.yaml auth/session.ts payments/charge.ts src/link.env "$TREE/home/.secrets/token" "$TREE/home/.aws/credentials" "$TREE/home/.config/gh/hosts.yml" /proc/self/environ /proc/thread-self/environ /proc/@ppid/environ /proc/self/mem ) -read_paths=(src/app.ts bin/fm-spawn.sh docs/configuration.md src/secrets/helper.ts /dev/fd/3 /dev/fd/4) +read_paths=( + src/app.ts bin/fm-spawn.sh docs/configuration.md src/secrets/helper.ts /dev/fd/3 /dev/fd/4 + "$TREE/toolchain/site-packages/pip/_internal/network/auth.py" "$TREE/toolchain/node_modules/pkg/migrations/001.js" +) ( cd "$TREE/work" || exit 1 export DOPPLER_TOKEN=d SUPABASE_URL=https://db.example SUPABASE_SERVICE_ROLE_KEY=s \ @@ -324,13 +331,17 @@ while IFS=$'\t' read -r action path extra; do done < "$TMP_ROOT/probe.out" pass "a free-model process cannot read secrets or sensitive paths, and other launches still can" +# The captain's documented free list: OpenCode Zen and OpenRouter free ids, +# big-pickle, and an OpenCode launch that names no model or `default`. # Paid OpenCode, Grok, Codex, and Claude are not free OpenCode models. -"$SENS" free-model --harness opencode --model opencode/glm-5.3-flash-free -"$SENS" free-model --harness opencode --model opencode/big-pickle && fail "big-pickle is not marked free" +for model in opencode/glm-5.3-flash-free opencode/deepseek-v4-free opencode/big-pickle \ + openrouter/deepseek/deepseek-chat-v3:free openrouter/z-ai/glm-4.5-air:free '' default; do + "$SENS" free-model --harness opencode --model "$model" || fail "OpenCode model '${model}' should be free" +done "$SENS" free-model --harness opencode --model anthropic/claude-sonnet-4-5 && fail "a paid OpenCode model was treated as free" "$SENS" free-model --harness grok --model grok-4-free && fail "a Grok model was treated as a free OpenCode model" "$SENS" free-model --harness codex --model gpt-5 && fail "Codex was treated as a free OpenCode model" "$SENS" free-model --harness claude --model claude-sonnet-4-5 && fail "Claude was treated as a free OpenCode model" -pass "only an OpenCode model id marked free is a free OpenCode model" +pass "documented free OpenCode models and a model-less OpenCode launch are free, and paid ones are not" echo "# all fm-free-model-sensitivity tests passed" diff --git a/tests/fm-spawn-dispatch-profile.test.sh b/tests/fm-spawn-dispatch-profile.test.sh index ada9f64e5b1..08df41bf6a2 100755 --- a/tests/fm-spawn-dispatch-profile.test.sh +++ b/tests/fm-spawn-dispatch-profile.test.sh @@ -2799,6 +2799,16 @@ test_free_opencode_sensitive_target_refuses_launch() { expect_code 1 "$status" "a sensitive target refuses a free OpenCode launch" assert_contains "$out" "refusing to launch free OpenCode model" "the refusal names the free model" [ ! -s "$LAUNCH_LOG" ] || fail "a refused free OpenCode launch must not start" + id=profile-opencode-secret-z8d + rec=$(make_spawn_case profile-opencode-secret-nomodel opencode "$id") + read_case_record "$rec" + printf '\nTarget paths: migrations/001.sql\n' >> "$HOME_DIR/data/$id/brief.md" + : > "$LAUNCH_LOG" + out=$(run_ship_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" 2>&1) + status=$? + expect_code 1 "$status" "a sensitive target refuses an OpenCode launch that names no model" + assert_contains "$out" "refusing to launch free OpenCode model 'default'" "the refusal covers OpenCode's own default" + [ ! -s "$LAUNCH_LOG" ] || fail "a refused model-less OpenCode launch must not start" pass "a sensitive target path does not launch a free OpenCode model" } From 85d9a3bedae4e630e9f23927b1ef9c283378d57a Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 17:26:15 -0500 Subject: [PATCH 4/8] no-mistakes(review): Block env and Doppler files outside the task worktree --- bin/fm-free-model-sensitivity.py | 9 ++++++--- docs/configuration.md | 2 +- tests/fm-free-model-sensitivity.test.sh | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/fm-free-model-sensitivity.py b/bin/fm-free-model-sensitivity.py index 4c558775b13..14ffa017e37 100755 --- a/bin/fm-free-model-sensitivity.py +++ b/bin/fm-free-model-sensitivity.py @@ -10,9 +10,10 @@ A paid OpenCode model and every other harness keep their environment and their read access. A routine path may still resolve to a free model. -The read block is a seccomp user notifier in the parent. Path classes apply -inside the task worktree, the directory confine starts in, so toolchain -files elsewhere stay readable. Secrets files and token stores apply anywhere. The child cannot +The read block is a seccomp user notifier in the parent. Segment classes +apply inside the task worktree, the directory confine starts in, so toolchain +files elsewhere stay readable. Env and Doppler file names, secrets files, +and token stores apply anywhere. The child cannot complete open, stat, or exec of a blocked path, including by a raw syscall. The parent opens an allowed file itself and installs that fd, so a symlink swap after the check cannot hand the child a secret inode. @@ -215,6 +216,8 @@ def proc_private(path: str) -> bool: def path_blocked(path: str, home: str, root: str) -> bool: + if sensitive_class(os.path.basename(path)) in ("env", "doppler"): + return True if _under(path, root) and sensitive_class(os.path.relpath(path, root)) is not None: return True return secrets_path(path, home) or proc_private(path) diff --git a/docs/configuration.md b/docs/configuration.md index a92b8d5c6e9..27c256cd4e1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2050,7 +2050,7 @@ A brief with no `Target paths:` line, no matching path, or a home whose rules de After that classification, a declared target path in a sensitive class cannot resolve to a free OpenCode model. [`bin/fm-free-model-sensitivity.sh`](../bin/fm-free-model-sensitivity.sh) owns the classes, the free-model mark, the token scrub, and the read block. A free OpenCode model is a `-free` or `:free` id, `big-pickle`, or an OpenCode launch that names no model or `default`. -The read block applies path classes inside the task worktree only, so toolchain files elsewhere stay readable. +The read block applies directory and file classes such as auth, migrations, infra, payments, and CI inside the task worktree only, so toolchain files elsewhere stay readable; env and Doppler file names, secrets files, and token stores stay blocked everywhere, including the primary checkout. A routine path may still resolve to a free OpenCode model, and a paid OpenCode model or any other harness keeps its environment and its read access. **What the model receives** diff --git a/tests/fm-free-model-sensitivity.test.sh b/tests/fm-free-model-sensitivity.test.sh index c071286a8f4..01f8b2d4921 100755 --- a/tests/fm-free-model-sensitivity.test.sh +++ b/tests/fm-free-model-sensitivity.test.sh @@ -258,6 +258,10 @@ mkdir -p "$TREE/home/.secrets" "$TREE/home/.aws" "$TREE/home/.config/gh" \ "$TREE/toolchain/site-packages/pip/_internal/network" "$TREE/toolchain/node_modules/pkg/migrations" printf 'PIP\n' > "$TREE/toolchain/site-packages/pip/_internal/network/auth.py" printf 'NODE\n' > "$TREE/toolchain/node_modules/pkg/migrations/001.js" +mkdir -p "$TREE/primary" +printf 'PRIMARY\n' > "$TREE/primary/.env.local" +printf 'DOP\n' > "$TREE/primary/doppler.yaml" +ln -s "$TREE/primary/.env.local" "$TREE/work/src/notes.txt" printf 'SECRET\n' > "$TREE/home/.secrets/token" printf 'AWS\n' > "$TREE/home/.aws/credentials" printf 'GH\n' > "$TREE/home/.config/gh/hosts.yml" @@ -291,11 +295,13 @@ PY # the tokens it unset. /dev/fd/3 is a routine file and /dev/fd/4 a pipe, both # opened by the caller as process substitution would. Path classes cover the # worktree the confine starts in, so toolchain files outside it stay readable. +# Env and Doppler files in another checkout stay blocked, as do symlinks to them. denied_paths=( .env .github/workflows/ci.yml migrations/001.sql infra/main.tf doppler.yaml auth/session.ts payments/charge.ts src/link.env "$TREE/home/.secrets/token" "$TREE/home/.aws/credentials" "$TREE/home/.config/gh/hosts.yml" /proc/self/environ /proc/thread-self/environ /proc/@ppid/environ /proc/self/mem + "$TREE/primary/.env.local" "$TREE/primary/doppler.yaml" src/notes.txt ) read_paths=( src/app.ts bin/fm-spawn.sh docs/configuration.md src/secrets/helper.ts /dev/fd/3 /dev/fd/4 From e4ad3625f017343b6f72d1ce43701452976ae971 Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 17:38:17 -0500 Subject: [PATCH 5/8] no-mistakes(test): Keep confine supervisor alive on O_PATH opens and cancelled notifications --- bin/fm-free-model-sensitivity.py | 27 ++++++++++++++++++++----- tests/fm-free-model-sensitivity.test.sh | 27 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/bin/fm-free-model-sensitivity.py b/bin/fm-free-model-sensitivity.py index 14ffa017e37..5f4018f1859 100755 --- a/bin/fm-free-model-sensitivity.py +++ b/bin/fm-free-model-sensitivity.py @@ -26,6 +26,7 @@ import json import os import platform +import select import socket import stat import struct @@ -520,15 +521,25 @@ def supervise(notify_fd: int, child: int, home: str, root: str, names: dict[str, # is a struct pointer, so the parent cannot install a checked fd for it. open_numbers = {names[name] for name in ("openat", "open") if name in names} path_at = {names[name] for name in ("openat", "openat2", "statx", "newfstatat", "faccessat", "faccessat2", "readlinkat", "name_to_handle_at") if name in names} + poller = select.poll() + poller.register(notify_fd, select.POLLIN) while True: + # POLLHUP without POLLIN means every task under the filter has exited. + # RECV alone cannot tell that apart from one cancelled notification, + # which also returns ENOENT when its task is signalled or dies. + events = 0 + for _fd, revents in poller.poll(): + events |= revents + if not events & select.POLLIN: + if events & (select.POLLHUP | select.POLLERR | select.POLLNVAL): + break + continue buf = ctypes.create_string_buffer(notif_size) try: ioctl(notify_fd, recv_req, buf) except OSError as exc: if exc.errno in (errno.ENOENT, errno.EINTR): - if exc.errno == errno.EINTR: - continue - break + continue raise ident, pid, _flags = struct.unpack_from("QII", buf.raw, 0) nr = struct.unpack_from("I", buf.raw, 16)[0] @@ -568,7 +579,9 @@ def supervise(notify_fd: int, child: int, home: str, root: str, names: dict[str, mode = 0o666 if flags & O_CREAT: mode = int(args[3 if nr != names.get("open") else 2]) & 0o7777 - if special_file(resolved, lexical): + # An O_PATH fd reads no data, and ADDFD rejects one + # with EBADF, so the checked call runs in the child. + if flags & os.O_PATH or special_file(resolved, lexical): continue_call = True else: fd = os.open(resolved, flags | O_CLOEXEC, mode) @@ -596,9 +609,13 @@ def supervise(notify_fd: int, child: int, home: str, root: str, names: dict[str, addfd_req, struct.pack("QIIII", ident, SECCOMP_ADDFD_FLAG_SEND, allow_fd, 0, remote_flags), ) + continue + except OSError as exc: + # A failed install must not end supervision: answer the call + # with the error so the loop keeps serving the worker. + error = exc.errno or errno.EIO finally: os.close(allow_fd) - continue flags_out = SECCOMP_USER_NOTIF_FLAG_CONTINUE if continue_call else 0 # seccomp_notif_resp.error is 0 or a negative errno. A positive value # is rejected, and the target would otherwise observe a live fd. diff --git a/tests/fm-free-model-sensitivity.test.sh b/tests/fm-free-model-sensitivity.test.sh index 01f8b2d4921..a395d26fb17 100755 --- a/tests/fm-free-model-sensitivity.test.sh +++ b/tests/fm-free-model-sensitivity.test.sh @@ -337,6 +337,33 @@ while IFS=$'\t' read -r action path extra; do done < "$TMP_ROOT/probe.out" pass "a free-model process cannot read secrets or sensitive paths, and other launches still can" +# open(2) with O_PATH succeeds on any reachable file, and runtimes such as +# opencode's use it at startup. The supervisor must keep serving after one, so +# a later ordinary read still works, while a sensitive O_PATH open stays denied. +opath_out=$(cd "$TREE/work" && "$SENS" confine --home "$TREE/home" -- python3 -c ' +import os +os.close(os.open("src/app.ts", os.O_PATH)) +try: + os.open(".env", os.O_PATH) + print("env-open") +except OSError as exc: + print("env-deny", exc.errno) +print(open("src/app.ts").read().strip()) +' 2>&1) || fail "an O_PATH open broke the confined process: $opath_out" +[ "$opath_out" = "env-deny 13"$'\n'"APP" ] || fail "O_PATH under confine gave: $opath_out" +pass "an O_PATH open neither ends supervision nor reaches a sensitive path" + +# A pipeline whose reader exits early kills its writer with SIGPIPE, which can +# cancel a pending notification. Supervision must outlive that, so the next +# command in the same confined shell can still exec and read files. +for _ in $(seq 1 10); do + pipe_out=$(cd "$TREE/work" && "$SENS" confine --home "$TREE/home" -- sh -c \ + 'yes 2>/dev/null | head -n 1 >/dev/null; env | grep -i path | sort >/dev/null; cat src/app.ts' 2>&1) || + fail "a routine pipeline broke the confined shell: $pipe_out" + [ "$pipe_out" = APP ] || fail "a routine pipeline broke the confined shell: $pipe_out" +done +pass "routine pipelines keep the confined shell supervised" + # The captain's documented free list: OpenCode Zen and OpenRouter free ids, # big-pickle, and an OpenCode launch that names no model or `default`. # Paid OpenCode, Grok, Codex, and Claude are not free OpenCode models. From 71c8b7ffd704af73fefa4e78f29fb44cd4ab1bba Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 18:11:11 -0500 Subject: [PATCH 6/8] no-mistakes(test): Run confined free OpenCode workers on a private standalone server --- bin/fm-spawn.sh | 8 ++++++++ tests/fm-spawn-dispatch-profile.test.sh | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index 7879411ca83..1058d61eeb0 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -7546,6 +7546,14 @@ if [ -n "$HARNESS" ]; then fi done <<<"$LAUNCH_ENV_NAMES" fi + # opencode otherwise runs the worker's tools in the shared background + # service, outside this confine. A private server keeps them inside it. + fm_confined_launch=${LAUNCH/ opencode / opencode --standalone } + if [ "$fm_confined_launch" = "$LAUNCH" ]; then + echo "error: cannot pin free OpenCode model '${MODEL:-default}' to a private server; refusing launch" >&2 + exit 1 + fi + LAUNCH=$fm_confined_launch LAUNCH="$(shell_quote "$SCRIPT_DIR/fm-free-model-sensitivity.sh") confine --home $(shell_quote "${HOME:-}") -- /bin/sh -c $(shell_quote "$LAUNCH")" ;; 1) ;; diff --git a/tests/fm-spawn-dispatch-profile.test.sh b/tests/fm-spawn-dispatch-profile.test.sh index 08df41bf6a2..69ef3e6cdf0 100755 --- a/tests/fm-spawn-dispatch-profile.test.sh +++ b/tests/fm-spawn-dispatch-profile.test.sh @@ -2777,6 +2777,9 @@ test_free_opencode_launch_is_confined() { assert_contains "$launch" "fm-free-model-sensitivity.sh" "a free OpenCode launch is confined" assert_contains "$launch" " confine " "a free OpenCode launch runs the confine command" assert_contains "$launch" "opencode/glm-5.3-flash-free" "the confined launch still names the free model" + # opencode --help: without --standalone the client hands tool execution to + # the shared background service, which runs outside the confine. + assert_contains "$launch" " opencode --standalone " "a free OpenCode launch runs its tools in a private server inside the confine" id=profile-opencode-paid-z8b rec=$(make_spawn_case profile-opencode-paid opencode "$id") read_case_record "$rec" @@ -2785,6 +2788,7 @@ test_free_opencode_launch_is_confined() { expect_code 0 "$status" "a paid OpenCode launch should succeed" paid=$(cat "$LAUNCH_LOG") assert_not_contains "$paid" "fm-free-model-sensitivity.sh" "a paid OpenCode launch keeps its environment" + assert_not_contains "$paid" "--standalone" "a paid OpenCode launch keeps the shared service" pass "only a free OpenCode launch is confined" } From bd8a0967a477a14d448da0d03829184249d816b9 Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 18:20:12 -0500 Subject: [PATCH 7/8] no-mistakes(test): Restore default SIGPIPE/SIGXFSZ in confined free-model workers --- bin/fm-free-model-sensitivity.py | 5 +++++ tests/fm-free-model-sensitivity.test.sh | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/bin/fm-free-model-sensitivity.py b/bin/fm-free-model-sensitivity.py index 5f4018f1859..77dc8592b07 100755 --- a/bin/fm-free-model-sensitivity.py +++ b/bin/fm-free-model-sensitivity.py @@ -27,6 +27,7 @@ import os import platform import select +import signal import socket import stat import struct @@ -642,6 +643,10 @@ def confine(home: str, command: list[str]) -> int: if pid == 0: try: parent.close() + # Python ignores SIGPIPE and SIGXFSZ, and exec keeps ignored + # signals ignored; restore the defaults so pipelines terminate. + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + signal.signal(signal.SIGXFSZ, signal.SIG_DFL) listener = install_filter(build_filter(audit, set(names.values()), set(deny_names.values())), sys_seccomp, sys_prctl) send_fd(child, listener) os.close(listener) diff --git a/tests/fm-free-model-sensitivity.test.sh b/tests/fm-free-model-sensitivity.test.sh index a395d26fb17..9514763aa21 100755 --- a/tests/fm-free-model-sensitivity.test.sh +++ b/tests/fm-free-model-sensitivity.test.sh @@ -364,6 +364,16 @@ for _ in $(seq 1 10); do done pass "routine pipelines keep the confined shell supervised" +# POSIX: a writer to a pipe with no reader gets SIGPIPE and dies, so an +# endless producer feeding `head -1` ends as soon as head exits. If the +# confine left SIGPIPE ignored, the producer would loop forever on EPIPE. +sigpipe_rc=0 +sigpipe_out=$(cd "$TREE/work" && timeout 10 "$SENS" confine --home "$TREE/home" -- sh -c \ + 'while :; do echo x; done | head -1' 2>/dev/null) || sigpipe_rc=$? +[ "$sigpipe_rc" -eq 0 ] && [ "$sigpipe_out" = x ] || + fail "an endless producer piped to head did not end under confine (rc=$sigpipe_rc)" +pass "pipelines end on SIGPIPE under the confine as they do outside it" + # The captain's documented free list: OpenCode Zen and OpenRouter free ids, # big-pickle, and an OpenCode launch that names no model or `default`. # Paid OpenCode, Grok, Codex, and Claude are not free OpenCode models. From ae3f249bdd2fbfd75b635c93b411cc0bee59abb2 Mon Sep 17 00:00:00 2001 From: max-metaplanet Date: Fri, 6 Nov 2026 18:31:44 -0500 Subject: [PATCH 8/8] no-mistakes(document): Document free OpenCode ids, Linux-only confine, and Orca refusal --- docs/configuration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 27c256cd4e1..4cc1d5f19dd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2049,9 +2049,10 @@ Without a rule declaring `path_force` this check is inert, whatever paths a brie A brief with no `Target paths:` line, no matching path, or a home whose rules declare no `path_force` leaves the Jev request and its output unchanged, so only some briefs carry this fact and the rest route exactly as before. After that classification, a declared target path in a sensitive class cannot resolve to a free OpenCode model. [`bin/fm-free-model-sensitivity.sh`](../bin/fm-free-model-sensitivity.sh) owns the classes, the free-model mark, the token scrub, and the read block. -A free OpenCode model is a `-free` or `:free` id, `big-pickle`, or an OpenCode launch that names no model or `default`. +A free OpenCode model is an id whose last segment is `free`, `big-pickle`, or ends in `-free` or `:free`, or an OpenCode launch that names no model or `default`. The read block applies directory and file classes such as auth, migrations, infra, payments, and CI inside the task worktree only, so toolchain files elsewhere stay readable; env and Doppler file names, secrets files, and token stores stay blocked everywhere, including the primary checkout. A routine path may still resolve to a free OpenCode model, and a paid OpenCode model or any other harness keeps its environment and its read access. +The read block is a Linux seccomp notifier on x86_64 or aarch64, so a free OpenCode launch fails on any other host, and a launch refuses when the [Orca environment source](#orca-environment-source-configlaunch-env-tmux-session) would forward one of the scrubbed token names. **What the model receives**