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: address review (opencode) — paginate the duplicate scan and keep a held follow-up task legible
[._.]/ Adam Eivydc583773cdb6
diff --git a/client/src/components/cos/tabs/AgentCard.jsx b/client/src/components/cos/tabs/AgentCard.jsxindex 5a050e3e4c..e2c06a3f99 100644--- a/client/src/components/cos/tabs/AgentCard.jsx+++ b/client/src/components/cos/tabs/AgentCard.jsx@@ -246,7 +246,15 @@ function GoalFidelityPanel({ review }) {// half-delivered. An arm that could not run says so, with its reason.function GoalFidelityFollowUp({ followUp }) {if (!followUp) return null;- const { issue, issueError, taskId, taskError } = followUp;+ const { issue, issueError, taskId, taskApprovalRequired, taskDuplicate, taskError } = followUp;+ // "Queued" is wrong for a task the loop policy held for the user and wrong+ // for one that folded into an existing investigation — both exist, but only+ // one of the three is going to run on its own.+ const taskLabel = taskApprovalRequired+ ? 'Follow-up task awaiting your approval'+ : taskDuplicate+ ? 'Folded into the follow-up task already open'+ : 'View the queued follow-up task';return (<div className="mt-1.5 text-xs text-gray-400 flex flex-col gap-0.5">{issue?.url && (@@ -259,7 +267,7 @@ function GoalFidelityFollowUp({ followUp }) {{issueError && <span role="status" className="text-port-warning">No issue filed: {issueError}</span>}{taskId && (<Link className="text-port-accent hover:underline w-fit" to={`/cos/tasks?task=${encodeURIComponent(taskId)}&source=internal`}>- View the queued follow-up task+ {taskLabel}</Link>)}{taskError && <span role="status" className="text-port-warning">No follow-up queued: {taskError}</span>}@@ -1019,9 +1027,11 @@ export default function AgentCard({ agent, onPause, onKill, onDelete, onResume,{agent.result?.goalFidelity && <GoalFidelityPanel review={agent.result.goalFidelity} />}{/* The manual button is the fallback for an install that has not armed- the automatic follow-up. Once that already queued a task for this- finding, offering it again would queue a second agent on the same- work — the panel above links the one that exists instead. */}+ the automatic follow-up. Once that produced a task for this finding,+ offering it again would put a second agent on the same work — the+ panel above links the one that exists instead. That holds for a task+ HELD for approval too: the answer there is to approve the task that+ exists, not to queue an unheld duplicate beside it. */}{completed && !remote && !agent.result?.goalFidelity?.followUp?.taskId&& ['fix-first', 'rethink'].includes(agent.result?.goalFidelity?.verdict) && (<InvestigateFindingsButton key={agent.id} agent={agent} />diff --git a/client/src/components/cos/tabs/AgentCard.test.jsx b/client/src/components/cos/tabs/AgentCard.test.jsxindex 45c65efd69..c828c22a19 100644--- a/client/src/components/cos/tabs/AgentCard.test.jsx+++ b/client/src/components/cos/tabs/AgentCard.test.jsx@@ -820,6 +820,35 @@ describe('AgentCard goal fidelity', () => {expect(screen.getByText(/could not be queued/)).toBeInTheDocument();});+// "Queued" is wrong for a task the loop policy held for the user: nothing+ // will pick it up until they approve it, and the card is where they find out.+ it('names a held follow-up task as awaiting approval, not queued', () => {+ render(+ <MemoryRouter>+ <AgentCard agent={withReview({+ verdict: 'rethink',+ followUp: { taskId: 'cos-9', taskApprovalRequired: true },+ })} completed />+ </MemoryRouter>+ );+ expect(screen.getByRole('link', { name: 'Follow-up task awaiting your approval' })).toBeInTheDocument();+ // Still no manual button: the answer is to approve the task that exists,+ // not to queue an unheld duplicate beside it.+ expect(screen.queryByRole('button', { name: 'Investigate findings' })).not.toBeInTheDocument();+ });++ it('names a folded duplicate task as folded, not freshly queued', () => {+ render(+ <MemoryRouter>+ <AgentCard agent={withReview({+ verdict: 'rethink',+ followUp: { taskId: 'cos-9', taskDuplicate: true },+ })} completed />+ </MemoryRouter>+ );+ expect(screen.getByRole('link', { name: 'Folded into the follow-up task already open' })).toBeInTheDocument();+ });+// Offering the manual button after the automation already queued a task would// put two agents on one finding.it('withdraws the manual button once the follow-up queued a task, and keeps it otherwise', () => {diff --git a/server/services/agentFinalization.goalFidelity.test.js b/server/services/agentFinalization.goalFidelity.test.jsindex 806ea77f3b..bab4fffc1f 100644--- a/server/services/agentFinalization.goalFidelity.test.js+++ b/server/services/agentFinalization.goalFidelity.test.js@@ -392,6 +392,25 @@ describe('finalizeAgent — goal-fidelity gate', () => {});});+// The card reads these to decide what to call the task and whether to still+ // offer the manual fallback, so the producer's verdict has to survive the+ // completion write, not just the log line.+ it("persists the producer's hold and duplicate verdict alongside the task id", async () => {+ runGoalFidelityFollowUpMock.mockResolvedValue({+ ran: true, task: { id: 'cos-9', approvalRequired: true, duplicate: false },+ });+ await finalize();+ expect(completion().goalFidelity.followUp).toEqual({ taskId: 'cos-9', taskApprovalRequired: true });+ });++ it('omits the hold flags for an ordinary queued task', async () => {+ runGoalFidelityFollowUpMock.mockResolvedValue({+ ran: true, task: { id: 'cos-9', approvalRequired: false, duplicate: false },+ });+ await finalize();+ expect(completion().goalFidelity.followUp).toEqual({ taskId: 'cos-9' });+ });+it('records the reason when an arm could not run', async () => {runGoalFidelityFollowUpMock.mockResolvedValue({ ran: true, issueError: 'gh unreachable', task: null, taskError: 'circuit open' });await finalize();diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.jsindex abc3fa364b..0f0f0fc74a 100644--- a/server/services/agentFinalization.js+++ b/server/services/agentFinalization.js@@ -1214,7 +1214,14 @@ export async function finalizeAgent({fidelity.review.followUp = {...(followUp.issue ? { issue: { number: followUp.issue.number, url: followUp.issue.url, duplicate: followUp.issue.duplicate === true } } : {}),...(followUp.issueError ? { issueError: followUp.issueError } : {}),- ...(followUp.task?.id ? { taskId: followUp.task.id } : {}),+ // The producer's verdict rides with the id: a task the loop policy HELD+ // is not a queued one, and the card must not offer the manual fallback+ // for a finding that already has a task waiting on the user.+ ...(followUp.task?.id ? {+ taskId: followUp.task.id,+ ...(followUp.task.approvalRequired ? { taskApprovalRequired: true } : {}),+ ...(followUp.task.duplicate ? { taskDuplicate: true } : {}),+ } : {}),...(followUp.taskError ? { taskError: followUp.taskError } : {}),};}diff --git a/server/services/goalFidelityFollowUp.js b/server/services/goalFidelityFollowUp.jsindex aa41f5f0c6..83483e44ef 100644--- a/server/services/goalFidelityFollowUp.js+++ b/server/services/goalFidelityFollowUp.js@@ -67,8 +67,17 @@ import {resolveGoalFidelityFollowUp,} from '../lib/goalFidelityFollowUp.js';-/** Page size for the label-filtered duplicate listing on every tracker. */+/** Rows per request for the label-filtered duplicate listing. */const PAGE_LIMIT = 100;+/**+ * Hard ceiling on how many of our own filed issues the duplicate scan will read.+ *+ * `gh issue list --limit` paginates internally, so GitHub reaches this in one+ * call; GitLab and JIRA page up to it. A tracker that has this many+ * goal-fidelity issues on one repo is not a backlog, it is a runaway — and the+ * scan says so (below) rather than reading a truncated page as "nothing filed".+ */+const SCAN_LIMIT = 1_000;/*** The last thing that happens to a title/body before a tracker sees it.@@ -143,10 +152,11 @@ const resolveForgeContext = (app, tracker) => resolveForgeExecOptions(*/async function listFiledIssues({ app, target, tracker, exec }) {if (tracker === 'github') {+ // `gh issue list --limit N` pages internally up to N, so one call suffices.const raw = await execGh(['issue', 'list', '--repo', target.repoSpec,'--label', GOAL_FIDELITY_ISSUE_LABEL, '--state', 'all',- '--limit', String(PAGE_LIMIT), '--json', 'number,title,body,url',+ '--limit', String(SCAN_LIMIT), '--json', 'number,title,body,url',], undefined, { cwd: exec.cwd, env: exec.env }).catch((err) => {console.error(`❌ goal-fidelity follow-up: gh issue list failed for ${target.repoSpec}: ${err.message}`);return null;@@ -156,18 +166,27 @@ async function listFiledIssues({ app, target, tracker, exec }) {}if (tracker === 'gitlab') {- // `--all` is every STATE, not every page — the page cap rides separately.- const { rows } = await execGlabJson(- ['issue', 'list', '--label', GOAL_FIDELITY_ISSUE_LABEL, '--all', '--per-page', String(PAGE_LIMIT)],- app.repoPath,- );- if (!Array.isArray(rows)) return null;- return rows.map((row) => ({- number: row?.iid ?? null,- title: row?.title || '',- body: row?.description || '',- url: row?.web_url || '',- }));+ // `--all` is every STATE, not every page — glab caps a page at 100, so the+ // pages are walked until one comes back short. Without the walk, the 101st+ // goal-fidelity issue pushes an older fingerprint off the only page read and+ // the scheduled task re-files it every cadence.+ const all = [];+ for (let page = 1; all.length < SCAN_LIMIT; page += 1) {+ const { rows } = await execGlabJson(+ ['issue', 'list', '--label', GOAL_FIDELITY_ISSUE_LABEL, '--all',+ '--per-page', String(PAGE_LIMIT), '--page', String(page)],+ app.repoPath,+ );+ if (!Array.isArray(rows)) return null;+ all.push(...rows.map((row) => ({+ number: row?.iid ?? null,+ title: row?.title || '',+ body: row?.description || '',+ url: row?.web_url || '',+ })));+ if (rows.length < PAGE_LIMIT) break;+ }+ return all;}// JIRA. The project is scoped explicitly — a label match across every project@@ -180,7 +199,7 @@ async function listFiledIssues({ app, target, tracker, exec }) {const jql = `project = "${escapeJql(app.jira.projectKey)}" AND labels = "${escapeJql(GOAL_FIDELITY_ISSUE_LABEL)}"`;const rows = await searchIssues(app.jira.instanceId, jql, {fields: 'summary,description,status',- maxResults: PAGE_LIMIT,+ maxResults: SCAN_LIMIT,}).catch((err) => {console.error(`❌ goal-fidelity follow-up: JIRA issue search failed for ${app.jira.projectKey}: ${err.message}`);return null;@@ -303,6 +322,13 @@ async function fileFollowUpIssue({ task, review, fingerprint }) {if (!existing) return { issue: null, error: `could not read the ${tracker} issue list to check for duplicates; nothing was filed` };const duplicate = existing.find((issue) => issueMatchesGoalFidelityMarker(issue, fingerprint));if (duplicate) return { issue: { ...duplicate, duplicate: true }, error: null };+ // A scan that came back at the ceiling did not prove ABSENCE — it proved we+ // stopped looking. Filing here is how the 1001st issue re-files the 1st, so+ // this fails closed like every other unreadable-tracker path. Reaching this+ // at all means something upstream is filing without bound; say so.+ if (existing.length >= SCAN_LIMIT) {+ return { issue: null, error: `this repository already carries ${SCAN_LIMIT}+ '${GOAL_FIDELITY_ISSUE_LABEL}' issues, so a duplicate cannot be ruled out; nothing was filed` };+ }const { title, body } = buildGoalFidelityIssue({ task, review, fingerprint });// Scrubbed on the way to the tracker: a filed issue is world-readable the@@ -343,7 +369,15 @@ async function queueFollowUpTask({ task, review, fingerprint, issue }) {context: `Auto-generated from a goal-fidelity ${review?.verdict} verdict`,...(task?.metadata?.app ? { app: task.metadata.app } : {}),});- return filed?.task ? { ...filed.task, approvalRequired: filed.approvalRequired === true } : null;+ if (!filed?.task) return { task: null, loopReason: filed?.loopReason || null };+ return {+ task: filed.task,+ approvalRequired: filed.approvalRequired === true,+ // A duplicate fold is addTask's signal that an open task already tracks+ // this cause — a usable outcome, not a failure.+ duplicate: filed.task.duplicate === true,+ loopReason: filed.loopReason || null,+ };}/**@@ -383,8 +417,21 @@ export async function runGoalFidelityFollowUp({ agentId, task, review }) {console.error(`❌ goal-fidelity follow-up: could not queue a task for ${agentId}: ${err.message}`);return null;});- result.task = queued;- if (!queued) result.taskError = 'the follow-up task could not be queued';+ result.task = queued?.task+ ? {+ id: queued.task.id,+ approvalRequired: queued.approvalRequired === true,+ duplicate: queued.duplicate === true,+ ...(queued.loopReason ? { loopReason: queued.loopReason } : {}),+ }+ : null;+ // Name the loop policy's own reason when it has one: "could not be queued"+ // is the least actionable thing we could say about a deliberate suppression.+ if (!result.task) {+ result.taskError = queued?.loopReason+ ? `the follow-up task was suppressed (${queued.loopReason})`+ : 'the follow-up task could not be queued';+ }}return result;diff --git a/server/services/goalFidelityFollowUp.test.js b/server/services/goalFidelityFollowUp.test.jsindex 80917ed82a..1a043fa326 100644--- a/server/services/goalFidelityFollowUp.test.js+++ b/server/services/goalFidelityFollowUp.test.js@@ -176,6 +176,19 @@ describe('runGoalFidelityFollowUp — GitHub', () => {expect(execGh).toHaveBeenCalledTimes(1);});+// A scan that came back at the ceiling proves we stopped looking, not that+ // nothing is filed — so it fails closed like every other unreadable tracker.+ it('refuses to file when the scan hit its ceiling without matching', async () => {+ settings({ fileIssue: true });+ execGh.mockResolvedValueOnce(ghRows(+ Array.from({ length: 1000 }, (_, i) => ({ number: i + 1, title: 't', body: 'other', url: 'u' })),+ ));+ const result = await run();+ expect(result.issue).toBeNull();+ expect(result.issueError).toMatch(/duplicate cannot be ruled out/);+ expect(execGh).toHaveBeenCalledTimes(1);+ });+it('refuses to file when the forge is unreachable, before reading or creating anything', async () => {settings({ fileIssue: true });ensureForgeReachable.mockResolvedValue({ ok: false, status: 'offline' });@@ -247,6 +260,30 @@ describe('runGoalFidelityFollowUp — GitLab', () => {expect(execGlab).not.toHaveBeenCalled();});+// Once more goal-fidelity issues exist than one page holds, an older+ // fingerprint falls off the only page read and the schedule re-files it every+ // cadence — the same silent-duplicate shape the unfiltered listing had.+ it('walks every page, so an issue past the first page still dedupes', async () => {+ settings({ fileIssue: true });+ const filler = Array.from({ length: 100 }, (_, i) => ({ iid: i + 1, title: 't', description: 'other', web_url: 'u' }));+ execGlabJson+ .mockResolvedValueOnce({ rows: filler, reason: 'ok' })+ .mockResolvedValueOnce({ rows: [{ iid: 200, title: 't', description: `x ${MARKER}`, web_url: 'u200' }], reason: 'ok' });+ const result = await run();+ expect(result.issue).toMatchObject({ number: 200, duplicate: true });+ expect(execGlabJson).toHaveBeenCalledTimes(2);+ expect(execGlabJson.mock.calls[1][0]).toContain('2'); // --page 2+ expect(execGlab).not.toHaveBeenCalled();+ });++ it('stops paging as soon as a page comes back short', async () => {+ settings({ fileIssue: true });+ execGlabJson.mockResolvedValue({ rows: [{ iid: 1, title: 't', description: 'other', web_url: 'u' }], reason: 'ok' });+ execGlab.mockResolvedValueOnce('').mockResolvedValueOnce('https://gitlab.com/acme/comics/-/issues/9');+ await run();+ expect(execGlabJson).toHaveBeenCalledTimes(1);+ });+it('refuses to file when glab could not answer', async () => {settings({ fileIssue: true });execGlabJson.mockResolvedValue({ rows: null, reason: 'cli-failed' });@@ -392,6 +429,25 @@ describe('runGoalFidelityFollowUp — the queued task', () => {expect(result.task).toMatchObject({ id: 'cos-9' });});+// "could not be queued" is the least actionable thing to say about a+ // deliberate suppression; the loop policy's own reason is the useful part.+ it('names the loop policy reason when the queue was suppressed', async () => {+ settings({ queueTask: true });+ fileInvestigationTask.mockResolvedValue({ task: null, loopReason: 'failure-storm' });+ const result = await run();+ expect(result.task).toBeNull();+ expect(result.taskError).toContain('failure-storm');+ });++ // The card reads this to decide what to call the task and whether to still+ // offer the manual fallback, so a held task must not read as queued.+ it('reports a folded duplicate distinctly from a fresh queue', async () => {+ settings({ queueTask: true });+ fileInvestigationTask.mockResolvedValue({ task: { id: 'cos-9', duplicate: true }, approvalRequired: false });+ const result = await run();+ expect(result.task).toMatchObject({ id: 'cos-9', duplicate: true, approvalRequired: false });+ });+it('reports a suppressed queue rather than silently returning nothing', async () => {settings({ queueTask: true });fileInvestigationTask.mockResolvedValue({ task: null });