Skip to content

fix(worktree): isolate sandbox tests and Git metadata - #196

Merged
datacas merged 3 commits into
mainfrom
task-177
Oct 7, 2026
Merged

datacas merged 3 commits into
mainfrom
task-177

Conversation

@datacas

@datacas datacas commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Issue: #177

Implementation route: profile cheap_coder; requested model openai/gpt-6-luna; effort high; resolved model ?.

Diagnosis

The sandbox failures came from two causes. The original temporary-repository hypothesis was disproved: the tests already create temporary repositories. With HERDR_ENV=1, workspace-selection tests inherited the host flag and invoked Herdr; a failing stub reproduced the resulting block. Separately, a writing Codex dispatch from a linked worktree had write access only to that worktree, while Git stores its common metadata under the main repository's .git directory. The invariant is that tests behave independently of the invoking agent host, and a writing stage can update the Git metadata required by its linked worktree. The corrected cause is within this issue's scope.

Related work checked: #176 is closed and confirms the unrelated validator failures are resolved. #182 tracks writable temporary directories for read-only review stages; that remains out of scope here. The widened search found no other related work addressed by this change.

Work units

Unit Behaviour Files Tests Verification Rollback
WU-1 Keep worktree and executor tests independent of inherited host settings, and give writing Codex dispatches the linked worktree's Git common directory. scripts/run_cycle.py, scripts/executors.py, tests/test_support.py, tests/test_run_cycle.py, tests/test_executors.py, tests/test_installed_cycle.py, docs/verification.md Host-environment regression, Codex write/read argv coverage, and installed-cycle tests. Package validator and full suite under both Herdr environment conditions below; no tests were skipped. Independent: reverting this commit restores the previous test and dispatch behavior.

Verification

Agent-reported:

  • rtk python3 scripts/validate-package.py — passed.
  • HERDR_ENV=1 PATH="/tmp/cc-herdr-stub:$PATH" rtk python3 -m unittest discover -s tests -q — 1,132 tests passed; the herdr stub exits 42 if invoked.
  • env -u HERDR_ENV PATH="/tmp/cc-no-herdr-bin:$clean_path" /home/datacas/.local/bin/rtk python3 -m unittest discover -s tests -q — 1,132 tests passed; Herdr was verified absent from PATH.
  • HERDR_ENV=1 PATH="/tmp/cc-herdr-stub:$PATH" rtk python3 -m unittest tests.test_run_cycle.WorkspaceSelectionTests.test_herdr_environment_in_the_invoking_shell_is_neutralized — passed at the subprocess boundary.

@datacas

datacas commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261007-001] · reviewer · anthropic/claude-sonnet-5-5→? · high · schema:1

Initial review — PR #196 (work item #177): APPROVED

Reviewed head 370367eda574ed147009280ab608c1722363a196 against merge base 04e73935278fcb306281d7d22a10c5f9e7d2fc40 (314-line accumulated diff, SHA-256 f31805e0…4586bee, read in full). Conventions applied: AGENTS.md routing (Serena/Context7 optional), .code-cycle.yml.

Summary

The change does two things. Test modules that exercise worktree selection and executor dispatch now clear host variables (HERDR_*, CODEX_*, CLAUDE_*, ORCA_*, CODE_CYCLE_HOME, XDG_CONFIG_HOME, APPDATA) through tests/test_support.py. Writing Codex dispatches from a linked worktree now get --add-dir <git-common-dir>. Scope matches the work item. No blocking defect found.

Checked by reading the code and by running it:

  • dispatch() (scripts/executors.py:1882) pops writable_dirs and forwards it only for codex + writes=True. ClaudeAdapter.dispatch and OrcaAdapter.dispatch don't accept the keyword, but adapter = registry.get(target.executor), so they never receive it.
  • _git_common_directory returns None for the main checkout and for synthetic marker-file worktrees, and resolves relative output against the workspace.
  • codex exec --help on this host lists --add-dir <DIR>.

Findings

[REV-001] · low · open · - · blocks:no — Granting the whole Git common directory widens the Codex write sandbox

