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): fold dependency sources into editorial staleness fingerprint

[._.]/ Adam Eivy3a25c97b02d1
diff --git a/server/lib/editorial/README.md b/server/lib/editorial/README.md
index 1cc2d03e09..c6c213ecef 100644
--- a/server/lib/editorial/README.md
+++ b/server/lib/editorial/README.md
@@ -100,6 +100,14 @@ its declared `sources` (order-independent):
dependency **cycle** is a registry bug — it's logged and the cycle's members fall
back to registry order. The dependent must therefore tolerate missing prior
findings. `dependsOn` shape (string-array, no self-reference) is enforced at load.
+- **Staleness is dependency-aware.** Because a dependency-consuming finding can
+ change when its *dependency's* source content drifts (not only its own), the
+ staleness fingerprint and the per-source I/O gates fold in each check's transitive
+ declared-dependency sources (`effectiveCheckSources` in the runner). So a compound
+ finding goes stale exactly when any source it transitively depended on changes —
+ never falsely fresh, never falsely stale — computed identically at seed-time and
+ read-time. A check with no `dependsOn` is fingerprinted on its own `sources` as
+ before.
## Discovery rule
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index f09d23199d..a8af2abbc5 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -287,6 +287,37 @@ function checkSources(check) {
return declared.filter((token) => SOURCE_RESOLVERS[token]);
}
+// The source tokens a check's findings EFFECTIVELY depend on for staleness: its
+// OWN declared sources PLUS, transitively, the sources of every check it lists in
+// `dependsOn` (#1627). A dependency-consuming check reads its dependency's findings
+// via ctx.priorFindings, so its compound finding can change when the DEPENDENCY's
+// source content drifts even though the dependent's own sources didn't. Folding the
+// dependencies' sources in keeps getReviewWithStaleness from marking such a finding
+// falsely fresh — and the matching I/O gates fetch that content so it isn't falsely
+// stale either. Resolved against the full registry (`checkById`) and cycle-guarded
+// so it's identical at seed-time and read-time. With no checkById (or no dependsOn)
+// it returns the check's own sources unchanged, so a check that opts out is untouched.
+export function effectiveCheckSources(check, checkById) {
+ const own = checkSources(check);
+ const deps = Array.isArray(check?.dependsOn) ? check.dependsOn : [];
+ if (!deps.length || !(checkById instanceof Map)) return own;
+ const tokens = new Set(own);
+ const seen = new Set([check?.id]);
+ const stack = [...deps];
+ while (stack.length) {
+ const id = stack.pop();
+ if (seen.has(id)) continue;
+ seen.add(id);
+ const dep = checkById.get(id);
+ if (!dep) continue;
+ for (const token of checkSources(dep)) tokens.add(token);
+ for (const next of (Array.isArray(dep.dependsOn) ? dep.dependsOn : [])) {
+ if (!seen.has(next)) stack.push(next);
+ }
+ }
+ return [...tokens];
+}
+
// Resolve every source token's content ONCE for a given inputs object
// (`{ manuscript, canon, series }`), so fingerprinting many checks/comments doesn't
// re-stringify the canon per call. Returns a token→string map the fingerprint reads.
@@ -301,8 +332,8 @@ function resolveSources(inputs) {
// independent of declaration order; each segment is prefixed with its token so two
// source sets can't collide on equal content. NUL joins segments (it can't appear
// in the JSON the resolvers emit) so they can't run together ambiguously.
-function fingerprintForCheck(check, resolved) {
- const segments = [...new Set(checkSources(check))]
+function fingerprintForCheck(check, resolved, checkById = null) {
+ const segments = [...new Set(effectiveCheckSources(check, checkById))]
.sort()
.map((token) => `${token}=${resolved[token]}`);
// A custom check's run logic IS its authored prompt (user data, not code), so a
@@ -357,23 +388,29 @@ const EDITORIAL_OUTPUT_RESERVE_TOKENS = 2_000;
* @param {object} [opts] — providerOverride/Default, modelOverride/Default, signal
* @returns {Promise<{ series, baseCtx, resolvedSources }>}
*/
-export async function buildEditorialContext(seriesId, enabled, { providerOverride, providerDefault, modelOverride, modelDefault, signal } = {}) {
+export async function buildEditorialContext(seriesId, enabled, { providerOverride, providerDefault, modelOverride, modelDefault, signal, checkById = null } = {}) {
const series = await getSeries(seriesId);
- const needsManuscript = enabled.some(({ check }) => check.needsManuscript);
+ // Gate each fetch on EFFECTIVE sources — a check's own sources plus its declared
+ // dependencies' (#1627) — so a dependency-consuming check pulls (and fingerprints)
+ // its dependency's inputs even when that dependency is disabled this run, keeping
+ // the seed-time and read-time hashes symmetric. With no deps this is exactly the
+ // check's own sources, so a run with no dependency declarations is unchanged.
+ const sourcesOf = (check) => effectiveCheckSources(check, checkById);
+ const needsManuscript = enabled.some(({ check }) => check.needsManuscript || sourcesOf(check).includes('manuscript'));
// Reverse-outline fetch is gated on the declared source (#1296) so a run with no
// scene-segmentation check pays no extra I/O — mirrors the needsManuscript gate.
// Either the scenes (`reverseOutline`) OR the plotline list (`reverseOutline.plotlines`,
// #1310) is served by the same single outline fetch.
const needsReverseOutline = enabled.some(({ check }) => {
- const sources = checkSources(check);
+ const sources = sourcesOf(check);
return sources.includes('reverseOutline') || sources.includes('reverseOutline.plotlines');
});
// Editorial-arc fetch is gated on the declared source (#1295) so a run with no
// POV/arc check pays no extra snapshot I/O — mirrors the needsReverseOutline gate.
- const needsEditorialArcs = enabled.some(({ check }) => checkSources(check).includes('editorialArcs'));
+ const needsEditorialArcs = enabled.some(({ check }) => sourcesOf(check).includes('editorialArcs'));
// Continuity-bible ledger fetch is gated on the declared source (#1581) so a run
// with no contradiction check pays no extra ledger I/O — mirrors the other gates.
- const needsContinuityBible = enabled.some(({ check }) => checkSources(check).includes('continuityBible'));
+ const needsContinuityBible = enabled.some(({ check }) => sourcesOf(check).includes('continuityBible'));
// Issues are fetched only when an enabled check declares an issue-derived source
// — storyboard.shots (#1315), comicScript (#1313, served via the comic.lettering
// check's ctx.issues), or the comic-pacing tokens comicScript.pacing /
@@ -383,7 +420,7 @@ export async function buildEditorialContext(seriesId, enabled, { providerOverrid
// comic page past the 1000th issue. Mirrors the gate + fetch on the
// getReviewWithStaleness path below.
const needsIssues = enabled.some(({ check }) => {
- const sources = checkSources(check);
+ const sources = sourcesOf(check);
return sources.includes('storyboard.shots')
|| sources.includes('comicScript')
|| sources.includes('comicScript.pacing')
@@ -572,10 +609,15 @@ export async function runEditorialChecks(seriesId, options = {}) {
return { runId, findings: [], perCheck: [], canceled: false };
}
+ // Every registered check by id (built-ins + custom), so a dependency-consuming
+ // check's I/O gates + staleness fingerprint can fold in its declared
+ // dependencies' sources (#1627). Resolved against the FULL registry so it matches
+ // the read-time map in getReviewWithStaleness even when a dependency is disabled.
+ const checkById = new Map(getAllChecks(settings).map((c) => [c.id, c]));
// Build the shared context once — every check reads from this (extracted to
// buildEditorialContext so the dry-run preview path reuses the exact same
// provider-sized chunking + source resolution as a real run, #1607).
- const { series, baseCtx, resolvedSources } = await buildEditorialContext(seriesId, enabled, { providerOverride, providerDefault, modelOverride, modelDefault, signal });
+ const { series, baseCtx, resolvedSources } = await buildEditorialContext(seriesId, enabled, { providerOverride, providerDefault, modelOverride, modelDefault, signal, checkById });
// Overlay this series' per-check config overrides (#1591) onto the global
// resolved config. The `needs*` gates inside the builder read only `check`
// (config-independent); only the run loop consumes the merged config here.
@@ -634,7 +676,7 @@ export async function runEditorialChecks(seriesId, options = {}) {
continue;
}
const raw = (await check.run(ctx)) || [];
- const sourceContentHash = fingerprintForCheck(check, resolvedSources);
+ const sourceContentHash = fingerprintForCheck(check, resolvedSources, checkById);
// Stamp each finding with its NATIVE severity (the check's own escalated /
// LLM-emitted level, or the registry default fallback) AND its EFFECTIVE
// severity: a pin (#1596) is authoritative across every check kind, else
@@ -835,31 +877,36 @@ export async function getReviewWithStaleness(seriesId) {
// still-registered check — a pure completeness review pays no extra I/O.
const evaluable = review.comments.filter((c) => c.checkId && c.sourceContentHash && checkFor(c.checkId));
if (!evaluable.length) return review;
+ // Re-fingerprint each finding against its check's EFFECTIVE sources — own plus
+ // declared-dependency sources (#1627) — exactly as the seed path stamped it, so a
+ // dependency-consuming finding's hash is computed against the same content on read
+ // as on seed. With no deps this is the check's own sources, unchanged.
+ const sourcesFor = (id) => effectiveCheckSources(checkFor(id), byId);
// Only pay the manuscript-collection I/O when an evaluable check declares it as
// a source (mirrors the run path's gate, now source-derived rather than the bare
// needsManuscript flag so it stays correct as the source vocabulary grows).
- const needsManuscript = evaluable.some((c) => checkSources(checkFor(c.checkId)).includes('manuscript'));
+ const needsManuscript = evaluable.some((c) => sourcesFor(c.checkId).includes('manuscript'));
const needsReverseOutline = evaluable.some((c) => {
- const sources = checkSources(checkFor(c.checkId));
+ const sources = sourcesFor(c.checkId);
return sources.includes('reverseOutline') || sources.includes('reverseOutline.plotlines');
});
- const needsEditorialArcs = evaluable.some((c) => checkSources(checkFor(c.checkId)).includes('editorialArcs'));
+ const needsEditorialArcs = evaluable.some((c) => sourcesFor(c.checkId).includes('editorialArcs'));
// Continuity-bible ledger re-fingerprint, gated like the others (#1581) — must
// mirror the run path's fetch so a timeline/canon finding's hash is computed
// against the SAME ledger content on read as on seed (else it always reads stale).
- const needsContinuityBible = evaluable.some((c) => checkSources(checkFor(c.checkId)).includes('continuityBible'));
+ const needsContinuityBible = evaluable.some((c) => sourcesFor(c.checkId).includes('continuityBible'));
// Issues are fetched here only when a storyboard-shots (#1315) OR comic-script
// (#1313 lettering / #1314 pacing) finding needs re-fingerprinting — all derive
// from the issue records, so a single gated fetch serves them. Mirrors the other
// per-source I/O gates.
- const needsStoryboards = evaluable.some((c) => checkSources(checkFor(c.checkId)).includes('storyboard.shots'));
+ const needsStoryboards = evaluable.some((c) => sourcesFor(c.checkId).includes('storyboard.shots'));
const needsComicScript = evaluable.some((c) => {
- const s = checkSources(checkFor(c.checkId));
+ const s = sourcesFor(c.checkId);
return s.includes('comicScript') || s.includes('comicScript.pacing') || s.includes('comicScript.layout');
});
// The prose source (#1589) reads the per-issue prose stage off the same `issues`
// fetch, so it gates the issues load too — a prose-only check still loads issues.
- const needsProse = evaluable.some((c) => checkSources(checkFor(c.checkId)).includes('prose'));
+ const needsProse = evaluable.some((c) => sourcesFor(c.checkId).includes('prose'));
const needsIssues = needsStoryboards || needsComicScript || needsProse;
const series = await getSeries(seriesId);
const [sections, canon, outline, editorial, issues, bible] = await Promise.all([
@@ -888,7 +935,7 @@ export async function getReviewWithStaleness(seriesId) {
comments: review.comments.map((c) => {
const check = c.checkId && c.sourceContentHash ? checkFor(c.checkId) : null;
if (!check) return c;
- const current = fingerprintForCheck(check, resolvedSources);
+ const current = fingerprintForCheck(check, resolvedSources, byId);
return { ...c, stale: c.sourceContentHash !== current };
}),
};
diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.js
index 74a05e0308..451cb9b572 100644
--- a/server/services/pipeline/editorial/checkRunner.test.js
+++ b/server/services/pipeline/editorial/checkRunner.test.js
@@ -76,7 +76,7 @@ vi.mock('../reverseOutline.js', () => ({ getReverseOutline: vi.fn(async () => ou
let editorialState = { characters: [] };
vi.mock('../editorialAnalysis.js', () => ({ getSeriesEditorial: vi.fn(async () => editorialState) }));
-const { runEditorialChecks, buildEditorialCheckPlan, getReviewWithStaleness, enabledChecksConsumeReverseOutline, summarizeCheckErrors, previewCustomCheck, buildScopedPriorFindings } = await import('./checkRunner.js');
+const { runEditorialChecks, buildEditorialCheckPlan, getReviewWithStaleness, enabledChecksConsumeReverseOutline, summarizeCheckErrors, previewCustomCheck, buildScopedPriorFindings, effectiveCheckSources } = await import('./checkRunner.js');
const { runStagedLLM, resolveStageContext } = await import('../../../lib/stageRunner.js');
const { collectManuscriptSections } = await import('../arcPlanner.js');
const { getSeriesCanon } = await import('../seriesCanon.js');
@@ -1071,3 +1071,70 @@ describe('runEditorialChecks — ctx.priorFindings injection (#1627)', () => {
expect(ctx.findingsByCheck('naming.dissimilar-names')).toEqual([]);
});
});
+
+// Dependency-aware staleness fingerprint (#1627, codex review): a check that
+// declares dependsOn must fingerprint its dependencies' sources too, so a compound
+// finding goes stale when the DEPENDENCY's content drifts (not only its own).
+describe('effectiveCheckSources (#1627)', () => {
+ const map = (...checks) => new Map(checks.map((c) => [c.id, c]));
+ const A = { id: 'a', sources: ['canon'] };
+ const B = { id: 'b', sources: ['manuscript'], needsManuscript: true, dependsOn: ['a'] };
+ const C = { id: 'c', sources: ['reverseOutline'], dependsOn: ['b'] };
+
+ it('returns a check\'s own sources unchanged when it declares no dependencies', () => {
+ expect(effectiveCheckSources(A, map(A, B, C)).sort()).toEqual(['canon']);
+ });
+ it('returns own sources unchanged when no checkById map is provided (opt-out)', () => {
+ expect(effectiveCheckSources(B, null).sort()).toEqual(['manuscript']);
+ });
+ it('folds a declared dependency\'s sources into the effective set', () => {
+ expect(effectiveCheckSources(B, map(A, B, C)).sort()).toEqual(['canon', 'manuscript']);
+ });
+ it('folds transitively (c→b→a) so the whole dependency chain\'s sources count', () => {
+ expect(effectiveCheckSources(C, map(A, B, C)).sort()).toEqual(['canon', 'manuscript', 'reverseOutline']);
+ });
+ it('tolerates a dependency cycle without looping', () => {
+ const X = { id: 'x', sources: ['canon'], dependsOn: ['y'] };
+ const Y = { id: 'y', sources: ['manuscript'], needsManuscript: true, dependsOn: ['x'] };
+ expect(effectiveCheckSources(X, map(X, Y)).sort()).toEqual(['canon', 'manuscript']);
+ });
+ it('ignores a dependency absent from the registry map', () => {
+ const Z = { id: 'z', sources: ['canon'], dependsOn: ['missing'] };
+ expect(effectiveCheckSources(Z, map(Z)).sort()).toEqual(['canon']);
+ });
+});
+
+describe('runEditorialChecks — dependency-aware staleness (#1627)', () => {
+ // Stamp a finding via a real run with naming declaring a dependency on a
+ // manuscript-reading check, then flip ONLY the manuscript and confirm the
+ // dependent's finding is re-fingerprinted as stale (its own source is canon).
+ it('marks a dependency-consuming finding stale when the dependency\'s source drifts', async () => {
+ const naming = getCheck('naming.dissimilar-names'); // deterministic, sources: ['canon']
+ const infoDump = getCheck('prose.info-dumping'); // LLM, sources: ['manuscript']
+ const hadDeps = Object.prototype.hasOwnProperty.call(naming, 'dependsOn');
+ const originalDeps = naming.dependsOn;
+ naming.dependsOn = ['prose.info-dumping']; // naming now depends on a manuscript reader
+ try {
+ // Seed: stamp findings with manuscript content fingerprinted into naming's hash.
+ await runEditorialChecks('s1');
+ const seeded = seedStore.find((f) => f.checkId === 'naming.dissimilar-names' && f.sourceContentHash);
+ expect(seeded, 'naming finding was seeded with a source hash').toBeTruthy();
+ reviewState = { comments: seedStore.map((f) => ({ ...f })) };
+
+ // No drift → naming finding reads fresh.
+ let annotated = await getReviewWithStaleness('s1');
+ let namingComment = annotated.comments.find((c) => c.checkId === 'naming.dissimilar-names');
+ expect(namingComment.stale).toBe(false);
+
+ // Drift ONLY the manuscript (naming's dependency's source, not naming's own).
+ collectManuscriptSections.mockResolvedValueOnce([
+ { number: 1, title: 'Pilot', stageId: 'prose', content: 'Entirely different manuscript text now.' },
+ ]);
+ annotated = await getReviewWithStaleness('s1');
+ namingComment = annotated.comments.find((c) => c.checkId === 'naming.dissimilar-names');
+ expect(namingComment.stale, 'compound finding stales on its dependency\'s source drift').toBe(true);
+ } finally {
+ if (hadDeps) naming.dependsOn = originalDeps; else delete naming.dependsOn;
+ }
+ });
+});