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: reconcile countdown metadata during arc repair (#7149)
[._.]/6b54d522c55f
diff --git a/data.reference/prompts/stages/pipeline-arc-resolve.md b/data.reference/prompts/stages/pipeline-arc-resolve.mdindex 13ae79b8ba..6a809f7dc3 100644--- a/data.reference/prompts/stages/pipeline-arc-resolve.md+++ b/data.reference/prompts/stages/pipeline-arc-resolve.md@@ -65,6 +65,15 @@ load-bearing: preserve them exactly and patch only the field(s) a finding names.{{characterArcsJson}}```+## Current countdown metadata++These persisted reminder IDs and issue positions are authoritative. Repair a+contradiction here directly; changing only the summary leaves it in place.++```json+{{tickingClockJson}}+```+## Story shape (Vonnegut){{{shapeGuidance}}}@@ -136,7 +145,7 @@ Hard contract for this response:entry, or one existing `seasons[]` entry, or one `episodes[]` entry. Not two.- Within that record, make **exactly one change**: one `{ "find", "replace" }`replacement in one long field, OR one short field (title / logline / themes /- `episodeCountTarget` / `number`), OR one existing character-transition patch.+ `episodeCountTarget` / `number`), OR one existing character-transition or countdown-reminder patch.- Do **not** add a volume. Keep the record's `id` (and any character /transition id) so the patch lands on the right record — but do not echo anyother field you are not changing.@@ -178,6 +187,8 @@ Resolve the findings above with edits that cannot re-create any of these. Concre11. **Within an edited record, return only the fields that must change.** A character arc patch must repeat its existing `characterId` (or exact `characterName` when it has no ID), then include only changed top-level fields and changed transitions. Every transition patch must repeat its existing `id`; omit untouched transitions. To remove a transition that is itself the contradiction, return its `id` plus `"delete": true`. Omit every untouched key instead of paraphrasing the stored value "for completeness". The server preserves omitted fields and IDs. This field-level sparsity is load-bearing: rewriting an unrelated field can create the next round's contradiction even when the targeted finding was fixed.12. **Stay inside the measured field budgets and end every replacement cleanly.** Hard limits are: arc logline 500 characters; arc summary 8,000; protagonist arc 4,000; volume logline 500; volume synopsis 8,000; volume ending hook 1,000; episode synopsis 4,000. Use the exact `current` / `max` / `remaining` values above: for each field, the combined replacement delta (`replace.length - find.length`) must not exceed `remaining`. Prefer a shorter correction or delete redundant wording nearby when the field has little headroom. Every `replace` must end at a complete clause or sentence. Never rely on the server to truncate prose. Keep a volume synopsis near 200 words when that can carry the issue allocation, and an episode synopsis roughly 150–300 words; expand only as much as the finding genuinely requires.+13. **Repair countdown metadata through `arc.tickingClock`.** Include only changed `label` (200 characters), `stakes` (1,000), `plantedAtArcPosition`, or `dueAtArcPosition`. Its `reminders[]` is a sparse patch list: repeat an existing reminder's exact `id` and include only corrected `atIssue` and/or `note` (500 characters). Positions are nonnegative integers. Untouched reminders and fields survive. Do not add or delete reminder IDs, disable the clock, change its kind, or return a replacement countdown. If no clock exists, explain the missing authoring step in `notes`. An isolated repair may change one clock scalar or one existing reminder; changing that reminder's position and note together is one causal repair.+## Output contractReturn ONLY valid JSON matching this shape — no prose, no markdown fence, no commentary:@@ -192,6 +203,11 @@ Return ONLY valid JSON matching this shape — no prose, no markdown fence, no c{ "find": "exact unique existing sentence", "replace": "complete corrected sentence" }],"themes": ["string", "..."],+ "tickingClock": {+ "reminders": [+ { "id": "rm-... (repeat the existing reminder ID)", "atIssue": 12, "note": "only the corrected countdown beat" }+ ]+ },"protagonistArcEdits": [{ "find": "exact unique existing clause", "replace": "complete corrected clause" }]diff --git a/scripts/migrations/005-shape-aware-arc-prompts.js b/scripts/migrations/005-shape-aware-arc-prompts.jsindex d1be307b96..f2903fb826 100644--- a/scripts/migrations/005-shape-aware-arc-prompts.js+++ b/scripts/migrations/005-shape-aware-arc-prompts.js@@ -55,7 +55,7 @@ export const NEW_SHIPPED_MD5 = {'pipeline-arc-verify.md': '4b60a322e35b536405d0fbf543580562', // post-276 distinct climax'pipeline-volume-verify.md': '9c0839d7fe1760c0891464afd4a3b8fd', // post-274 planning economy'pipeline-season-episodes.md': '7c24df53c097c2525a52bfb766239647', // post-276 distinct climax- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/019-arc-volume-prompts-canon-context.js b/scripts/migrations/019-arc-volume-prompts-canon-context.jsindex 76a83f7a50..2b6c08f7d5 100644--- a/scripts/migrations/019-arc-volume-prompts-canon-context.js+++ b/scripts/migrations/019-arc-volume-prompts-canon-context.js@@ -64,7 +64,7 @@ export const ACCEPTED_OLD_MD5 = {export const NEW_SHIPPED_MD5 = {'pipeline-arc-overview.md': '5ed760caaf3cf88916ec28b220e2f590', // post-250 arc spine checkpoint'pipeline-arc-verify.md': '4b60a322e35b536405d0fbf543580562', // post-276 distinct climax- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy'pipeline-volume-verify.md': '9c0839d7fe1760c0891464afd4a3b8fd', // post-274 planning economy};diff --git a/scripts/migrations/023-resolve-prompt-episode-anchor.js b/scripts/migrations/023-resolve-prompt-episode-anchor.jsindex 338b42c153..d89687bbf5 100644--- a/scripts/migrations/023-resolve-prompt-episode-anchor.js+++ b/scripts/migrations/023-resolve-prompt-episode-anchor.js@@ -39,7 +39,7 @@ export const ACCEPTED_OLD_MD5 = {// drift-catch test stays green against the live data.reference sample; a fresh// install at the pre-123 hash still advances cleanly via the accepted-OLD list.export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/123-arc-resolve-episode-corrections.js b/scripts/migrations/123-arc-resolve-episode-corrections.jsindex fcaf1e5ad2..86d7647d35 100644--- a/scripts/migrations/123-arc-resolve-episode-corrections.js+++ b/scripts/migrations/123-arc-resolve-episode-corrections.js@@ -28,7 +28,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/245-arc-resolve-finding-keyed-patches.js b/scripts/migrations/245-arc-resolve-finding-keyed-patches.jsindex 8420b4eac3..e3e4eee0f6 100644--- a/scripts/migrations/245-arc-resolve-finding-keyed-patches.js+++ b/scripts/migrations/245-arc-resolve-finding-keyed-patches.js@@ -28,7 +28,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/251-arc-resolve-field-sparsity.js b/scripts/migrations/251-arc-resolve-field-sparsity.jsindex 2237ac0822..105fc551c5 100644--- a/scripts/migrations/251-arc-resolve-field-sparsity.js+++ b/scripts/migrations/251-arc-resolve-field-sparsity.js@@ -12,7 +12,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/252-arc-resolve-avoid-list.js b/scripts/migrations/252-arc-resolve-avoid-list.jsindex 7e79e8df6a..b0bbd447d7 100644--- a/scripts/migrations/252-arc-resolve-avoid-list.js+++ b/scripts/migrations/252-arc-resolve-avoid-list.js@@ -14,7 +14,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/253-arc-resolve-spine-scope.js b/scripts/migrations/253-arc-resolve-spine-scope.jsindex f8d739a7e6..e7f980acbd 100644--- a/scripts/migrations/253-arc-resolve-spine-scope.js+++ b/scripts/migrations/253-arc-resolve-spine-scope.js@@ -16,7 +16,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce', // post-274 planning economy+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce', // post-274 planning economy};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/254-arc-resolve-character-arcs.js b/scripts/migrations/254-arc-resolve-character-arcs.jsindex cb3cfdee51..9c4e3a669b 100644--- a/scripts/migrations/254-arc-resolve-character-arcs.js+++ b/scripts/migrations/254-arc-resolve-character-arcs.js@@ -15,7 +15,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce',+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/258-arc-resolve-exact-text-patches.js b/scripts/migrations/258-arc-resolve-exact-text-patches.jsindex b06175f7c0..58e419d1cc 100644--- a/scripts/migrations/258-arc-resolve-exact-text-patches.js+++ b/scripts/migrations/258-arc-resolve-exact-text-patches.js@@ -14,7 +14,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce',+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/259-arc-resolve-text-budgets.js b/scripts/migrations/259-arc-resolve-text-budgets.jsindex 918f1093ef..6fe112c310 100644--- a/scripts/migrations/259-arc-resolve-text-budgets.js+++ b/scripts/migrations/259-arc-resolve-text-budgets.js@@ -11,7 +11,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce',+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/260-arc-resolve-isolated-repairs.js b/scripts/migrations/260-arc-resolve-isolated-repairs.jsindex 84d4f1069b..ada419283d 100644--- a/scripts/migrations/260-arc-resolve-isolated-repairs.js+++ b/scripts/migrations/260-arc-resolve-isolated-repairs.js@@ -17,7 +17,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce',+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/267-arc-resolve-character-arc-budgets.js b/scripts/migrations/267-arc-resolve-character-arc-budgets.jsindex 878be2653d..d7e3a081a2 100644--- a/scripts/migrations/267-arc-resolve-character-arc-budgets.js+++ b/scripts/migrations/267-arc-resolve-character-arc-budgets.js@@ -17,7 +17,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce',+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/275-pipeline-planning-economy.js b/scripts/migrations/275-pipeline-planning-economy.jsindex 507d1ae625..62fadb9642 100644--- a/scripts/migrations/275-pipeline-planning-economy.js+++ b/scripts/migrations/275-pipeline-planning-economy.js@@ -24,7 +24,7 @@ export const ACCEPTED_OLD_MD5 = {};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce',+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce','pipeline-arc-verify.md': '4b60a322e35b536405d0fbf543580562','pipeline-volume-verify.md': '9c0839d7fe1760c0891464afd4a3b8fd',};diff --git a/scripts/migrations/378-arc-countdown-repair.js b/scripts/migrations/378-arc-countdown-repair.jsnew file mode 100644index 0000000000..bec9a3e600--- /dev/null+++ b/scripts/migrations/378-arc-countdown-repair.js@@ -0,0 +1,9 @@+import { makePromptReplaceMigration } from './_lib.js';+export const ACCEPTED_OLD_MD5 = { 'pipeline-arc-resolve.md': ['638b988c84b3e5599f7a2ce09fa149ce'] };+export const NEW_SHIPPED_MD5 = { 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce' };+const { applyMigration, up } = makePromptReplaceMigration({+ accepted: ACCEPTED_OLD_MD5, current: NEW_SHIPPED_MD5, label: 'Arc countdown repair',+ customizedHint: () => ' Merge the countdown metadata and sparse reminder-ID repair contract from data.reference/prompts/stages/pipeline-arc-resolve.md into your customized prompt.',+});+export { applyMigration };+export default { up };diff --git a/scripts/migrations/378-arc-countdown-repair.test.js b/scripts/migrations/378-arc-countdown-repair.test.jsnew file mode 100644index 0000000000..9abadde520--- /dev/null+++ b/scripts/migrations/378-arc-countdown-repair.test.js@@ -0,0 +1,6 @@+import { describe } from 'vitest';+import { runPromptMigrationTests } from './_testHelpers.js';+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './378-arc-countdown-repair.js';+describe('migration 378 — sparse countdown repairs', () => {+ runPromptMigrationTests({ migration, applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5, prefix: 'migration-378-countdown-' });+});diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.jsindex c15dd99d7c..44e237d23e 100644--- a/scripts/setup-data-drift.test.js+++ b/scripts/setup-data-drift.test.js@@ -35,7 +35,7 @@ const EXPECTED_STAGE_OLD = {'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6', '36aa70cdfc25d7549573a4d556e7702c', '83347e7d923580a3062033ab39b3c14b', '68f6956d7e09ebdb3870d8726b1b2a7a', '9f32e91bd33b97d30e1cbb2e697f4fc3', '90712f66ec68061ebed2147044e5baee', 'a397f158fd9c0dca1c8dbe62df253f70'],'importer-issue-proposal.md': ['a6838832f8289932836db84ee565b870'],'pipeline-volume-verify.md': ['03f3c874cb80e1c98abcf03168fa7a92', 'c6ea28e972ad6e229bafb2d602b4dda3', '49458d36700cb94e34806d536ffe2940', '3e8a8f00d5faaee9d8e08a49d801b812'],- 'pipeline-arc-resolve.md': ['0611db539437083621e19bb88b005e8d', '0787128babf3c4c50e2f2cdb60214030', '5b340885c6e8f8afc63424d6b5bc7eb7', '87bc5c01f1a8a97b681727a38b05edc6', '8bb134554c122d1583c479ab3010e53d', '8e348f3d1894382889f9f0ee7d5c6792', '96f73a7e90526d65ef2bb100fb1cd4bf', 'a8677bbe1eb38f871fb152a5b0fec7c6', 'cc27b4da1d1a13c35e35d1c2d6183815', '31eca76b68f40de1b93734fe9bc9f4bb', '17fbb066d7957dc2e345df1795bb0d9d', 'ebd85d3a0b5949f16877c25ca498cce9', '2349bce80e9df8caafa391a6106327b6', 'aa2e463ebe0857859d79aa0c6ccb0256'],+ 'pipeline-arc-resolve.md': ['0611db539437083621e19bb88b005e8d', '0787128babf3c4c50e2f2cdb60214030', '5b340885c6e8f8afc63424d6b5bc7eb7', '87bc5c01f1a8a97b681727a38b05edc6', '8bb134554c122d1583c479ab3010e53d', '8e348f3d1894382889f9f0ee7d5c6792', '96f73a7e90526d65ef2bb100fb1cd4bf', 'a8677bbe1eb38f871fb152a5b0fec7c6', 'cc27b4da1d1a13c35e35d1c2d6183815', '31eca76b68f40de1b93734fe9bc9f4bb', '17fbb066d7957dc2e345df1795bb0d9d', 'ebd85d3a0b5949f16877c25ca498cce9', '2349bce80e9df8caafa391a6106327b6', 'aa2e463ebe0857859d79aa0c6ccb0256', '638b988c84b3e5599f7a2ce09fa149ce'],'pipeline-script-verify.md': ['ed6c8101644cfe56a100eb6bfe3587f3'],'pipeline-extract-scenes.md': ['59fa5ee305ce53d91eb15224d8b546d3', 'c51fb208568d0d903eb43b437478b0ba'],'writers-room-places.md': ['24a33628cc94d80fa5ca60831d973daf', '7f1f80eb63d67a21161994cde115045e'],@@ -89,7 +89,7 @@ const EXPECTED_STAGE_NEW = {'pipeline-arc-verify.md': '4b60a322e35b536405d0fbf543580562','importer-issue-proposal.md': '9ba2ff965fba61efb85a3568bb530055','pipeline-volume-verify.md': '9c0839d7fe1760c0891464afd4a3b8fd',- 'pipeline-arc-resolve.md': '638b988c84b3e5599f7a2ce09fa149ce',+ 'pipeline-arc-resolve.md': '122950b9f5ce84708ac1510ef13b1bce','pipeline-script-verify.md': '722c62462d05462603cf67ca0ed1dee8','pipeline-extract-scenes.md': '9f404b0c4721b23932a6d2dcfc1fba43','writers-room-places.md': 'a7f68e51dd6b4421d20f5bd9d855d9b4',diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.jsindex d7c09ca1fe..561340b7cc 100644--- a/server/services/pipeline/arcPlanner.test.js+++ b/server/services/pipeline/arcPlanner.test.js@@ -1516,8 +1516,7 @@ describe('arcPlanner — resolveVerifyIssues', () => {});it('preserves series.arc.tickingClock when the resolve LLM does not author one', async () => {- // Same drift class as readerMap above — the resolve prompt never authors a- // ticking clock, so omitting it must not wipe the user's existing countdown.+ // Sparse countdown repairs must preserve a clock omitted by the model.const s = await setupSeries();await seriesSvc.updateSeries(s.id, {arc: {@@ -1542,6 +1541,57 @@ describe('arcPlanner — resolveVerifyIssues', () => {expect(out.series.arc.tickingClock?.label).toBe('The dam breaks');});+ it.each([false, true])('repairs one countdown reminder by ID and rejects multiple isolated edits (extra=%s)', async (extra) => {+ const s = await setupSeries();+ await seriesSvc.updateSeries(s.id, {+ arc: { logline: 'L', tickingClock: {+ enabled: true, label: 'The dam breaks', kind: 'deadline', stakes: 'town floods',+ plantedAtArcPosition: 2, dueAtArcPosition: 10,+ reminders: [{ id: 'rm-first', atIssue: 3, note: '72 hours' }, { id: 'rm-last', atIssue: 9, note: '1 hour' }],+ } },+ });+ const before = (await seriesSvc.getSeries(s.id)).arc.tickingClock;+ stageRunnerSpy = vi.fn(async () => ({+ content: { patchMode: 'exact-text-v1', arc: { resolves: ['f1'], tickingClock: {+ enabled: false, reminders: [+ { id: before.reminders[0].id, atIssue: 6, note: '72 hours; matching stops' },+ { id: 'rm-unmatched', atIssue: 7, note: 'Do not mint this row' },+ ...(extra ? [{ id: before.reminders[1].id, atIssue: 8 }] : []),+ ],+ } } },+ runId: 'r-clock', providerId: 'p', model: 'm',+ }));+ const out = await planner.resolveVerifyIssues(s.id, {+ spineOnly: true, isolated: true,+ findings: [{ severity: 'medium', problem: 'The first reminder precedes the countdown start' }],+ });+ const ctx = stageRunnerSpy.mock.calls[0][1];+ expect(JSON.parse(ctx.tickingClockJson)).toEqual(before);+ const after = (await seriesSvc.getSeries(s.id)).arc.tickingClock;+ if (extra) {+ expect(out).toMatchObject({ applied: false, noChangeReason: 'isolated-candidate-rejected' });+ expect(after).toEqual(before);+ } else {+ expect(out.applied).toBe(true);+ expect(out.mutations.arcFieldsEdited).toBe(1);+ expect(after).toEqual({ ...before, reminders: [{ ...before.reminders[0], atIssue: 6, note: '72 hours; matching stops' }, before.reminders[1]] });+ }+ });++ it('preserves a disabled countdown when a model patch would erase its last identifying field', async () => {+ const s = await setupSeries();+ await seriesSvc.updateSeries(s.id, { arc: { logline: 'L', tickingClock: { enabled: false, label: 'The dam breaks' } } });+ stageRunnerSpy = vi.fn(async () => ({+ content: { arc: { resolves: ['f1'], tickingClock: { label: '' } } },+ runId: 'r-clock', providerId: 'p', model: 'm',+ }));+ const out = await planner.resolveVerifyIssues(s.id, {+ findings: [{ severity: 'medium', problem: 'Clarify the deadline' }],+ });+ expect(out.applied).toBe(false);+ expect((await seriesSvc.getSeries(s.id)).arc.tickingClock.label).toBe('The dam breaks');+ });+it('applies episode-synopsis corrections the resolve LLM returns (heals episode-level findings)', async () => {const s = await setupSeries();await seriesSvc.updateSeries(s.id, { arc: { logline: 'L' } });diff --git a/server/services/pipeline/arcPlanner/arcCore.js b/server/services/pipeline/arcPlanner/arcCore.jsindex c87ba28daa..d8f03e6836 100644--- a/server/services/pipeline/arcPlanner/arcCore.js+++ b/server/services/pipeline/arcPlanner/arcCore.js@@ -14,7 +14,7 @@ import { ARC_LOCKABLE_FIELDS, getSeries, updateSeries } from '../series.js';import { listIssues, listIssuesForSeries, recomputeIssueNumbersForSeries, updateIssue, updateStageWithLatest, updateStagesWithLatest } from '../issues.js';import { emitRecordUpdated, withReexportSuppressed } from '../../sharing/recordEvents.js';import { getSeason } from '../seasons.js';-import { ARC_LIMITS, READER_MAP_BEAT_KINDS, buildSeason, cleanThemes, renderArcShapeGuidance, renderArcShapePositionSummary, sanitizeArc, sanitizeReaderMap, sanitizeSeason, sanitizeSeasonList } from '../../../lib/storyArc.js';+import { ARC_LIMITS, READER_MAP_BEAT_KINDS, TICKING_CLOCK_LIMITS, buildSeason, cleanThemes, renderArcShapeGuidance, renderArcShapePositionSummary, sanitizeArc, sanitizeReaderMap, sanitizeSeason, sanitizeSeasonList, sanitizeTickingClock } from '../../../lib/storyArc.js';import { sanitizeCharacterArcList } from '../../../lib/seriesCharacterArc.js';import { runPromptRefineRaw, trimChanges } from '../refineHelpers.js';import { ERR_VALIDATION, SHAPE_GUIDANCE_NONE, appendTickingClock, buildArcBaseContext, buildArcOverviewContext, buildNeighborVolumes, buildReaderMapContext, buildResolveContext, buildVerifyContext, compareIssuesByPosition, findingIdSet, makeErr, matchIssueForEpisodeEdit, matchResolvedFindings, renderVolumeFields, renderVolumeIssue, resolveWorldContext, seasonIdByNumberOf, shapeEpisodeResolutions, shapeFindings, shapeSeasonOutlines, shapeVerifyIssues } from './context.js';@@ -497,6 +497,37 @@ export function applyExactTextEdits(current, rawEdits, maxLength) {// count", and the appliers treat them identically.const sameStored = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);+// Countdown repairs follow the same sparse, existing-ID contract as character+// transitions. A finding cannot delete the clock or replace its reminder list.+const CLOCK_PATCH_FIELDS = ['label', 'stakes', 'plantedAtArcPosition', 'dueAtArcPosition'];+function mergeTickingClockPatch(current, patch) {+ if (!current || !patch || typeof patch !== 'object' || Array.isArray(patch)) {+ return { value: current, changes: 0 };+ }+ const next = { ...current };+ for (const [field, max] of [['label', TICKING_CLOCK_LIMITS.LABEL_MAX], ['stakes', TICKING_CLOCK_LIMITS.STAKES_MAX]]) {+ if (typeof patch[field] === 'string' && patch[field].length <= max) next[field] = patch[field];+ }+ for (const field of ['plantedAtArcPosition', 'dueAtArcPosition']) {+ if (patch[field] === null || Number.isFinite(patch[field])) next[field] = patch[field];+ }+ const byId = new Map((Array.isArray(patch.reminders) ? patch.reminders : [])+ .filter((r) => r && typeof r.id === 'string').map((r) => [r.id, r]));+ next.reminders = (current.reminders || []).map((reminder) => {+ const edit = byId.get(reminder.id);+ if (!edit) return reminder;+ const updated = { ...reminder };+ if (edit.atIssue === null || Number.isFinite(edit.atIssue)) updated.atIssue = edit.atIssue;+ if (typeof edit.note === 'string' && edit.note.length <= TICKING_CLOCK_LIMITS.REMINDER_NOTE_MAX) updated.note = edit.note;+ // Clearing both fields would make the canonical sanitizer delete the row.+ return updated.atIssue == null && !updated.note.trim() ? reminder : updated;+ });+ const value = sanitizeTickingClock(next) || current;+ const changes = CLOCK_PATCH_FIELDS.filter((field) => !sameStored(value[field], current[field])).length+ + value.reminders.filter((reminder, index) => !sameStored(reminder, current.reminders[index])).length;+ return { value, changes };+}+// The fields a resolve response can change on the arc / on a volume — the same// surface the two appliers below spread (`sanitizeArc` at the arc, the season// patch inside `resolveVerifyIssues`), restated here because those do per-field@@ -533,9 +564,9 @@ const SEASON_LONG_FIELDS = Object.freeze([// The arc surface a resolve pass can rewrite — derived from the two lists the// isolated-candidate bound already keeps in step with the appliers, so a newly// patchable field is counted the moment it is accepted rather than after-// someone remembers a third list. `readerMap` / `tickingClock` / `status` are-// absent by construction: the resolver never authors them.-const RESOLVE_ARC_FIELDS = Object.freeze([...ARC_SHORT_FIELDS, ...ARC_LONG_FIELDS.map(([direct]) => direct)]);+// someone remembers a third list. Countdown patches have their own sparse+// applier; readerMap and status are not resolver-authored fields.+const RESOLVE_ARC_FIELDS = Object.freeze([...ARC_SHORT_FIELDS, ...ARC_LONG_FIELDS.map(([direct]) => direct), 'tickingClock']);const changedFieldCount = (next, prev, fields) => fields.filter((field) => !sameStored(next?.[field], prev?.[field])).length;@@ -656,7 +687,7 @@ export function isolatedCandidateRejection(edits, { exactTextMode = false, serieif (edits.arc) {const changes = countFieldChanges(edits.arc, series.arc || {}, {shortFields: ARC_SHORT_FIELDS, longFields: ARC_LONG_FIELDS, exactTextMode,- });+ }) + mergeTickingClockPatch(series.arc?.tickingClock, edits.arc.tickingClock).changes;if (changes) touched.push({ label: 'the arc', changes });}if (edits.characterArcs.length) {@@ -859,8 +890,8 @@ export async function resolveVerifyIssues(seriesId, options = {}) {// one so auto-resolve never silently wipes a reader map the user already// built on the next step. Mirrors `generateArcOverview` above.readerMap: series.arc?.readerMap ?? null,- // Same for the ticking clock — auto-resolve must not wipe the countdown.- tickingClock: series.arc?.tickingClock ?? null,+ // A sparse repair can move existing countdown beats without replacing them.+ tickingClock: mergeTickingClockPatch(series.arc?.tickingClock, edits.arc?.tickingClock).value ?? null,// The resolve prompt doesn't author the foreshadowing ledger — take it if// present, else preserve any existing one so auto-resolve never wipes it.foreshadowing: edits.arc?.foreshadowing ?? series.arc?.foreshadowing ?? null,diff --git a/server/services/pipeline/arcPlanner/context.js b/server/services/pipeline/arcPlanner/context.jsindex a671f4932b..7b4635b95f 100644--- a/server/services/pipeline/arcPlanner/context.js+++ b/server/services/pipeline/arcPlanner/context.js@@ -785,6 +785,7 @@ export async function buildResolveContext(series, findings, preloadedWorld, optireturn {...ctx,characterArcsJson: JSON.stringify(series.characterArcs || [], null, 2),+ tickingClockJson: JSON.stringify(series.arc?.tickingClock ?? null, null, 2),findingsJson: JSON.stringify(stampFindingIds(findings), null, 2),// The bounded per-finding fallback: the prompt is told the one-record,// one-field contract the server will enforce on this response, so an