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: report accurate Persistent Mind issue lookup completeness and keep rows within budget (#10513)
[._.]/ Adam Eivyb41d46a166dc
diff --git a/docs/API_TOOL_CONTRACT.md b/docs/API_TOOL_CONTRACT.mdindex 12f120c528..4a3996d9cb 100644--- a/docs/API_TOOL_CONTRACT.md+++ b/docs/API_TOOL_CONTRACT.md@@ -172,7 +172,17 @@ resolved work tracker is GitHub or GitLab. `issues.file` requires bothdispatch axes (`model`, `effort`), applies the `persistent-mind` and`planner:<model>` attribution labels, accepts only a closed category-labelvocabulary, and refuses to file when the tracker could not be read — an-unreadable tracker never reads as an empty backlog. Editing, closing,+unreadable tracker never reads as an empty backlog. `issues.list` returns open+issues only, with a local case-insensitive substring `search` and an exact+`label` filter, plus additive completeness fields: `fetchedCount`,+`matchedCount`, `returnedCount`, `complete`, `truncated`, and+`truncationReasons` (`source-limit`, `body-clipped`, `row-limit`,+`response-budget`). `totalOpen` is the exact open count, or `null` when the+forge page was capped (200 GitHub / 100 GitLab) and so cannot certify a total.+Rows are fitted under ~3,500 characters (previews shrink first, then trailing+rows drop, never below one). Only `complete: true` with zero matches is a+conclusive negative for that scope; for a duplicate check beyond it, use the+forge CLI in the app repository with all-state search and pagination. Editing, closing,commenting on, assigning, and relabeling an existing issue are out of scope.### Saved read recipesdiff --git a/server/services/appIssues.js b/server/services/appIssues.jsindex 18000844dc..72c29f40fa 100644--- a/server/services/appIssues.js+++ b/server/services/appIssues.js@@ -149,8 +149,19 @@ function buildGitlabLabelMap(labelRows) {* a CLI that answered with zero rows is the definitive `no-open-issues`, never* conflated with a read we couldn't make.*/-function toIssueResult(rows, normalize) {- return { issues: rows.map(normalize), reason: rows.length ? 'ok' : 'no-open-issues', transient: false };+function toIssueResult(rows, normalize, pageLimit) {+ const issues = rows.map(normalize);+ return {+ issues,+ reason: rows.length ? 'ok' : 'no-open-issues',+ transient: false,+ // A full page is conservatively incomplete: neither CLI reports whether more+ // rows existed, so only a page shorter than the cap proves exhaustion.+ enumeration: {+ capped: rows.length >= pageLimit,+ bodiesClipped: issues.some((issue) => issue.body.length > BODY_MAX_CHARS),+ },+ };}/**@@ -187,7 +198,7 @@ async function fetchGithubIssues(repoSpec, apiHost, { repoPath = null, forgeAccoremedy: 'run `gh issue list` in the repo to see what gh reports',};}- return toIssueResult(rows, normalizeGithubIssue);+ return toIssueResult(rows, normalizeGithubIssue, GH_LIST_LIMIT);}/**@@ -223,7 +234,7 @@ async function fetchGitlabIssues(repoPath) {// `color: null` and the issue list is returned untouched.const labelLookup = await execGlabJson(['label', 'list', '--per-page', String(GL_PER_PAGE)], repoPath);const labelMap = labelLookup.rows ? buildGitlabLabelMap(labelLookup.rows) : null;- return toIssueResult(rows, (issue) => normalizeGitlabIssue(issue, labelMap));+ return toIssueResult(rows, (issue) => normalizeGitlabIssue(issue, labelMap), GL_PER_PAGE);}/**@@ -276,6 +287,7 @@ export async function listAppIssues(app) {tracker,fullName: target.fullName,issues: result.issues,+ enumeration: result.enumeration || null,reason: result.reason,transient: result.transient,// Headline + remedy ride WITH the reason, so the sentence and the state itdiff --git a/server/services/appIssues.test.js b/server/services/appIssues.test.jsindex 30185bb1fa..9a30e18d2e 100644--- a/server/services/appIssues.test.js+++ b/server/services/appIssues.test.js@@ -149,6 +149,14 @@ describe('listAppIssues — GitHub', () => {expect(result.issues[0].body).toMatch(/truncated/);});+ it('flags a full capped page and clipped bodies so a lookup cannot certify a negative', async () => {+ const rows = Array.from({ length: 200 }, (_, i) => ({ number: i + 1, title: 't', body: i === 0 ? 'x'.repeat(9000) : '', labels: [], assignees: [] }));+ execGh.mockResolvedValue(JSON.stringify(rows));+ expect((await listAppIssues(APP)).enumeration).toEqual({ capped: true, bodiesClipped: true });+ execGh.mockResolvedValue(JSON.stringify(rows.slice(1, 5)));+ expect((await listAppIssues(APP)).enumeration).toEqual({ capped: false, bodiesClipped: false });+ });+it('passes the app-pinned forge account token and repo cwd to gh and reachability check', async () => {resolveForgeForRepoMock.mockResolvedValue({cli: 'gh',diff --git a/server/services/persistentMindIssueCapability.js b/server/services/persistentMindIssueCapability.jsindex f7ea448855..230d511b83 100644--- a/server/services/persistentMindIssueCapability.js+++ b/server/services/persistentMindIssueCapability.js@@ -68,7 +68,7 @@ Issue filing access is ON, but no authorized managed app currently resolves to areturn `# Issue tracker capabilityIssue filing access is ON. Filing an issue is the PREFERRED way to queue concrete work: an issue is durable, a human can read and re-scope it, and a coding agent can claim it later even on a machine that has none attached right now. Prefer it over describing work only in conversation, and use it instead of a CoS task whenever you are not the one dispatching the work.-Read before you write. Call issues.list for the target app first and skip anything already tracked; duplicates are refused on an exact title match, but a near-duplicate still wastes the backlog.+Read before you write. Call issues.list for the target app first and skip anything already tracked; duplicates are refused on an exact title match, but a near-duplicate still wastes the backlog. Only a result with complete: true and zero matches shows nothing matching among OPEN issues; a truncated result (see truncationReasons) or a null totalOpen proves nothing, and closed issues are never listed.File with issues.file. Write the body so someone can pick it up cold: what is wrong or missing, where in the repo, why it matters now, and the chosen fix. Do not file speculative or future-only refactors.@@ -103,7 +103,47 @@ const resolveTarget = async (appId) => {return { app, root };};-/** Open issues on the app's tracker, projected down to what a prompt can use. */+// Headroom under the adapter's 4,000-char tool-result ceiling (see+// persistentMindAdapter.boundedToolResult), so the structured rows survive intact.+const LIST_RESULT_BUDGET_CHARS = 3_500;+const LIST_TITLE_CHARS = 120;+// Progressively leaner row shapes; previews go first, then optional detail.+const LIST_ROW_DETAIL_LEVELS = [+ { preview: PERSISTENT_MIND_ISSUE_LIMITS.bodyPreviewChars, detail: true },+ { preview: 200, detail: true },+ { preview: 0, detail: true },+ { preview: 0, detail: false },+];++const projectIssueRow = (issue, { preview, detail }) => ({+ number: issue.number,+ title: String(issue.title || '').slice(0, LIST_TITLE_CHARS),+ url: issue.url,+ ...(detail ? { labels: issue.labels.map((label) => label.name), assignees: issue.assignees, updatedAt: issue.updatedAt } : {}),+ ...(preview ? { bodyPreview: String(issue.body || '').slice(0, preview) } : {}),+});++/** Fit rows under the budget: shrink detail first, then drop trailing rows (never to zero). */+const fitIssueRows = (matches, envelope) => {+ const size = (rows) => JSON.stringify({ ...envelope, issues: rows }).length;+ for (const level of LIST_ROW_DETAIL_LEVELS) {+ const rows = matches.map((issue) => projectIssueRow(issue, level));+ if (size(rows) <= LIST_RESULT_BUDGET_CHARS) return rows;+ }+ const lean = matches.map((issue) => projectIssueRow(issue, LIST_ROW_DETAIL_LEVELS.at(-1)));+ while (lean.length > 1 && size(lean) > LIST_RESULT_BUDGET_CHARS) lean.pop();+ return lean;+};++/**+ * Open issues on the app's tracker, projected down to what a prompt can use.+ *+ * Completeness is reported explicitly so a conclusive negative is never inferred+ * from a partial read: `complete` is true only when the whole open backlog was+ * enumerated, every body that was searched was whole, and no matching row was+ * omitted. `totalOpen` is the exact open count, or null when the forge page was+ * capped (`fetchedCount` is then only the page size).+ */export async function listPersistentMindIssues(args) {const { app, error } = await resolveTarget(args.appId);if (error) return { ok: false, error };@@ -113,29 +153,40 @@ export async function listPersistentMindIssues(args) {}const search = args.search ? args.search.toLowerCase() : null;const limit = args.limit || PERSISTENT_MIND_ISSUE_LIMITS.defaultListLimit;- const issues = result.issues+ const matches = result.issues.filter((issue) => !args.label || issue.labels.some((label) => label.name === args.label))- .filter((issue) => !search || `${issue.title}\n${issue.body}`.toLowerCase().includes(search))- .slice(0, limit)- .map((issue) => ({- number: issue.number,- title: issue.title,- url: issue.url,- labels: issue.labels.map((label) => label.name),- assignees: issue.assignees,- updatedAt: issue.updatedAt,- bodyPreview: String(issue.body || '').slice(0, PERSISTENT_MIND_ISSUE_LIMITS.bodyPreviewChars),- }));- return {+ .filter((issue) => !search || `${issue.title}\n${issue.body}`.toLowerCase().includes(search));+ const limited = matches.slice(0, limit);++ const fetchedCount = result.issues.length;+ const sourceCapped = Boolean(result.enumeration?.capped);+ const envelope = {ok: true,appId: args.appId,forge: app.forge,repository: result.fullName,+ totalOpen: sourceCapped ? null : fetchedCount,+ fetchedCount,+ matchedCount: matches.length,+ returnedCount: limited.length,+ complete: true,+ truncated: false,+ truncationReasons: ['source-limit', 'body-clipped', 'row-limit', 'response-budget'],+ };+ const issues = fitIssueRows(limited, envelope);++ const reasons = [];+ if (sourceCapped) reasons.push('source-limit');+ if (search && result.enumeration?.bodiesClipped) reasons.push('body-clipped');+ if (matches.length > limited.length) reasons.push('row-limit');+ if (limited.length > issues.length) reasons.push('response-budget');+ return {+ ...envelope,issues,- // The tracker's real open count, so a truncated page never reads as the- // whole backlog when the mind checks for an existing item.- totalOpen: result.issues.length,- truncated: result.issues.length > issues.length,+ returnedCount: issues.length,+ complete: reasons.length === 0,+ truncated: reasons.length > 0,+ truncationReasons: reasons,};}diff --git a/server/services/persistentMindIssueCapability.test.js b/server/services/persistentMindIssueCapability.test.jsindex 4974ef42ac..1917022561 100644--- a/server/services/persistentMindIssueCapability.test.js+++ b/server/services/persistentMindIssueCapability.test.js@@ -66,7 +66,7 @@ const openIssue = (overrides = {}) => ({...overrides,});-const okList = (issues) => ({ issues, reason: 'ok', transient: false, fullName: 'example/demo' });+const okList = (issues, enumeration = { capped: false, bodiesClipped: false }) => ({ issues, enumeration, reason: 'ok', transient: false, fullName: 'example/demo' });const fileRequest = (overrides = {}) => ({appId: 'demo-app', title: 'Add a retry to the sync poller', body: 'Body prose.',@@ -198,7 +198,38 @@ describe('persistent mind issue capability', () => {expect((await listPersistentMindIssues({ appId: 'demo-app', search: 'POLLER' })).issues.map((i) => i.number)).toEqual([1]);// A page cut short must say so — otherwise a partial read reads as the// whole backlog when the mind checks for an existing item.- expect(await listPersistentMindIssues({ appId: 'demo-app', limit: 1 })).toMatchObject({ truncated: true, totalOpen: 2 });+ expect(await listPersistentMindIssues({ appId: 'demo-app', limit: 1 })).toMatchObject({ truncated: true, totalOpen: 2, complete: false, truncationReasons: ['row-limit'], matchedCount: 2, returnedCount: 1 });+ });++ describe('lookup completeness', () => {+ const fourteen = () => Array.from({ length: 14 }, (_, i) => openIssue({+ number: i + 1, title: `Synthetic issue ${i + 1}`, body: 'x'.repeat(600), url: `https://github.com/example/demo/issues/${i + 1}`,+ }));++ it('reports a fully enumerated zero-match search as complete, not truncated', async () => {+ mocks.listAppIssues.mockResolvedValue(okList(fourteen()));+ expect(await listPersistentMindIssues({ appId: 'demo-app', search: 'no-such-synthetic-term' })).toMatchObject({+ issues: [], totalOpen: 14, matchedCount: 0, returnedCount: 0, complete: true, truncated: false, truncationReasons: [],+ });+ });++ it('fits 14 long-bodied rows under the result budget with identities kept', async () => {+ mocks.listAppIssues.mockResolvedValue(okList(fourteen()));+ const result = await listPersistentMindIssues({ appId: 'demo-app' });+ expect(JSON.stringify(result).length).toBeLessThanOrEqual(3_500);+ expect(result.issues.length).toBeGreaterThan(0);+ expect(result.issues[0]).toMatchObject({ number: 1, url: expect.stringContaining('/issues/1') });+ expect(result.returnedCount).toBe(result.issues.length);+ if (result.issues.length < 14) expect(result).toMatchObject({ complete: false, truncationReasons: ['response-budget'] });+ });++ it('never certifies a capped page or clipped bodies as a conclusive negative', async () => {+ mocks.listAppIssues.mockResolvedValue(okList(fourteen(), { capped: true, bodiesClipped: true }));+ expect(await listPersistentMindIssues({ appId: 'demo-app', search: 'no-such-synthetic-term' })).toMatchObject({+ issues: [], totalOpen: null, fetchedCount: 14, complete: false, truncated: true,+ truncationReasons: ['source-limit', 'body-clipped'],+ });+ });});it('surfaces an unreadable tracker as a failed read, never as an empty backlog', async () => {