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: per-issue text prompts listed every character twice (bible + roster)
[._.]/ Adam Eivy03c1260cbd2a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 233d6c9c87..5ea120c234 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -17,6 +17,7 @@## Fixed+- **Per-issue text generation no longer lists every character twice.** Each prose/comic-script/teleplay prompt rendered the series-canon characters as full bible records in `### Characters`, and then re-listed the very same characters in the terse `### Universe at a glance` roster — so every character appeared twice in the prompt (wasted tokens, and the source of a "why is this character in here twice" report). The roster now excludes characters already in the full bible (as its own code comment always intended — it's meant to add *places/objects + other* canon not in the series bible), keeping its places/objects and any non-series-canon characters. (`server/lib/universePromptRenderers.js`, `server/services/pipeline/textStages.js`)- **A usage-limited provider is no longer benched for up to a day.** When a CLI provider (e.g. Codex) hit its usage limit, PortOS parsed the provider's self-reported reset ("resets in 21h 52m") and benched it for that entire span — sidelining the primary for nearly a day even though usage limits reset on a rolling window (≈5h max) and capacity usually frees much sooner. The usage-limit bench is now a tight retry interval (default 10 minutes), hard-capped at the 5h reset window, and it still respects a genuinely *shorter* stated reset. The provider's stated reset is kept for display. (`server/lib/aiToolkit/providerStatus.js`)- **Autopilot editorial auto-fix now honors the run's chosen provider/model.** The editorial loop passed the run's provider override to the manuscript *review* but not to fix *generation*, so auto-fixes silently ran on the active/default provider (and its runtime fallback) instead of the model selected for the run — which, when the default was rate-limited, degraded fixes onto a weak fallback. Fix generation now threads the same override as the review. (`server/services/pipeline/seriesAutopilot.js`)- **Manuscript editorial review no longer reports a fully-drafted book as "empty."** The completeness pass injected the entire universe canon (characters + places + objects JSON, which for a large universe can be 800K+ chars / 200K+ tokens) as fixed context on every call. On any model whose context window the canon exceeded, the budgeter's usable-input budget collapsed to zero and the manuscript was sliced to an empty string — so the LLM "reviewed" a blank draft and returned a wall of identical "the drafted manuscript is empty" findings that could never be resolved, hard-pausing the autopilot at editorial review. The canon is now hard-capped to a reference-sized budget and window-aware-trimmed so the manuscript always keeps a budget floor (mirroring the editorial *check* runner's #1459 protection): a frontier-window model reviews the whole book in one pass, a smaller window chunks it — but the draft is never starved to empty.diff --git a/server/lib/universePromptRenderers.js b/server/lib/universePromptRenderers.jsindex 65d757c2f7..0a00754c25 100644--- a/server/lib/universePromptRenderers.js+++ b/server/lib/universePromptRenderers.js@@ -178,11 +178,21 @@ const SUMMARY_SECTIONS = [* (prose/teleplay/comic-script) where the budget can't afford the full* dump but the LLM still needs continuity anchors.*/-export function renderEntitiesSummary(world, { maxPerKind = ENTITIES_SUMMARY_MAX_PER_KIND } = {}) {+// `excludeCharacterNames` (a Set of lower-cased names) drops characters already+// rendered in full elsewhere in the same prompt — e.g. the per-issue text stages+// list the series-canon characters as full bible records, so re-listing them in+// this terse roster is pure duplication. Places/objects are never excluded (they+// have no full-record block to overlap with). The exclusion happens BEFORE the+// top-N slice so the "+N more" count reflects what's actually withheld.+export function renderEntitiesSummary(world, { maxPerKind = ENTITIES_SUMMARY_MAX_PER_KIND, excludeCharacterNames = null } = {}) {if (!world || typeof world !== 'object') return '';+ const exclude = excludeCharacterNames instanceof Set ? excludeCharacterNames : null;const lines = [];for (const { field, header, formatEntry } of SUMMARY_SECTIONS) {- const entries = Array.isArray(world[field]) ? world[field] : [];+ let entries = Array.isArray(world[field]) ? world[field] : [];+ if (field === 'characters' && exclude && exclude.size) {+ entries = entries.filter((e) => !exclude.has((e?.name || '').trim().toLowerCase()));+ }if (!entries.length) continue;const shown = entries.slice(0, maxPerKind);const hidden = entries.length - shown.length;diff --git a/server/lib/universePromptRenderers.test.js b/server/lib/universePromptRenderers.test.jsindex d75125e46f..4eccb3253d 100644--- a/server/lib/universePromptRenderers.test.js+++ b/server/lib/universePromptRenderers.test.js@@ -25,6 +25,35 @@ describe('renderEntitiesSummary', () => {expect(out.split('\n')).toHaveLength(3);});+ it('excludes characters already in the bible (excludeCharacterNames), keeping places/objects', () => {+ const world = {+ characters: [+ { name: 'Mira', role: 'surveyor' },+ { name: 'ASTER-9 CHANDELIER', role: 'fixture' },+ { name: 'Off-canon Extra', role: 'walk-on' },+ ],+ places: [{ name: 'The Foundry', description: 'industrial district' }],+ };+ const out = renderEntitiesSummary(world, {+ excludeCharacterNames: new Set(['mira', 'aster-9 chandelier']),+ });+ // Bible characters dropped from the roster; the non-canon one survives.+ expect(out).not.toContain('Mira');+ expect(out).not.toContain('ASTER-9 CHANDELIER');+ expect(out).toContain('Off-canon Extra');+ // Places are never excluded.+ expect(out).toContain('Places: The Foundry');+ });++ it('drops the whole characters line + corrects the +N more count when excluded', () => {+ const chars = Array.from({ length: ENTITIES_SUMMARY_MAX_PER_KIND + 5 }, (_, i) => ({ name: `C${i + 1}`, role: 'r' }));+ // Exclude the first 5 → remaining exactly ENTITIES_SUMMARY_MAX_PER_KIND, no "+N more".+ const exclude = new Set(['c1', 'c2', 'c3', 'c4', 'c5']);+ const out = renderEntitiesSummary({ characters: chars }, { excludeCharacterNames: exclude });+ expect(out).not.toContain('C1 (');+ expect(out).not.toContain('(+'); // exactly maxPerKind remain after exclusion+ });+it('omits kinds with zero entries', () => {const out = renderEntitiesSummary({characters: [{ name: 'Mira', role: 'surveyor' }],diff --git a/server/services/pipeline/textStages.js b/server/services/pipeline/textStages.jsindex ec95bedee1..661aacfb85 100644--- a/server/services/pipeline/textStages.js+++ b/server/services/pipeline/textStages.js@@ -220,8 +220,16 @@ function buildStageContext({ series, canon, world, issue, stageId, seedInput, so// canon-block token cost — `series.characters` already covers the bible-// sized character context, this adds places/objects + other characters not// pulled into the series-canon for continuity anchors.+ // Exclude the series-canon characters from the terse roster — they're already+ // rendered in full in the bible's "### Characters" block above, so re-listing+ // them in "Universe at a glance" duplicates every character in the prompt. The+ // roster then does what its comment intends: adds places/objects + any OTHER+ // characters not pulled into the series canon.+ const seriesCharacterNames = new Set(+ (canon?.characters || []).map((c) => (c?.name || '').trim().toLowerCase()).filter(Boolean),+ );const worldEntitiesSummary = world- ? (renderEntitiesSummary(world) || '(none)')+ ? (renderEntitiesSummary(world, { excludeCharacterNames: seriesCharacterNames }) || '(none)'): NO_LINKED_UNIVERSE_PLACEHOLDER;return {series: {diff --git a/server/services/pipeline/textStages.test.js b/server/services/pipeline/textStages.test.jsindex 1d22dbf29f..469c799d52 100644--- a/server/services/pipeline/textStages.test.js+++ b/server/services/pipeline/textStages.test.js@@ -180,7 +180,7 @@ describe('pipeline text stage generator', () => {expect(ctx.worldEntitiesSummary).toBe('(none — series has no linked Universe Builder world)');});- it('prompt context carries a rendered worldEntitiesSummary when series links a universe', async () => {+ it('renders worldEntitiesSummary roster but does NOT re-list characters already in the full bible', async () => {const { series, issue } = await seed();const world = await universeSvc.createUniverse({ name: 'Salt Verse' });await universeSvc.updateUniverse(world.id, {@@ -193,9 +193,12 @@ describe('pipeline text stage generator', () => {await seriesSvc.updateSeries(series.id, { universeId: world.id });await textStages.generateStage(issue.id, 'idea');const ctx = ctxFromCall(llmCalls[0]);- expect(ctx.worldEntitiesSummary).toContain('Mira (surveyor — broad-shouldered)');- expect(ctx.worldEntitiesSummary).toContain('Jonas (foreman — cunning)');+ // The characters appear in full in the bible (series.characters)…+ expect((ctx.series.characters || []).map((c) => c.name)).toEqual(expect.arrayContaining(['Mira', 'Jonas']));+ // …so the terse roster must NOT duplicate them — it carries places/objects.expect(ctx.worldEntitiesSummary).toContain('The Foundry (industrial district)');+ expect(ctx.worldEntitiesSummary).not.toContain('Mira');+ expect(ctx.worldEntitiesSummary).not.toContain('Jonas');});it('prompt context carries lengthTargets from a named non-default profile (extended)', async () => {