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: don't cite an empty plannedWork block, and compare the raw merge rate (#2698)
[._.]/ Adam Eivyd9f4664e2d80
diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.js b/server/services/autonomousJobs/layeredIntelligenceHooks.jsindex 0181067dc4..afae5ad3cf 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.js@@ -52,7 +52,8 @@ import {fileProposalToJira,resolveJiraBlockKey,applyJiraBlockingLabel,- computeOutcomesReport+ computeOutcomesReport,+ hasPlannedWorkListing} from '../layeredIntelligence.js'import { recordFiledProposal, listOutcomes, reconcileOutcomes } from '../layeredIntelligenceOutcomes.js'@@ -315,11 +316,13 @@ export async function buildTaskInput({ app } = {}) {if (!trackerReadFailed) await reconcileOutcomes({ appId: app.id, existingIssues })const outcomes = await listOutcomes({ appId: app.id })// The low-merge-rate warning cites the plannedWork block by name — only let it- // do that when one was actually gathered (the source is per-app-toggleable and- // yields nothing on an unresolvable tracker).+ // do that when a real BACKLOG LISTING was gathered. The source is+ // per-app-toggleable, yields nothing on an unresolvable tracker, and renders a+ // sentinel (not a listing) when the tracker is empty or unreadable — none of+ // which are something the reasoner can go review.outcomesReport = computeOutcomesReport({outcomes,- hasPlannedWork: typeof sources.plannedWork === 'string' && !!sources.plannedWork.trim()+ hasPlannedWork: hasPlannedWorkListing(sources.plannedWork)})}diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js b/server/services/autonomousJobs/layeredIntelligenceHooks.test.jsindex 85d8f0e2a4..0c82a72960 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.test.js@@ -55,7 +55,11 @@ vi.mock('../layeredIntelligence.js', () => ({fileProposalToJira: vi.fn().mockResolvedValue({ success: true, key: 'PROJ-1' }),resolveJiraBlockKey: vi.fn(() => null),applyJiraBlockingLabel: vi.fn().mockResolvedValue({ success: true }),- computeOutcomesReport: vi.fn(() => '')+ computeOutcomesReport: vi.fn(() => ''),+ // The predicate's own semantics (listing vs. either sentinel) are unit-tested in+ // layeredIntelligence.test.js; here it's a spy so the hook's WIRING can be+ // asserted — that the gathered plannedWork string is what gets classified.+ hasPlannedWorkListing: vi.fn((s) => typeof s === 'string' && !!s.trim())}));// Outcome-store I/O (#2428) — spies so the hook's feedback-loop wiring can be@@ -244,16 +248,19 @@ describe('buildTaskInput', () => {}));});- it('tells computeOutcomesReport whether a plannedWork block exists to cite (#2698)', async () => {+ it('classifies the gathered plannedWork string and tells computeOutcomesReport (#2698)', async () => {li.getEffectiveConfig.mockReturnValue({ providerId: 'ollama', model: 'qwen', allowedScopes: ['app-improvement'], sources: { outcomes: true } });li.gatherSources.mockResolvedValue({ goals: 'g', plannedWork: '1 item(s):\n- #3 Ship X' });+ li.hasPlannedWorkListing.mockReturnValue(true);await buildTaskInput({ app: APP });+ // The gathered string — not some other value — is what gets classified.+ expect(li.hasPlannedWorkListing).toHaveBeenCalledWith('1 item(s):\n- #3 Ship X');expect(li.computeOutcomesReport).toHaveBeenCalledWith(expect.objectContaining({ hasPlannedWork: true }));- // Source off / unresolvable tracker → the warning must not cite a block the- // prompt doesn't contain.+ // A sentinel (empty/unreadable tracker) or an absent source is NOT a listing:+ // the warning must not tell the reasoner to go review a backlog that isn't there.li.computeOutcomesReport.mockClear();- li.gatherSources.mockResolvedValue({ goals: 'g' });+ li.hasPlannedWorkListing.mockReturnValue(false);await buildTaskInput({ app: APP });expect(li.computeOutcomesReport).toHaveBeenCalledWith(expect.objectContaining({ hasPlannedWork: false }));});diff --git a/server/services/layeredIntelligence.js b/server/services/layeredIntelligence.jsindex 632ab883ca..2cb295abbb 100644--- a/server/services/layeredIntelligence.js+++ b/server/services/layeredIntelligence.js@@ -63,6 +63,10 @@ export const PLANNED_WORK_GUIDANCE = 'Cross-reference your proposal against the// is legible to the reasoner as a real answer rather than a missing source.export const PLANNED_WORK_NONE = 'No actively-planned work is currently tracked for this app. (The tracker was read successfully — this is a real "nothing is planned", not a failed read.)';+// Stable opening of the failed-read marker, so `hasPlannedWorkListing` can tell a+// sentinel from a real backlog listing without re-deriving the whole sentence.+export const PLANNED_WORK_UNAVAILABLE_PREFIX = 'Planned work could NOT be read';+// Jira labels can't contain spaces, and a ':' is unsafe on some Jira versions,// so the Jira pause label swaps the ':' for a '-'. The base LI_LABEL is already// Jira-safe (kebab, no colon) and is reused verbatim across all trackers.@@ -545,15 +549,18 @@ export function computeOutcomesReport({ outcomes = [], hasPlannedWork = false }// alarming an app whose first proposal is simply still in flight. The sample// floor is the same idea one step further out: 0-of-1 is not evidence of a rate.const resolved = merged + rejected + abandoned;- const resolvedMergeRate = resolved > 0 ? Math.round((merged / resolved) * 100) : null;+ // Compare the RAW ratio and round only for display: rounding first would let+ // 10-of-51 (19.6%) round up to 20 and suppress a warning the threshold says+ // should fire.+ const rawMergeRate = resolved > 0 ? (merged / resolved) * 100 : null;const lowMergeWarning = (- resolvedMergeRate !== null+ rawMergeRate !== null&& resolved >= LOW_MERGE_RATE_MIN_SAMPLE- && resolvedMergeRate < LOW_MERGE_RATE_THRESHOLD+ && rawMergeRate < LOW_MERGE_RATE_THRESHOLD)? ['',- `WARNING: your merge rate is critically low — only ${merged} of ${resolved} resolved proposals (${resolvedMergeRate}%) were merged.`,+ `WARNING: your merge rate is critically low — only ${merged} of ${resolved} resolved proposals (${Math.round(rawMergeRate)}%) were merged.`,// Only point at the plannedWork block when one was actually gathered — the// source is per-app-toggleable and yields nothing on an unresolvable// tracker, and citing a section that isn't in the prompt is just noise.@@ -691,7 +698,23 @@ function runCli(cmd, args, options = {}) {* CLAUDE.md exists to prevent.*/export function plannedWorkUnavailable(why) {- return `Planned work could NOT be read (${why}). Do NOT treat this as "nothing is planned" — this app may well have a committed backlog that simply could not be listed this run. Be conservative: prefer proposal: null over filing work that might already be in scope.`;+ return `${PLANNED_WORK_UNAVAILABLE_PREFIX} (${why}). Do NOT treat this as "nothing is planned" — this app may well have a committed backlog that simply could not be listed this run. Be conservative: prefer proposal: null over filing work that might already be in scope.`;+}++/**+ * Whether a gathered plannedWork string is an actual LISTING of committed work —+ * i.e. something the reasoner can be told to go read — as opposed to one of the+ * two sentinels ("nothing is planned" / "could not be read"). Both sentinels are+ * meaningful in the prompt and still render, but neither is a backlog: telling+ * the reasoner its proposals "may be overlapping with committed work — review the+ * plannedWork source above" directly beneath a block stating no planned work+ * exists is a contradiction that just biases it toward filing nothing.+ */+export function hasPlannedWorkListing(plannedWork) {+ if (typeof plannedWork !== 'string') return false;+ const text = plannedWork.trim();+ if (!text || text === PLANNED_WORK_NONE) return false;+ return !text.startsWith(PLANNED_WORK_UNAVAILABLE_PREFIX);}/**diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.jsindex 5357c02ee2..c738941276 100644--- a/server/services/layeredIntelligence.test.js+++ b/server/services/layeredIntelligence.test.js@@ -66,6 +66,8 @@ import {PLANNED_WORK_MAX_ITEMS,PLANNED_WORK_NONE,PLANNED_WORK_GUIDANCE,+ PLANNED_WORK_UNAVAILABLE_PREFIX,+ hasPlannedWorkListing,LOW_MERGE_RATE_THRESHOLD,LOW_MERGE_RATE_MIN_SAMPLE} from './layeredIntelligence.js';@@ -1441,6 +1443,31 @@ describe('plannedWorkUnavailable', () => {});});+describe('hasPlannedWorkListing', () => {+ it('is true only for a real backlog listing', () => {+ expect(hasPlannedWorkListing('2 item(s) of actively-planned work:\n- #3 Ship X')).toBe(true);+ });++ it('is false for BOTH sentinels — neither is a backlog to go review', () => {+ // "nothing is planned" and "could not be read" both render in the prompt and+ // both mean something, but telling the reasoner "review the plannedWork source+ // — you may be overlapping committed work" under either is a contradiction.+ expect(hasPlannedWorkListing(PLANNED_WORK_NONE)).toBe(false);+ expect(hasPlannedWorkListing(plannedWorkUnavailable('the gh issue list failed'))).toBe(false);+ });++ it('is false for an absent / blank / non-string source', () => {+ expect(hasPlannedWorkListing(undefined)).toBe(false);+ expect(hasPlannedWorkListing(null)).toBe(false);+ expect(hasPlannedWorkListing(' ')).toBe(false);+ expect(hasPlannedWorkListing(['#3'])).toBe(false);+ });++ it('tracks the sentinels through their constructors (no drifting copy of the text)', () => {+ expect(plannedWorkUnavailable('x').startsWith(PLANNED_WORK_UNAVAILABLE_PREFIX)).toBe(true);+ });+});+describe('plannedWorkJql', () => {it('filters to not-Done plan-labeled tickets and orders by priority', () => {const jql = plannedWorkJql('PROJ');@@ -1718,6 +1745,17 @@ describe('computeOutcomesReport low-merge-rate warning (#2698)', () => {expect(LOW_MERGE_RATE_THRESHOLD).toBe(20);});+ it('compares the RAW rate — a sub-threshold rate that rounds up still warns', () => {+ // 10 merged of 51 resolved = 19.6% — genuinely below 20, but rounds to 20.+ // Rounding before the comparison would suppress the warning entirely.+ const report = computeOutcomesReport({+ outcomes: [...Array.from({ length: 10 }, () => filed('merged')), ...rejected(41)]+ });+ expect(report).toContain('WARNING');+ // ...while the DISPLAYED figure is still the friendly rounded one.+ expect(report).toContain('10 of 51 resolved proposals (20%)');+ });+it('does NOT cite a plannedWork block that is not in the prompt', () => {// The source is per-app-toggleable and yields nothing on an unresolvable// tracker — citing a section that isn't there is just noise.