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

fix: stop arc verification stalling on a clipped character-arc milestone

[._.]/ Adam Eivy38175eb933a0
diff --git a/.changelog/next/fixed-agent-0cc4bdb5.md b/.changelog/next/fixed-agent-0cc4bdb5.md
new file mode 100644
index 0000000000..2ecc9233a4
--- /dev/null
+++ b/.changelog/next/fixed-agent-0cc4bdb5.md
@@ -0,0 +1 @@
+- Arc verification no longer stalls on a truncated character-arc milestone: over-cap transition labels now end on a complete clause, and the arc-resolve prompt receives the per-character and per-transition field budgets it was previously writing blind against
diff --git a/data.reference/prompts/stages/pipeline-arc-resolve.md b/data.reference/prompts/stages/pipeline-arc-resolve.md
index fd40a5de60..cbc8b70517 100644
--- a/data.reference/prompts/stages/pipeline-arc-resolve.md
+++ b/data.reference/prompts/stages/pipeline-arc-resolve.md
@@ -101,7 +101,7 @@ The verification pass flagged these problems. Resolve **every** one of them in y
{{findingsJson}}
```
-## Exact-text field budgets
+## Field budgets
These are measured from the current persisted strings above. For every exact
replacement, `replace.length - find.length` must be less than or equal to the
@@ -109,6 +109,14 @@ field's `remaining` value. A negative delta frees space. The server rejects the
entire replacement instead of truncating it when the resulting field would
exceed `max`.
+Character-arc fields are rewritten whole rather than by exact replacement, so
+each one you return must itself fit inside its `max`. Those caps are far tighter
+than the arc prose — a transition `label` gets 200 characters — and an over-cap
+label is **clipped, not rejected**, which lands a milestone that stops
+mid-thought and reads to the next verification pass as an incomplete record.
+Write the whole irreversible commitment inside the cap, compressing wording
+instead of running past it, and put supporting terms in the transition `note`.
+
```json
{{textBudgetsJson}}
```
diff --git a/scripts/migrations/005-shape-aware-arc-prompts.js b/scripts/migrations/005-shape-aware-arc-prompts.js
index 9d138d9d06..5b2be95590 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': '9f32e91bd33b97d30e1cbb2e697f4fc3', // post-263 world category canon
'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940', // post-019
'pipeline-season-episodes.md': 'a88e8e78a949b7aaf500d03314e2ea0b', // post-172 (structure rules)
- 'pipeline-arc-resolve.md': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
};
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.js
index 932a701bb1..0ca80e3bdc 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': '9f32e91bd33b97d30e1cbb2e697f4fc3', // post-263 world category canon
- 'pipeline-arc-resolve.md': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940', // post-019
};
diff --git a/scripts/migrations/023-resolve-prompt-episode-anchor.js b/scripts/migrations/023-resolve-prompt-episode-anchor.js
index 5227a09bba..e46de864ac 100644
--- a/scripts/migrations/023-resolve-prompt-episode-anchor.js
+++ b/scripts/migrations/023-resolve-prompt-episode-anchor.js
@@ -40,7 +40,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': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/123-arc-resolve-episode-corrections.js b/scripts/migrations/123-arc-resolve-episode-corrections.js
index 1c82982f1a..c31ab69f5a 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': '2349bce80e9df8caafa391a6106327b6', // post-260 (isolated one-patch repairs)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
};
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.js
index 28bebcb26a..5b23f22a31 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': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/251-arc-resolve-field-sparsity.js b/scripts/migrations/251-arc-resolve-field-sparsity.js
index 8ecd400470..35d7f1bcb2 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': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/252-arc-resolve-avoid-list.js b/scripts/migrations/252-arc-resolve-avoid-list.js
index 5735c74f36..dfb6536087 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': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/253-arc-resolve-spine-scope.js b/scripts/migrations/253-arc-resolve-spine-scope.js
index c064852dfa..2bc2312c70 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': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256', // post-267 (character-arc budgets)
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/254-arc-resolve-character-arcs.js b/scripts/migrations/254-arc-resolve-character-arcs.js
index 07919f914d..1114889f38 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': '2349bce80e9df8caafa391a6106327b6',
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256',
};
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.js
index 359b757a85..3f026331d9 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': '2349bce80e9df8caafa391a6106327b6',
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/259-arc-resolve-text-budgets.js b/scripts/migrations/259-arc-resolve-text-budgets.js
index 002da8c51c..5d11f6c43b 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': '2349bce80e9df8caafa391a6106327b6',
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256',
};
const { applyMigration, up } = makePromptReplaceMigration({
diff --git a/scripts/migrations/260-arc-resolve-isolated-repairs.js b/scripts/migrations/260-arc-resolve-isolated-repairs.js
index 1078bf878b..5431fa0aac 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': '2349bce80e9df8caafa391a6106327b6',
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256',
};
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.js
new file mode 100644
index 0000000000..cdf0297459
--- /dev/null
+++ b/scripts/migrations/267-arc-resolve-character-arc-budgets.js
@@ -0,0 +1,33 @@
+/**
+ * Publish the character-arc field budgets to the arc-resolve prompt.
+ *
+ * The measured-budget block only ever covered the arc + volume prose, whose
+ * caps run to 8,000 characters. A transition `label` gets 200 and is CLIPPED
+ * rather than rejected when the resolver overruns it — so a milestone rewrite
+ * landed as a half-clause ("...escrows the proceeds with no repayment lien,
+ * no"), the next verification round reported the record as textually
+ * incomplete, and the loop diverged. The prompt now names the whole-field
+ * (not exact-text) contract for character arcs and receives their budgets.
+ */
+
+import { makePromptReplaceMigration } from './_lib.js';
+
+export const ACCEPTED_OLD_MD5 = {
+ 'pipeline-arc-resolve.md': ['2349bce80e9df8caafa391a6106327b6'],
+};
+
+export const NEW_SHIPPED_MD5 = {
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256',
+};
+
+const { applyMigration, up } = makePromptReplaceMigration({
+ accepted: ACCEPTED_OLD_MD5,
+ current: NEW_SHIPPED_MD5,
+ label: 'arc-resolve character-arc budgets',
+ customizedHint: (filename) =>
+ ` To upgrade it manually, diff data.reference/prompts/stages/${filename}\n` +
+ ` against data/prompts/stages/${filename} and add the character-arc field budget rules.`,
+});
+
+export { applyMigration };
+export default { up };
diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.js
index b1fdadd4e6..6fe5af93ff 100644
--- a/scripts/setup-data-drift.test.js
+++ b/scripts/setup-data-drift.test.js
@@ -33,7 +33,7 @@ const EXPECTED_STAGE_OLD = {
'pipeline-arc-overview.md': ['6a3ecab43d1f46b7ef9aab6c69ea0326', 'd34d72b8e49ba303d38607845dd87f1c', '0a1f6ffa6908522e3690c5e9e53a6ee0', '612f8b04950e2ff26dd350dd76a062fe', '74d6c26548660d85fc345b2099c63b6c', '648e11352cd1565aee490de1f662bef0'],
'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6', '36aa70cdfc25d7549573a4d556e7702c', '83347e7d923580a3062033ab39b3c14b', '68f6956d7e09ebdb3870d8726b1b2a7a'],
'pipeline-volume-verify.md': ['03f3c874cb80e1c98abcf03168fa7a92', 'c6ea28e972ad6e229bafb2d602b4dda3'],
- 'pipeline-arc-resolve.md': ['0611db539437083621e19bb88b005e8d', '0787128babf3c4c50e2f2cdb60214030', '5b340885c6e8f8afc63424d6b5bc7eb7', '87bc5c01f1a8a97b681727a38b05edc6', '8bb134554c122d1583c479ab3010e53d', '8e348f3d1894382889f9f0ee7d5c6792', '96f73a7e90526d65ef2bb100fb1cd4bf', 'a8677bbe1eb38f871fb152a5b0fec7c6', 'cc27b4da1d1a13c35e35d1c2d6183815', '31eca76b68f40de1b93734fe9bc9f4bb', '17fbb066d7957dc2e345df1795bb0d9d', 'ebd85d3a0b5949f16877c25ca498cce9'],
+ 'pipeline-arc-resolve.md': ['0611db539437083621e19bb88b005e8d', '0787128babf3c4c50e2f2cdb60214030', '5b340885c6e8f8afc63424d6b5bc7eb7', '87bc5c01f1a8a97b681727a38b05edc6', '8bb134554c122d1583c479ab3010e53d', '8e348f3d1894382889f9f0ee7d5c6792', '96f73a7e90526d65ef2bb100fb1cd4bf', 'a8677bbe1eb38f871fb152a5b0fec7c6', 'cc27b4da1d1a13c35e35d1c2d6183815', '31eca76b68f40de1b93734fe9bc9f4bb', '17fbb066d7957dc2e345df1795bb0d9d', 'ebd85d3a0b5949f16877c25ca498cce9', '2349bce80e9df8caafa391a6106327b6'],
'pipeline-script-verify.md': ['ed6c8101644cfe56a100eb6bfe3587f3'],
'pipeline-extract-scenes.md': ['59fa5ee305ce53d91eb15224d8b546d3', 'c51fb208568d0d903eb43b437478b0ba'],
'writers-room-places.md': ['24a33628cc94d80fa5ca60831d973daf', '7f1f80eb63d67a21161994cde115045e'],
@@ -65,7 +65,7 @@ const EXPECTED_STAGE_NEW = {
'pipeline-arc-overview.md': '5ed760caaf3cf88916ec28b220e2f590',
'pipeline-arc-verify.md': '9f32e91bd33b97d30e1cbb2e697f4fc3',
'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940',
- 'pipeline-arc-resolve.md': '2349bce80e9df8caafa391a6106327b6',
+ 'pipeline-arc-resolve.md': 'aa2e463ebe0857859d79aa0c6ccb0256',
'pipeline-script-verify.md': '722c62462d05462603cf67ca0ed1dee8',
'pipeline-extract-scenes.md': '9f404b0c4721b23932a6d2dcfc1fba43',
'writers-room-places.md': 'a7f68e51dd6b4421d20f5bd9d855d9b4',
diff --git a/server/lib/seriesCharacterArc.test.js b/server/lib/seriesCharacterArc.test.js
index 6d63dd3fd4..205a205c27 100644
--- a/server/lib/seriesCharacterArc.test.js
+++ b/server/lib/seriesCharacterArc.test.js
@@ -54,6 +54,17 @@ describe('sanitizeTransition', () => {
expect(out).toBe(first.trim());
});
+ // The live failure this fixes (ser-bcebcf41, 2026-08-13): a milestone label is
+ // one clause-chained sentence with no terminator inside 200 chars, so the
+ // whole-word cut ended it on "…with no repayment lien, no" and the spine gate
+ // reported the record as textually incomplete every round.
+ it('ends a clause-chained over-long label on a complete clause', () => {
+ const label = 'Proves with the validated holder block that the hostile takeover cannot reach liquidation quorum, then closes the short position and escrows the proceeds with no repayment lien, no personal withdrawal key, and no veto';
+ const out = sanitizeTransition({ kind: 'point-of-no-return', label }).label;
+ expect(out.length).toBeLessThanOrEqual(CHARACTER_ARC_LIMITS.TRANSITION_LABEL_MAX);
+ expect(out.endsWith('with no repayment lien')).toBe(true);
+ });
+
it('falls back to a whole-word cut when an over-long note has no sentence break', () => {
const note = `${'word '.repeat(CHARACTER_ARC_LIMITS.TRANSITION_NOTE_MAX / 2)}tail`;
const out = sanitizeTransition({ kind: 'decision', label: 'x', note }).note;
diff --git a/server/lib/storyBible.js b/server/lib/storyBible.js
index 9ccd6536f3..8377c0457c 100644
--- a/server/lib/storyBible.js
+++ b/server/lib/storyBible.js
@@ -314,6 +314,15 @@ const SENTENCE_CUT_FLOOR = 0.3;
const SENTENCE_END_RE = /[.!?]["'’”)\]]*(?=\s|$)/g;
const COMMON_ABBREVIATION_RE = /\b(?:dr|etc|jr|mr|mrs|ms|prof|sr|st|vs)\.$/i;
+// A clause boundary — the weaker cut used when a short field holds no sentence
+// terminator at all. Short caps (a 200-char transition label) routinely hold one
+// long clause-chained sentence, where the whole-word fallback leaves a dangling
+// half-clause ("...escrows the proceeds with no repayment lien, no") that reads
+// as an authoring gap to the next verify round. Because it is weaker than a
+// sentence break, it has to keep more of the field to be worth taking.
+const CLAUSE_END_RE = /[,;:—–]/g;
+const CLAUSE_CUT_FLOOR = 0.6;
+
// Boundary-aware cap for PROSE fields (loglines, synopses, ending hooks). A hard
// `slice(0, max)` clips mid-word ("...tracing the brand and"), which downstream
// verify passes flag as "truncated mid-sentence" — and because a resolver then
@@ -321,10 +330,11 @@ const COMMON_ABBREVIATION_RE = /\b(?:dr|etc|jr|mr|mrs|ms|prof|sr|st|vs)\.$/i;
// verify→resolve loop never converges. When the text fits, it's returned
// untouched. When it must be clipped, back off to the last sentence terminator
// (. ! ?) within the budget, provided that cut keeps at least
-// SENTENCE_CUT_FLOOR of it; otherwise (one run-on sentence, or a break so early
-// that honoring it would gut the field) fall back to the last whitespace
-// boundary so the result still ends on a whole word. Never returns more than
-// `max` chars.
+// SENTENCE_CUT_FLOOR of it; failing that, to the last clause boundary (, ; : —)
+// keeping at least CLAUSE_CUT_FLOOR; and failing that (a single clause running
+// past the cap, or a break so early that honoring it would gut the field) to the
+// last whitespace boundary so the result still ends on a whole word. Never
+// returns more than `max` chars.
export function trimToClause(v, max) {
if (!isStr(v)) return '';
const s = v.trim();
@@ -339,7 +349,14 @@ export function trimToClause(v, max) {
end = m.index + m[0].length;
}
if (end >= Math.floor(max * SENTENCE_CUT_FLOOR)) return window.slice(0, end).trim();
- // No usable sentence break — clip on the last whole word instead of mid-word.
+ // No usable sentence break — back off to the last clause boundary instead, so
+ // the result ends on a complete clause rather than mid-thought. The mark itself
+ // is dropped (cut is exclusive) so the value never ends on a hanging comma.
+ let clause = -1;
+ CLAUSE_END_RE.lastIndex = 0;
+ for (let m = CLAUSE_END_RE.exec(window); m; m = CLAUSE_END_RE.exec(window)) clause = m.index;
+ if (clause >= Math.floor(max * CLAUSE_CUT_FLOOR)) return window.slice(0, clause).trim();
+ // Not even a usable clause break — clip on the last whole word instead of mid-word.
const space = window.lastIndexOf(' ');
return (space > 0 ? window.slice(0, space) : window).trim();
}
diff --git a/server/lib/storyBible.test.js b/server/lib/storyBible.test.js
index 8062602d02..f285e0cfc1 100644
--- a/server/lib/storyBible.test.js
+++ b/server/lib/storyBible.test.js
@@ -1518,6 +1518,32 @@ describe('storyBible — trimToClause (boundary-aware prose cap)', () => {
expect(trimToClause(text, 50)).toBe('The operator said, "Stop now."');
});
+ it('backs off to a clause boundary when the field holds no sentence break', () => {
+ // The shape a saturated 200-char transition label takes: one clause-chained
+ // sentence, no terminator anywhere in budget. Cutting on the last whole word
+ // leaves "...with no repayment lien, no" — a dangling half-clause the next
+ // verification round reports as an incomplete record.
+ const label = 'Proves with the validated block that the takeover cannot reach quorum, then closes the short and escrows the proceeds with no repayment lien, no personal withdrawal key, and no veto';
+ const out = trimToClause(label, 160);
+ expect(out).toBe('Proves with the validated block that the takeover cannot reach quorum, then closes the short and escrows the proceeds with no repayment lien');
+ expect(out.length).toBeLessThanOrEqual(160);
+ expect(/[,;:—–]$/.test(out)).toBe(false);
+ });
+
+ it('prefers a usable sentence break over a later clause break', () => {
+ const text = 'The vote carries after a long night of argument. The crews ratify, the boosters transfer, and the manifest is certified.';
+ expect(trimToClause(text, 70)).toBe('The vote carries after a long night of argument.');
+ });
+
+ it('ignores a clause break so early that honoring it would gut the field', () => {
+ // Comma at ~8% of the budget: keeping only "Yes" is worse than the ragged
+ // whole-word edge, so the word fallback still wins.
+ const text = `Yes, ${'word '.repeat(40)}`;
+ const out = trimToClause(text, 60);
+ expect(out.startsWith('Yes, word')).toBe(true);
+ expect(out.length).toBeGreaterThan(50);
+ });
+
it('never clips mid-word — falls back to a whole-word boundary on a run-on', () => {
// No sentence terminator within budget → must still end on a complete word,
// not "...tracing the brand an".
diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.js
index 1fce308bce..0c9b34fb5b 100644
--- a/server/services/pipeline/arcPlanner.test.js
+++ b/server/services/pipeline/arcPlanner.test.js
@@ -908,6 +908,60 @@ describe('arcPlanner — resolveVerifyIssues', () => {
});
});
+ // Transition labels cap at 200 and the sanitizer CLIPS an overrun instead of
+ // rejecting it, so a resolver writing blind lands a half-clause milestone that
+ // the next spine round reports as an incomplete record — the budget block is
+ // what tells it the cap it is actually measured against.
+ it('publishes per-transition character-arc budgets to the resolve prompt', async () => {
+ const s = await setupSeries();
+ await seriesSvc.updateSeries(s.id, {
+ arc: { logline: 'seed', summary: 'The queue claim changes hands.', status: 'draft' },
+ characterArcs: [{
+ characterId: 'chr-11111111-2222-3333-4444-555555555555',
+ characterName: 'Queue broker',
+ want: 'To keep the queue claim.',
+ transitions: [{
+ id: 'trn-11111111-2222-3333-4444-555555555555',
+ kind: 'point-of-no-return',
+ atIssue: 14,
+ label: 'Escrows the proceeds with no lien.',
+ note: 'The queue claim passes to the coalition.',
+ }],
+ }],
+ });
+
+ stageRunnerSpy = vi.fn(async () => ({
+ content: { notes: '' }, runId: 'r1', providerId: 'p', model: 'm',
+ }));
+ await planner.resolveVerifyIssues(s.id, {
+ findings: [{ severity: 'medium', problem: 'milestone is incomplete', suggestion: 'complete it' }],
+ });
+
+ const budgets = JSON.parse(stageRunnerSpy.mock.calls[0][1].textBudgetsJson);
+ expect(budgets.characterArcs).toHaveLength(1);
+ const [arcBudget] = budgets.characterArcs;
+ expect(arcBudget.characterId).toBe('chr-11111111-2222-3333-4444-555555555555');
+ expect(arcBudget.want).toEqual({
+ current: 'To keep the queue claim.'.length,
+ max: 1000,
+ remaining: 1000 - 'To keep the queue claim.'.length,
+ });
+ expect(arcBudget.transitions[0]).toEqual({
+ id: 'trn-11111111-2222-3333-4444-555555555555',
+ atIssue: 14,
+ label: {
+ current: 'Escrows the proceeds with no lien.'.length,
+ max: 200,
+ remaining: 200 - 'Escrows the proceeds with no lien.'.length,
+ },
+ note: {
+ current: 'The queue claim passes to the coalition.'.length,
+ max: 1000,
+ remaining: 1000 - 'The queue claim passes to the coalition.'.length,
+ },
+ });
+ });
+
it('rejects ambiguous, whole-field, and over-limit exact text edits', () => {
expect(planner.applyExactTextEdits(
'repeat here; repeat here',
diff --git a/server/services/pipeline/arcPlanner/context.js b/server/services/pipeline/arcPlanner/context.js
index 9d0587b0d2..acd7f3cbe7 100644
--- a/server/services/pipeline/arcPlanner/context.js
+++ b/server/services/pipeline/arcPlanner/context.js
@@ -11,7 +11,7 @@ import { MANUSCRIPT_TYPES } from '../series.js';
import { listIssues, STAGE_INPUT_MAX } from '../issues.js';
import { ARC_LIMITS, ARC_ROLES as ARC_ROLE_LIST, ARC_SHAPE_IDS, READER_MAP_BEAT_KINDS, buildSeason, renderArcShapeGuidance, renderTickingClock, sanitizeSeasonList } from '../../../lib/storyArc.js';
import { composeStyleNotes } from '../../../lib/styleGuide.js';
-import { renderCharacterArcsForPrompt } from '../../../lib/seriesCharacterArc.js';
+import { CHARACTER_ARC_LIMITS, renderCharacterArcsForPrompt } from '../../../lib/seriesCharacterArc.js';
import { describeStructure, recommendStructure } from '../../../lib/seasonStructure.js';
import { DEFAULT_LENGTH_PROFILE, LENGTH_PROFILE_NAMES } from '../../../lib/issueLength.js';
import { getUniverse } from '../../universeBuilder.js';
@@ -739,6 +739,15 @@ export function matchResolvedFindings(raw, validIds) {
* its scope prohibition on — see `resolveVerifyIssues` for why the two halves
* have to agree (#3789).
*/
+/**
+ * One entry of the resolve prompt's `textBudgetsJson`: what a field currently
+ * holds, its cap, and how much an exact-text replacement may add. Pure.
+ */
+const fieldBudget = (value, max) => {
+ const current = (typeof value === 'string' ? value : '').length;
+ return { current, max, remaining: Math.max(0, max - current) };
+};
+
export async function buildResolveContext(series, findings, preloadedWorld, options = {}) {
const ctx = await buildVerifyContext(series, preloadedWorld, { spineOnly: options.spineOnly === true });
const structure = recommendStructure(series.issueCountTarget);
@@ -756,30 +765,34 @@ export async function buildResolveContext(series, findings, preloadedWorld, opti
avoidJson: JSON.stringify(avoid, null, 2),
textBudgetsJson: JSON.stringify({
arc: {
- summary: {
- current: (series.arc?.summary || '').length,
- max: ARC_LIMITS.SUMMARY_MAX,
- remaining: Math.max(0, ARC_LIMITS.SUMMARY_MAX - (series.arc?.summary || '').length),
- },
- protagonistArc: {
- current: (series.arc?.protagonistArc || '').length,
- max: ARC_LIMITS.PROTAGONIST_ARC_MAX,
- remaining: Math.max(0, ARC_LIMITS.PROTAGONIST_ARC_MAX - (series.arc?.protagonistArc || '').length),
- },
+ summary: fieldBudget(series.arc?.summary, ARC_LIMITS.SUMMARY_MAX),
+ protagonistArc: fieldBudget(series.arc?.protagonistArc, ARC_LIMITS.PROTAGONIST_ARC_MAX),
},
seasons: (series.seasons || []).map((season) => ({
id: season.id,
number: season.number,
- synopsis: {
- current: (season.synopsis || '').length,
- max: ARC_LIMITS.SEASON_SYNOPSIS_MAX,
- remaining: Math.max(0, ARC_LIMITS.SEASON_SYNOPSIS_MAX - (season.synopsis || '').length),
- },
- endingHook: {
- current: (season.endingHook || '').length,
- max: ARC_LIMITS.SEASON_ENDING_HOOK_MAX,
- remaining: Math.max(0, ARC_LIMITS.SEASON_ENDING_HOOK_MAX - (season.endingHook || '').length),
- },
+ synopsis: fieldBudget(season.synopsis, ARC_LIMITS.SEASON_SYNOPSIS_MAX),
+ endingHook: fieldBudget(season.endingHook, ARC_LIMITS.SEASON_ENDING_HOOK_MAX),
+ })),
+ // Transition labels are capped an order of magnitude tighter than the arc
+ // prose (200 vs 8000), and the sanitizer clips an over-cap one instead of
+ // rejecting it — so a resolver writing blind lands a half-clause milestone,
+ // which the next round reports as an incomplete record and never converges
+ // on. Publishing the per-transition budget is what keeps the rewrite inside
+ // the cap it is actually being measured against.
+ characterArcs: (series.characterArcs || []).map((arc) => ({
+ characterId: arc.characterId,
+ characterName: arc.characterName,
+ want: fieldBudget(arc.want, CHARACTER_ARC_LIMITS.WANT_MAX),
+ need: fieldBudget(arc.need, CHARACTER_ARC_LIMITS.NEED_MAX),
+ startState: fieldBudget(arc.startState, CHARACTER_ARC_LIMITS.START_STATE_MAX),
+ endState: fieldBudget(arc.endState, CHARACTER_ARC_LIMITS.END_STATE_MAX),
+ transitions: (arc.transitions || []).map((transition) => ({
+ id: transition.id,
+ atIssue: transition.atIssue,
+ label: fieldBudget(transition.label, CHARACTER_ARC_LIMITS.TRANSITION_LABEL_MAX),
+ note: fieldBudget(transition.note, CHARACTER_ARC_LIMITS.TRANSITION_NOTE_MAX),
+ })),
})),
}, null, 2),
recommendedStructure: structure