Skip to content

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

address review (codex r2): fail closed on incomplete review, scope + gate bulk fix

[._.]/ Adam Eivy887e23c7f014
diff --git a/client/src/components/pipeline/SeriesReviewPanel.jsx b/client/src/components/pipeline/SeriesReviewPanel.jsx
index 7d20d79098..07c263472c 100644
--- a/client/src/components/pipeline/SeriesReviewPanel.jsx
+++ b/client/src/components/pipeline/SeriesReviewPanel.jsx
@@ -122,14 +122,26 @@ export default function SeriesReviewPanel({ series, onSeriesUpdate, onIssuesUpda
if (!seriesId) return;
const res = await getPipelineSeriesReview(seriesId, { silent: true }).catch(() => null);
if (!res) return;
- if (res.review) { setReview(res.review); setConfirmDismissed(false); }
+ // Always adopt the server's verdict (including null) so switching to a series
+ // with no stored review clears the previous series' findings (P2).
+ setReview(res.review ?? null);
+ setConfirmDismissed(false);
if (res.fix) setFixAvail(res.fix);
}, [seriesId]);
- // Initial load — restore the last verdict + re-attach to an in-flight review.
+ // Initial load / series switch — reset transient state first (React Router
+ // reuses this component across seriesIds, so stale review/run state must not
+ // carry over), then restore the verdict + re-attach to any in-flight run.
useEffect(() => {
if (!seriesId) return undefined;
let canceled = false;
+ setReview(null);
+ setFeedback('');
+ setConfirmDismissed(false);
+ setReviewing(false);
+ setFixing(false);
+ reviewRunIdRef.current = null;
+ fixRunIdRef.current = null;
loadVerdict();
getPipelineSeriesReviewStatus(seriesId, { silent: true })
.then((s) => { if (!canceled && s?.active) setReviewing(true); })
@@ -191,6 +203,10 @@ export default function SeriesReviewPanel({ series, onSeriesUpdate, onIssuesUpda
.catch((err) => { toast.error(err.message || 'Could not start review'); return null; });
setStarting(false);
if (!res) return;
+ // The note has now been consumed by this run — clear it so a later re-review
+ // (after fixes clear `review`, re-showing the textarea) can't silently re-seed
+ // the same note as a fresh duplicate finding.
+ if (body.feedback) setFeedback('');
reviewRunIdRef.current = res.runId || null;
setReviewing(true);
}, [seriesId, feedback, review]);
@@ -201,11 +217,14 @@ export default function SeriesReviewPanel({ series, onSeriesUpdate, onIssuesUpda
const startFix = useCallback(async () => {
setFixStarting(true);
- // Patch each open finding at its anchor via the per-finding manuscriptFix
+ // Patch each DISPLAYED finding at its anchor via the per-finding manuscriptFix
// machinery (server-side, cos-execute-gated + budgeted). Not the autopilot —
// that only auto-resolves completeness findings, so it can't fix the
- // editorial-check findings this review surfaced.
- const res = await startPipelineSeriesFix(seriesId, {}, { silent: true })
+ // editorial-check findings this review surfaced. Scope to the ids the user
+ // reviewed here, so a finding added by another run after this snapshot isn't
+ // silently auto-fixed too (P1).
+ const commentIds = (review?.findings || []).map((f) => f.commentId);
+ const res = await startPipelineSeriesFix(seriesId, { commentIds }, { silent: true })
.catch((err) => { toast.error(err?.message || 'Could not start fixing'); return null; });
setFixStarting(false);
if (!res) return;
@@ -213,13 +232,17 @@ export default function SeriesReviewPanel({ series, onSeriesUpdate, onIssuesUpda
setConfirmDismissed(true);
setFixing(true);
toast.success('Fixing started — patching findings at their anchors');
- }, [seriesId]);
+ }, [seriesId, review]);
if (!seriesId) return null;
const reviewLabel = reviewing ? (reviewFrameLabel(reviewLatest) || 'Working…') : null;
const groups = review ? groupFindings(review.findings) : [];
const hasIssues = review?.verdict === 'issues';
+ // Only the manuscript-review findings are auto-fixable; a verdict that is
+ // 'issues' solely because of foundation / canon / an incomplete run has no
+ // fixable comments, so the bulk-fix action must not be offered (P2).
+ const hasFixableFindings = (review?.findings?.length || 0) > 0;
const canFix = fixAvail?.canFix !== false;
const showConfirm = hasIssues && !confirmDismissed && !fixing && !reviewing;
@@ -235,7 +258,8 @@ export default function SeriesReviewPanel({ series, onSeriesUpdate, onIssuesUpda
<button
type="button"
onClick={runReview}
- disabled={starting}
+ disabled={starting || fixing || fixStarting}
+ title={fixing || fixStarting ? 'Fixing is in progress — wait for it to finish before re-reviewing' : undefined}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded text-sm font-medium border bg-port-bg text-port-accent border-port-border hover:border-port-accent/40 disabled:opacity-40"
>
{starting ? <Loader2 size={14} className="animate-spin" /> : <ClipboardCheck size={14} />}
@@ -317,12 +341,15 @@ export default function SeriesReviewPanel({ series, onSeriesUpdate, onIssuesUpda
) : null}
</div>
- {/* Incomplete-review warning — a requested check errored, so this
- verdict is not trustworthy as "ready" (P2). */}
- {review.checksErrored > 0 ? (
+ {/* Incomplete-review warning — a stage errored / never ran, so the
+ verdict can't be trusted as "ready" (P2). */}
+ {review.incomplete ? (
<p className="text-[11px] text-port-warning flex items-center gap-1.5">
<AlertTriangle size={12} />
- {review.checksErrored} editorial check(s) errored (e.g. a provider was unavailable) — this review is incomplete; re-run before trusting it.
+ {review.checksErrored > 0
+ ? `${review.checksErrored} editorial check(s) errored (e.g. a provider was unavailable) — `
+ : `Some review steps${review.failedStages?.length ? ` (${review.failedStages.join(', ')})` : ''} did not complete — `}
+ this review is incomplete; re-run before trusting it.
</p>
) : null}
@@ -374,23 +401,33 @@ export default function SeriesReviewPanel({ series, onSeriesUpdate, onIssuesUpda
>
<ThumbsUp size={12} /> Looks good
</button>
- <button
- type="button"
- onClick={startFix}
- disabled={fixStarting || !canFix}
- title={canFix ? 'Patch each finding at its anchor via the per-finding manuscript fixer' : 'Auto-fixing needs the CoS auto-run domain set to execute'}
- className="inline-flex items-center gap-1 px-2.5 py-1 rounded text-xs font-medium text-port-accent border border-port-border bg-port-bg hover:border-port-accent/40 disabled:opacity-40"
- >
- {fixStarting ? <Loader2 size={12} className="animate-spin" /> : <Wrench size={12} />} Fix these issues
- </button>
+ {/* Bulk-fix is only meaningful when there are auto-fixable
+ manuscript findings; a verdict blocked only by foundation /
+ canon / an incomplete run has none, so offer only "Looks good". */}
+ {hasFixableFindings ? (
+ <button
+ type="button"
+ onClick={startFix}
+ disabled={fixStarting || !canFix}
+ title={canFix ? 'Patch each finding at its anchor via the per-finding manuscript fixer' : 'Auto-fixing needs the CoS auto-run domain set to execute'}
+ className="inline-flex items-center gap-1 px-2.5 py-1 rounded text-xs font-medium text-port-accent border border-port-border bg-port-bg hover:border-port-accent/40 disabled:opacity-40"
+ >
+ {fixStarting ? <Loader2 size={12} className="animate-spin" /> : <Wrench size={12} />} Fix these issues
+ </button>
+ ) : null}
</div>
- {!canFix ? (
+ {hasFixableFindings && !canFix ? (
<p className="w-full text-[11px] text-gray-500 mt-1">
{fixAvail?.mode === 'dry-run'
? 'Auto-fixing is preview-only right now (CoS auto-run is in dry-run — it makes no changes). Set it to execute, or open each finding above and fix it manually.'
: 'Auto-fixing is off (CoS auto-run domain is disabled). You can still open each finding above and fix it manually.'}
</p>
) : null}
+ {!hasFixableFindings ? (
+ <p className="w-full text-[11px] text-gray-500 mt-1">
+ These blockers (foundation, canon, or an incomplete run) aren&apos;t auto-fixable here — address them from their own pages, then re-review.
+ </p>
+ ) : null}
</div>
) : null}
</div>
diff --git a/server/services/pipeline/seriesReview.js b/server/services/pipeline/seriesReview.js
index 3dafea0bb1..883e100549 100644
--- a/server/services/pipeline/seriesReview.js
+++ b/server/services/pipeline/seriesReview.js
@@ -34,6 +34,7 @@
*/
import { join } from 'path';
+import { unlink } from 'fs/promises';
import { PATHS, atomicWrite, ensureDir, tryReadFile, safeJSONParse } from '../../lib/fileUtils.js';
import { createSseRunner } from '../../lib/sseUtils.js';
import { runStageScopedInlineLLM } from '../../lib/stageRunner.js';
@@ -82,18 +83,17 @@ const SEVERITY_RANK = { high: 0, medium: 1, low: 2 };
* The single 'ready' | 'issues' verdict. A series is only "ready to move
* forward" when the editorial-health readiness gate is clean AND the foundation
* clears the quality threshold AND every drawn noun is described (canon ready)
- * AND no requested editorial check errored out (an unevaluated check means the
- * review is incomplete — it must never read as 'ready'). Any of those failing →
- * 'issues'. Pure.
+ * AND the review actually completed (`incomplete` false — a stage that errored /
+ * never ran means the verdict is untrustworthy and must never read 'ready').
+ * Any of those failing → 'issues'. Pure.
*/
-export function computeReviewVerdict({ health, foundation, canon, threshold = DEFAULT_FOUNDATION_THRESHOLD, checksErrored = 0 } = {}) {
+export function computeReviewVerdict({ health, foundation, canon, threshold = DEFAULT_FOUNDATION_THRESHOLD, incomplete = false } = {}) {
const healthReady = health?.ready === true;
const foundationReady = !foundation || !Number.isFinite(foundation.weightedScore)
? true
: foundation.weightedScore >= threshold;
const canonReady = canon?.ready !== false;
- const checksClean = !(Number(checksErrored) > 0);
- return healthReady && foundationReady && canonReady && checksClean ? 'ready' : 'issues';
+ return healthReady && foundationReady && canonReady && !incomplete ? 'ready' : 'issues';
}
/**
@@ -241,12 +241,18 @@ export async function runSeriesReview(seriesId, {
const weights = mergeSeverityWeights(series?.severityWeights);
const aborted = () => signal?.aborted;
+ // Stages that errored / never ran this pass — any of these makes the verdict
+ // untrustworthy, so it must never read 'ready' (fail closed). Surfaced on the
+ // result so the UI can warn the review is incomplete.
+ const failedStages = [];
// 1. Foundation judge (holistic pre-draft quality — catches "looks complete
- // but no development"). Writes only its own snapshot.
+ // but no development"). Writes only its own snapshot. A throw is a genuine
+ // failure (judgeFoundation otherwise always returns a snapshot), not an
+ // absent-but-fine result — record it so the verdict fails closed.
onProgress({ type: 'step:start', kind: 'foundation' });
const foundation = await judgeFoundation(seriesId, { providerId: providerOverride, model: modelOverride, force })
- .catch((err) => { console.error(`⚠️ series-review foundation judge failed — series=${seriesId.slice(0, 12)} ${err.message}`); return null; });
+ .catch((err) => { console.error(`⚠️ series-review foundation judge failed — series=${seriesId.slice(0, 12)} ${err.message}`); failedStages.push('foundation'); return null; });
onProgress({ type: 'step:complete', kind: 'foundation', weightedScore: foundation?.weightedScore ?? null });
if (aborted()) return null;
@@ -262,24 +268,31 @@ export async function runSeriesReview(seriesId, {
// 3. Editorial checks — registry-driven review; seeds the shared review store.
onProgress({ type: 'step:start', kind: 'editorialChecks' });
+ // A runner-level REJECT (e.g. it threw while building shared context, before
+ // producing any perCheck entries) is a whole-pass failure — the checks never
+ // ran, so mark the review incomplete rather than reporting an empty clean pass.
+ let checksRunFailed = false;
const checks = await runEditorialChecks(seriesId, {
providerOverride,
modelOverride,
signal,
onProgress,
- }).catch((err) => { console.error(`⚠️ series-review editorial checks failed — series=${seriesId.slice(0, 12)} ${err.message}`); return { findings: [], perCheck: [], canceled: false }; });
- // A check that threw (e.g. an unavailable LLM provider) is caught internally by
- // the runner and surfaced in perCheck as `{ checkId, error }` — that dimension
- // was never evaluated, so it must block a 'ready' verdict (P2).
+ }).catch((err) => { console.error(`⚠️ series-review editorial checks failed — series=${seriesId.slice(0, 12)} ${err.message}`); checksRunFailed = true; failedStages.push('editorialChecks'); return { findings: [], perCheck: [], canceled: false }; });
+ // A single check that threw (e.g. an unavailable LLM provider) is caught
+ // internally by the runner and surfaced in perCheck as `{ checkId, error }` —
+ // that dimension was never evaluated, so it too must block a 'ready' verdict.
const erroredCheckIds = (Array.isArray(checks?.perCheck) ? checks.perCheck : [])
.filter((p) => p && p.error).map((p) => p.checkId);
const checksErrored = erroredCheckIds.length;
- onProgress({ type: 'step:complete', kind: 'editorialChecks', findingCount: checks?.findings?.length ?? 0, errored: checksErrored });
+ onProgress({ type: 'step:complete', kind: 'editorialChecks', findingCount: checks?.findings?.length ?? 0, errored: checksErrored, failed: checksRunFailed });
if (aborted() || checks?.canceled) return null;
- // 4. Canon readiness (deterministic — no LLM).
+ // 4. Canon readiness (deterministic — no LLM). A throw is a genuine failure —
+ // record it so the verdict fails closed rather than treating the missing
+ // result as "canon fine".
onProgress({ type: 'step:start', kind: 'canon' });
- const canon = await checkSeriesCanonReadiness(seriesId).catch(() => null);
+ const canon = await checkSeriesCanonReadiness(seriesId)
+ .catch((err) => { console.error(`⚠️ series-review canon readiness failed — series=${seriesId.slice(0, 12)} ${err.message}`); failedStages.push('canon'); return null; });
onProgress({ type: 'step:complete', kind: 'canon', ready: canon?.ready !== false });
// 5. Health + readiness + the seeded findings — both only READ the store the
@@ -291,10 +304,14 @@ export async function runSeriesReview(seriesId, {
]);
onProgress({ type: 'step:complete', kind: 'health', ready: health?.ready === true, score: health?.score ?? null });
const findings = collectReviewFindings(review.comments);
+ if (!health) failedStages.push('health');
const threshold = Number.isFinite(settings?.pipelineEditorialChecks?.foundationThreshold)
? settings.pipelineEditorialChecks.foundationThreshold
: DEFAULT_FOUNDATION_THRESHOLD;
- const verdict = computeReviewVerdict({ health, foundation, canon, threshold, checksErrored });
+ // The review is incomplete when ANY dimension errored/never-ran OR an
+ // individual check errored — the verdict then fails closed (never 'ready').
+ const incomplete = failedStages.length > 0 || checksErrored > 0;
+ const verdict = computeReviewVerdict({ health, foundation, canon, threshold, incomplete });
const result = {
seriesId,
@@ -313,8 +330,12 @@ export async function runSeriesReview(seriesId, {
: null,
findings,
findingCount: findings.length,
- // Requested checks that errored out this run (never evaluated) — surfaced so
- // the UI can warn that a 'ready'-looking review is actually incomplete (P2).
+ // Whether the review actually completed every dimension. When false, a stage
+ // errored / never ran, so the verdict is forced to 'issues' and the UI warns
+ // the review is incomplete (P2). `failedStages` names which dimensions failed;
+ // `checksErrored`/`erroredCheckIds` detail individual check errors.
+ incomplete,
+ failedStages,
checksErrored,
erroredCheckIds,
hadFeedback: !!(feedback && String(feedback).trim()),
@@ -333,6 +354,13 @@ async function saveSnapshot(result) {
await atomicWrite(snapshotPath(result.seriesId), result);
}
+// Drop the persisted verdict for a series so a reload/remount doesn't restore a
+// now-stale review (e.g. after fixes accepted findings + mutated the manuscript).
+// GET /review then returns `{ review: null }` until the user re-reviews.
+async function clearSnapshot(seriesId) {
+ await unlink(snapshotPath(seriesId)).catch(() => {}); // best-effort; ENOENT is fine
+}
+
/**
* Read the last stored review verdict for a series (null when never run). Also
* reports whether the FIX path is currently available (cos-domain autonomy):
@@ -420,6 +448,9 @@ export async function runSeriesFix(seriesId, { commentIds, providerOverride, mod
if (applied) { fixed += 1; onProgress({ type: 'fix:done', commentId: f.commentId }); }
else { skipped += 1; onProgress({ type: 'fix:skip', commentId: f.commentId, reason: 'could not anchor' }); }
}
+ // Fixes accepted findings + rewrote manuscript sections, so the persisted
+ // verdict is now stale — drop it so a reload can't re-surface (and re-fix) it.
+ if (fixed > 0) await clearSnapshot(seriesId);
console.log(`🔧 series fix — series=${seriesId.slice(0, 12)} fixed=${fixed} skipped=${skipped}/${open.length}${budgetStopped ? ' (budget-stopped)' : ''}`);
return { fixed, skipped, total: open.length, budgetStopped };
}
diff --git a/server/services/pipeline/seriesReview.test.js b/server/services/pipeline/seriesReview.test.js
index 2744220869..d34578ba63 100644
--- a/server/services/pipeline/seriesReview.test.js
+++ b/server/services/pipeline/seriesReview.test.js
@@ -53,21 +53,21 @@ describe('computeReviewVerdict', () => {
})).toBe('ready');
});
- it("is 'issues' when a requested check errored (review incomplete, must not read ready)", () => {
+ it("is 'issues' when the review is incomplete (a stage errored / never ran — must not read ready)", () => {
expect(computeReviewVerdict({
health: { ready: true },
foundation: { weightedScore: 9 },
canon: { ready: true },
- checksErrored: 1,
+ incomplete: true,
})).toBe('issues');
});
- it('is unaffected when zero checks errored', () => {
+ it("is 'ready' when complete and all dimensions pass (incomplete false)", () => {
expect(computeReviewVerdict({
health: { ready: true },
foundation: { weightedScore: 9 },
canon: { ready: true },
- checksErrored: 0,
+ incomplete: false,
})).toBe('ready');
});
});