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
feat([issue-2689]): tell the LI reasoner why each recently-closed proposal was rejected
[._.]/ Adam Eivy3cd85ac11bb9
diff --git a/server/services/layeredIntelligence.js b/server/services/layeredIntelligence.jsindex 5e21c86e19..57395f00cb 100644--- a/server/services/layeredIntelligence.js+++ b/server/services/layeredIntelligence.js@@ -30,7 +30,7 @@ import { validateCommand } from '../lib/commandSecurity.js';import { getSettings } from './settings.js';import { createTicket, searchIssues, addLabels, escapeJql } from './jira.js';import { computeWindowedStats, computeEffectiveSuccessRate, extractTaskType } from './taskLearning/store.js';-import { formatRejectionReasons } from './layeredIntelligenceRejections.js';+import { formatRejectionReasons, formatRejectionReason } from './layeredIntelligenceRejections.js';// Tracker labels + slug marker. The slug is the stable dedup key the reasoner// chooses; it is embedded in each filed issue body so a later run (or the@@ -655,24 +655,60 @@ export function computeOutcomesReport({ outcomes = [], hasPlannedWork = false }// against, and past this many the reasoner has the pattern anyway.export const SELF_EVAL_MAX_SUPPRESSED_LISTED = 8;+/**+ * Recover a suppressed issue's normalized dedup slug — the key the reasoner must+ * avoid re-using and the join key onto the outcome store's rejectionReason. Shapes+ * vary by tracker: forge/jira rows carry `{ number, title, body }` (the slug lives+ * in the body marker), while the `plan` filer yields bare `{ slug, state }`.+ * Normalized both ways so the value matches the outcome record's stored slug+ * (`normalizeSlug(slug)` at file time) exactly. Returns null when unrecoverable.+ */+export function suppressedIssueSlug(issue) {+ if (issue?.slug) return normalizeSlug(issue.slug);+ return normalizeSlug(extractSlugFromBody(issue?.body) || extractSlugFromBody(issue?.title));+}++/**+ * Build a `slug → rejectionReason` lookup from reconciled outcome records, so the+ * self-eval "recently closed" line can tell the reasoner not just WHICH proposals+ * to avoid but WHY each was closed — the feedback loop of #2689 (ask #4), closing+ * the loop with the taxonomy #2735 already persists rather than any new signal.+ *+ * Only a RESOLVED non-merged record carries a diagnosis: a merged, unresolved, or+ * still-unclassified (`rejectionReason == null`) record contributes nothing, so the+ * annotation appears only where there is a real failure pattern to learn from.+ * First diagnosed record per slug wins (records arrive newest-filed-first). Pure.+ */+export function rejectionReasonBySlug(outcomes = []) {+ const map = new Map();+ for (const o of Array.isArray(outcomes) ? outcomes : []) {+ if (!o || (o.outcome !== 'rejected' && o.outcome !== 'abandoned') || !o.rejectionReason) continue;+ const slug = normalizeSlug(o.slug);+ if (slug && !map.has(slug)) map.set(slug, o.rejectionReason);+ }+ return map;+}+/*** Identify a suppressed proposal for the prompt: its slug (the actual dedup key the* reasoner must avoid re-using) plus its title for human-readable context. Returns* null when neither is recoverable — an unidentifiable entry is left to the count* rather than rendered as a mystery bullet the reasoner can't act on.*- * Shapes vary by tracker: forge/jira rows carry `{ number, title, body }` (the slug- * lives in the body marker), while the `plan` filer yields bare `{ slug, state }`.+ * When `reasonBySlug` (from rejectionReasonBySlug) holds this slug's diagnosis, it+ * is appended as glossed prose so the reasoner sees the specific failure pattern+ * that sank the earlier proposal (#2689), not merely a slug to route around. An+ * undiagnosed (null) or unmatched slug renders exactly as before.*/-export function describeSuppressedIssue(issue) {- const slug = issue?.slug- ? normalizeSlug(issue.slug)- : (extractSlugFromBody(issue?.body) || extractSlugFromBody(issue?.title));+export function describeSuppressedIssue(issue, reasonBySlug = null) {+ const slug = suppressedIssueSlug(issue);const title = typeof issue?.title === 'string' ? issue.title.trim() : '';if (!slug && !title) return null;const ref = issue?.number ? `#${issue.number} ` : '';- if (!slug) return `${ref}${title}`.trim();- return `${ref}[${slug}]${title ? ` ${title}` : ''}`.trim();+ const reason = slug && reasonBySlug instanceof Map ? reasonBySlug.get(slug) : null;+ const why = reason ? ` — previously closed: ${formatRejectionReason(reason)}` : '';+ if (!slug) return `${ref}${title}${why}`.trim();+ return `${ref}[${slug}]${title ? ` ${title}` : ''}${why}`.trim();}/**@@ -765,8 +801,14 @@ export function computeSelfEvalSummary({// whole run re-proposing something the dedup guard silently drops. Capped so a// long tail can't crowd out the sources it is meant to be reasoning about.if (closedSuppressed.length) {+ // Join each suppressed proposal to its reconciled rejection reason (#2689),+ // so the "do NOT re-propose" line also carries WHY each was closed — a+ // no-extra-cost read of the outcome records selfEval already received. Empty+ // when outcomes weren't gathered this run (`outcomes` not an array), leaving+ // the line exactly as before.+ const reasonBySlug = rejectionReasonBySlug(Array.isArray(outcomes) ? outcomes : []);const named = closedSuppressed- .map(i => describeSuppressedIssue(i))+ .map(i => describeSuppressedIssue(i, reasonBySlug)).filter(Boolean).slice(0, SELF_EVAL_MAX_SUPPRESSED_LISTED);if (named.length) {diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.jsindex 264d9c7dee..50d514c005 100644--- a/server/services/layeredIntelligence.test.js+++ b/server/services/layeredIntelligence.test.js@@ -38,6 +38,8 @@ import {LI_SCHEDULED_TASK_TYPE,SELF_EVAL_MAX_SUPPRESSED_LISTED,describeSuppressedIssue,+ suppressedIssueSlug,+ rejectionReasonBySlug,LI_DEGRADED_SUCCESS_THRESHOLD,LI_DEGRADED_MIN_SAMPLE,PROPOSAL_OUTCOMES,@@ -684,6 +686,49 @@ describe('summarizeOutcomeStats', () => {});});+describe('suppressedIssueSlug + rejectionReasonBySlug (#2689 feedback loop)', () => {+ it('recovers a normalized slug from a forge body marker, a bare plan row, or nothing', () => {+ expect(suppressedIssueSlug({ body: '<!-- lil-slug: Add-Telemetry -->' })).toBe('add-telemetry');+ expect(suppressedIssueSlug({ slug: 'Fix Thing' })).toBe('fix-thing');+ expect(suppressedIssueSlug({ title: 'no marker here' })).toBe(null);+ expect(suppressedIssueSlug({})).toBe(null);+ });++ it('indexes only resolved, diagnosed, non-merged records — merged/unclassified contribute nothing', () => {+ const map = rejectionReasonBySlug([+ { slug: 'a', outcome: 'rejected', rejectionReason: 'scope-mismatch' },+ { slug: 'b', outcome: 'abandoned', rejectionReason: 'unknown-reason' },+ { slug: 'c', outcome: 'merged', rejectionReason: 'scope-mismatch' }, // merged: not a rejection+ { slug: 'd', outcome: 'rejected', rejectionReason: null }, // unclassified: nothing to say+ { slug: 'e', outcome: null, rejectionReason: 'duplicate' } // unresolved+ ]);+ expect(map.get('a')).toBe('scope-mismatch');+ expect(map.get('b')).toBe('unknown-reason');+ expect(map.has('c')).toBe(false);+ expect(map.has('d')).toBe(false);+ expect(map.has('e')).toBe(false);+ });++ it('keeps the first diagnosed record per slug and tolerates non-array input', () => {+ const map = rejectionReasonBySlug([+ { slug: 'dup', outcome: 'rejected', rejectionReason: 'duplicate' },+ { slug: 'dup', outcome: 'rejected', rejectionReason: 'quality-issue' }+ ]);+ expect(map.get('dup')).toBe('duplicate');+ expect(rejectionReasonBySlug(null).size).toBe(0);+ expect(rejectionReasonBySlug(undefined).size).toBe(0);+ });++ it('describeSuppressedIssue appends the glossed reason only when the slug is diagnosed', () => {+ const reasons = new Map([['add-telemetry', 'scope-mismatch']]);+ expect(describeSuppressedIssue({ number: 12, title: 'Add telemetry', body: '<!-- lil-slug: add-telemetry -->' }, reasons))+ .toBe("#12 [add-telemetry] Add telemetry — previously closed: outside the app's scope");+ // Unmatched slug or no lookup → unchanged output (back-compat).+ expect(describeSuppressedIssue({ slug: 'other' }, reasons)).toBe('[other]');+ expect(describeSuppressedIssue({ slug: 'add-telemetry' })).toBe('[add-telemetry]');+ });+});+describe('computeSelfEvalSummary (#2700)', () => {const liMetrics = (over = {}) => ({read: true,@@ -776,6 +821,41 @@ describe('computeSelfEvalSummary (#2700)', () => {expect(report).toContain('[fix-thing]');});+ it('annotates each named suppressed proposal with WHY it was closed (#2689 feedback loop)', () => {+ const now = Date.now();+ const recent = new Date(now - 5 * 24 * 60 * 60 * 1000).toISOString();+ const report = computeSelfEvalSummary({+ // The reconciled outcome store carries the rejection diagnosis per slug.+ outcomes: [+ { appId: 'a', slug: 'add-telemetry', outcome: 'rejected', rejectionReason: 'scope-mismatch' },+ { appId: 'a', slug: 'fix-thing', outcome: 'abandoned', rejectionReason: 'duplicate' }+ ],+ existingIssues: [+ { number: 12, title: 'Add telemetry', body: '<!-- lil-slug: add-telemetry -->', state: 'closed', closedAt: recent },+ { slug: 'fix-thing', state: 'closed' }+ ],+ now+ });+ // The reasoner sees the specific failure pattern, not merely a slug to route around.+ expect(report).toContain("#12 [add-telemetry] Add telemetry — previously closed: outside the app's scope");+ expect(report).toContain('[fix-thing] — previously closed: already tracked elsewhere (duplicate)');+ });++ it('leaves an undiagnosed suppressed proposal unannotated', () => {+ const now = Date.now();+ const recent = new Date(now - 5 * 24 * 60 * 60 * 1000).toISOString();+ const report = computeSelfEvalSummary({+ // No outcomes gathered this run — the line renders exactly as before.+ outcomes: null,+ existingIssues: [+ { number: 12, title: 'Add telemetry', body: '<!-- lil-slug: add-telemetry -->', state: 'closed', closedAt: recent }+ ],+ now+ });+ expect(report).toContain('#12 [add-telemetry] Add telemetry');+ expect(report).not.toContain('previously closed:');+ });+it('caps the named list and counts the remainder', () => {const now = Date.now();const closedAt = new Date(now - 24 * 60 * 60 * 1000).toISOString();