Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: gate the sandbox-write fallback on the real git apply, not --check

Adam Eivyb3cd9596a244
diff --git a/server/services/taskPromptDefaults.test.js b/server/services/taskPromptDefaults.test.js
index a1f91daa6a..ca46aa0c2d 100644
--- a/server/services/taskPromptDefaults.test.js
+++ b/server/services/taskPromptDefaults.test.js
@@ -1008,9 +1008,23 @@ describe('taskPromptDefaults integrity snapshot', () => {
expect(current).toContain('.claude/agents');
expect(current).toContain('.claude/commands');
expect(current).toContain('.claude/hooks');
+ expect(current).toContain('.claude/workflows');
+ expect(current).toContain('.mcp.json');
expect(current).toContain('git apply --cached -- <patch>');
expect(current).toContain('git show :<path>');
- expect(current).toContain('never by reading the\n working-tree file');
+ // Reflow-tolerant: every whitespace run (including a line-wrap newline,
+ // wherever it happens to fall) matches `\s+`, so a harmless rewrap of this
+ // prose can't break the assertion.
+ expect(current).toMatch(/never\s+by\s+reading\s+the\s+working-tree\s+file/);
expect(current).toContain('never `defer` for this reason alone');
+ // `git apply --check` performs no writes, so the fallback must gate on the
+ // real (write) `git apply` failing — not on `--check`, which the sandbox's
+ // write-only protection can never cause to fail (#5963 review finding).
+ expect(current).toContain('`--check` makes no filesystem writes');
+ expect(current).not.toContain('When `--check` fails ONLY on');
+ // A deleted protected file has no index blob left for `git show :<path>`
+ // to read — the fallback must verify absence instead.
+ expect(current).toContain('git ls-files --cached -- <path>');
+ expect(current).toContain('deleted protected file');
});
});
diff --git a/server/services/taskPromptDefaults/integrity.snapshot.json b/server/services/taskPromptDefaults/integrity.snapshot.json
index f3609e41f6..ee2e679d1a 100644
--- a/server/services/taskPromptDefaults/integrity.snapshot.json
+++ b/server/services/taskPromptDefaults/integrity.snapshot.json
@@ -29,7 +29,7 @@
"plan-task": "b85fe92999aa4ee4a8910320457c4242",
"pr-reviewer": "679680b3b382aeb6786df01c4d1a90c6",
"pr-reviewer-eligibility": "ba358b2bb9380e2b7d9117969607231f",
- "pr-reviewer-review": "78e75a273c62e6530f1a98a8dad4821e",
+ "pr-reviewer-review": "d8ad0de83427da1dcc05d93d0009363b",
"pr-reviewer-security": "d1e99626b12939ee39ab38eaa7d23f59",
"pr-watcher": "53ead8e26d396849bfa78f28550bd691",
"react-lifecycle": "14b3816d1bcc10f0d7d6357e55cc5e69",
diff --git a/server/services/taskPromptDefaults/prompts.js b/server/services/taskPromptDefaults/prompts.js
index 22e8bde71e..dc3872cc6d 100644
--- a/server/services/taskPromptDefaults/prompts.js
+++ b/server/services/taskPromptDefaults/prompts.js
@@ -2391,24 +2391,32 @@ PR state and exact content fingerprint.
1. Read the supplied envelope and evaluate every eligible PR exactly once.
Preserve each exact numeric \`number\` and 40-character \`headSha\`.
2. Read \`.portos-public-review/PORTOS_PUBLIC_REVIEW_PATCHES.json\` to map a PR
- number to its patch. For each PR, run \`git apply --check -- <patch>\` and,
- if it applies, \`git apply -- <patch>\` in the disposable worktree. Never
- use \`--unsafe-paths\`, \`--3way\`, a remote ref, or a replacement patch.
+ number to its patch. For each PR, run \`git apply --check -- <patch>\` first.
+ \`--check\` makes no filesystem writes, so a failure there is a genuine
+ patch-application problem, never the sandbox's write protection below —
+ treat it as an unapplied patch under step 3. When \`--check\` succeeds, run
+ \`git apply -- <patch>\` in the disposable worktree. Never use
+ \`--unsafe-paths\`, \`--3way\`, a remote ref, or a replacement patch.
The sandbox permanently denies working-tree writes under a small set of
Claude Code-owned paths even inside this disposable worktree — for example
\`.claude/skills\`, \`.claude/agents\`, \`.claude/commands\`, \`.claude/hooks\`,
\`.claude/workflows\`, and \`.mcp.json\` — and no setting can lift that
- protection from inside the sandbox. When \`git apply --check\` fails ONLY on
- those protected paths (every other file in the patch applies cleanly),
- apply the same patch to the index instead of the working tree with
- \`git apply --cached -- <patch>\`, then verify each protected file's exact
- content from the index with \`git show :<path>\` (never by reading the
- working-tree file, which the sandbox refused to write) and confirm it
- matches the patch hunk-for-hunk. That is a fully verified change, not
- partial evidence — use \`approve\` when the indexed content is correct and
- the rest of the review supports it, never \`defer\` for this reason alone.
- If \`--check\` fails for any other reason, treat the PR as unapplied under
- step 3 below.
+ protection from inside the sandbox. Because \`--check\` already confirmed
+ the patch applies cleanly, a working-tree \`git apply\` failure that names
+ only those protected paths is that write denial, not a bad patch: fall back
+ to applying the same patch to the index instead with
+ \`git apply --cached -- <patch>\`. For a modified or added protected file,
+ verify its exact content from the index with \`git show :<path>\` (never by
+ reading the working-tree file, which the sandbox refused to write) and
+ confirm it matches the patch hunk-for-hunk; for a deleted protected file,
+ confirm it is now absent from the index with
+ \`git ls-files --cached -- <path>\` (expect empty output) instead — \`git
+ show\` has no blob left to read once a path is removed from the index.
+ That is a fully verified change, not partial evidence — use \`approve\`
+ when the verified content is correct and the rest of the review supports
+ it, never \`defer\` for this reason alone. If the working-tree \`git apply\`
+ fails for any other reason, or on a file outside those protected paths,
+ treat the PR as unapplied under step 3 below.
3. Inspect the resulting code and run the narrowest relevant existing tests,
followed by broader tests when practical. Tests may take several minutes;
completeness and trustworthy evidence matter more than throughput. If a