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
address review (claude): stable consensus finding key, total partition, empty-path reconcile
[._.]/ Adam Eivy66c7f4bef713
diff --git a/server/lib/editorial/panelDisagreement.js b/server/lib/editorial/panelDisagreement.jsindex a3ba8ba2a6..d7687562c3 100644--- a/server/lib/editorial/panelDisagreement.js+++ b/server/lib/editorial/panelDisagreement.js@@ -162,8 +162,11 @@ export function minePanelDisagreements(responses, { validIssueNumbers = null, copersonas: [...personaSet],count,};+ // consensus = at/above the routing bar; everything else flagged (by some+ // but not all, OR unanimous-yet-below a custom threshold) is attention —+ // a total fall-through so no flagged concern is silently dropped.if (count >= consensusThreshold) consensus.push(entry);- else if (count < totalPersonas) attention.push(entry);+ else attention.push(entry);}}@@ -192,8 +195,17 @@ export function minePanelDisagreements(responses, { validIssueNumbers = null, co/*** Shape consensus entries into `seedReviewFromFindings` findings. A concern* agreed by every persona is `high`; one merely at/above the consensus bar is- * `medium`. `problem` names the agreeing personas and folds in a short quote from- * each so the triage view shows WHY it was flagged.+ * `medium`.+ *+ * `problem` is kept STABLE across re-convenes — it names only the invariant+ * (question + issue number), NOT the persona set or their verbatim quotes, both+ * of which the LLM re-generates every run. Because `manuscriptReview.findingKey`+ * folds `problem` into the finding's identity (`checkId|issueNumber|anchorQuote|+ * problem`), a volatile `problem` would mint a new key each convene — dismissing+ * the prior finding and re-raising an already-accepted concern as a fresh open+ * one. The volatile detail (who agreed + their quotes) rides in `suggestion`,+ * which is not part of the key, so the triage view still shows WHY it was+ * flagged without destabilizing identity.*/export function consensusToFindings(consensus, responses, { checkId = 'reader-panel.consensus', totalPersonas } = {}) {const list = Array.isArray(responses) ? responses : [];@@ -209,11 +221,13 @@ export function consensusToFindings(consensus, responses, { checkId = 'reader-pa}).filter(Boolean).join(' ');- const lead = `Reader panel (${entry.count}/${denom}: ${names}) agree on "${entry.questionLabel}" at issue #${entry.issueNumber}.`;findings.push({severity: entry.count >= denom ? 'high' : 'medium',category: entry.category,- problem: `${lead}${snippets ? ` ${snippets}` : ''}`.slice(0, PROBLEM_MAX),+ // Stable key-bearing text (question + issue only).+ problem: `Reader panel consensus on "${entry.questionLabel}" at issue #${entry.issueNumber}.`.slice(0, PROBLEM_MAX),+ // Volatile detail — kept out of the finding key.+ suggestion: `${entry.count}/${denom} personas agree (${names}).${snippets ? ` ${snippets}` : ''}`.slice(0, PROBLEM_MAX),issueNumber: entry.issueNumber,checkId,});diff --git a/server/lib/editorial/panelDisagreement.test.js b/server/lib/editorial/panelDisagreement.test.jsindex 28b4f7429b..ad85422f35 100644--- a/server/lib/editorial/panelDisagreement.test.js+++ b/server/lib/editorial/panelDisagreement.test.js@@ -176,8 +176,29 @@ describe('consensusToFindings', () => {expect(f.checkId).toBe('reader-panel.consensus');expect(f.category).toBe('pacing'); // momentum_loss categoryexpect(f.severity).toBe('high'); // 4/4 == all personas+ // problem is the STABLE key-bearing text (question + issue only) — no persona+ // names or verbatim quotes, so the finding key survives a re-convene.expect(f.problem).toContain('#4');- expect(f.problem).toContain('The Editor');+ expect(f.problem).not.toContain('The Editor');+ // volatile detail (who agreed + quotes) rides in suggestion, off the key.+ expect(f.suggestion).toContain('The Editor');+ expect(f.suggestion).toContain('4/4');+ });++ it('keeps problem stable across re-convenes with different persona quotes', () => {+ const run1 = [+ persona('editor', { momentum_loss: [4] }),+ persona('genre-reader', { momentum_loss: [4] }),+ persona('writer', { momentum_loss: [4] }),+ ];+ // Same consensus (issue 4, momentum_loss), but the personas re-worded their answers.+ const run2 = run1.map((r) => ({ ...r, answers: { ...r.answers, momentum_loss: { text: `${r.persona} reworded`, issues: [4] } } }));+ const m1 = minePanelDisagreements(run1, { validIssueNumbers: [4] });+ const m2 = minePanelDisagreements(run2, { validIssueNumbers: [4] });+ const f1 = consensusToFindings(m1.consensus, run1, { totalPersonas: 4 })[0];+ const f2 = consensusToFindings(m2.consensus, run2, { totalPersonas: 4 })[0];+ expect(f1.problem).toBe(f2.problem); // identity-bearing text unchanged+ expect(f1.suggestion).not.toBe(f2.suggestion); // detail differs});it('grades a non-unanimous consensus as medium', () => {diff --git a/server/services/pipeline/readerPanel.js b/server/services/pipeline/readerPanel.jsindex e591fcbf19..c119bc98e5 100644--- a/server/services/pipeline/readerPanel.js+++ b/server/services/pipeline/readerPanel.js@@ -129,6 +129,17 @@ export async function finalizePanel(seriesId, digest, responses, { runId = nullreturn snapshot;}+/**+ * Dismiss any prior reader-panel consensus findings when the panel can't produce+ * a fresh read (no analyzable content). A `fresh`-mode seed with no findings+ * auto-dismisses every open finding of this check id, so removing all content+ * doesn't strand old consensus findings as open (inflating the health score). A+ * no-op when none exist.+ */+export async function reconcileConsensusFindings(seriesId, { runId = null } = {}) {+ await seedReviewFromFindings(seriesId, [], { runId, mode: 'fresh', checkId: CONSENSUS_CHECK_ID });+}+// Re-hash the current issue content to decide whether a stored panel is stale// (the drafts moved since the digest was built). Cheap — issue list + content// only, no series record or scene segmentation (the hash ignores both).diff --git a/server/services/pipeline/readerPanel.test.js b/server/services/pipeline/readerPanel.test.jsnew file mode 100644index 0000000000..b920f76960--- /dev/null+++ b/server/services/pipeline/readerPanel.test.js@@ -0,0 +1,114 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';++// Mock the I/O + cross-service edges so the orchestration logic (seed contract,+// snapshot shape, staleness branch) is testable without a DB or the LLM. The+// pure mining (panelDisagreement.js) is left REAL — it's the logic under test.+const seedReviewFromFindings = vi.fn(async () => ({}));+const atomicWrite = vi.fn(async () => {});+const ensureDir = vi.fn(async () => {});+const tryReadFile = vi.fn(async () => null);+const computeSourceContentHash = vi.fn(async () => 'hash-current');++vi.mock('../../lib/fileUtils.js', () => ({+ PATHS: { data: '/tmp/panel-test-data' },+ atomicWrite: (...a) => atomicWrite(...a),+ ensureDir: (...a) => ensureDir(...a),+ tryReadFile: (...a) => tryReadFile(...a),+ safeJSONParse: (s) => (s == null ? null : JSON.parse(s)),+}));+vi.mock('../../lib/stageRunner.js', () => ({ runStagedLLM: vi.fn() }));+vi.mock('./readerPanelDigest.js', () => ({+ computeSourceContentHash: (...a) => computeSourceContentHash(...a),+ renderDigestText: (d) => JSON.stringify(d),+}));+vi.mock('./manuscriptReview.js', () => ({+ seedReviewFromFindings: (...a) => seedReviewFromFindings(...a),+}));++const { finalizePanel, getReaderPanel, reconcileConsensusFindings } = await import('./readerPanel.js');++// Build a persona response with a given per-question citation set.+function persona(id, cites = {}) {+ const answers = {};+ for (const q of ['momentum_loss', 'earned_ending', 'cut_candidate', 'missing_scene', 'thinnest_character', 'best_scene', 'worst_scene', 'would_recommend', 'haunts_you', 'next_book']) {+ answers[q] = { text: `${id}-${q}`, issues: cites[q] || [] };+ }+ return { persona: id, answers, verdict: `${id} verdict` };+}++const digest = { sourceContentHash: 'hash-run', generatedAt: '2026-07-04T00:00:00Z', issueNumbers: [4], issueCount: 1 };++beforeEach(() => {+ seedReviewFromFindings.mockClear();+ atomicWrite.mockClear();+ ensureDir.mockClear();+ tryReadFile.mockReset().mockResolvedValue(null);+ computeSourceContentHash.mockReset().mockResolvedValue('hash-current');+});++describe('finalizePanel', () => {+ const responses = ['editor', 'genre-reader', 'writer'].map((id) => persona(id, { momentum_loss: [4] }));++ it('seeds ≥3-persona consensus into review in fresh mode under the reader-panel checkId', async () => {+ const snap = await finalizePanel('ser-1', digest, responses, { runId: 'run-1' });+ expect(seedReviewFromFindings).toHaveBeenCalledTimes(1);+ const [seriesId, findings, opts] = seedReviewFromFindings.mock.calls[0];+ expect(seriesId).toBe('ser-1');+ expect(opts).toMatchObject({ mode: 'fresh', checkId: 'reader-panel.consensus', runId: 'run-1' });+ expect(findings).toHaveLength(1);+ expect(findings[0]).toMatchObject({ issueNumber: 4, checkId: 'reader-panel.consensus' });++ // Snapshot persisted with the mined disagreements + provenance.+ expect(atomicWrite).toHaveBeenCalledTimes(1);+ expect(snap.status).toBe('complete');+ expect(snap.seededFindings).toBe(1);+ expect(snap.checkId).toBe('reader-panel.consensus');+ expect(snap.sourceContentHash).toBe('hash-run');+ expect(snap.disagreements.consensus).toHaveLength(1);+ expect(snap.personas).toHaveLength(3);+ });++ it('still reconciles (fresh, zero findings) when the panel found no consensus', async () => {+ const noConsensus = [persona('editor', { momentum_loss: [4] }), persona('writer', {})];+ const snap = await finalizePanel('ser-2', digest, noConsensus, { runId: 'run-2' });+ expect(seedReviewFromFindings).toHaveBeenCalledTimes(1);+ const [, findings, opts] = seedReviewFromFindings.mock.calls[0];+ expect(findings).toEqual([]);+ expect(opts.mode).toBe('fresh');+ expect(snap.seededFindings).toBe(0);+ });+});++describe('reconcileConsensusFindings', () => {+ it('fresh-seeds an empty finding set to dismiss stale consensus findings', async () => {+ await reconcileConsensusFindings('ser-3', { runId: 'run-3' });+ expect(seedReviewFromFindings).toHaveBeenCalledWith('ser-3', [], { runId: 'run-3', mode: 'fresh', checkId: 'reader-panel.consensus' });+ });+});++describe('getReaderPanel / staleness', () => {+ it('returns status none when no panel has been convened', async () => {+ tryReadFile.mockResolvedValue(null);+ const panel = await getReaderPanel('ser-4');+ expect(panel.status).toBe('none');+ expect(computeSourceContentHash).not.toHaveBeenCalled();+ });++ it('flags stale when current content hash differs from the stored hash', async () => {+ tryReadFile.mockResolvedValue(JSON.stringify({ seriesId: 'ser-5', status: 'complete', sourceContentHash: 'hash-old', personas: [] }));+ computeSourceContentHash.mockResolvedValue('hash-new');+ const panel = await getReaderPanel('ser-5');+ expect(panel.stale).toBe(true);+ });++ it('is not stale when the hash matches', async () => {+ tryReadFile.mockResolvedValue(JSON.stringify({ seriesId: 'ser-6', status: 'complete', sourceContentHash: 'hash-x', personas: [] }));+ computeSourceContentHash.mockResolvedValue('hash-x');+ const panel = await getReaderPanel('ser-6');+ expect(panel.stale).toBe(false);+ });++ it('rejects a path-traversal series id', async () => {+ await expect(getReaderPanel('../etc/passwd')).rejects.toThrow(/Invalid series id/);+ });+});diff --git a/server/services/pipeline/readerPanelRunner.js b/server/services/pipeline/readerPanelRunner.jsindex 8b6056000f..1c6744554e 100644--- a/server/services/pipeline/readerPanelRunner.js+++ b/server/services/pipeline/readerPanelRunner.js@@ -13,7 +13,7 @@import { createSseRunner } from '../../lib/sseUtils.js';import { PANEL_PERSONAS } from '../../lib/editorial/panelDisagreement.js';import { buildDigestForSeries } from './readerPanelDigest.js';-import { runPersona, finalizePanel } from './readerPanel.js';+import { runPersona, finalizePanel, reconcileConsensusFindings } from './readerPanel.js';const runner = createSseRunner({ logLabel: 'reader panel' });@@ -38,6 +38,9 @@ export function startReaderPanel(seriesId, options = {}) {return runner.start(seriesId, async ({ runId, record, broadcast }) => {const digest = await buildDigestForSeries(seriesId);if (!digest.issueCount) {+ // No analyzable content — clear any stale consensus findings a prior panel+ // seeded so they don't linger open after the content was removed.+ await reconcileConsensusFindings(seriesId, { runId });broadcast({ type: 'complete', runId, personas: 0, empty: true, completedAt: new Date().toISOString() });return;}