Path: scripts/run_cycle.py:1530, scripts/executors.py:989.
--add-dir <common-dir> makes hooks/, config, and every branch's refs writable by a writing Codex stage, not only the worktree's own metadata. A stage could plant a hook that the coordinator's unsandboxed Git later runs, or move another branch's ref. This is the trade-off the work item accepts, and the stage can already write code that the tests run. It is a potential risk, not a demonstrated exploit. Suggestion: record the trade-off in docs/verification.md, or narrow the grant to the worktree's worktrees/<name> metadata plus objects/refs if Codex allows it.

[REV-002] · low · open · - · blocks:no — The dispatch-level wiring has no test

Path: tests/test_executors.py:536, tests/test_run_cycle.py:1599.
Tests cover CodexAdapter.argv and _git_common_directory. Nothing covers run_cycle putting writable_dirs into dispatch_kwargs, or dispatch() withholding it from non-Codex targets and read-only stages. If a refactor leaked the keyword to ClaudeAdapter.dispatch, it would fail with a TypeError that no test would catch.

Security triage

The deterministic rule (security_review.always_when) is not configured in .code-cycle.yml. Defaults applied; no path, filename, or label matched (no labels). Reviewer judgement added: the diff changes a sandbox write boundary (executor dispatch permissions) and environment handling, so cc-security-review criteria were applied inline to the change. Result: no confirmed vulnerability; one potential risk, REV-001. No secrets, input parsing, auth, or dependency changes.

