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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
stop pr-reviewer stage 3 marking sandbox and probe failures as review failures
[._.]/ Adam Eivy547d6c4a825f
diff --git a/server/lib/README.md b/server/lib/README.mdindex 1babb188a8..9de192ee3d 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -480,7 +480,7 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and| `asyncApiSpec.js` | Builds the AsyncAPI 3 Socket.IO document from the generated event catalog with direction-aware operations and explicit modeled/generated payload status. || `mergeGateContract.js` | `mergeGateOwed({taskOpenPR, ownsPrWorkflow, leaveOpen})` decides whether a completing run actually owed its own PR merge; `resolveMergeGateVerdict({prProbe, summary, alreadyReprompted})` classifies a run that did (`merged` / `unreadable` / `leave-open-stated` / `needs-reprompt` / `reprompt-exhausted`) from the PR's live state and the agent's own sentinel text; `summaryStatesLeaveOpen` and `buildMergeGateReprompt` are its text-matching and corrective-prompt helpers. Pure — the PR lookup lives in `../services/prProbe.js`, the re-prompt delivery in `agentTuiSpawning.js`. || `prDisposition.js` | `resolvePrCompletion(metadata)` resolves the explicit `review-then-merge` / `merge-on-green` / `leave-open` policy, with legacy `reviewLoop` fallback; `leavesPrForHuman(task)` + `PR_STAYS_OPEN_TASK_TYPES` keep JIRA hand-offs open. Shared by the agent prompt builder and `agentWorktreeCleanup` so both halves agree. `resolvePrCreation({taskOpenPR, agentOwnsPr, prClaimVerified})` → a `PR_CREATION` tri-state (`never` / `if-missing` / `always`) naming who opens the change request for a completing worktree agent, so the runner, TUI, and direct-CLI completion paths cannot drift into double-firing `gh pr create`. |-| `prReviewReport.js` | Owns the structured PR-decision contract end to end: `PR_REVIEW_DECISION_CONTRACT` is the envelope both review producers (pr-reviewer stage 3, issue-watcher reasoning pass) interpolate into their prompts, `normalizeReviewReport` bounds what comes back, `reviewReportText` hands every model-authored string to the abuse scan, and `renderReviewBody`/`renderFinding` turn it into the markdown a human reads on the PR page — verdict banner, scope line, blocking/non-blocking index anchored to `path:line`, test-evidence bullets, notes, collapsed verified-claims list, and inline comments with an optional GitHub suggestion block. Bounded by `MAX_REVIEW_BODY_CHARS`, dropping whole low-priority sections instead of truncating mid-sentence. Pure. |+| `prReviewReport.js` | Owns the structured PR-decision contract end to end: `PR_REVIEW_DECISION_CONTRACT` is the envelope both review producers (pr-reviewer stage 3, issue-watcher reasoning pass) interpolate into their prompts, `normalizeReviewReport` bounds what comes back, `reviewReportText` hands every model-authored string to the abuse scan, and `renderReviewBody`/`renderFinding` turn it into the markdown a human reads on the PR page — verdict banner, scope line, blocking/non-blocking index anchored to `path:line`, test-evidence bullets (`TEST_EVIDENCE_STATUSES` keeps `fail` for "the change is broken", with `expected-fail` and `blocked` for the non-zero exits that say nothing about it), notes, collapsed verified-claims list, and inline comments with an optional GitHub suggestion block. Bounded by `MAX_REVIEW_BODY_CHARS`, dropping whole low-priority sections instead of truncating mid-sentence. Pure. || `repoStateExpectations.js` | Post-completion repo-state audit, pure half. `resolveRepoStateExpectation({...})` answers whether one finished worktree agent should be audited — naming every not-audited path via `REPO_STATE_SKIPS` (a failed run is preserved for its retry; a review-loop follow-up or pr-watcher pending merge still owns the branch) — and returns just `staysOpen` + `prExpected`, from which `classifyRepoStateIssues(expectation, observed)` derives every check into `REPO_STATE_ISSUES` codes. Observations are tri-state: `null` ("could not ask") never produces an issue. `repoStateVerificationEnabled(app)` reads the per-app `verifyRepoStateOnCompletion` switch (unset = on). Probing + remediation live in `services/agentRepoStateVerification.js`. || `shellCd.js` | `buildCdCommand(path, shell)` + `formatShellCommandLine(command, args, shell)` + `detectShellFlavor(shell, platform?)` + `quoteForShell(value, flavor, position?)` — build `cd` and arbitrary command-token lines for the shell a PTY session is ACTUALLY running (`cmd.exe` → Windows-escaped double quotes, PowerShell → doubled single quotes with `&` for a quoted command token, everything else → POSIX `shellQuote`). The Shell page's "cd to app" picker used to hard-code the POSIX form, which on Windows both mis-quoted the path and silently refused to cross drives (a bare `cd` does not switch drive). Flavor comes from the shell binary name, not the platform, so git-bash on Windows still gets POSIX quoting. `formatShellCommandLine` joins a command + argv into one quoted line and is shared by `agentTuiSpawning.js#buildTuiSpawnConfig` and the AI Providers page's "Launch in Shell" deep link, so a hand-launched TUI provider is quoted exactly the way the CoS runner would quote it. Renders the LINE only; the Enter byte that submits it is `SUBMIT_KEY` in `tuiHandshake.js`. || `shellExit.js` | `buildRunThenExitCommand(commandLine, shell)` — "run this CLI, then close the shell with its status", in the dialect the session speaks. An agent TUI shell exists only to host one CLI and must die with it. The POSIX `cmd; exit $?` was applied everywhere and is actively wrong off-POSIX: in PowerShell `$?` is a BOOLEAN, so `exit $?` reports success as 1 and failure as 0 (inverted) — use `$LASTEXITCODE`, pre-seeded to 1 so a command that never ran still exits non-zero; in cmd.exe `;` is an argument separator, so the CLI is handed `;`/`exit`/`$?` as arguments — use `& exit`. Verified against node-pty on Windows 11 for pwsh 7, PowerShell 5.1 and cmd.exe. |diff --git a/server/lib/prReviewReport.js b/server/lib/prReviewReport.jsindex 198a72695d..289e69fba0 100644--- a/server/lib/prReviewReport.js+++ b/server/lib/prReviewReport.js@@ -33,8 +33,29 @@ const MAX_FINDING_TITLE_CHARS = 160;const MAX_FINDING_BODY_CHARS = 3_000;const MAX_SUGGESTION_CHARS = 2_000;const MAX_INDEX_LABEL_CHARS = 160;-const TEST_STATUSES = ['pass', 'fail', 'not-run'];-const STATUS_ICON = { pass: '✅', fail: '❌', 'not-run': '⏭️' };+/**+ * What one command says about THE CHANGE, which is not the same thing as its+ * exit code. `fail` is the only status a reader sees as a red mark, so the two+ * ways a non-zero exit means nothing about the patch need statuses of their+ * own: without them a model with an honest story has to stamp `fail` and put+ * the exculpation in `detail`, which is how an ✅ Approved review shipped three+ * ❌ rows — one deliberate mutation probe that was *supposed* to fail, and two+ * whole-suite runs whose thousands of failures were the review sandbox denying+ * sockets, out-of-tree writes, GPU access, and language toolchains.+ *+ * The icon map is the single source of truth and the accepted-status list is+ * derived from it, so a status can never exist without a mark to render it+ * with. Exported so the contract test can prove each one is documented in+ * PR_REVIEW_DECISION_CONTRACT — the half no construction can guarantee.+ */+const STATUS_ICON = {+ pass: '✅',+ fail: '❌',+ 'expected-fail': '🧪',+ blocked: '🚧',+ 'not-run': '⏭️',+};+export const TEST_EVIDENCE_STATUSES = Object.keys(STATUS_ICON);const TRIM_NOTE = '_Some sections of this review were omitted to stay within the comment size limit._';const DOWNGRADE_NOTE = 'PortOS could not anchor one or more reported findings to this diff, so the review is blocking until they are restated against exact added lines.';@@ -68,7 +89,7 @@ Each pull-request decision has this shape:"summary": "1-3 sentences: the verdict and why it is that verdict","scope": "one line naming what the change touches","testEvidence": [- {"command": "npm test -w server", "status": "pass|fail|not-run", "detail": "counts, failure, or why it could not run"}+ {"command": "npm test -w server", "status": "pass|fail|expected-fail|blocked|not-run", "detail": "counts, the failure, or why the run says nothing about the change"}],"verified": ["one claim you confirmed, citing path:line"],"concerns": ["a non-blocking observation with no specific line to anchor"],@@ -91,6 +112,15 @@ Field rules:- \`scope\` is one line ("docs-only change to two files under docs/").- \`testEvidence\` is one entry per command you actually ran, plus one\`not-run\` entry naming each relevant suite you could not run and why.+ Choose the status by what the run proves about THIS CHANGE, never by the+ exit code — \`fail\` is the only one a reader sees as a red mark, so it is+ reserved for "the change breaks this command". Use \`expected-fail\` for a+ deliberate probe that had to fail to prove something (reverting the fix to+ show a new test is not vacuous), \`blocked\` when the command ran but its+ failures came from the environment — a sandbox denial, a missing toolchain+ or service, a resource limit — so it proved nothing either way, and+ \`not-run\` when you never ran it. If you find yourself writing a \`detail\`+ that explains a \`fail\` away, the status was wrong.- \`verified\` holds claims you checked against the code, one per entry, eachciting the \`path:line\` that proves it. Leave it empty rather than padding.- \`concerns\` is for non-blocking observations that have no line to anchor to.@@ -124,7 +154,7 @@ function normalizeTestEvidence(value) {const command = line(item?.command, MAX_BULLET_CHARS);const detail = line(item?.detail, MAX_BULLET_CHARS);if (!command && !detail) return null;- const status = TEST_STATUSES.includes(item?.status) ? item.status : 'not-run';+ const status = TEST_EVIDENCE_STATUSES.includes(item?.status) ? item.status : 'not-run';return { command, status, detail };}).filter(Boolean)diff --git a/server/lib/prReviewReport.test.js b/server/lib/prReviewReport.test.jsindex 7cee502268..d680d94689 100644--- a/server/lib/prReviewReport.test.js+++ b/server/lib/prReviewReport.test.js@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';import {MAX_REVIEW_BODY_CHARS,PR_REVIEW_DECISION_CONTRACT,+ TEST_EVIDENCE_STATUSES,normalizeReviewReport,renderFinding,renderReviewBody,@@ -40,6 +41,42 @@ describe('renderReviewBody', () => {expect(body).toContain('<details><summary>Claims verified against the code</summary>');});+ // A ❌ on an approved review is a lie a human has to read past. Stage 3 hits+ // two non-zero exits that say nothing about the patch — a deliberate mutation+ // probe that must fail, and a suite the review sandbox strangles — and each+ // needs its own mark, or the model stamps `fail` and explains it away in the+ // detail (which is exactly what shipped three ❌ rows under an ✅ Approved).+ it('marks a deliberate probe and an environment-blocked run without the red fail icon', () => {+ const body = renderReviewBody({+ verdict: 'approve',+ report: {+ testEvidence: [+ { command: 'npx vitest run installState.test.js -t "Finder metadata"', status: 'expected-fail', detail: 'with the guard reverted, so the new test is not vacuous' },+ { command: 'npx vitest run', status: 'blocked', detail: 'EPERM on listen and spawn inside the review sandbox' },+ ],+ },+ });+ expect(body).toContain('- 🧪 `npx vitest run installState.test.js -t "Finder metadata"` — with the guard reverted, so the new test is not vacuous');+ expect(body).toContain('- 🚧 `npx vitest run` — EPERM on listen and spawn inside the review sandbox');+ expect(body).not.toContain('❌');+ });++ // Deriving the status list from the icon map already makes "every status has+ // an icon" true by construction. What that cannot guarantee is that the+ // statuses stay DISTINGUISHABLE, and that exactly one of them is the red+ // mark — give `blocked` a ❌ and the misleading review is back with no+ // vocabulary change to notice.+ it('renders each evidence status distinguishably, with only `fail` as the red mark', () => {+ const icons = TEST_EVIDENCE_STATUSES.map((status) => renderReviewBody({+ verdict: 'approve',+ report: { testEvidence: [{ command: 'cmd', status, detail: 'd' }] },+ }).match(/- (\S+) `cmd`/)?.[1]);++ expect(new Set(icons).size).toBe(TEST_EVIDENCE_STATUSES.length);+ expect(icons[TEST_EVIDENCE_STATUSES.indexOf('fail')]).toBe('❌');+ expect(icons.filter((icon) => icon === '❌')).toHaveLength(1);+ });+it('still renders a legacy plain-string summary with no structured fields', () => {const body = renderReviewBody({ verdict: 'approve', report: { summary: 'Looks good.' } });expect(body).toBe('✅ **Approved**\n\nLooks good.');@@ -175,7 +212,9 @@ describe('PR_REVIEW_DECISION_CONTRACT', () => {for (const field of ['path', 'line', 'side', 'blocking', 'title', 'body', 'suggestion']) {expect(PR_REVIEW_DECISION_CONTRACT, field).toContain(`"${field}"`);}- for (const status of ['pass', 'fail', 'not-run']) {+ // Derived from the real list: a status the normalizer accepts but the+ // contract never names is one the model has no way to know it may use.+ for (const status of TEST_EVIDENCE_STATUSES) {expect(PR_REVIEW_DECISION_CONTRACT, status).toContain(status);}});diff --git a/server/services/taskPromptDefaults.test.js b/server/services/taskPromptDefaults.test.jsindex ca46aa0c2d..c9ce74a028 100644--- a/server/services/taskPromptDefaults.test.js+++ b/server/services/taskPromptDefaults.test.js@@ -1027,4 +1027,23 @@ describe('taskPromptDefaults integrity snapshot', () => {expect(current).toContain('git ls-files --cached -- <path>');expect(current).toContain('deleted protected file');});++ // A stage-3 review ran the ENTIRE server suite twice — once patched, once at+ // the unpatched base — to establish that all 3533 failures were the sandbox+ // (that suite is green outside it), then reported both runs as `fail`. That+ // is ~76k tests of spend for zero signal plus two misleading ❌ rows under an+ // ✅ Approved verdict. Step 3 must scope test selection to the patched files+ // and name the honest statuses for the two non-zero exits that say nothing+ // about the change.+ it('pr-reviewer-review scopes test runs to the patched files and names the non-fail evidence statuses', () => {+ const current = DEFAULT_TASK_PROMPTS['pr-reviewer-review'];+ expect(current).toContain('test files that cover the\n patched files');+ expect(current).toContain('Do NOT run a whole workspace suite as review evidence');+ // The wasteful half is the SECOND full run, so the prompt has to forbid it+ // by name rather than leaving "compare against the base" open-ended.+ expect(current).toContain('do not re-run everything at the base');+ expect(current).toMatch(/re-run only the\s+failing files there/);+ expect(current).toContain('`blocked`');+ expect(current).toContain('`expected-fail`');+ });});diff --git a/server/services/taskPromptDefaults/integrity.snapshot.json b/server/services/taskPromptDefaults/integrity.snapshot.jsonindex ee2e679d1a..877ed154dd 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": "d8ad0de83427da1dcc05d93d0009363b",+ "pr-reviewer-review": "913282777b12500e288d0550914999cd","pr-reviewer-security": "d1e99626b12939ee39ab38eaa7d23f59","pr-watcher": "53ead8e26d396849bfa78f28550bd691","react-lifecycle": "14b3816d1bcc10f0d7d6357e55cc5e69",diff --git a/server/services/taskPromptDefaults/prompts.js b/server/services/taskPromptDefaults/prompts.jsindex dc3872cc6d..832fffd090 100644--- a/server/services/taskPromptDefaults/prompts.js+++ b/server/services/taskPromptDefaults/prompts.js@@ -2417,11 +2417,25 @@ PR state and exact content fingerprint.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- patch cannot be applied or a relevant test cannot run, use \`defer\` unless- the evidence supports a clearly blocking review finding.+3. Inspect the resulting code and run the existing test files that cover the+ patched files — the narrowest suite first, then the suites its callers live+ in. Tests may take several minutes; completeness and trustworthy evidence+ matter more than throughput. If a patch cannot be applied or a relevant+ test cannot run, use \`defer\` unless the evidence supports a clearly+ blocking review finding.+ Do NOT run a whole workspace suite as review evidence. This sandbox denies+ network binds and outbound requests, writes outside the worktree, GPU+ access, and the language toolchains and background services a minority of+ suites need, so a from-zero full run reports failures by the thousands for+ reasons that have nothing to do with the patch — and re-running the whole+ suite unpatched to demonstrate that costs a second full run and still+ yields no signal about the change. When a broader run you did attempt+ reports failures, do not re-run everything at the base: re-run only the+ failing files there, and record that command as \`blocked\` rather than+ \`fail\` for failures that reproduce unpatched or name one of those+ denials. A probe you ran deliberately to prove a new test is not+ vacuous — reverting the fix and watching the test fail — is+ \`expected-fail\`, never \`fail\`.4. After recording each PR's decision, return the worktree to its clean basewith \`git reset --hard HEAD\` and \`git clean -fd --exclude=PORTOS_PUBLIC_REVIEW_INPUT.json --exclude=.portos-public-review\`before applying the next patch. Do not alter the supplied input or patch