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

address review (codex): race-free stale-concept guard and whitespace-tolerant shape

[._.]/ Adam Eivy1e5699e6fe1a
diff --git a/client/src/pages/Pipeline.jsx b/client/src/pages/Pipeline.jsx
index a67de92d3c..54e8c62300 100644
--- a/client/src/pages/Pipeline.jsx
+++ b/client/src/pages/Pipeline.jsx
@@ -7,7 +7,7 @@
* drills into its detail page where issues are created and managed.
*/
-import { useEffect, useMemo, useRef, useState } from 'react';
+import { useEffect, useMemo, useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { Plus, Workflow as WorkflowIcon, Trash2, Loader2, Globe2, FileInput, Sparkles } from 'lucide-react';
import toast from '../components/ui/Toast';
@@ -54,10 +54,6 @@ export default function Pipeline() {
const [generating, setGenerating] = useState(false);
const [showForm, setShowForm] = useState(false);
const [form, setForm] = useState(emptyForm);
- // Mirror the live universe selection so an in-flight generate can detect the
- // user switching universes mid-request and drop the now-stale concept.
- const universeIdRef = useRef(form.universeId);
- useEffect(() => { universeIdRef.current = form.universeId; }, [form.universeId]);
useEffect(() => {
Promise.all([
@@ -119,19 +115,26 @@ export default function Pipeline() {
if (!concept) return;
// The request can outlive the selection: if the user switched universes
// while it was in flight, applying a concept seeded from the old universe
- // would pair the new universeId with a mismatched story. Drop the stale
- // result — gate both the form merge and the toast on the live selection.
- if (universeIdRef.current !== requestedUniverseId) return;
- setForm((f) => ({
- ...f,
- name: concept.name || f.name,
- logline: concept.logline || f.logline,
- premise: concept.premise || f.premise,
- // The generated concept owns the story shape — apply it verbatim,
- // including null (LLM picked none), so a stale earlier pick can't
- // misrepresent the freshly generated concept.
- shape: concept.shape,
- }));
+ // would pair the new universeId with a mismatched story. Gate the merge on
+ // the LIVE state inside the functional updater (race-free — `f` is the
+ // committed value, unlike a passively-synced ref), and gate the toast on
+ // whether the merge actually applied.
+ let applied = false;
+ setForm((f) => {
+ if (f.universeId !== requestedUniverseId) return f;
+ applied = true;
+ return {
+ ...f,
+ name: concept.name || f.name,
+ logline: concept.logline || f.logline,
+ premise: concept.premise || f.premise,
+ // The generated concept owns the story shape — apply it verbatim,
+ // including null (LLM picked none), so a stale earlier pick can't
+ // misrepresent the freshly generated concept.
+ shape: concept.shape,
+ };
+ });
+ if (!applied) return;
toast.success(
concept.rationale
? `Generated "${concept.name}" — ${concept.rationale}`
diff --git a/server/services/pipeline/seriesGenerate.js b/server/services/pipeline/seriesGenerate.js
index 780955497a..940ebed4d0 100644
--- a/server/services/pipeline/seriesGenerate.js
+++ b/server/services/pipeline/seriesGenerate.js
@@ -122,8 +122,10 @@ export async function generateSeriesConcept(universeId, options = {}) {
const name = content.name.trim().slice(0, NAME_MAX);
const logline = typeof content.logline === 'string' ? content.logline.trim().slice(0, LOGLINE_MAX) : '';
const premise = typeof content.premise === 'string' ? content.premise.trim().slice(0, PREMISE_MAX) : '';
- // Drop an unrecognized shape rather than poison the form — the create path
- // already treats `null` as "no shape picked."
- const shape = typeof content.shape === 'string' && ARC_SHAPE_IDS.includes(content.shape) ? content.shape : null;
+ // Trim before the allow-list check so a valid id with incidental whitespace
+ // (e.g. "man-in-hole\n") isn't discarded; drop an unrecognized shape rather
+ // than poison the form — the create path treats `null` as "no shape picked."
+ const shapeRaw = typeof content.shape === 'string' ? content.shape.trim() : '';
+ const shape = ARC_SHAPE_IDS.includes(shapeRaw) ? shapeRaw : null;
return { name, logline, premise, shape, rationale, runId, providerId, model };
}
diff --git a/server/services/pipeline/seriesGenerate.test.js b/server/services/pipeline/seriesGenerate.test.js
index 202f5a78ce..bfd98b9c31 100644
--- a/server/services/pipeline/seriesGenerate.test.js
+++ b/server/services/pipeline/seriesGenerate.test.js
@@ -64,6 +64,12 @@ describe('generateSeriesConcept', () => {
});
});
+ it('trims a valid shape with incidental whitespace before validating', async () => {
+ mockLLM({ name: 'X', logline: 'l', premise: 'p', shape: ' man-in-hole\n' });
+ const out = await generateSeriesConcept('uni-1');
+ expect(out.shape).toBe('man-in-hole');
+ });
+
it('drops an unrecognized story shape to null', async () => {
mockLLM({ name: 'X', logline: 'l', premise: 'p', shape: 'not-a-real-shape' });
const out = await generateSeriesConcept('uni-1');