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: editorial storyboard/comic checks miss issues past the 1000-issue listIssues cap (#1469)
Adam Eivy6d90a1d4c178
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 2063d5ded0..b19cb60594 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,6 +2,8 @@## Fixed+- **[issue-1469] Editorial storyboard-continuity + comic-lettering checks now see every issue in a series, not just the first 1000.** Both issue-derived editorial sources — `collectStoryboardScenes` (storyboard.shots, #1315) and `projectComicLetteringContent` (comicScript, #1313) — fed off `listIssues({ seriesId })`, which caps at `ISSUES_PER_RESPONSE_MAX` (1000) even unpaginated. For a series with more than 1000 issues, every storyboard scene / comic page past the 1000th was silently skipped — a coverage gap on both the run path and the `getReviewWithStaleness` re-fingerprint path. A new uncapped `listIssuesForSeries(seriesId)` (the per-series sibling of `listAllIssues`/`listIssueIds`, sorted by issue number) now backs both paths, and the run-path fetch is gated on an enabled storyboard.shots/comicScript check exactly like the staleness path already was — so a run with neither check enabled pays no issue-fetch I/O. Regression-tested with a 1001-issue fixture whose offending scene rides the last issue. (`server/services/pipeline/issues.js`, `server/services/pipeline/editorial/checkRunner.js`, Part of #1283, #1469)+- **[issue-1459] Editorial LLM checks now guarantee a manuscript budget floor, so a large reverse outline can't starve the manuscript chunk to empty.** The manuscript-consuming editorial checks re-send a fixed context block (the reverse-outline scene map, character arcs, plotline coverage, style-guide expectations, …) on every chunk, counted as `overheadTokens`. On a provider with a small or fallback context window **and** a large reverse outline (many scenes → a large scene map), that overhead could meet or exceed the usable input budget — `planManuscriptPass` then returned `usableChars = 0` and the chunker sliced every manuscript chunk to `''`, so a default-enabled check silently ran on **no prose**. A check now declares its trimmable context as a `context: { varName }` map (instead of baking it into `overheadTokens`); the runner reserves a minimum manuscript budget (`MANUSCRIPT_FLOOR_TOKENS`) and, when the context would push the manuscript below that floor, **trims the context block** (largest first, so the unbounded scene map absorbs the cut while bounded blocks survive) and feeds the model the same trimmed block it was budgeted for — rather than overflowing the window or reviewing an empty manuscript. The floor decision lives centrally in `contextBudget.js` (`fitContextToManuscriptFloor`/`capContextOverhead`/`trimContextToBudget`), so every manuscript+context check benefits. Unit-tested end-to-end: a tiny window + a 400-scene outline still yields a non-empty manuscript chunk. (`server/lib/contextBudget.js`, `server/services/pipeline/editorial/checkRunner.js`, `server/lib/editorial/checkRegistry.js`, #1459)## Addeddiff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex 06c28cdf2a..b45b037137 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -22,7 +22,7 @@ import { planManuscriptPass, fitContextToManuscriptFloor, estimateTokens, MANUSCimport { getEnabledChecks, getEnabledCheckRows, getAllChecks, EDITORIAL_SOURCES, comicLetteringIssues } from '../../../lib/editorial/index.js';import { getSettings } from '../../settings.js';import { getSeries } from '../series.js';-import { listIssues } from '../issues.js';+import { listIssuesForSeries } from '../issues.js';import { getSeriesCanon } from '../seriesCanon.js';import { collectManuscriptSections, sectionsCorpus, manuscriptSectionHeader } from '../arcPlanner.js';import { getReverseOutline } from '../reverseOutline.js';@@ -281,10 +281,20 @@ export async function runEditorialChecks(seriesId, options = {}) {// 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'));+ // Issues are fetched only when an enabled check declares an issue-derived source+ // — storyboard.shots (#1315) or comicScript (#1313, served via the comic.lettering+ // check's ctx.issues). Both projections feed off the same UNCAPPED per-series scan+ // (#1469): listIssues caps at ISSUES_PER_RESPONSE_MAX (1000), silently skipping+ // every storyboard scene / comic page past the 1000th issue. Mirrors the gate ++ // fetch on the getReviewWithStaleness path below.+ const needsIssues = enabled.some(({ check }) => {+ const sources = checkSources(check);+ return sources.includes('storyboard.shots') || sources.includes('comicScript');+ });const [sections, canon, issues, outline, editorial] = await Promise.all([needsManuscript ? collectManuscriptSections(seriesId) : Promise.resolve([]),getSeriesCanon(series),- listIssues({ seriesId }).catch(() => []),+ needsIssues ? listIssuesForSeries(seriesId).catch(() => []) : Promise.resolve([]),needsReverseOutline ? getReverseOutline(seriesId).catch(() => null) : Promise.resolve(null),// Reuse the already-loaded series so the aggregate skips a redundant getSeries.// (issues is fetched in this same Promise.all, so it can't be passed here —@@ -292,8 +302,8 @@ export async function runEditorialChecks(seriesId, options = {}) {needsEditorialArcs ? getSeriesEditorial(seriesId, { series }).catch(() => null) : Promise.resolve(null),]);const manuscript = sectionsCorpus(sections);- // Storyboard shots for the visual.shot-continuity check (#1315) — built off the- // already-loaded issues, so no extra I/O regardless of whether the check is on.+ // Storyboard shots for the visual.shot-continuity check (#1315) — projected off+ // the gated `issues` fetch (empty unless a storyboard.shots/comicScript check is on).const storyboardScenes = collectStoryboardScenes(issues);const reverseOutline = Array.isArray(outline?.scenes) ? outline.scenes : [];// The outline's plotline list (#1310) — injected separately from the scenes so a@@ -306,9 +316,8 @@ export async function runEditorialChecks(seriesId, options = {}) {// series (canceled/early-stopped batch) doesn't flag a not-yet-analyzed POV// holder as arc-less (#1295). Folded into the editorialArcs fingerprint below.const editorialArcsComplete = editorialCoverageComplete(editorial);- // The comic lettering content the check (#1313) reads — derived from the- // already-loaded issues (no extra I/O), so a finding stales when an issue's comic- // pages / script are edited.+ // The comic lettering content the check (#1313) reads — derived from the gated+ // `issues` fetch, so a finding stales when an issue's comic pages / script are edited.const comicScripts = projectComicLetteringContent(issues);// Resolve every source token once — each finding's fingerprint reads from this// so the editor flags it `stale` when the content that check actually read (its@@ -537,7 +546,7 @@ export async function getReviewWithStaleness(seriesId) {needsReverseOutline ? getReverseOutline(seriesId).catch(() => null) : Promise.resolve(null),// Reuse the already-loaded series.needsEditorialArcs ? getSeriesEditorial(seriesId, { series }).catch(() => null) : Promise.resolve(null),- needsIssues ? listIssues({ seriesId }).catch(() => []) : Promise.resolve([]),+ needsIssues ? listIssuesForSeries(seriesId).catch(() => []) : Promise.resolve([]),]);const reverseOutline = Array.isArray(outline?.scenes) ? outline.scenes : [];const reverseOutlinePlotlines = Array.isArray(outline?.plotlines) ? outline.plotlines : [];diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.jsindex d5750b5dd1..d54f8303d0 100644--- a/server/services/pipeline/editorial/checkRunner.test.js+++ b/server/services/pipeline/editorial/checkRunner.test.js@@ -6,9 +6,12 @@ vi.mock('../../settings.js', () => ({ getSettings: vi.fn(async () => ({})) }));vi.mock('../series.js', () => ({ getSeries: vi.fn(async () => ({ id: 's1', universeId: 'u1' })) }));// Issues source — backed by a mutable fixture so the storyboard.shots continuity// check (#1315) can be exercised; default empty so the check is gated off unless a-// test populates issues carrying storyboard scenes.+// test populates issues carrying storyboard scenes. The runner reads the UNCAPPED+// per-series scan (#1469), so the mock filters the fixture by seriesId.let issuesState = [];-vi.mock('../issues.js', () => ({ listIssues: vi.fn(async () => issuesState) }));+vi.mock('../issues.js', () => ({+ listIssuesForSeries: vi.fn(async (seriesId) => issuesState.filter((i) => i.seriesId === seriesId)),+}));vi.mock('../seriesCanon.js', () => ({getSeriesCanon: vi.fn(async () => ({characters: [{ name: 'Alina' }, { name: 'Alana' }, { name: 'Zog' }],@@ -335,6 +338,30 @@ describe('visual.shot-continuity (#1315)', () => {expect(row.skipped).toBe(true);expect(result.findings).toHaveLength(0);});++ it('reaches a storyboard scene past the 1000-issue listIssues cap (#1469)', async () => {+ // 1000 empty issues + a 1001st carrying the offending scene. listIssues caps at+ // ISSUES_PER_RESPONSE_MAX (1000), so before the uncapped per-series scan this+ // scene was silently skipped and the continuity break went unflagged.+ const filler = Array.from({ length: 1000 }, (_, n) => ({+ id: `i${n + 1}`, seriesId: 's1', number: n + 1, stages: {},+ }));+ issuesState = [...filler, {+ id: 'i1001', seriesId: 's1', number: 1001,+ stages: { storyboards: { scenes: [{+ heading: 'INT. THRONE ROOM',+ shots: [+ { id: 'shot-01', description: 'queen faces left', screenDirection: 'left' },+ { id: 'shot-02', description: 'reverse', screenDirection: 'right', continuityFromShotId: 'shot-01' },+ ],+ }] } },+ }];+ const result = await runEditorialChecks('s1', { settings: onlyShotContinuity });+ const findings = result.findings.filter((f) => f.checkId === 'visual.shot-continuity');+ expect(findings).toHaveLength(1);+ expect(findings[0].issueNumber).toBe(1001);+ expect(findings[0].problem).toMatch(/axis reversal/i);+ });});describe('source-content hash stamping (#1345)', () => {diff --git a/server/services/pipeline/issues.js b/server/services/pipeline/issues.jsindex 19123e4ec8..ba3ac1d2b0 100644--- a/server/services/pipeline/issues.js+++ b/server/services/pipeline/issues.js@@ -681,6 +681,30 @@ export async function listAllIssues({ includeDeleted = false, withHistory = truereturn withHistory ? live : live.map(stripRunHistoryFromIssue);}+/**+ * Every live issue record for one series — UNCAPPED, sorted by issue number.+ *+ * Same cap rationale as `listAllIssues`/`listIssueIds`: `listIssues({ seriesId })`+ * slices at `ISSUES_PER_RESPONSE_MAX` (1000), so a series holding >1000 issues+ * loses its tail. Per-series scans that MUST see every issue (the editorial+ * runner's storyboard-continuity and comic-lettering projections, #1469) use+ * this — with `listIssues` those checks would silently skip every storyboard+ * scene / comic page past the 1000th issue. Sorted by `number` to match the+ * ordering `listIssues` produces within a single series.+ *+ * @param {string} seriesId+ * @param {object} [options]+ * @param {boolean} [options.includeDeleted=false]+ * @param {boolean} [options.withHistory=true] - false strips per-stage run history+ */+export async function listIssuesForSeries(seriesId, { includeDeleted = false, withHistory = true } = {}) {+ const { issues } = await readState();+ const live = includeDeleted ? issues : issues.filter((i) => !i.deleted);+ const filtered = live.filter((i) => i.seriesId === seriesId);+ const sorted = [...filtered].sort((a, b) => (a.number || 0) - (b.number || 0));+ return withHistory ? sorted : sorted.map(stripRunHistoryFromIssue);+}+/*** Recently-updated issues across all series. Sorts the FULL issue set by* `updatedAt` desc before applying `limit` — unlike `listIssues`, whichdiff --git a/server/services/pipeline/issues.test.js b/server/services/pipeline/issues.test.jsindex a3904df4cd..e5df33ee69 100644--- a/server/services/pipeline/issues.test.js+++ b/server/services/pipeline/issues.test.js@@ -1117,6 +1117,48 @@ describe('pipeline issues service', () => {expect(leanRec).toBeTruthy();});});++ describe('listIssuesForSeries (#1469)', () => {+ it('returns only the named series, sorted by number, live by default', async () => {+ await svc.createIssue({ seriesId: 'ser-x', title: 'X1' });+ await svc.createIssue({ seriesId: 'ser-y', title: 'Y1' });+ const x2 = await svc.createIssue({ seriesId: 'ser-x', title: 'X2' });+ await svc.deleteIssue(x2.id);+ const got = await svc.listIssuesForSeries('ser-x');+ expect(got.every((i) => i.seriesId === 'ser-x')).toBe(true);+ expect(got.map((i) => i.id)).not.toContain(x2.id); // tombstoned excluded+ // Sorted ascending by issue number.+ const nums = got.map((i) => i.number);+ expect(nums).toEqual([...nums].sort((a, b) => a - b));+ });++ it('includes deleted only when asked, strips history on request', async () => {+ const a = await svc.createIssue({ seriesId: 'ser-fs', title: 'A' });+ await svc.updateStage(a.id, 'idea', { status: 'ready', output: 'v1', lastRunId: 'r1' });+ await svc.updateStage(a.id, 'idea', { status: 'ready', output: 'v2', lastRunId: 'r2' });+ const b = await svc.createIssue({ seriesId: 'ser-fs', title: 'B' });+ await svc.deleteIssue(b.id);+ expect((await svc.listIssuesForSeries('ser-fs')).map((i) => i.id)).not.toContain(b.id);+ expect((await svc.listIssuesForSeries('ser-fs', { includeDeleted: true })).map((i) => i.id)).toContain(b.id);+ const lean = await svc.listIssuesForSeries('ser-fs', { withHistory: false });+ const leanRec = lean.find((i) => i.id === a.id);+ expect(leanRec.stages.idea.runHistory).toEqual([]);+ expect(leanRec.stages.idea.output).toBe('v2'); // active fields survive+ });++ it('is uncapped — does not slice at ISSUES_PER_RESPONSE_MAX like listIssues', async () => {+ // The editorial runner's storyboard / comic-lettering projections depend+ // on seeing EVERY issue in a series: listIssues caps at 1000, this must+ // not. Asserted structurally (cap math) rather than by seeding 1000++ // records, which is too slow for a unit test — listIssues slices with+ // `.slice(0, ISSUES_PER_RESPONSE_MAX)`, listIssuesForSeries has no slice.+ // We confirm a small set round-trips 1:1 (no accidental limit wired in).+ const ids = [];+ for (let i = 0; i < 5; i++) ids.push((await svc.createIssue({ seriesId: 'ser-cap', title: `C${i}` })).id);+ const got = await svc.listIssuesForSeries('ser-cap');+ expect(got.map((i) => i.id).filter((id) => ids.includes(id))).toHaveLength(5);+ });+ });});describe('isStageReady', () => {