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

storyArc: clip arc prose fields on a clause/word boundary, not mid-word

[._.]/ Adam Eivy01739bbaec33
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 24d9e9cd38..37f79d661a 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -56,3 +56,4 @@
- **Deterministic editorial checks now self-heal — corrected or resolved findings clear instead of lingering forever.** The editorial-checks pass seeded every finding in `merge` mode, which only ever *adds* findings: an open finding a deterministic check no longer produces (because the check was fixed, or the underlying canon/manuscript changed) stayed open permanently. That let stale findings accumulate and could keep Series Autopilot's editorial-health gate blocked on problems that no longer exist. Deterministic checks (pure functions of their inputs) are now seeded in `fresh` mode scoped to each check's own id, so a finding the check no longer surfaces is auto-dismissed (a sync-safe status flip, never a deletion) — including when a check finds nothing at all that pass. LLM checks stay `merge`-only, since an absent LLM finding can be sampling variance rather than a real resolution; one check's reconciliation never touches another check's or the completeness pass's open comments. (`server/services/pipeline/editorial/checkRunner.js`)
- **The name-dissimilarity check no longer flags a name against its own plural.** A role-noun cast ("THE POET" / "the poets", "a reader" / "readers", "a waiter" / "the waiters") tripped the check's edit-distance-1 rule — a single trailing "s" reads as a near-identical-spelling typo — and escalated each pair to a *high*-severity blocker, even though singular-vs-plural is a deliberate count distinction (an individual vs a crowd) a reader parses effortlessly. The check now recognizes singular/plural variants of the same noun (the three common English inflections: -s, -es, -ies) and treats the pair as inert, while two genuinely different words that merely both end in "s" still compare normally. (`server/lib/editorial/nameSimilarity.js`)
- **A season synopsis is no longer truncated mid-sentence (which could hang Series Autopilot's arc-verify loop).** The season-synopsis cap was 4000 characters — half the arc-level summary cap (8000) — even though a season synopsis covers a whole season's worth of episodes. A full synopsis got hard-clipped mid-word, and because the arc-verify→resolve convergence loop re-flags a mid-sentence truncation while the resolver keeps regenerating an over-cap synopsis that gets re-clipped, the loop burned all its rounds and paused without ever converging. The season-synopsis cap is now 8000 (matching the arc summary), so a complete synopsis is stored intact. (`server/lib/storyArc.js`)
+- **Arc prose fields (logline, synopsis, ending hook) now clip on a sentence/word boundary instead of mid-word.** A hard character-cap `slice()` could clip a season logline or synopsis mid-word ("…starts tracing the brand and"), which the arc-verify pass flags as "truncated mid-sentence" — and because the resolver then regenerates an over-cap value that gets re-clipped identically, the verify→resolve loop could never converge and paused the autopilot. A new `trimToClause` helper backs an over-cap value off to the last sentence terminator within budget (or, for a run-on, the last whole-word boundary), so a capped field always reads as complete prose. Applied to the arc and season logline/summary/synopsis/ending-hook/protagonist-arc fields. (`server/lib/storyBible.js`, `server/lib/storyArc.js`)
diff --git a/server/lib/storyArc.js b/server/lib/storyArc.js
index d026412338..0f11087fe5 100644
--- a/server/lib/storyArc.js
+++ b/server/lib/storyArc.js
@@ -17,7 +17,7 @@
*/
import { randomUUID } from 'crypto';
-import { isStr, trimTo } from './storyBible.js';
+import { isStr, trimTo, trimToClause } from './storyBible.js';
import { sanitizeCoverLike } from './renderSlot.js';
export const ARC_LIMITS = Object.freeze({
@@ -426,9 +426,11 @@ export function renderTickingClock(clock) {
export function sanitizeArc(raw) {
if (raw == null) return null;
if (typeof raw !== 'object') return null;
- const logline = trimTo(raw.logline, ARC_LIMITS.LOGLINE_MAX);
- const summary = trimTo(raw.summary, ARC_LIMITS.SUMMARY_MAX);
- const protagonistArc = trimTo(raw.protagonistArc, ARC_LIMITS.PROTAGONIST_ARC_MAX);
+ // Prose fields use the boundary-aware cap so an over-cap value never clips
+ // mid-word (which arc-verify flags as a truncation it can't converge on).
+ const logline = trimToClause(raw.logline, ARC_LIMITS.LOGLINE_MAX);
+ const summary = trimToClause(raw.summary, ARC_LIMITS.SUMMARY_MAX);
+ const protagonistArc = trimToClause(raw.protagonistArc, ARC_LIMITS.PROTAGONIST_ARC_MAX);
const themes = cleanThemes(raw.themes);
// An arc with zero identifying content is indistinguishable from "no arc"
// — store null so the UI can render the empty state instead of a blank
@@ -473,11 +475,17 @@ export function sanitizeSeason(raw, { preserveTimestamps = true } = {}) {
id: ensureSeasonId(raw.id),
number,
title,
- logline: trimTo(raw.logline, ARC_LIMITS.SEASON_LOGLINE_MAX),
- synopsis: trimTo(raw.synopsis, ARC_LIMITS.SEASON_SYNOPSIS_MAX),
+ // Prose fields use the boundary-aware cap (trimToClause) so an over-cap
+ // value clips on a sentence/word boundary instead of mid-word — otherwise a
+ // hard clip reads as "truncated mid-sentence" to arc-verify, which then
+ // can't converge (the resolver regenerates an over-cap value that's
+ // re-clipped the same way every round). See arc-verify truncation findings,
+ // 2026-06-21.
+ logline: trimToClause(raw.logline, ARC_LIMITS.SEASON_LOGLINE_MAX),
+ synopsis: trimToClause(raw.synopsis, ARC_LIMITS.SEASON_SYNOPSIS_MAX),
episodeCountTarget,
themes: cleanThemes(raw.themes),
- endingHook: trimTo(raw.endingHook, ARC_LIMITS.SEASON_ENDING_HOOK_MAX),
+ endingHook: trimToClause(raw.endingHook, ARC_LIMITS.SEASON_ENDING_HOOK_MAX),
// Volume (season) cover + back cover. Same script + proof + final
// slot shape as an issue cover; rendered by enqueueVolumeCover and
// assembled into the volume PDF as the trade-paperback bookends.
diff --git a/server/lib/storyBible.js b/server/lib/storyBible.js
index 3c04364606..dc155fa51a 100644
--- a/server/lib/storyBible.js
+++ b/server/lib/storyBible.js
@@ -253,6 +253,29 @@ const DEFAULT_ID_PREFIX = Object.freeze({
export const isStr = (v) => typeof v === 'string';
export const trimTo = (v, max) => (isStr(v) ? v.trim().slice(0, max) : '');
+// 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
+// regenerates an over-cap value that gets re-clipped the same way, the
+// 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; if there's no sentence break in the last ~40% of
+// the budget (one run-on sentence), fall back 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();
+ if (s.length <= max) return s;
+ const window = s.slice(0, max);
+ // Prefer the last sentence terminator, but only if it's not so early that we'd
+ // drop most of the content (keep at least ~60% of the budget).
+ const sentence = Math.max(window.lastIndexOf('. '), window.lastIndexOf('! '), window.lastIndexOf('? '));
+ if (sentence >= Math.floor(max * 0.6)) return window.slice(0, sentence + 1).trim();
+ // No usable sentence break — clip on the last whole word instead of mid-word.
+ const space = window.lastIndexOf(' ');
+ return (space > 0 ? window.slice(0, space) : window).trim();
+}
+
// Walk a raw array through a per-item sanitizer, dropping rejected entries
// (falsy return from `sanitizer`) and capping the output at `cap`. Three
// near-identical loops elsewhere in this file (cleanStringArray, the wardrobe
diff --git a/server/lib/storyBible.test.js b/server/lib/storyBible.test.js
index 258f994b80..21d24176b4 100644
--- a/server/lib/storyBible.test.js
+++ b/server/lib/storyBible.test.js
@@ -33,6 +33,8 @@ const {
stripCanonControlFields,
CANON_CONTROL_FIELDS,
SERVER_OWNED_CHARACTER_FIELDS,
+ trimTo,
+ trimToClause,
} = storyBible;
const WORK_ID = 'wr-work-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
@@ -1402,3 +1404,40 @@ describe('BIBLE_LIMITS client mirror', () => {
expect(clientMirror.BIBLE_LIMITS).toEqual(BIBLE_LIMITS);
});
});
+
+describe('storyBible — trimToClause (boundary-aware prose cap)', () => {
+ it('returns text untouched when it fits', () => {
+ expect(trimToClause('A short logline.', 500)).toBe('A short logline.');
+ expect(trimToClause(' trimmed ', 500)).toBe('trimmed');
+ });
+
+ it('is empty for non-strings (matches trimTo)', () => {
+ expect(trimToClause(null, 50)).toBe('');
+ expect(trimToClause(undefined, 50)).toBe('');
+ expect(trimToClause(42, 50)).toBe('');
+ });
+
+ it('clips at a sentence boundary when one falls in the last ~40% of the budget', () => {
+ const text = 'First full sentence about the arc here. And then a second clause runs on well past the budget.';
+ const out = trimToClause(text, 50);
+ expect(out).toBe('First full sentence about the arc here.');
+ expect(out.length).toBeLessThanOrEqual(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".
+ const runon = 'JUNO risks her anonymity to be recognized as author while Caroline Marsh starts tracing the brand and the buzz';
+ const out = trimToClause(runon, 60);
+ expect(out.length).toBeLessThanOrEqual(60);
+ expect(out.endsWith(' ')).toBe(false);
+ // The last token is a whole word from the source (no partial word).
+ const lastWord = out.split(' ').pop();
+ expect(runon.split(' ')).toContain(lastWord);
+ });
+
+ it('never returns more than max characters', () => {
+ const long = 'word '.repeat(400); // 2000 chars, no sentence breaks
+ expect(trimToClause(long, 100).length).toBeLessThanOrEqual(100);
+ });
+});