Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/capability-parity-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ given instead of line numbers so the references stay valid.
| PA-11 | Each stage writes only to the cycle's own change request and work item, and only the artefacts its role owns (implement opens the PR, review posts the review) | `_check_gh` scope checks and `GH_TABLE` roles in `stage_permissions` | Every artefact can be attributed to one stage attempt and receipt | #142 | role contract | — |
| PA-12 | The required controls of an execution plan and the frozen checks of a cycle cannot be removed or demoted by an agent | `scripts/execution_plan.py`, `scripts/verification_plan.py` | Controls chosen by the user or the plan, not by the agent under review | #327, #328, #393 | role contract | — |
| PA-45 | A resume with stored plan revisions but no recoverable frozen checks and results stops with a diagnostic; first starts without matching history create a fresh plan. Verification-only dispatches retain the frozen executor/profile and cannot implement, commit or publish | `scripts/cycle_plan.py`, `scripts/cycle.py`, `scripts/cycle_history.py` | Preserves the user's existing check obligations and attribution; does not restrict direct agent operations | #491 | role contract | — |
| PA-46 | When the native isolation probe cannot create or bind its localhost listener, it reports `not_verified` with the operating-system cause and lets the stage record it instead of crashing | `scripts/native_prerequisites.py` `isolation_probe`; `scripts/executors.py` `native_sandbox_preflight` evidence | The probe cannot establish isolation when the operating system denies socket creation | #508: no-network Codex sandbox denied `AF_INET` socket creation | real limit | #508 |
| PA-13 | A check without executed evidence is never reported as passed; `verification_unverified` stops once with a question the user can answer with `--verification-answer KEY=accept` | `scripts/verification_plan.py`, `scripts/run_cycle.py` | Evidence integrity | #414, #425 | role contract | — |
| PA-14 | A consent answer holds in every stage role (#500): a decision is the operation or pattern, not the role that was asked. The one boundary kept is that a global (`forever`) grant never covers `review` or `rereview`. A resume grant is resolved into the selected dispatch policy before the agent starts, and an inapplicable grant is reported with its reason | `scripts/grants.py` (`command_entries`, `load(allow_global=…)`), `stage_permissions.same_operation`, `cycle._permission_context` | Reviewers judge untrusted changes and never receive a global grant; the first resumed dispatch must receive its authorized operation | #406, #483, #500 | role contract | — |
| PA-15 | Implementation runs in a task-specific linked worktree unless the run says `workspace=current` | `cc-implement-issue` *Implementation workspace*; `scripts/cycle_workspace.py` | Concurrent cycles never share a checkout | Worktree policy design; no single incident | role contract | — |
Expand Down Expand Up @@ -101,6 +102,7 @@ Why each real limit and role contract stays.
| PA-12 | These are user-defined boundaries. The agent whose work is being checked cannot loosen its own checks. |
| PA-13 | Calling an unexecuted check a pass would be a false claim. The user can accept an unverified check explicitly, so this rule never vetoes the user. |
| PA-45 | Recovery never replaces a frozen check with a new identity or loses executed evidence. With no stored plan for the work item and change request, a fresh review or resolution remains available. The verification-only role executes the selected checks without changing the work being judged. Missing evidence from stored revisions is named rather than invented; the user's underlying agent capabilities stay unchanged. |
| PA-46 | The operating system or sandbox can deny local socket creation. The probe records that cause as unavailable and unverified; a failed isolation probe never becomes a pass, and the stage does not fail with an uncaught exception. |
| PA-14 | The user approves the operation or pattern once and it holds in every stage role (#500); the question says so. A global grant still never reaches `review` or `rereview`. |
| PA-15 | A shared checkout let one cycle's dirty tree reach another. `workspace=current` is the user's per-run choice. |
| PA-16 | A review of uncommitted edits would not describe the head the change request publishes. |
Expand Down
6 changes: 5 additions & 1 deletion docs/dependency-preparation.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ make a concrete check fail or become unverified.
Presence alone does not prove isolation. Claude stages needing confined Bash
verification run a fixed host-owned probe of allowed writes, denied reads and
writes, and denied local network access. Preparation separately probes `srt`.
These probes run no repository code. If the required Bash boundary cannot
These probes run no repository code. If the environment denies creation or
binding of the probe's localhost listener, the probe records the operating
system error as unavailable isolation (`not_verified`); the stage continues
with that evidence instead of raising a dispatch traceback. This does not
establish that isolation passed. If the required Bash boundary cannot
start, the command hook removes verification and arbitrary-code grants; the
stage continues source work with checks recorded as `not_verified`. Reviews
retain the disposable clone and publication guards and cover static findings
Expand Down
12 changes: 11 additions & 1 deletion scripts/native_prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,19 @@ def isolation_probe(kind: str, *, runner, path: str | None = None) -> tuple[bool
target.write_text("synthetic credential probe")
credential_files.append(target)
credential_denials = list(sp.credential_read_denials(home=home))
with socket.socket() as listener:
listener = None
try:
listener = socket.socket()
listener.bind(("127.0.0.1", 0))
listener.listen()
except OSError as error:
if listener is not None:
try:
listener.close()
except OSError:
pass
return False, f"{kind} isolation probe unavailable: {error}"
with listener:
script = (
"import pathlib,socket,sys\n"
f"pathlib.Path({str(allowed / 'ok')!r}).write_text('ok')\n"
Expand Down
11 changes: 9 additions & 2 deletions tests/test_ci_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io
import json
import re
import subprocess
import sys
import tempfile
import unittest
Expand Down Expand Up @@ -492,17 +493,23 @@ def test_the_new_head_is_synchronized_and_recorded_before_rereview(self) -> None
self.github.set_checks(HEAD, PENDING)
self.github.set_checks(OTHER, PASSED)

worktree = git_repo(self)
origin = worktree.parent / "origin.git"
subprocess.run(["git", "init", "--bare", str(origin)], check=True,
capture_output=True, text=True)
git(worktree, "remote", "add", "origin", str(origin))

def push(now):
self.github.head = OTHER

self.clock.on_sleep = push
with mock.patch.object(rc, "probe_change_request",
return_value=mock.Mock(head_sha=OTHER)), mock.patch.object(
rc, "synchronize_worktree", return_value=(HEAD, OTHER)) as sync:
report = self.parallel(cwd=str(ROOT))
report = self.parallel(cwd=str(worktree))

self.assertTrue(sync.called, report.explain())
sync.assert_called_once_with("4", str(ROOT), target_head=OTHER)
sync.assert_called_once_with("4", str(worktree), target_head=OTHER)
self.assertTrue(any(HEAD in line and OTHER in line for _, line in report.notes))
sync_events = cj.events(self.store.path, "owner/api", task_id="API-7",
kinds=("stage_result",))
Expand Down
41 changes: 37 additions & 4 deletions tests/test_native_prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
from pathlib import Path
import subprocess
import shutil
import socket
import sys
import tarfile
import tempfile
import unittest
from unittest.mock import Mock, patch
from unittest.mock import MagicMock, Mock, patch

sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts"))
import native_prerequisites as native
Expand Down Expand Up @@ -211,6 +212,25 @@ def test_nonlinux_does_not_install_or_infer_failure_from_platform(self):


class PreflightTests(unittest.TestCase):
def require_local_listener(self):
listener = None
try:
listener = socket.socket()
listener.bind(("127.0.0.1", 0))
listener.listen()
except OSError as error:
self.skipTest(f"local sockets denied: {error}")
finally:
if listener is not None:
listener.close()

def test_local_listener_failure_skips_with_os_cause(self):
with patch.object(socket, "socket", side_effect=PermissionError("Operation not permitted")):
with self.assertRaises(unittest.SkipTest) as skipped:
self.require_local_listener()

self.assertEqual("local sockets denied: Operation not permitted", str(skipped.exception))

def test_host_tools_preserve_path_order(self):
original = os.pathsep.join(("/venv/bin", "/local/bin", "/system/bin"))
for outcome in ("reused", "available"):
Expand All @@ -221,6 +241,14 @@ def test_host_tools_preserve_path_order(self):
with patch.object(native.shutil, "which", side_effect=lambda tool, **kw: f"/system/bin/{tool}"):
self.assertEqual(original, native.tool_path(original))

def test_socket_creation_failure_is_reported_as_unverified(self):
with patch("socket.socket", side_effect=PermissionError("Operation not permitted")):
ok, evidence = native.isolation_probe("srt", runner=Mock())

self.assertFalse(ok)
self.assertIn("unavailable", evidence)
self.assertIn("Operation not permitted", evidence)

@unittest.skipIf(os.name == "nt", "the fake executables are POSIX")
def test_host_rg_does_not_switch_verification_python_at_process_boundary(self):
with tempfile.TemporaryDirectory() as temporary:
Expand Down Expand Up @@ -280,6 +308,7 @@ def test_recovered_rg_precedes_system_srt_directory_with_broken_rg(self):

@unittest.skipIf(os.name == "nt", "the fake sandbox executable is POSIX")
def test_srt_probe_gets_managed_rg_at_the_process_boundary(self):
self.require_local_listener()
with tempfile.TemporaryDirectory() as temporary:
home = Path(temporary)
tools = home / ".local/lib/code-cycle-tools"
Expand All @@ -304,6 +333,7 @@ def test_srt_probe_gets_managed_rg_at_the_process_boundary(self):

@unittest.skipIf(os.name == "nt", "the fake executables are POSIX")
def test_selected_system_rg_is_not_shadowed_by_stale_managed_rg(self):
self.require_local_listener()
with tempfile.TemporaryDirectory() as temporary:
home = Path(temporary)
tools = home / ".local/lib/code-cycle-tools"
Expand Down Expand Up @@ -367,20 +397,23 @@ def test_probe_failure_and_timeout_are_not_verified(self):
with patch.object(native.shutil, "which", return_value="/tools/bwrap"):
for runner in (Mock(return_value=subprocess.CompletedProcess([], 1, "", "namespace denied")),
Mock(side_effect=subprocess.TimeoutExpired("probe", 30))):
ok, evidence = native.isolation_probe("bwrap", runner=runner)
with patch.object(socket, "socket", return_value=MagicMock()):
ok, evidence = native.isolation_probe("bwrap", runner=runner)
self.assertFalse(ok)
self.assertIn("probe", evidence)
argv = runner.call_args.args[0]
self.assertIn("--unshare-net", argv)

def test_lying_probe_success_is_not_verified(self):
with patch.object(native.shutil, "which", return_value="/tools/bwrap"):
ok, _ = native.isolation_probe("bwrap", runner=Mock(
return_value=subprocess.CompletedProcess([], 0, "", "")))
with patch.object(socket, "socket", return_value=MagicMock()):
ok, _ = native.isolation_probe("bwrap", runner=Mock(
return_value=subprocess.CompletedProcess([], 0, "", "")))
self.assertFalse(ok)

@unittest.skipIf(os.name == "nt", "the fake sandbox executable is POSIX")
def test_nonzero_real_process_boundary(self):
self.require_local_listener()
with tempfile.TemporaryDirectory() as scratch:
binary = Path(scratch) / "bwrap"
binary.write_text("#!/bin/sh\necho 'bwrap: Creating new namespace failed' >&2\nexit 1\n")
Expand Down
Loading