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: stop the LI report claiming nothing was closed unmerged while listing rejections (#2689)
[._.]/ Adam Eivy2531cd74b965
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 17ec5427ac..27d118ba8d 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -18,7 +18,7 @@- [issue-2702] **The Creative Director now shows you what it made.** Project cards on `/creative-director` lead with a preview of the produced media — the final video's poster with a play badge (click the artwork to open the project, the badge to play it inline), a rendered scene, or a produced image from a directive plan — falling back to a tidy "no render yet" placeholder instead of a wall of text. The Overview tab renders the final cut inline instead of showing only a job id, keeping the Media History link alongside it; plans that emit images show the image. Previews respect each project's aspect ratio (16:9 / 9:16 / 1:1), and the grid never downloads a video until you actually press play.-- [issue-2689] **Layered Intelligence now diagnoses *why* its proposals were turned down, instead of parroting the tracker back at itself.** When a filed proposal is closed unmerged, it's classified against a fixed vocabulary — duplicate, declined, out of scope, missing context, quality, environment blocker, and more — read from the issue's close reason and its labels, and stored alongside the outcome. The loop's feedback block used to tell it "common rejection reasons: not_planned", which restates the outcome rather than explaining it; it now reads "already tracked elsewhere (2); the user declined it (1)". A proposal closed with nothing to explain it is recorded as an explicit unknown and counted, so "3 of 4 closed with no recorded reason" is reported to the loop as the blind spot it is — never dressed up as a real diagnosis, and never allowed to read as "nothing was ever rejected". Merged proposals never acquire a rejection reason, which matters for Jira- and PLAN.md-backed apps whose trackers report no close reason at all and whose ordinary close *is* a merge. Costs no extra AI calls and no extra tracker reads — every reason is derived from issue data the loop already fetches — and rejection history recorded before this upgrade is re-diagnosed on the next run rather than needing a reset.+- [issue-2689] **Layered Intelligence now diagnoses *why* its proposals were turned down, instead of parroting the tracker back at itself.** When a filed proposal is closed unmerged, it's classified against a fixed vocabulary — duplicate, declined, out of scope, missing context, quality, environment blocker, and more — read from the issue's close reason and its labels, and stored alongside the outcome. The loop's feedback block used to tell it "common rejection reasons: not_planned", which restates the outcome rather than explaining it; it now reads "already tracked elsewhere (2); the user declined it (1)". A proposal closed with nothing to explain it is recorded as an explicit unknown and counted, so "3 of 4 closed with no recorded reason" is reported to the loop as the blind spot it is — never dressed up as a real diagnosis, and never allowed to read as "nothing was ever rejected". Rejections the loop hasn't classified yet are reported as their own separate count rather than being folded in with the ones it examined and couldn't explain, because the two have different remedies. Merged proposals never acquire a rejection reason, which matters for Jira- and PLAN.md-backed apps whose trackers report no close reason at all and whose ordinary close *is* a merge. Costs no extra AI calls and no extra tracker reads — every reason is derived from issue data the loop already fetches — and rejection history recorded before this upgrade is re-diagnosed on the next run rather than needing a reset.- Daily log entries now re-embed into the Chief-of-Staff memory index once you settle (coalesced per day, ~30s after your last edit) instead of on every single save. Autosave means a day's entry is now written every couple of seconds while you type; re-embedding per save would have meant an embedding call per typing pause — and, once a day's log grows past the embedding size budget, an unrequested AI summarization call each time too. Search results are unchanged; the index simply updates when you pause rather than mid-sentence, which also produces a better vector than embedding a half-typed sentence a hundred times. Journals now use the same debounced, coalesced re-embed path every other Brain record type already used.diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.jsindex 19c7099186..264d9c7dee 100644--- a/server/services/layeredIntelligence.test.js+++ b/server/services/layeredIntelligence.test.js@@ -622,12 +622,27 @@ describe('computeOutcomesReport', () => {expect(report).toContain('Why non-merged proposals were closed: nothing has been closed unmerged yet');});+ it('never claims nothing was closed unmerged while reporting rejections (#2689)', () => {+ // A resolved record that reconcile has not classified yet (a pre-taxonomy+ // install, or an issue that fell out of the tracker read) must not make the+ // report contradict its own "Rejected: 2" line two rows above.+ const report = computeOutcomesReport({+ outcomes: [+ { scope: 'app-improvement', outcome: 'rejected' },+ { scope: 'app-improvement', outcome: 'abandoned' }+ ]+ });+ expect(report).toContain('Rejected: 1 (50%)');+ expect(report).not.toContain('nothing has been closed unmerged yet');+ expect(report).toContain('Why non-merged proposals were closed: 2 of 2 not yet classified');+ });+it('reports abandoned distinctly and excludes it from the merged numerator (#2620)', () => {const outcomes = [{ scope: 'app-improvement', outcome: 'merged' },{ scope: 'app-improvement', outcome: 'abandoned' },{ scope: 'app-improvement', outcome: 'abandoned' },- { scope: 'app-improvement', outcome: 'rejected', outcomeReason: 'dup' }+ { scope: 'app-improvement', outcome: 'rejected', rejectionReason: 'duplicate' }];const report = computeOutcomesReport({ outcomes });expect(report).toContain('Abandoned: 2 (50%)');@@ -842,7 +857,7 @@ describe('computeSelfEvalSummary (#2700)', () => {it('rates a well-measured 0% merge rate as HIGH confidence in a bad result, not low', () => {// Confidence rates the EVIDENCE, not the news. A loop with solid evidence that// it is failing should act decisively, not hedge as if it were flying blind.- const outcomes = Array.from({ length: 8 }, () => ({ outcome: 'rejected', outcomeReason: 'NOT_PLANNED' }));+ const outcomes = Array.from({ length: 8 }, () => ({ outcome: 'rejected', rejectionReason: 'user-rejected' }));const report = computeSelfEvalSummary({outcomes,existingIssues: [{ slug: 'a', state: 'open' }],diff --git a/server/services/layeredIntelligenceOutcomes.test.js b/server/services/layeredIntelligenceOutcomes.test.jsindex 0c3c9d7d8e..59aac47408 100644--- a/server/services/layeredIntelligenceOutcomes.test.js+++ b/server/services/layeredIntelligenceOutcomes.test.js@@ -287,6 +287,26 @@ describe('reconcileOutcomes', () => {expect((await rowsBySlug())['mystery'].rejectionReason).toBe('duplicate');});+ it('clears a stale rejection reason when a proposal is reopened and then merged', async () => {+ // rejected → reopened → closed completed. The write side must drop the old+ // diagnosis, not just rely on the sanitizer stripping it on read.+ await recordFiledProposal({ appId: 'app-1', slug: 'revived' }, store);+ await reconcileOutcomes({+ appId: 'app-1',+ existingIssues: [{ slug: 'revived', state: 'closed', stateReason: 'not_planned', closedAt: '2026-07-01T00:00:00Z' }]+ }, store);+ expect((await rowsBySlug())['revived'].rejectionReason).toBe('user-rejected');++ const updated = await reconcileOutcomes({+ appId: 'app-1',+ existingIssues: [{ slug: 'revived', state: 'closed', stateReason: 'completed', closedAt: '2026-07-09T00:00:00Z' }]+ }, store);+ expect(updated).toBe(1);+ const row = (await rowsBySlug())['revived'];+ expect(row.outcome).toBe('merged');+ expect(row.rejectionReason).toBeNull();+ });+it('does not churn a settled record whose classification is unchanged', async () => {await recordFiledProposal({ appId: 'app-1', slug: 's' }, store);const issue = { slug: 's', state: 'closed', stateReason: 'not_planned', closedAt: '2026-07-01T00:00:00Z' };diff --git a/server/services/layeredIntelligenceRejections.js b/server/services/layeredIntelligenceRejections.jsindex ec67596daf..85a0840290 100644--- a/server/services/layeredIntelligenceRejections.js+++ b/server/services/layeredIntelligenceRejections.js@@ -75,9 +75,15 @@ const REJECTION_REASON_LABELS = {[UNKNOWN_REJECTION_REASON]: 'closed with no recorded reason'};-/** Render one token as prose for the reasoner. Unknown tokens pass through. */+/**+ * Render one token as prose for the reasoner. An unglossed token passes through;+ * a nullish (unclassified) input renders as '' — mapping it onto the sentinel+ * would invert this module's central rule by dressing "not classified" up as+ * "classified, and we found nothing".+ */export function formatRejectionReason(reason) {- return REJECTION_REASON_LABELS[reason] || reason || UNKNOWN_REJECTION_REASON;+ if (!reason) return '';+ return REJECTION_REASON_LABELS[reason] || reason;}// Normalize a tracker token (label name or stateReason) for matching: lowercased,@@ -151,30 +157,40 @@ export function classifyRejection({ outcome = null, stateReason = null, labels =}/**- * Tally rejection reasons across an outcome list.+ * Tally rejection reasons across every non-merged RESOLVED proposal. A pending+ * proposal is awaiting triage, not rejected, and a merged one has nothing to+ * explain — neither is counted.*- * Counts only non-merged RESOLVED records: a pending proposal is awaiting triage,- * not rejected. Records with no stored classification (`null` — merged, or written- * before the taxonomy existed) are counted in neither bucket; they are unclassified- * data, not a measured gap, and folding them into `unknown` would overstate the gap- * this metric exists to track.+ * Returns `{ entries, unknown, unclassified, diagnosed, total }`:+ * - `entries` — `[{ reason, count }]` of REAL diagnoses only, commonest first.+ * - `unknown` — classified as `unknown-reason`: we looked and no signal+ * explained it. A MEASURED gap.+ * - `unclassified` — no valid diagnosis stored at all: written before the taxonomy+ * existed, or reconcile hasn't reached it yet. An UNMEASURED+ * gap — a different fact from `unknown`, with a different+ * remedy (reconcile it vs. enrich the signals).+ * - `diagnosed` — records carrying a real diagnosis (sum of `entries`).+ * - `total` — every non-merged resolved proposal: the full population being+ * diagnosed. `total === 0` means, and only means, "nothing has+ * been closed unmerged".*- * Returns `{ entries, unknown, diagnosed, total }`:- * - `entries` — `[{ reason, count }]` of REAL diagnoses only, commonest first.- * - `unknown` — records classified as `unknown-reason` (the data gap).- * - `diagnosed`— records carrying a real diagnosis (sum of `entries`).- * - `total` — `diagnosed + unknown`, i.e. every classified record.- * `unknown` is kept OUT of `entries` so it can't crowd real diagnoses out of a- * caller's top-N list — it is the measure of missing data, not a finding.+ * The three buckets stay apart for the same reason the record field is three-valued:+ * collapsing them would either fabricate a diagnosis or hide the data gap this+ * metric exists to track. `unknown`/`unclassified` stay OUT of `entries` so they+ * can't crowd real diagnoses out of a caller's top-N list — they measure missing+ * data, they are not findings.*/export function summarizeRejectionReasons(outcomes = []) {const counts = new Map();let unknown = 0;+ let unclassified = 0;for (const o of Array.isArray(outcomes) ? outcomes : []) {if (!o || (o.outcome !== 'rejected' && o.outcome !== 'abandoned')) continue;const reason = o.rejectionReason;if (reason === UNKNOWN_REJECTION_REASON) { unknown += 1; continue; }- if (!REJECTION_REASONS.includes(reason)) continue;+ // Absent OR unrecognized (hand-edited, or a token from a newer version): both+ // mean we hold no valid diagnosis for a proposal that demonstrably didn't merge.+ if (!REJECTION_REASONS.includes(reason)) { unclassified += 1; continue; }counts.set(reason, (counts.get(reason) || 0) + 1);}const entries = [...counts.entries()]@@ -183,26 +199,31 @@ export function summarizeRejectionReasons(outcomes = []) {.sort((a, b) => b[1] - a[1] || REJECTION_REASONS.indexOf(a[0]) - REJECTION_REASONS.indexOf(b[0])).map(([reason, count]) => ({ reason, count }));const diagnosed = entries.reduce((n, e) => n + e.count, 0);- return { entries, unknown, diagnosed, total: diagnosed + unknown };+ return { entries, unknown, unclassified, diagnosed, total: diagnosed + unknown + unclassified };}/*** Render a tally as one prompt line: the commonest `limit` diagnoses, glossed,- * plus the undiagnosed share when there is one.+ * followed by whichever gaps are non-zero.*- * Returns '' when NOTHING is classified, so the caller omits the line rather than- * emitting "rejection reasons: none" — which reads as "nothing was ever rejected"- * when the truth may be "we don't know why anything was".+ * Returns '' ONLY when nothing has been closed unmerged, so a caller may safely read+ * '' as "there is nothing to explain". It must never fall silent merely because the+ * closures are undiagnosed: a report that says "Rejected: 2" and then "nothing has+ * been closed unmerged yet" is a self-contradiction, and staying quiet about a gap+ * is exactly the blindness this taxonomy exists to remove.*/export function formatRejectionReasons(outcomes = [], limit = 3) {- const { entries, unknown, total } = summarizeRejectionReasons(outcomes);+ const { entries, unknown, unclassified, total } = summarizeRejectionReasons(outcomes);if (total === 0) return '';const listed = entries.slice(0, limit).map(({ reason, count }) => `${formatRejectionReason(reason)} (${count})`).join('; ');- // Always name the gap: a run that can only say "3 of 3 closed with no recorded- // reason" is reporting a real, actionable fact about its own blind spot.- const gap = unknown ? `${unknown} of ${total} closed with no recorded reason` : '';- return [listed, gap].filter(Boolean).join(' — ');+ // Name every gap: "3 of 3 closed with no recorded reason" is a real, actionable+ // fact about the loop's own blind spot, and the honest line when it's all we have.+ const gaps = [+ unknown ? `${unknown} of ${total} closed with no recorded reason` : '',+ unclassified ? `${unclassified} of ${total} not yet classified` : ''+ ];+ return [listed, ...gaps].filter(Boolean).join(' — ');}diff --git a/server/services/layeredIntelligenceRejections.test.js b/server/services/layeredIntelligenceRejections.test.jsindex a34dbb104b..b669e6168f 100644--- a/server/services/layeredIntelligenceRejections.test.js+++ b/server/services/layeredIntelligenceRejections.test.js@@ -31,6 +31,14 @@ describe('rejection taxonomy', () => {}expect(formatRejectionReason('some-future-token')).toBe('some-future-token');});++ it('renders a nullish (unclassified) input as empty, NOT as the unknown sentinel', () => {+ // Mapping "not classified" onto "classified, found nothing" would invert the+ // module's central rule at its most-reused helper.+ expect(formatRejectionReason(null)).toBe('');+ expect(formatRejectionReason(undefined)).toBe('');+ expect(formatRejectionReason('')).toBe('');+ });});describe('classifyRejection', () => {@@ -103,20 +111,22 @@ describe('classifyRejection', () => {});describe('summarizeRejectionReasons', () => {- it('counts diagnoses and the unknown gap separately', () => {- const { entries, unknown, diagnosed, total } = summarizeRejectionReasons([+ it('counts diagnoses, the unknown gap, and the unclassified gap separately', () => {+ const { entries, unknown, unclassified, diagnosed, total } = summarizeRejectionReasons([rejected('duplicate'),rejected('duplicate'),rejected('user-rejected'),- rejected(UNKNOWN_REJECTION_REASON)+ rejected(UNKNOWN_REJECTION_REASON),+ rejected(null)]);expect(entries).toEqual([{ reason: 'duplicate', count: 2 },{ reason: 'user-rejected', count: 1 }]);expect(unknown).toBe(1);+ expect(unclassified).toBe(1);expect(diagnosed).toBe(3);- expect(total).toBe(4);+ expect(total).toBe(5);});it('keeps the unknown sentinel out of entries so it cannot crowd out real diagnoses', () => {@@ -139,20 +149,25 @@ describe('summarizeRejectionReasons', () => {expect(unknown).toBe(0);});- it('counts an unclassified (pre-taxonomy) record in NEITHER bucket', () => {- // Reading a null as `unknown` would overstate the very data gap this measures.- const { total, unknown, diagnosed } = summarizeRejectionReasons([+ it('counts a pre-taxonomy record as unclassified, never as unknown', () => {+ // Reading a null as `unknown` would claim we looked and found nothing, when in+ // fact we never looked — overstating the measured gap and hiding the real one.+ const { total, unknown, unclassified, diagnosed } = summarizeRejectionReasons([{ outcome: 'rejected', rejectionReason: null },{ outcome: 'rejected', rejectionReason: 'duplicate' }]);expect(diagnosed).toBe(1);expect(unknown).toBe(0);- expect(total).toBe(1);+ expect(unclassified).toBe(1);+ // The population is every non-merged resolved proposal, diagnosed or not.+ expect(total).toBe(2);});- it('drops an unrecognized stored token rather than counting it', () => {- const { total } = summarizeRejectionReasons([rejected('not-a-real-token')]);- expect(total).toBe(0);+ it('counts an unrecognized stored token as unclassified, not as a diagnosis', () => {+ const { total, unclassified, diagnosed } = summarizeRejectionReasons([rejected('not-a-real-token')]);+ expect(diagnosed).toBe(0);+ expect(unclassified).toBe(1);+ expect(total).toBe(1);});it('orders ties by taxonomy order so output does not depend on record order', () => {@@ -169,10 +184,18 @@ describe('summarizeRejectionReasons', () => {});describe('formatRejectionReasons', () => {- it('returns empty when nothing is classified, so the caller omits the line', () => {- // '' must not become "reasons: none", which reads as "nothing was rejected".+ it('returns empty ONLY when nothing was closed unmerged', () => {expect(formatRejectionReasons([])).toBe('');expect(formatRejectionReasons([{ outcome: 'merged', rejectionReason: null }])).toBe('');+ expect(formatRejectionReasons([{ outcome: null, rejectionReason: null }])).toBe('');+ });++ it('never falls silent on a rejection it simply has not classified yet', () => {+ // The caller reads '' as "nothing to explain" and prints "nothing has been+ // closed unmerged yet". Returning '' here would contradict the "Rejected: 2"+ // line printed directly above it.+ const out = formatRejectionReasons([rejected(null), { outcome: 'abandoned', rejectionReason: null }]);+ expect(out).toBe('2 of 2 not yet classified');});it('renders glossed diagnoses with counts, commonest first', () => {@@ -209,4 +232,17 @@ describe('formatRejectionReasons', () => {expect(out).toContain('1 of 5 closed with no recorded reason');expect(out).not.toContain('quality');});++ it('reports the measured and unmeasured gaps as separate facts', () => {+ // "we looked and found nothing" and "we never looked" have different remedies,+ // so the line must not merge them into one number.+ const out = formatRejectionReasons([+ rejected('duplicate'),+ rejected(UNKNOWN_REJECTION_REASON),+ rejected(null)+ ]);+ expect(out).toBe(+ 'already tracked elsewhere (duplicate) (1) — 1 of 3 closed with no recorded reason — 1 of 3 not yet classified'+ );+ });});