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([issue-731]): flag Story Builder steps stale on out-of-band output edits

[._.]/ Adam Eivy8b0c4de1f071
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 74abef9a57..86b7a023ca 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -78,5 +78,6 @@
- **[issue-728] Imported stories no longer fake a "Ready" aesthetic or reader map** — when you start a Story Builder session from an import, only the steps the importer actually fills (idea, plot arc, characters, issues) open as "Ready" to review. The Universe Aesthetic and Reader Map steps now start "pending" instead of showing an empty step under a misleading "Ready" badge, so you generate them like you would in a from-scratch build.
- **Self-update no longer crashes at the "Rebuilding esbuild" step** — the updater rebuilt esbuild via a hardcoded `node_modules/esbuild/install.js` path that assumed esbuild was hoisted to the top of each dependency tree. It no longer is (esbuild nests under Vite/Vitest, and the server dropped its esbuild dependency entirely with Vitest 4 → Vite 8), so the path 404'd and aborted the whole update with exit code 1. The updater now uses `npm rebuild esbuild`, which finds esbuild wherever it lives and skips cleanly when absent; the same fix lands in `npm run install:all` and the Windows updater.
- **[issue-796] Agent CPU/memory readouts work on Windows** — on Windows installs, the live CPU and memory stats for running agents always read as zero. The stats reader expected Unix `ps` output but was being handed Windows `tasklist`'s comma-quoted format, so it never found the numbers. It now reads the Windows format correctly, reporting real memory usage and marking a finished agent as done rather than leaving it in an unknown state.
+- **[issue-731] Locked Story Builder steps flag stale when their own content is edited elsewhere** — locking a step (e.g. Universe Aesthetic) only gates the Story Builder wizard; the underlying universe and series records stay editable in Universe Builder, Arc Planner, and the cast editor. Editing a locked step's own content out-of-band — changing the universe logline, rewriting the arc, or adding a character — now marks that step stale so you re-review and re-lock it, instead of silently trusting a lock whose content has since changed.
## Removed
diff --git a/server/services/storyBuilder.js b/server/services/storyBuilder.js
index 31b64ad8b6..eb37fa2e40 100644
--- a/server/services/storyBuilder.js
+++ b/server/services/storyBuilder.js
@@ -317,12 +317,21 @@ function buildUpstreamInputs(session, universe, series) {
seriesLogline: series?.logline || '',
seriesPremise: series?.premise || '',
};
+ // Each step's hash folds in its OWN outputs (`ownOutputs`) alongside its
+ // upstream inputs. The session lock only gates the wizard UI — the underlying
+ // universe/series records stay editable in Universe Builder, Arc Planner, etc.
+ // Fingerprinting a step's own output means an out-of-band edit to that content
+ // (e.g. changing universe.logline directly while the aesthetic step is locked)
+ // flags the locked step stale, not just edits to an earlier step's inputs
+ // (#731). The `issues`/`production` steps carry no `ownOutputs` — their output
+ // lives in large child-record collections already covered by their upstream
+ // inputs, and hashing every child issue/page would be needless churn.
return {
- idea: { intakeMode: session.intakeMode, seedIdea: session.seedIdea || '' },
- universeAesthetic: { seedIdea: session.seedIdea || '', ideaOutputs },
- plotArc: { aesthetic, seedIdea: session.seedIdea || '', ideaOutputs },
- readerMap: { arc },
- characters: { readerMap, arcSummary: arc.summary, aesthetic },
+ idea: { intakeMode: session.intakeMode, seedIdea: session.seedIdea || '', ownOutputs: ideaOutputs },
+ universeAesthetic: { seedIdea: session.seedIdea || '', ideaOutputs, ownOutputs: aesthetic },
+ plotArc: { aesthetic, seedIdea: session.seedIdea || '', ideaOutputs, ownOutputs: arc },
+ readerMap: { arc, ownOutputs: readerMap },
+ characters: { readerMap, arcSummary: arc.summary, aesthetic, ownOutputs: cast },
issues: { arc, readerMap, cast },
production: { arc, readerMap, cast },
};
diff --git a/server/services/storyBuilder.test.js b/server/services/storyBuilder.test.js
index 9c3957748a..c8b3c7842e 100644
--- a/server/services/storyBuilder.test.js
+++ b/server/services/storyBuilder.test.js
@@ -130,7 +130,22 @@ describe('storyBuilder — lock state machine + gating', () => {
// `buildUpstreamInputs`) surfaces as a failure on this line instead of
// silently passing a shape-only regex. A buggy impl that always stamped
// `hashUpstream('idea', null)` would now fail.
- const expectedHash = hashUpstream('idea', { intakeMode: 'seed', seedIdea: 'seed' });
+ // The idea step's hash now folds in its OWN outputs (#731) — the idea-expand
+ // results on the just-minted universe/series — alongside its upstream inputs.
+ // Derive the expected own-output projection from the live records so the
+ // assertion stays correct if seed-minting defaults change, while still
+ // failing loudly if the idea step's INPUT set drifts.
+ const universe = await universeSvc.getUniverse(s.universeId);
+ const series = await seriesSvc.getSeries(s.seriesId);
+ const expectedHash = hashUpstream('idea', {
+ intakeMode: 'seed',
+ seedIdea: 'seed',
+ ownOutputs: {
+ starterPrompt: universe.starterPrompt || '',
+ seriesLogline: series.logline || '',
+ seriesPremise: series.premise || '',
+ },
+ });
expect(locked.steps.idea.upstreamHash).toBe(expectedHash);
// Sanity: the derived hash is still the documented 64-char hex shape.
expect(expectedHash).toMatch(/^[0-9a-f]{64}$/);
@@ -208,6 +223,55 @@ describe('storyBuilder — integrity / staleness', () => {
view = await sb.getStorySessionView(s.id);
expect(view.staleSteps).toContain('universeAesthetic');
});
+
+ it('flags a locked universeAesthetic stale when its OWN output is edited out-of-band (#731)', async () => {
+ // The session lock only gates the wizard — the universe record stays
+ // editable in Universe Builder. Before #731, mutating universe.logline (an
+ // aesthetic-step OUTPUT, not an upstream input) left the locked aesthetic
+ // step un-flagged because the hash only tracked upstream inputs. Now the
+ // step fingerprints its own outputs, so any post-lock edit flags it stale.
+ const s = await sb.createStorySession({ title: 'X', seedIdea: 'seed' });
+ await universeSvc.updateUniverse(s.universeId, {
+ logline: 'a world of salt and rust', premise: 'the foundry goes silent',
+ });
+ await sb.lockStep(s.id, 'universeAesthetic');
+ let view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).not.toContain('universeAesthetic');
+ // Edit the locked step's own logline directly (out-of-band, e.g. Universe Builder).
+ await universeSvc.updateUniverse(s.universeId, { logline: 'a CHANGED world of salt and rust' });
+ view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).toContain('universeAesthetic');
+ });
+
+ it('flags a locked plotArc stale when the arc itself is edited out-of-band (#731)', async () => {
+ const s = await sb.createStorySession({ title: 'X' });
+ await seriesSvc.updateSeries(s.seriesId, { arc: { logline: 'spine', summary: 'sum' } });
+ await sb.lockStep(s.id, 'plotArc');
+ let view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).not.toContain('plotArc');
+ // updateSeries respects series.locked.arc set by lockStep, but a direct edit
+ // that clears the lock + rewrites the arc still surfaces as stale on read.
+ await seriesSvc.updateSeries(s.seriesId, {
+ arc: { logline: 'REWRITTEN spine', summary: 'sum' }, locked: {},
+ });
+ view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).toContain('plotArc');
+ });
+
+ it('flags a locked characters step stale when the cast is edited out-of-band (#731)', async () => {
+ const s = await sb.createStorySession({ title: 'X' });
+ await universeSvc.updateUniverse(s.universeId, {
+ characters: [{ name: 'Ada', descriptor: 'the foundry forewoman' }],
+ });
+ await sb.lockStep(s.id, 'characters');
+ let view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).not.toContain('characters');
+ await universeSvc.updateUniverse(s.universeId, {
+ characters: [{ name: 'Ada', descriptor: 'the foundry forewoman' }, { name: 'Rook', descriptor: 'the rival' }],
+ });
+ view = await sb.getStorySessionView(s.id);
+ expect(view.staleSteps).toContain('characters');
+ });
});
describe('storyBuilder — generate delegation', () => {