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 (codex P2): scope the severity re-grade to checks that ran (#1596)
[._.]/ Adam Eivyc2dc8850a90a
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex a8700e50d4..aa2da7ea60 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -551,6 +551,11 @@ export async function runEditorialChecks(seriesId, options = {}) {// reconcile each of them — including those that produced zero findings, which// must dismiss their now-stale prior open comments.const deterministicRanIds = new Set();+ // Every check (any kind) that ran to completion this pass (#1596). The review+ // seed scopes its severity re-grade to this set, so a targeted subset run — or+ // the completeness pass — never rewrites the severity of comments for checks it+ // didn't run (which would silently clear an unrelated check's active pin).+ const ranCheckIds = new Set();let canceled = false;for (const { check, config, severityOverride } of enabledResolved) {if (signal?.aborted) { canceled = true; break; }@@ -593,6 +598,7 @@ export async function runEditorialChecks(seriesId, options = {}) {// no longer produces is genuinely resolved (not provider variance) — mark it// for fresh-mode reconciliation. LLM checks stay merge-only (an absent// finding could just be sampling noise).+ ranCheckIds.add(check.id);if (check.kind === 'deterministic') deterministicRanIds.add(check.id);const bySeverity = severityBreakdown(stamped);perCheck.push({ checkId: check.id, count: stamped.length, bySeverity });@@ -637,19 +643,24 @@ export async function runEditorialChecks(seriesId, options = {}) {}// Fresh-reconcile each deterministic check that ran, scoped to its checkId —// passing only that check's findings so the scoped 'fresh' pass dismisses the- // stale opens it no longer produces.+ // stale opens it no longer produces. `regradeCheckIds` scopes the severity+ // re-grade to this check alone.for (const checkId of deterministicRanIds) {const own = findings.filter((f) => f.checkId === checkId);- lastReview = await seedReviewFromFindings(seriesId, own, { runId, mode: 'fresh', checkId, severityOverrides });+ lastReview = await seedReviewFromFindings(seriesId, own, { runId, mode: 'fresh', checkId, severityOverrides, regradeCheckIds: [checkId] });}// Seed the remaining (non-deterministic) findings in merge mode. Also run// when there are active overrides but no merged findings, so a pinned check// that produced ZERO findings this pass still re-grades its lingering open// comments (#1596) — merge mode never dismisses, so an empty seed is a safe- // no-op aside from the authoritative severity re-grade.+ // no-op aside from the authoritative severity re-grade. `regradeCheckIds` is+ // the set of non-deterministic checks that actually RAN this pass, so the+ // re-grade never touches comments for a pinned check excluded from a targeted+ // subset run.const merged = findings.filter((f) => !deterministicRanIds.has(f.checkId));+ const mergedRanCheckIds = [...ranCheckIds].filter((id) => !deterministicRanIds.has(id));if (merged.length || Object.keys(severityOverrides).length) {- lastReview = await seedReviewFromFindings(seriesId, merged, { runId, mode: 'merge', severityOverrides });+ lastReview = await seedReviewFromFindings(seriesId, merged, { runId, mode: 'merge', severityOverrides, regradeCheckIds: mergedRanCheckIds });}// Record a revision-trend snapshot for EVERY non-canceled run (#1316) — a run// is a revision boundary, and a CLEAN run (0 new findings, or a reconciliationdiff --git a/server/services/pipeline/manuscriptReview.js b/server/services/pipeline/manuscriptReview.jsindex 52fad306b6..174c56319e 100644--- a/server/services/pipeline/manuscriptReview.js+++ b/server/services/pipeline/manuscriptReview.js@@ -202,7 +202,7 @@ const findingKey = (c) => `${c.checkId ?? ''}|${c.issueNumber ?? ''}|${c.anchorQ* New findings resolve their issueId/stageId from the current manuscript* sections by issueNumber.*/-export async function seedReviewFromFindings(seriesId, findings, { runId = null, mode = 'merge', checkId = null, severityOverrides = null } = {}) {+export async function seedReviewFromFindings(seriesId, findings, { runId = null, mode = 'merge', checkId = null, severityOverrides = null, regradeCheckIds = null } = {}) {const scopeCheckId = checkId ?? null;// Per-check severity overrides (#1596): a pinned check's level is authoritative// for EVERY open comment of that check, so we re-grade carried open comments@@ -210,6 +210,13 @@ export async function seedReviewFromFindings(seriesId, findings, { runId = null,// value — only a valid level forces a re-grade.const pins = severityOverrides && typeof severityOverrides === 'object' && !Array.isArray(severityOverrides)? severityOverrides : null;+ // The pin/native severity re-grade of a NON-resurfaced carried comment is+ // scoped to the checks that actually RAN this pass (#1596). Without this scope+ // a targeted subset run — or the completeness seed, which carries every+ // comment — would re-grade comments for checks it didn't run and silently+ // clear their active pins. `null` (no scope passed) disables the non-match+ // re-grade entirely, so legacy/external seed callers never mutate severities.+ const regradeScope = Array.isArray(regradeCheckIds) ? new Set(regradeCheckIds) : null;const sections = await collectManuscriptSections(seriesId);const byNumber = new Map(sections.map((s) => [s.number, s]));return queueReviewWrite(seriesId, async () => {@@ -284,8 +291,11 @@ export async function seedReviewFromFindings(seriesId, findings, { runId = null,// `nativeSeverity`, so CLEARING a pin re-grades even a non-resurfaced// open back to its true native level (not a guessed default). For a// never-pinned comment native == severity, so this is a no-op (no churn).- const pin = pins && c.checkId && ['high', 'medium', 'low'].includes(pins[c.checkId]) ? pins[c.checkId] : null;- const carriedNative = ['high', 'medium', 'low'].includes(c.nativeSeverity) ? c.nativeSeverity : null;+ // Cases 2 & 3 (non-match re-grade) only apply to checks that ran this pass+ // (`regradeScope`), so an unrelated check's pin is never silently cleared.+ const inRegradeScope = !!(regradeScope && c.checkId && regradeScope.has(c.checkId));+ const pin = inRegradeScope && pins && ['high', 'medium', 'low'].includes(pins[c.checkId]) ? pins[c.checkId] : null;+ const carriedNative = inRegradeScope && ['high', 'medium', 'low'].includes(c.nativeSeverity) ? c.nativeSeverity : null;const nextSeverity = (match && match.severity) ? match.severity : (pin || carriedNative);if (nextSeverity && nextSeverity !== c.severity) {patch.severity = nextSeverity;diff --git a/server/services/pipeline/manuscriptReview.test.js b/server/services/pipeline/manuscriptReview.test.jsindex 255b1af9c6..4429538f12 100644--- a/server/services/pipeline/manuscriptReview.test.js+++ b/server/services/pipeline/manuscriptReview.test.js@@ -351,39 +351,39 @@ describe('manuscriptReview — sourceContentHash staleness fingerprint (#1345)',describe('manuscriptReview — authoritative severity override re-grade (#1596)', () => {beforeEach(() => { fileStore.clear(); });- const finding = (severity) => ({ problem: 'adverb density', anchorQuote: 'quickly', checkId: 'prose.adverb-density', severity });+ const CHECK = 'prose.adverb-density';+ const finding = (severity) => ({ problem: 'adverb density', anchorQuote: 'quickly', checkId: CHECK, severity });+ const ran = { regradeCheckIds: [CHECK] }; // this check ran this passit('re-grades a re-surfaced open comment to the pinned level via severityOverrides', async () => {- await seedReviewFromFindings('ser-sev', [finding('low')]);+ await seedReviewFromFindings('ser-sev', [finding('low')], ran);// Same finding key (severity is NOT part of the key) re-surfaces while the- // check is now pinned to `high`.+ // check is now pinned to `high` — the candidate carries the effective level.const second = await seedReviewFromFindings('ser-sev', [finding('high')], {- severityOverrides: { 'prose.adverb-density': 'high' },+ ...ran, severityOverrides: { [CHECK]: 'high' },});expect(second.comments).toHaveLength(1); // deduped, not appendedexpect(second.comments[0].severity).toBe('high'); // re-graded to the pinned level});it('re-grades a NON-resurfaced open comment of a pinned check (merge mode)', async () => {- await seedReviewFromFindings('ser-sev-merge', [finding('low')]);+ await seedReviewFromFindings('ser-sev-merge', [finding('low')], ran);// A later merge-mode run finds nothing for this check (LLM variance), but the- // check is pinned to `high` — the lingering open comment must still re-grade.+ // check ran and is pinned to `high` — the lingering open must still re-grade.const second = await seedReviewFromFindings('ser-sev-merge', [], {- mode: 'merge',- severityOverrides: { 'prose.adverb-density': 'high' },+ ...ran, mode: 'merge', severityOverrides: { [CHECK]: 'high' },});expect(second.comments).toHaveLength(1); // not dismissed in merge modeexpect(second.comments[0].severity).toBe('high');});it('re-grades a re-surfaced open comment back to native when a pin is CLEARED', async () => {- // Pinned to high.await seedReviewFromFindings('ser-sev-clear', [finding('high')], {- severityOverrides: { 'prose.adverb-density': 'high' },+ ...ran, severityOverrides: { [CHECK]: 'high' },});// Pin cleared (no override map) and the finding re-surfaces at its native// 'low' level — the comment must drop back to 'low', not stay stuck at 'high'.- const second = await seedReviewFromFindings('ser-sev-clear', [finding('low')]);+ const second = await seedReviewFromFindings('ser-sev-clear', [finding('low')], ran);expect(second.comments).toHaveLength(1);expect(second.comments[0].severity).toBe('low');});@@ -391,29 +391,44 @@ describe('manuscriptReview — authoritative severity override re-grade (#1596)'it('re-grades a NON-resurfaced open comment back to native when a pin is cleared', async () => {// Mirror the runner's stamp for a pinned finding: effective high, native low.await seedReviewFromFindings('ser-sev-clearmerge', [- { problem: 'adverb density', anchorQuote: 'quickly', checkId: 'prose.adverb-density', severity: 'high', nativeSeverity: 'low' },- ], { severityOverrides: { 'prose.adverb-density': 'high' } });- // Pin cleared, and a later merge run produces NO finding for this check — the+ { problem: 'adverb density', anchorQuote: 'quickly', checkId: CHECK, severity: 'high', nativeSeverity: 'low' },+ ], { ...ran, severityOverrides: { [CHECK]: 'high' } });+ // Pin cleared, and a later merge run (this check ran, found nothing) — the// lingering open must still drop from the old pin back to its stored native.- const second = await seedReviewFromFindings('ser-sev-clearmerge', [], { mode: 'merge' });+ const second = await seedReviewFromFindings('ser-sev-clearmerge', [], { ...ran, mode: 'merge' });expect(second.comments).toHaveLength(1); // preserved in merge modeexpect(second.comments[0].severity).toBe('low'); // restored from stored nativeSeverity});+ it('does NOT re-grade a pinned comment for a check excluded from a targeted subset run', async () => {+ // A comment pinned high (native low) for adverb-density.+ await seedReviewFromFindings('ser-sev-subset', [+ { problem: 'adverb density', anchorQuote: 'quickly', checkId: CHECK, severity: 'high', nativeSeverity: 'low' },+ ], { ...ran, severityOverrides: { [CHECK]: 'high' } });+ // A later SUBSET run targets a DIFFERENT check only: adverb-density neither+ // re-surfaces nor appears in severityOverrides/regradeCheckIds. Its pinned+ // comment must be left alone (NOT silently cleared back to native).+ const second = await seedReviewFromFindings('ser-sev-subset', [+ { problem: 'other', anchorQuote: 'x', checkId: 'prose.other-check', severity: 'medium', nativeSeverity: 'medium' },+ ], { mode: 'merge', severityOverrides: {}, regradeCheckIds: ['prose.other-check'] });+ const pinned = second.comments.find((c) => c.checkId === CHECK);+ expect(pinned.severity).toBe('high'); // pin preserved — not cleared to native+ });+it('does NOT churn a never-pinned non-resurfaced comment (native == severity)', async () => {- const first = await seedReviewFromFindings('ser-sev-stable', [finding('high')]);+ const first = await seedReviewFromFindings('ser-sev-stable', [finding('high')], ran);const stamp = first.comments[0].updatedAt;expect(first.comments[0].nativeSeverity).toBe('high'); // defaults to severity- const second = await seedReviewFromFindings('ser-sev-stable', [], { mode: 'merge' });+ const second = await seedReviewFromFindings('ser-sev-stable', [], { ...ran, mode: 'merge' });expect(second.comments[0].severity).toBe('high'); // unchangedexpect(second.comments[0].updatedAt).toBe(stamp); // no rewrite});it('does NOT churn updatedAt when the pinned level already matches', async () => {- const first = await seedReviewFromFindings('ser-sev-nochurn', [finding('high')]);+ const first = await seedReviewFromFindings('ser-sev-nochurn', [finding('high')], ran);const stamp = first.comments[0].updatedAt;const second = await seedReviewFromFindings('ser-sev-nochurn', [finding('high')], {- severityOverrides: { 'prose.adverb-density': 'high' },+ ...ran, severityOverrides: { [CHECK]: 'high' },});expect(second.comments[0].updatedAt).toBe(stamp); // unchanged — no rewrite});