Execution evidence (observed)

  • python3 scripts/validate-package.py — exit 0: VALID: 15 skills (7 cycle, 8 supporting), shared sections in sync, cross-agent manifests aligned.
  • HERDR_ENV=1 python3 -m unittest discover -s tests -q — Ran 1132 tests … OK (no tests skipped by the runner's summary).
  • HERDR_ENV=1 PATH=<stub herdr exiting 42>:$PATH python3 -m unittest tests.test_run_cycle.WorkspaceSelectionTests.test_herdr_environment_in_the_invoking_shell_is_neutralized — OK.

Not verified: a real Codex run confirming that the extra root lets a linked-worktree commit succeed (needs Codex credentials and network); the HERDR_ENV unset run (author-reported only); the Windows APPDATA path.

CI (gh pr checks 196)

Skills, manifests, and Bash installer: pass (×2 runs). PowerShell installer: pass (×2 runs). The workflows are validate.yml and release.yml; no required check is missing, pending, or skipped.

Residual risks

REV-001 (sandbox widening); REV-002 (untested wiring); the end-to-end Codex behaviour above.

Verdict

APPROVED — head 370367eda574ed147009280ab608c1722363a196 fully reviewed, all checks pass, no open finding blocks approval.

@datacas

datacas commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner Author

[CCR-20261007-001] · reviewer · anthropic/claude-sonnet-5-5→? · high · schema:1

[CCT-20261007-001] · cheap_coder · openai/gpt-6-luna→? · high · triaged:370367eda574ed147009280ab608c1722363a196 · schema:1

Resolution summary — PR #196 (work item #177): RESOLVED

Resolved both valid findings. Fix commits: 5a2bd4c9ee8d31f3652472dc7030f3a4977edee7 and 20554c290d5d48a2cba37030cef1852a2e4f942a.

[REV-001] · low · resolved · valid · blocks:no — Granting the whole Git common directory widens the Codex write sandbox

Path: scripts/run_cycle.py, scripts/executors.py, docs/verification.md, docs/instrumentation.md.
The requested common-directory grant remains limited to writing Codex stages in linked worktrees, as required for their Git operations. Both guides now disclose that this exposes shared refs, hooks, and configuration. This records the accepted trade-off; the broader sandbox access remains a residual risk.

[REV-002] · low · resolved · valid · blocks:no — The dispatch-level wiring has no test

Path: tests/test_executors.py, tests/test_run_cycle.py.
Added dispatch-gate coverage for Codex write, Codex read-only, and non-Codex stages, plus a run_cycle regression proving the selected linked worktree's common directory reaches a writing Codex dispatch.

Post-change review and security triage

  • cc-code-review read the complete 424-line accumulated diff against origin/main in three sections. It found no P0 or P1 defect. Its initial P1 report was the same shared-metadata trade-off as REV-001; it was withdrawn after the instrumentation guide was updated. No separate finding remains.
  • The deterministic security rule is not configured, and the PR labels do not identify a sensitive area. Reviewer judgement activated cc-security-review because the change grants a sandbox write root. No confirmed vulnerability was found; the potential shared-metadata exposure is REV-001 and is documented above.

Verification

Agent-reported results:

  • rtk python3 -m unittest tests.test_executors.DispatchGateTests.test_git_common_dir_reaches_only_writing_codex_dispatches tests.test_run_cycle.LocalOnlyPolicyTests.test_writing_codex_stage_receives_the_linked_git_common_dir -v — exit 1; the package-qualified executor test import failed because this repository discovers tests/ modules directly, while the run-cycle test passed. The corrected discovery commands below passed.
  • rtk python3 -m unittest discover -s tests -p 'test_executors.py' -k test_git_common_dir_reaches_only_writing_codex_dispatches -v — exit 0; 1 test passed.
  • rtk python3 -m unittest discover -s tests -p 'test_run_cycle.py' -k test_writing_codex_stage_receives_the_linked_git_common_dir -v — exit 0; 2 runs passed (including the cross-platform path assertion rerun).
  • rtk python3 scripts/validate-package.py — exit 0.
  • rtk proxy python3 -m unittest discover -s tests -q — exit 0; 1,134 tests passed.
  • rtk python3 /tmp/pr196_boundary_check.py — exit 0; a fake Codex CLI verified the linked-worktree write grant, read-only exclusion, and non-zero exit handling.
  • rtk git diff --check — exit 0.

The local suite ran on Linux with Python 3.10.12 and Git 2.34.1, using temporary repositories and SQLite state. GitHub's Linux and Windows validation jobs also passed on the final head.

Checks of pushed head

Head: 20554c290d5d48a2cba37030cef1852a2e4f942a.

  • Skills, manifests, and Bash installer — pass (push and pull_request runs).
  • PowerShell installer — pass (push and pull_request runs).
  • Counts: 4 passed, 0 failed, 0 pending. No skipped or missing expected checks.

An earlier intermediate head (5a2bd4c9ee8d31f3652472dc7030f3a4977edee7) had failing Windows runs whose GitHub log downloads returned 403. The path assertion was made case/canonicalization tolerant, and all checks passed on the final head.

@datacas

datacas commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner Author

[CCR-20261007-001] · reviewer · anthropic/claude-sonnet-5-5→? · high · schema:1

[CCT-20261007-001] · cheap_coder · openai/gpt-6-luna→? · high · triaged:370367eda574ed147009280ab608c1722363a196 · schema:1

[CCR-20261007-002] · reviewer · anthropic/claude-sonnet-5-5→? · high · schema:1

Rereview — PR #196 (work item #177): APPROVED

Reviewed head 20554c290d5d48a2cba37030cef1852a2e4f942a (previous reviewed head 370367eda574ed147009280ab608c1722363a196) against merge base 04e73935278fcb306281d7d22a10c5f9e7d2fc40. The 427-line accumulated diff (SHA-256 26293730…d44) was read in full in two sections. Conventions applied: AGENTS.md routing (Serena/Context7 optional, not needed), .code-cycle.yml.

What changed since the previous review

  • 5a2bd4c and 20554c2: docs disclosure of the Git common-directory grant (docs/instrumentation.md, docs/verification.md); a dispatch-gate test and a run_cycle regression test for writable_dirs; a path-normalization fix in the run-cycle test assertion.
  • No production code changed in these commits beyond what the initial review covered. scripts/executors.py and scripts/run_cycle.py are unchanged in behaviour.

Previous findings

[REV-001] · low · resolved · valid · blocks:no — Granting the whole Git common directory widens the Codex write sandbox

Paths: docs/instrumentation.md, docs/verification.md, scripts/run_cycle.py, scripts/executors.py.
Both guides now state that the grant exposes shared hooks, configuration, and every branch's refs, and that it applies only to writing Codex stages in linked worktrees. dispatch() (scripts/executors.py:1882-1884) forwards writable_dirs only for codex with writes=True; CodexAdapter.argv adds --add-dir only when writes is true. The sandbox widening itself remains by design; it is a documented, accepted trade-off and stays as residual risk. Resolved means the disclosure is in place, not that the exposure is gone.

[REV-002] · low · resolved · valid · blocks:no — The dispatch-level wiring has no test

Paths: tests/test_executors.py, tests/test_run_cycle.py.
Verified by execution: test_git_common_dir_reaches_only_writing_codex_dispatches covers Codex write (forwarded), Codex read-only (not forwarded), and Claude write (not forwarded). test_writing_codex_stage_receives_the_linked_git_common_dir creates a real linked worktree and asserts writes=True and the resolved common directory in the dispatch kwargs. Both pass.

New findings

None.

Security triage and audit

security_review.always_when is not configured; no labels. Reviewer judgement: the change grants a sandbox write root, so the cc-security-review criteria were applied inline. No confirmed vulnerability. Potential risk: the shared-metadata exposure (REV-001, documented). The change handles no secrets, authentication, or user input. CODEX_HOME is redirected to a temporary directory only inside the test modules.

Verification evidence (executed here, head 20554c2)

  • python3 scripts/validate-package.py — exit 0: VALID: 15 skills (7 cycle, 8 supporting), shared sections in sync, cross-agent manifests aligned.
  • HERDR_ENV=1 python3 -m unittest discover -s tests -p 'test_executors.py' -k test_git_common_dir_reaches_only_writing_codex_dispatches -v — Ran 1 test … OK.
  • HERDR_ENV=1 python3 -m unittest discover -s tests -p 'test_run_cycle.py' -k test_writing_codex_stage_receives_the_linked_git_common_dir -v — Ran 1 test … OK.
  • HERDR_ENV=1 CODEX_HOME=/nonexistent python3 -m unittest discover -s tests -q — Ran 1134 tests in 88.702s … OK, exit 0. The host-variable isolation holds with a hostile HERDR_ENV and CODEX_HOME.

Not verified: a real Codex run showing the extra root lets a commit succeed in a linked worktree (needs Codex credentials and network); the Windows path assertion locally (it passed in CI); the git diff --check over the PR range (no origin remote in this clone; the author reported it clean).

CI (gh pr view 196 --json statusCheckRollup, head 20554c2)

Skills, manifests, and Bash installer — SUCCESS (×2 runs). PowerShell installer — SUCCESS (×2 runs). 4 passed, 0 failed, 0 pending; no skipped or missing expected check.

Residual risk

  • Sandbox widening for writing Codex stages (REV-001, accepted and documented).
  • End-to-end Codex behaviour not observed here.

Verdict

APPROVED — head 20554c290d5d48a2cba37030cef1852a2e4f942a fully rereviewed, both previous findings verified resolved, all checks pass, no open finding blocks approval.

ORCHESTRATION_RESULT (JSON)

ORCHESTRATION_RESULT
{
"skill": "cc-rereview",
"status": "APPROVED",
"issue_provider": "github",
"issue_id": "177",
"code_host": "github",
"change_request_id": "196",
"change_request_url": "#196",
"pr_number": 196,
"issue_number": 177,
"comment_url": "#196 (comment)",
"previous_reviewed_head_sha": "370367eda574ed147009280ab608c1722363a196",
"reviewed_head_sha": "20554c290d5d48a2cba37030cef1852a2e4f942a",
"head_sha": "20554c290d5d48a2cba37030cef1852a2e4f942a",
"review_run_id": "CCR-20261007-002",
"reviewer": {
"profile": "reviewer",
"provider": "anthropic",
"model_requested": "claude-sonnet-5-5",
"model_resolved": null,
"effort": "high"
},
"verified_findings": [
{"id": "REV-001", "severity": "low", "blocks_approval": false, "status": "resolved", "disposition": "valid"},
{"id": "REV-002", "severity": "low", "blocks_approval": false, "status": "resolved", "disposition": "valid"}
],
"new_findings": [],
"blocking_findings": [],
"blocking": false
}
END_ORCHESTRATION_RESULT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant