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): observe cancellation between manuscript chunks

[._.]/ Adam Eivy58f687c6803c
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 4987f3e024..7079b04a77 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -237,6 +237,10 @@ async function runManuscriptLlmCheck(ctx, { stage, category, overheadTokens = 0,
const chunks = await ctx.planManuscriptChunks(stage, { overheadTokens });
const perChunk = [];
for (const manuscript of chunks) {
+ // Stop launching further chunk calls once the run is cancelled — the runner
+ // only checks the signal around the whole check, so without this a multi-
+ // chunk check keeps paying for LLM calls whose results will be discarded.
+ if (ctx.signal?.aborted) break;
const { content } = await ctx.callStagedLLM(stage, buildVars(manuscript), { returnsJson: true, source: stage });
perChunk.push(mapLlmFindings(content?.findings, {
severityDefault: ctx.severityDefault,
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index ba0a74b1ff..de6d204ff3 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -84,6 +84,10 @@ export async function runEditorialChecks(seriesId, options = {}) {
canon,
providerOverride,
modelOverride,
+ // The run's AbortSignal, so a multi-chunk LLM check can stop launching
+ // further chunk calls mid-run (the runner only checks it before/after each
+ // check.run()). Mirrors the per-chunk cancel check in the completeness pass.
+ signal,
// Injected LLM caller — keeps server/lib/editorial pure. Forwards the
// provider/model overrides so an LLM check honors the autopilot's choice.
callStagedLLM: (stage, vars, opts = {}) =>
diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.js
index 06d5feaf34..b72386e611 100644
--- a/server/services/pipeline/editorial/checkRunner.test.js
+++ b/server/services/pipeline/editorial/checkRunner.test.js
@@ -175,6 +175,26 @@ describe('runEditorialChecks', () => {
expect(sent).toContain('kingdom fell'); // the actual section content, not an empty slice
});
+ it('stops launching chunk calls once cancelled mid-run (issue #1340)', async () => {
+ // Three chunks; cancel during the first chunk's LLM call. The remaining
+ // chunks must NOT be sent to the model, and the run is canceled (no seed).
+ const big = (marker) => `${marker} ${'A'.repeat(12_000)}`;
+ collectManuscriptSections.mockResolvedValueOnce([
+ { number: 1, title: 'One', stageId: 'prose', content: big('SEC1') },
+ { number: 2, title: 'Two', stageId: 'prose', content: big('SEC2') },
+ { number: 3, title: 'Three', stageId: 'prose', content: big('SEC3') },
+ ]);
+ resolveStageContext.mockResolvedValueOnce({ provider: { type: 'api', endpoint: 'http://localhost:11434' }, model: 'm', contextWindow: 10_000 });
+ const controller = new AbortController();
+ runStagedLLM.mockImplementationOnce(async () => { controller.abort(); return { content: { findings: [] } }; });
+
+ const result = await runEditorialChecks('s1', { checkIds: ['prose.info-dumping'], signal: controller.signal });
+
+ expect(runStagedLLM).toHaveBeenCalledTimes(1); // chunks 2 and 3 skipped after abort
+ expect(result.canceled).toBe(true);
+ expect(seedReviewFromFindings).not.toHaveBeenCalled();
+ });
+
it('one failing check does not abort the pass', async () => {
// Make info-dumping the only enabled LLM check so the single rejection lands
// on it (the object LLM checks would otherwise consume the mockRejectedOnce).