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: validate operator-closed claim outcomes without a PR
[._.]/ Adam Eivy064a2270499b
diff --git a/server/services/agentFinalization.outputHooks.test.js b/server/services/agentFinalization.outputHooks.test.jsindex 2ef6f96008..08e3a13c83 100644--- a/server/services/agentFinalization.outputHooks.test.js+++ b/server/services/agentFinalization.outputHooks.test.js@@ -604,11 +604,12 @@ describe('recovery output-hook dispatch (#3182)', () => {expect(addTask).not.toHaveBeenCalled();});- it.each(['normal', 'restart'])('settles a selected claim no-op from the shared verifier during %s completion', async mode => {+ it.each(['normal', 'restart'].flatMap(mode => ['not-planned', 'operator-closed'].map(disposition => [mode, disposition])))+ ('settles a selected claim no-op during %s completion from a verified %s disposition', async (mode, disposition) => {isProgrammaticIoTaskType.mockReturnValue(false);const task = { id: 'claim-example', taskType: 'user', metadata: { app: 'app-example', claimFlow: true, claimTarget: '42' } };const taskOutcome = { status: 'no-action-needed', reason: 'Selected issue no longer requires a change.' };- const claimDisposition = { status: 'verified', taskId: task.id, issues: [{ issue: 42, disposition: 'not-planned' }] };+ const claimDisposition = { status: 'verified', taskId: task.id, issues: [{ issue: 42, disposition }] };persistedAgent.taskId = task.id;persistedAgent.metadata.taskOutcome = taskOutcome;persistedAgent.metadata.taskOutcomeSource = 'terminal-result';@@ -622,6 +623,9 @@ describe('recovery output-hook dispatch (#3182)', () => {expect(completeAgent).toHaveBeenLastCalledWith(persistedAgent.id, expect.objectContaining({ success: true,validationPassed: true, taskOutcome, claimDisposition }));expect(hook).not.toHaveBeenCalled();+ expect(addTask).not.toHaveBeenCalled();+ if (mode === 'normal') expect(updateTask).toHaveBeenLastCalledWith(task.id,+ expect.objectContaining({ status: 'completed', metadata: expect.objectContaining({ taskOutcome }) }), task.taskType);} finally { isProgrammaticIoTaskType.mockReturnValue(true); }});diff --git a/server/services/claimDisposition.js b/server/services/claimDisposition.jsindex cbcfba528f..0db32873d9 100644--- a/server/services/claimDisposition.js+++ b/server/services/claimDisposition.js@@ -9,6 +9,12 @@ const unverified = reason => ({ status: 'unverified', reason });const sameRepo = (a, b) => typeof a === 'string' && typeof b === 'string' && a.toLowerCase() === b.toLowerCase();const positiveIssue = value => /^[1-9]\d*$/.test(String(value ?? '')) && Number.isSafeInteger(Number(value)) ? Number(value) : null;+async function trustedGithubClosure(closed, target, run) {+ const { createGithubActorTrust } = await import('./forgeActorTrust.js');+ const trust = await createGithubActorTrust({ runGh: run, host: target.apiHost, repoFullName: target.fullName });+ return trust.isTrusted(closed.actor?.login);+}+function selectedIssues(task, agent) {const branches = agent?.metadata?.claimBranches;if (Array.isArray(branches) && branches.length) {@@ -62,9 +68,7 @@ async function githubDisposition({ number, target, run }) {if (issue.stateReason === 'NOT_PLANNED') {// A typed stand-down is distinct from delivery. Only a repository operator// may invalidate work: arbitrary contributor labels/comments grant nothing.- const { createGithubActorTrust } = await import('./forgeActorTrust.js');- const trust = await createGithubActorTrust({ runGh: run, host: target.apiHost, repoFullName: target.fullName });- if (!await trust.isTrusted(closed.actor?.login)) return unverified('closure-authority-unverified');+ if (!await trustedGithubClosure(closed, target, run)) return unverified('closure-authority-unverified');return { status: 'verified', disposition: 'not-planned', issue: number, closedAt: closed.createdAt };}if (issue.stateReason !== 'COMPLETED') return unverified('closure-reason-unverified');@@ -72,9 +76,16 @@ async function githubDisposition({ number, target, run }) {if (typeof defaultBranch !== 'string' || !defaultBranch) return unverified('default-branch-unavailable');const candidates = [closed.closer, ...events.map(event => event?.source)];const pr = candidates.find(candidate => deliveredPr(candidate, number, target, defaultBranch, closed.createdAt));- return pr ? { status: 'verified', disposition: 'delivered', issue: number, closedAt: closed.createdAt,- changeRequest: pr.number, mergeCommit: pr.mergeCommit.oid, defaultBranch }- : unverified('merged-delivery-unverified');+ if (pr) return { status: 'verified', disposition: 'delivered', issue: number, closedAt: closed.createdAt,+ changeRequest: pr.number, mergeCommit: pr.mergeCommit.oid, defaultBranch };+ // Revalidation can find a fix shipped without a closing-keyword link, or+ // superseding work. A trusted manual closure settles the selected task; it+ // does not prove a particular PR delivered code. An automatic PR closure+ // still needs the exact merged/default-branch evidence above.+ if (closed.closer != null) return unverified('merged-delivery-unverified');+ if (!await trustedGithubClosure(closed, target, run)) return unverified('closure-authority-unverified');+ return { status: 'verified', disposition: 'operator-closed', issue: number,+ closedAt: closed.createdAt, closedBy: closed.actor.login };}async function gitlabDisposition({ number, target, run }) {@@ -100,9 +111,15 @@ async function gitlabDisposition({ number, target, run }) {changeRequest: mr.iid, mergeCommit: mr.merge_commit_sha, defaultBranch: repository.default_branch };}}- // GitLab has no equivalent typed NOT_PLANNED closure in this API. Closed- // without a proven merged relationship stays unverified, even with labels.- return unverified('merged-delivery-unverified');+ // GitLab has no typed NOT_PLANNED reason. Verify the actual closer's project+ // write authority rather than treating labels or agent prose as a disposition.+ const closerId = issue.closed_by?.id;+ if (!Number.isSafeInteger(closerId) || closerId < 1) return unverified('closure-authority-unverified');+ const member = await read(`${project}/members/all/${closerId}`);+ if (member?.id !== closerId || !Number.isInteger(member.access_level) || member.access_level < 30) {+ return unverified('closure-authority-unverified');+ }+ return { status: 'verified', disposition: 'operator-closed', issue: number, closedAt: issue.closed_at };}/**diff --git a/server/services/claimDisposition.test.js b/server/services/claimDisposition.test.jsindex 1040d2539e..b5c5044d43 100644--- a/server/services/claimDisposition.test.js+++ b/server/services/claimDisposition.test.js@@ -53,6 +53,24 @@ describe('selected claim tracker completion', () => {expect((await verify()).issues[0]).not.toHaveProperty('mergeCommit');});+ it('settles a trusted manual COMPLETED closure even when shipped work has no closing-keyword link', async () => {+ repository.issue.timelineItems.nodes[0].source.closingIssuesReferences.nodes = [];+ const result = await verify();+ expect(result).toMatchObject({ status: 'verified', issues: [{ issue: 42, disposition: 'operator-closed', closedBy: 'example' }] });+ expect(result.issues[0]).not.toHaveProperty('mergeCommit');+ expect(result.issues[0]).not.toHaveProperty('changeRequest');+ // Later retries see only the same closure; no PR or new agent is needed.+ repository.issue.timelineItems.nodes = [closure()];+ expect(await verify()).toEqual(result);+ });++ it('requires authority from the latest manual closure, ignoring earlier trusted closures', async () => {+ repository.issue.timelineItems.nodes = [closure(), { ...closure(),+ createdAt: '2026-10-02T11:00:00Z', actor: { login: 'outside-contributor' } }];+ execGh.mockImplementation(async args => args[1] === 'graphql' ? JSON.stringify({ data: { repository } }) : '{}');+ expect(await verify()).toMatchObject({ status: 'unverified', reason: 'closure-authority-unverified' });+ });+it('preserves delegated collaborator closure authority and rejects an untrusted invalidation', async () => {repository.issue.stateReason = 'NOT_PLANNED';repository.issue.timelineItems.nodes = [{ ...closure(), actor: { login: 'delegated-agent' } }];@@ -78,6 +96,8 @@ describe('selected claim tracker completion', () => {['unproven merge commit', r => { r.issue.timelineItems.nodes[0].source.mergeCommit = null; }],['closure before merge', r => { r.issue.timelineItems.nodes[0].source.mergedAt = '2026-10-02T00:00:00Z'; }],])('refuses %s despite affirmative agent prose', async (_name, mutate) => {+ // An automatic PR closure must still satisfy the exact delivery contract.+ repository.issue.timelineItems.nodes[1].closer = repository.issue.timelineItems.nodes[0].source;mutate(repository);expect(await verify()).toMatchObject({ status: 'unverified' });});@@ -128,7 +148,7 @@ describe('GitLab selected claim delivery', () => {const mr = { iid: 7, project_id: 5, target_project_id: 5, state: 'merged', target_branch: 'main',merge_commit_sha: 'b'.repeat(40), merged_at: '2026-10-01T10:00:00Z' };- it('requires a same-project merged MR that explicitly closes this issue, and refuses unsupported closure-only claims', async () => {+ it('requires a same-project merged MR that explicitly closes this issue, or a verified operator closure', async () => {resolveAppForgeTarget.mockResolvedValue({ tracker: 'gitlab', target: { ...target, forge: 'gitlab' } });resolveForgeForRepo.mockResolvedValue({ cli: 'glab', env: { GITLAB_TOKEN: 'invented-token' } });let closes = [issue];@@ -141,8 +161,26 @@ describe('GitLab selected claim delivery', () => {expect(execGlab.mock.calls[0]).toEqual([expect.arrayContaining(['--hostname', target.webHost, '--method', 'GET']),'/example/project', undefined, { env: { GITLAB_TOKEN: 'invented-token' } }]);closes = [{ ...issue, project_id: 6 }];- expect(await verify()).toMatchObject({ status: 'unverified', reason: 'merged-delivery-unverified' });+ expect(await verify()).toMatchObject({ status: 'unverified', reason: 'closure-authority-unverified' });closes = [];expect(await verify()).toMatchObject({ status: 'unverified' });});++ it('verifies the GitLab closer through inherited project membership, and refuses read-only or mismatched members', async () => {+ resolveAppForgeTarget.mockResolvedValue({ tracker: 'gitlab', target: { ...target, forge: 'gitlab' } });+ resolveForgeForRepo.mockResolvedValue({ cli: 'glab' });+ let member = { id: 9, access_level: 30 };+ execGlab.mockImplementation(async args => {+ const endpoint = args.at(-1);+ return JSON.stringify(endpoint.includes('/members/all/') ? member+ : endpoint.includes('related_merge_requests') ? [] : endpoint.endsWith('/42') ? { ...issue, closed_by: { id: 9 } } : project);+ });+ const result = await verify();+ expect(result).toMatchObject({ status: 'verified', issues: [{ issue: 42, disposition: 'operator-closed' }] });+ expect(result.issues[0]).not.toHaveProperty('mergeCommit');+ member = { id: 9, access_level: 20 };+ expect(await verify()).toMatchObject({ status: 'unverified', reason: 'closure-authority-unverified' });+ member = { id: 10, access_level: 50 };+ expect(await verify()).toMatchObject({ status: 'unverified', reason: 'closure-authority-unverified' });+ });});diff --git a/server/services/promptSections/completion.js b/server/services/promptSections/completion.jsindex bada0b3219..cec06fdf8e 100644--- a/server/services/promptSections/completion.js+++ b/server/services/promptSections/completion.js@@ -77,7 +77,7 @@ const SENTINEL_WATCH_TAIL = 'PortOS watches this sentinel and finalizes the run* per-section splice the next mode had to remember. Composing it here keeps* "prints a sentinel path" and "says the write is permitted" one fact.*/-const TASK_OUTCOME_GUIDANCE = 'Write a JSON envelope with `summary` (your markdown report), `taskOutcome: { "status": "completed" | "no-action-needed" | "blocked" | "incomplete", "reason": "specific evidence or blocker" }`, and the existing `payload` when your task requires one. Use completed only when the requested deliverable is finished; no-action-needed only when checks verified no work remains; blocked for an unmet prerequisite; incomplete for unfinished work. Unfinished work resumes automatically within the existing retry/spawn budget. If ONLY repository cleanup remains after verified delivery, add `recovery: { "mode": "cleanup" }` inside taskOutcome: the server owns cleanup after this run releases its ownership, without another agent. Do not use cleanup mode for unmerged PRs, red validation, missing deliverables, or unresolved review findings. For a PortOS investigation whose merged fix must be running before verification, report blocked with `recovery: { "mode": "runtime", "prUrl": "https://github.com/owner/repository/pull/123", "requiredCommit": "<full merged PR head or merge commit>" }`. The server verifies integration and boot ancestry, preserves the same task and remaining budgets, and waits for the configured idle update policy; never restart or force an update yourself. Only when proceeding needs a human safety or preference decision, add `recovery: { "mode": "approval", "options": ["concrete option and consequence", "alternative and consequence"] }`; explain the decision in reason. Never request approval for routine mechanical recovery. Process exit and writing this file do not prove task achievement. Preserve unfinished work and name what remains in the reason.';+const TASK_OUTCOME_GUIDANCE = 'Write a JSON envelope with `summary` (your markdown report), `taskOutcome: { "status": "completed" | "no-action-needed" | "blocked" | "incomplete", "reason": "specific evidence or blocker" }`, and the existing `payload` when your task requires one. Use completed only when the requested deliverable is finished; no-action-needed only when checks verified no work remains (including a selected claim issue already resolved or closed with evidence); blocked for an unmet prerequisite; incomplete for unfinished work. For a claim that needs no code or PR, use no-action-needed even when your only action was closing the issue. Record the selected issue, live closure state, and why no work remains in reason and summary. The server independently verifies the bound issue and either its merged closing PR or a repository operator\'s closure; prose alone and an open issue do not pass. Unfinished work resumes automatically within the existing retry/spawn budget. If ONLY repository cleanup remains after verified delivery, add `recovery: { "mode": "cleanup" }` inside taskOutcome: the server owns cleanup after this run releases its ownership, without another agent. Do not use cleanup mode for unmerged PRs, red validation, missing deliverables, or unresolved review findings. For a PortOS investigation whose merged fix must be running before verification, report blocked with `recovery: { "mode": "runtime", "prUrl": "https://github.com/owner/repository/pull/123", "requiredCommit": "<full merged PR head or merge commit>" }`. The server verifies integration and boot ancestry, preserves the same task and remaining budgets, and waits for the configured idle update policy; never restart or force an update yourself. Only when proceeding needs a human safety or preference decision, add `recovery: { "mode": "approval", "options": ["concrete option and consequence", "alternative and consequence"] }`; explain the decision in reason. Never request approval for routine mechanical recovery. Process exit and writing this file do not prove task achievement. Preserve unfinished work and name what remains in the reason.';const sentinelCompletionSection = (notice, writeInstruction) =>[notice, '', `${writeInstruction} ${SENTINEL_WATCH_TAIL}`, '', TASK_OUTCOME_GUIDANCE, '', SENTINEL_WRITE_PERMISSION_NOTE].join('\n');