From eb59f76a71707d030d959df07bbc734601eee8c4 Mon Sep 17 00:00:00 2001 From: zixiao Date: Fri, 3 Apr 2026 11:58:10 +0800 Subject: [PATCH] fix: preserve runtimeStateDelta after chapter content normalization When chapter content is normalized or revised (finalContent !== output.content), buildPersistenceOutput calls analyzeChapter whose output may not include runtimeStateDelta. This caused chapter_summaries.json to not be updated, making the planner repeat the previous chapter plot events on the next write. Also fix mustAdvance hook sort direction (ascending, not descending) so that the most neglected hooks are surfaced first. --- packages/core/src/pipeline/runner.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/src/pipeline/runner.ts b/packages/core/src/pipeline/runner.ts index 2816f87b..d2f2045a 100644 --- a/packages/core/src/pipeline/runner.ts +++ b/packages/core/src/pipeline/runner.ts @@ -2051,6 +2051,13 @@ ${matrix}`, postWriteWarnings: [], hookHealthIssues: output.hookHealthIssues, tokenUsage: output.tokenUsage, + // Preserve runtime state artifacts from the original write output if the + // chapter analyzer did not produce new ones. Without this, normalizing + // chapter content causes runtimeStateDelta to be dropped, which prevents + // saveRuntimeStateSnapshot from running and leaves chapter_summaries.json + // stale — causing the next chapter to repeat the same plot events. + runtimeStateDelta: analyzed.runtimeStateDelta ?? output.runtimeStateDelta, + runtimeStateSnapshot: analyzed.runtimeStateSnapshot ?? output.runtimeStateSnapshot, }; }