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
fix: accept current-head optional inconclusive merge evidence (#12555)
[._.]/ Adam Eivy2c05fc06976e
diff --git a/server/services/cosMergeHandoff.js b/server/services/cosMergeHandoff.jsindex 056b9d8956..6706bddcca 100644--- a/server/services/cosMergeHandoff.js+++ b/server/services/cosMergeHandoff.js@@ -63,11 +63,11 @@ async function readReviewEvidence(workspace) {if (!relative) return { status: 'unreadable', head: null };const content = await readFile(resolve(workspace, relative), 'utf-8').catch((err) => (err.code === 'ENOENT' ? null : undefined));if (content === null) return { status: null, head: null };- const values = (pattern) => [...String(content ?? '').matchAll(pattern)].map((m) => m[1]);- const statuses = values(/^REVIEW_STATUS=(\S+)\s*$/gm);- const heads = values(/^REVIEW_HEAD=(\S+)\s*$/gm);+ const values = (pattern) => [...String(content ?? '').matchAll(pattern)].map((m) => m[1].trim());+ const statuses = values(/^REVIEW_STATUS=([^\r\n]*)$/gm);+ const heads = values(/^REVIEW_HEAD=([^\r\n]*)$/gm);return {- status: statuses.length === 0 ? 'unreadable' : statuses.find((status) => status !== 'clean') ?? 'clean',+ status: statuses.length === 1 ? statuses[0] : 'unreadable',head: heads.length === 1 ? heads[0].toLowerCase() : null,};}@@ -76,12 +76,13 @@ async function readReviewEvidence(workspace) {// reviewers, so there only a recorded block or unreadable status refuses. When// every local reviewer is optional the in-session merge treats them as// non-blocking, so a clean status needs no head: capped rounds that all returned-// (fixed) findings never record one.+// (fixed) findings never record one. Explicit optional-inconclusive evidence+// instead names the attempted head; it never represents a clean reviewer verdict.function reviewEvidenceAccepted({ status, head: reviewedHead }, head, policy, { reviewers = [], optionalReviewers = [] } = {}) {if (policy === PR_COMPLETIONS.MERGE_ON_GREEN) return status === null || status === 'clean';- if (status !== 'clean') return false;const allOptional = reviewers.length > 0 && reviewers.every((reviewer) => optionalReviewers.includes(reviewer));- return allOptional || reviewedHead === head;+ if (status === 'optional-inconclusive') return allOptional && reviewedHead === head;+ return status === 'clean' && (allOptional || reviewedHead === head);}async function followUpRoster(task, policy) {diff --git a/server/services/cosMergeHandoff.test.js b/server/services/cosMergeHandoff.test.jsindex 28acab44f5..89ebc98a78 100644--- a/server/services/cosMergeHandoff.test.js+++ b/server/services/cosMergeHandoff.test.js@@ -6,7 +6,7 @@ import { join } from 'node:path';// Agent → server pending-merge handoff (#12247), end to end through the real// admission service and the real pr-watcher coordinator over synthetic stores.const f = vi.hoisted(() => ({- state: null, tasks: {}, apps: new Map(), checkouts: {}, pr: null, foreign: new Set(), optionalReviewers: [], queueWriteFailure: false,+ state: null, tasks: {}, apps: new Map(), checkouts: {}, pr: null, foreign: new Set(), reviewers: [], optionalReviewers: [], queueWriteFailure: false,}));vi.mock('./cosState.js', async () => {const { createFileWriteQueue } = await import('../lib/fileWriteQueue.js');@@ -45,7 +45,7 @@ vi.mock('./apps.js', () => ({}));vi.mock('./untrustedContent.js', () => ({ screenUntrustedContent: async () => ({ ok: true, screening: { safe: true } }) }));vi.mock('./codeReview.js', () => ({- resolveReviewLoopOptions: async () => ({ reviewers: ['codex'], usernames: [], optionalReviewers: f.optionalReviewers, reviewerMaxRounds: {} }),+ resolveReviewLoopOptions: async () => ({ reviewers: f.reviewers, usernames: [], optionalReviewers: f.optionalReviewers, reviewerMaxRounds: {} }),}));const mergePrMock = vi.fn();vi.mock('./git.js', () => ({ mergePR: (...args) => mergePrMock(...args) }));@@ -99,6 +99,7 @@ beforeEach(async () => {f.apps = new Map([['app1', { id: 'app1', repoPath: '/repos/source', forgeAccount: null, mergeHandoffMinQueuedRuns: 3 }]]);f.checkouts = { [workspace]: { branch: 'claim/issue-1', head: HEAD } };f.foreign = new Set();+ f.reviewers = ['codex'];f.optionalReviewers = [];f.queueWriteFailure = false;f.pr = {@@ -333,6 +334,47 @@ describe('pending-merge handoff', () => {expect(await handoff()).toMatchObject({ queued: false, reason: 'review-evidence-incomplete' });});+ it('queues current-head optional quota/no-verdict evidence without inventing a clean verdict', async () => {+ f.optionalReviewers = ['codex'];+ await writeFile(join(workspace, 'portos-review-status'), `REVIEW_STATUS=optional-inconclusive\nREVIEW_HEAD=${HEAD}\n`);+ expect(await handedOff()).toMatchObject({ queued: true });+ expect(pending()[0].handoff).toMatchObject({ reviewStatus: 'optional-inconclusive', headSha: HEAD });+ greenChecks();+ expect(await processPendingMergePrs(f.apps.get('app1'))).toMatchObject({ merged: 1 });+ expect(mergePrMock).toHaveBeenCalledWith('/repos/source', 7, { forgeAccount: null, expectedHeadSha: HEAD });+ });++ it.each([[[]], [['codex', 'claude']]])('refuses optional inconclusive evidence without an all-optional nonempty roster: %j', async (reviewers) => {+ f.reviewers = reviewers;+ f.optionalReviewers = ['codex'];+ await writeFile(join(workspace, 'portos-review-status'), `REVIEW_STATUS=optional-inconclusive\nREVIEW_HEAD=${HEAD}\n`);+ expect(await handoff()).toMatchObject({ queued: false, reason: 'review-evidence-incomplete' });+ expect(pending()).toEqual([]);+ });++ it.each([+ ['a required reviewer', `REVIEW_STATUS=optional-inconclusive\nREVIEW_HEAD=${HEAD}\n`, false],+ ['an earlier attempted head', `REVIEW_STATUS=optional-inconclusive\nREVIEW_HEAD=${'f'.repeat(40)}\n`],+ ['no attempted head', 'REVIEW_STATUS=optional-inconclusive\n'],+ ['a malformed head', 'REVIEW_STATUS=optional-inconclusive\nREVIEW_HEAD=invalid\n'],+ ['an empty duplicate status', `REVIEW_STATUS=optional-inconclusive\nREVIEW_STATUS=\nREVIEW_HEAD=${HEAD}\n`],+ ['duplicate heads', `REVIEW_STATUS=optional-inconclusive\nREVIEW_HEAD=${HEAD}\nREVIEW_HEAD=${HEAD}\n`],+ ['duplicate statuses', `REVIEW_STATUS=optional-inconclusive\nREVIEW_STATUS=clean\nREVIEW_HEAD=${HEAD}\n`],+ ['pending review', `REVIEW_STATUS=pending\nREVIEW_HEAD=${HEAD}\n`],+ ['unresolved findings', `REVIEW_STATUS=findings\nREVIEW_HEAD=${HEAD}\n`],+ ['a required availability block', `REVIEW_STATUS=review-blocked\nREVIEW_HEAD=${HEAD}\n`],+ ['an unspecified inconclusive result', `REVIEW_STATUS=inconclusive\nREVIEW_HEAD=${HEAD}\n`],+ ['empty evidence', ''],+ ['missing evidence', null],+ ])('refuses optional handoff with %s', async (_name, evidence, optional = true) => {+ f.optionalReviewers = optional ? ['codex'] : [];+ if (evidence === null) await rm(join(workspace, 'portos-review-status'));+ else await writeFile(join(workspace, 'portos-review-status'), evidence);+ expect(await handoff()).toMatchObject({ queued: false, reason: 'review-evidence-incomplete' });+ expect(pending()).toEqual([]);+ expect(mergePrMock).not.toHaveBeenCalled();+ });+it('keeps an already-green PR with its original owner for immediate merge', async () => {greenChecks();expect(await handoff()).toMatchObject({ queued: false, reason: 'pr-not-waiting-on-healthy-ci' });diff --git a/server/services/promptSections/completion.js b/server/services/promptSections/completion.jsindex ba5ad2426a..fcc4e118c1 100644--- a/server/services/promptSections/completion.js+++ b/server/services/promptSections/completion.js@@ -590,8 +590,9 @@ function buildClaimOwnershipSection(agentId) {}// The record a review phase leaves for the handoff: one REVIEW_HEAD line naming-// the commit its final clean round covered, beside REVIEW_STATUS (#12247).+// the commit its final clean round covered or its optional review attempted.// A missing status file stays missing: a REVIEW_HEAD alone would read as unreadable evidence.+const RECORD_OPTIONAL_INCONCLUSIVE = 'F="$(git rev-parse --git-path portos-review-status)"; [ -f "$F" ] && [ "$(grep -c "^REVIEW_STATUS=" "$F")" = 1 ] && grep -qxE "REVIEW_STATUS=(clean|optional-inconclusive)" "$F" && [ "${REVIEW_ATTEMPTED_HEAD:-}" = "$(git rev-parse HEAD)" ] && printf "REVIEW_STATUS=optional-inconclusive\\nREVIEW_HEAD=%s\\n" "$REVIEW_ATTEMPTED_HEAD" > "$F.tmp" && mv "$F.tmp" "$F"';const RECORD_REVIEW_HEAD = 'F="$(git rev-parse --git-path portos-review-status)"; if [ -f "$F" ]; then { grep -v "^REVIEW_HEAD=" "$F"; printf "REVIEW_HEAD=%s\\n" "$(git rev-parse HEAD)"; } > "$F.tmp" && mv "$F.tmp" "$F"; fi';/**@@ -604,7 +605,9 @@ function buildPendingMergeHandoffLines(agentId) {return ['**PortOS pending-merge handoff (GitHub, same-repository PR, only for measured CI backlog):** By default this run owns CI, confirmed merge and safe cleanup. Early finish requires the app setting `mergeHandoffMinQueuedRuns` and a fresh server-observed queued workflow count meeting that threshold; absent settings or unknown backlog keep ownership here. The server coordinator then owns the exact reviewed head, failure recovery, merge confirmation and cleanup across restarts. When a configured local review round returns clean, record the head it reviewed beside REVIEW_STATUS (any later commit, fix, rebase or conflict resolution means that head was not reviewed, so rerun the affected review first):','```bash', RECORD_REVIEW_HEAD, '```',- 'Once the published head (`git rev-parse HEAD` equals the PR head) has passed local validation and every configured review, and the PR is ready (not draft), request a handoff only if backlog policy is configured — unless review is `review-blocked` or the PR is being left open, whose stop rules still apply. Replace PR_URL, HEAD_SHA (the full 40-character head) and WORKTREE_PATH (this checkout):',+ 'For handoff evidence, before each local review attempt capture `REVIEW_ATTEMPTED_HEAD=$(git rev-parse HEAD)` and retain that exact value across shell calls. When the completed loop has a nonempty all-optional roster and its only non-clean outcomes are availability, quota/provider, timeout, transport, malformed/empty, or no-verdict failures, record the aggregate status below. This handoff-specific record overrides instructions to leave REVIEW_STATUS=clean for optional unavailability; it does not label any reviewer verdict clean. Never use it for pending review, a required reviewer, accepted unresolved findings or rejection, failed validation, or unpushed fixes. Do not overwrite review-blocked. Any later commit, rebase or conflict resolution requires new review attempts; never replace the attempted head with the later head. If writing fails, do not hand off:',+ '```bash', RECORD_OPTIONAL_INCONCLUSIVE, '```',+ 'Once the published head (`git rev-parse HEAD` equals the PR head) has passed local validation and every configured review is satisfied or explicitly optional-inconclusive, and the PR is ready (not draft), request a handoff only if backlog policy is configured — unless review is `review-blocked` or the PR is being left open, whose stop rules still apply. Replace PR_URL, HEAD_SHA (the full 40-character head) and WORKTREE_PATH (this checkout):','```bash', command, '```','Require a parsed JSON response with queued:true and a receipt whose headSha equals HEAD_SHA. Then the receipt is your merge outcome: do not wait for CI, acquire admission, merge, enable auto-merge, close the issue, release a claim, or remove the branch or worktree; the coordinator merges or dispatches recovery (a moved head, failed check or conflict). Report the PR URL, head and receipt id, say the PR is handed to the PortOS pending-merge coordinator with CI pending and is NOT yet merged, write the completion sentinel if this run uses one, and stop. This overrides later CI waits, MERGED-only completion and cleanup instructions, including delegated slashdo workflows. On queued:false with retryable:true, retry up to 3 times 5 seconds apart. Any other refusal, an HTTP/auth/transport error or unreadable JSON means no handoff: continue with the CI wait and admission-gated merge below. A refusal never permits merging without admission.',];diff --git a/server/services/promptSections/completion.test.js b/server/services/promptSections/completion.test.jsindex 1bfb12e130..79921cece7 100644--- a/server/services/promptSections/completion.test.js+++ b/server/services/promptSections/completion.test.js@@ -110,6 +110,35 @@ describe('pending-merge handoff instructions (#12247)', () => {expect(buildClaimFlowCompletionSection({ agentId: 'parent-example', prStaysOpen: true })).not.toContain('/merge-handoff');});+ it.skipIf(process.platform === 'win32')('records optional inconclusive evidence only for the attempted head and preserves blocked evidence', () => {+ const prompt = buildClaimFlowCompletionSection({ agentId: 'parent-example' });+ expect(prompt).toContain('before each local review attempt capture `REVIEW_ATTEMPTED_HEAD=$(git rev-parse HEAD)`');+ expect(prompt).toContain('nonempty all-optional roster');+ expect(prompt).toContain('accepted unresolved findings or rejection');+ const command = prompt.split('\n').find((line) => line.includes('printf "REVIEW_STATUS=optional-inconclusive'));+ const repo = mkdtempSync(join(tmpdir(), 'optional-review-head-'));+ try {+ const git = (...args) => execFileSync('git', args, { cwd: repo, encoding: 'utf8' }).trim();+ git('init', '-q');+ git('-c', 'user.name=Example', '-c', '[email protected]', 'commit', '-q', '--allow-empty', '-m', 'example');+ const head = git('rev-parse', 'HEAD');+ const statusFile = join(repo, git('rev-parse', '--git-path', 'portos-review-status'));+ const run = (attempted) => execFileSync('sh', ['-c', command], { cwd: repo, env: { ...process.env, REVIEW_ATTEMPTED_HEAD: attempted } });+ for (const blocked of ['review-blocked', 'findings', 'pending']) {+ writeFileSync(statusFile, `REVIEW_STATUS=${blocked}\n`);+ expect(() => run(head)).toThrow();+ expect(readFileSync(statusFile, 'utf8')).toBe(`REVIEW_STATUS=${blocked}\n`);+ }+ writeFileSync(statusFile, 'REVIEW_STATUS=clean\n');+ expect(() => run('f'.repeat(40))).toThrow();+ expect(readFileSync(statusFile, 'utf8')).toBe('REVIEW_STATUS=clean\n');+ run(head);+ expect(readFileSync(statusFile, 'utf8')).toBe(`REVIEW_STATUS=optional-inconclusive\nREVIEW_HEAD=${head}\n`);+ } finally {+ rmSync(repo, { recursive: true, force: true });+ }+ });+// The recorded line must be the one shape cosMergeHandoff reads: REVIEW_STATUS// kept, exactly one REVIEW_HEAD naming the reviewed commit.it.skipIf(process.platform === 'win32')('records exactly one REVIEW_HEAD for the reviewed commit beside REVIEW_STATUS', () => {