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([style-probe-image-uses-draft-not-saved]): block style probe while influences are unsaved

[._.]/ Adam Eivya64b2d63330f
diff --git a/client/src/components/universe/StyleProbeImage.jsx b/client/src/components/universe/StyleProbeImage.jsx
index 0580c42b7c..7af16f2c4c 100644
--- a/client/src/components/universe/StyleProbeImage.jsx
+++ b/client/src/components/universe/StyleProbeImage.jsx
@@ -35,7 +35,7 @@ export function hasStyleForProbe(universe) {
return Boolean(prompt.trim());
}
-export default function StyleProbeImage({ universe, onUniverseChange, canRender = true, onPreview = null, onRenderComplete = null }) {
+export default function StyleProbeImage({ universe, onUniverseChange, canRender = true, styleDirty = false, onPreview = null, onRenderComplete = null }) {
const [imageCfg, setImageCfg] = useState(PIPELINE_IMAGE_DEFAULTS);
const [jobId, setJobId] = useState(null);
// MediaJobThumb's onFilename effect can fire more than once — process each
@@ -49,8 +49,16 @@ export default function StyleProbeImage({ universe, onUniverseChange, canRender
}, []);
const styleReady = hasStyleForProbe(universe);
+ // The probe prompt is built from the in-memory `influences`, but `onComplete`
+ // persists only the resulting `styleImageRefs` to the SERVER's saved record.
+ // When the draft's influences have unsaved edits, that record's influences are
+ // still the prior values — so persisting the probe would pin it to style the
+ // record never had (and it would survive even after the user discards the
+ // draft). Block rendering until the style is saved.
+ const canProbe = canRender && !styleDirty;
const render = async () => {
+ if (styleDirty) { toast.error('Save your style changes before probing the base style'); return; }
if (!styleReady) { toast.error('Add embrace influences before probing the base style'); return; }
const baseOpts = pipelineImageCfgToRenderOpts(imageCfg);
const probe = buildStyleProbePrompt(universe);
@@ -84,7 +92,7 @@ export default function StyleProbeImage({ universe, onUniverseChange, canRender
};
const hasExistingImage = Array.isArray(universe?.styleImageRefs) && universe.styleImageRefs.length > 0;
- const regenerateEnabled = canRender && Boolean(universe?.id) && styleReady && !jobId;
+ const regenerateEnabled = canProbe && Boolean(universe?.id) && styleReady && !jobId;
return (
<div className="flex items-start gap-3">
@@ -94,7 +102,7 @@ export default function StyleProbeImage({ universe, onUniverseChange, canRender
onRender={render}
onComplete={onComplete}
onPreview={onPreview}
- canRender={canRender && Boolean(universe?.id) && styleReady}
+ canRender={canProbe && Boolean(universe?.id) && styleReady}
alt="Base style"
size="xl"
/>
@@ -103,13 +111,16 @@ export default function StyleProbeImage({ universe, onUniverseChange, canRender
Rendered from the positive/negative influences with no subject — a quick read on the world's base visual
emphasis. Style notes are excluded so this matches what downstream image prompts will actually use.
{!styleReady && <span className="text-port-warning"> Add embrace influences first.</span>}
+ {styleReady && styleDirty && (
+ <span className="text-port-warning"> Save your style changes first — the probe renders from your current influences but pins to the saved universe.</span>
+ )}
{hasExistingImage ? (
<div className="mt-2">
<button
type="button"
onClick={render}
disabled={!regenerateEnabled}
- title={regenerateEnabled ? 'Render a new base style image' : 'Add embrace influences or save the universe first'}
+ title={regenerateEnabled ? 'Render a new base style image' : (styleDirty ? 'Save your style changes first' : 'Add embrace influences or save the universe first')}
className="inline-flex items-center gap-1 px-2 py-1 rounded border border-port-border bg-port-bg/40 text-gray-300 hover:border-port-accent/50 hover:text-port-accent hover:bg-port-accent/5 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:border-port-border disabled:hover:text-gray-300 disabled:hover:bg-port-bg/40 transition-colors"
>
<Sparkles size={12} />
diff --git a/client/src/components/universe/StyleProbeImage.test.jsx b/client/src/components/universe/StyleProbeImage.test.jsx
index 10fa15fea2..8a1c051100 100644
--- a/client/src/components/universe/StyleProbeImage.test.jsx
+++ b/client/src/components/universe/StyleProbeImage.test.jsx
@@ -1,5 +1,17 @@
-import { describe, it, expect } from 'vitest';
-import { buildStyleProbePrompt, hasStyleForProbe } from './StyleProbeImage';
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen, act } from '@testing-library/react';
+
+// StyleProbeImage loads pipeline-image settings on mount; flush that microtask
+// so the async setState lands inside act() and the test output stays clean.
+const flushEffects = () => act(async () => { await Promise.resolve(); });
+
+vi.mock('../../services/api', () => ({
+ getSettings: vi.fn(() => Promise.resolve({})),
+ generateImage: vi.fn(() => Promise.resolve(null)),
+ updateUniverse: vi.fn(() => Promise.resolve(null)),
+}));
+
+import StyleProbeImage, { buildStyleProbePrompt, hasStyleForProbe } from './StyleProbeImage';
describe('StyleProbeImage — buildStyleProbePrompt', () => {
it('uses embrace tokens as positive and avoid tokens as negative', () => {
@@ -45,3 +57,23 @@ describe('StyleProbeImage — hasStyleForProbe', () => {
expect(hasStyleForProbe({ influences: { embrace: [], avoid: ['bright'] } })).toBe(false);
});
});
+
+describe('StyleProbeImage — styleDirty gating', () => {
+ const universe = { id: 'u1', influences: { embrace: ['noir'], avoid: [] }, styleImageRefs: [] };
+
+ it('disables the render button and warns when the draft style is unsaved', async () => {
+ render(<StyleProbeImage universe={universe} styleDirty />);
+ await flushEffects();
+ // The empty-state slot button is inert until the style is saved, so the
+ // probe can never pin to a record that lacks the in-progress influences.
+ expect(screen.getByRole('button')).toBeDisabled();
+ expect(screen.getByText(/Save your style changes first/i)).toBeInTheDocument();
+ });
+
+ it('enables the render button and shows no warning when the style is saved', async () => {
+ render(<StyleProbeImage universe={universe} styleDirty={false} />);
+ await flushEffects();
+ expect(screen.getByRole('button')).toBeEnabled();
+ expect(screen.queryByText(/Save your style changes first/i)).not.toBeInTheDocument();
+ });
+});
diff --git a/client/src/pages/UniverseBuilder.jsx b/client/src/pages/UniverseBuilder.jsx
index bf735507c5..e9450269c3 100644
--- a/client/src/pages/UniverseBuilder.jsx
+++ b/client/src/pages/UniverseBuilder.jsx
@@ -561,8 +561,16 @@ export default function UniverseBuilder() {
// flush via handleSave() when they diverge so the server doesn't operate
// on a stale copy.
const savedDraftSnapshotRef = useRef(draftSnapshotForDirty(emptyTemplate()));
+ // Saved-record influences snapshot, tracked alongside the full-draft snapshot.
+ // StyleProbeImage builds its prompt from `influences` but persists only the
+ // resulting `styleImageRefs` to the SERVER record — so a probe rendered from
+ // unsaved influence edits would get pinned to a record whose influences are
+ // still the prior values. Comparing this against the live draft tells the
+ // probe when the style is dirty so it can block until the user saves.
+ const savedStyleSnapshotRef = useRef(JSON.stringify(ensureInfluences(emptyTemplate().influences)));
const markDraftSaved = useCallback((snapshotSource) => {
savedDraftSnapshotRef.current = draftSnapshotForDirty(snapshotSource);
+ savedStyleSnapshotRef.current = JSON.stringify(ensureInfluences(snapshotSource?.influences));
}, []);
const isDraftDirty = useCallback(
() => savedDraftSnapshotRef.current !== draftSnapshotForDirty(draftRef.current || draft),
@@ -1686,6 +1694,10 @@ export default function UniverseBuilder() {
const categoryKeys = getCategoryKeys(draft.categories);
const totalVariations = totalVariationCount(draft);
const totalSheets = draft.compositeSheets?.length || 0;
+ // True when the draft's influences diverge from the saved record. The style
+ // probe renders from these influences but pins its filename server-side, so a
+ // probe taken while dirty would mis-attribute to style the record never had.
+ const styleProbeDirty = savedStyleSnapshotRef.current !== JSON.stringify(ensureInfluences(draft.influences));
// URL-driven tab + bucket state (per CLAUDE.md "Linkable routes for all
// views"). `?tab=cast&bucket=heroes` deep-links into a sub-bucket; both fall
@@ -1863,6 +1875,7 @@ export default function UniverseBuilder() {
totalSheets={totalSheets}
onPreview={openPreviewByFilename}
onStyleProbeRenderComplete={bumpGalleryRefresh}
+ styleProbeDirty={styleProbeDirty}
/>
)}
@@ -2962,6 +2975,7 @@ function BibleTab({
totalVariations, categoryKeyCount, totalSheets,
onPreview,
onStyleProbeRenderComplete = null,
+ styleProbeDirty = false,
}) {
const { providers, providerModels, providerLabel, activeProviderId } = llm;
const {
@@ -3153,12 +3167,15 @@ function BibleTab({
/>
<div className="mt-4 pt-4 border-t border-port-border">
{/* StyleProbeImage persists styleImageRefs server-side itself; merge
- only that field into the draft so unsaved style edits aren't lost. */}
+ only that field into the draft so unsaved style edits aren't lost.
+ `styleDirty` blocks the render while influences have unsaved edits —
+ otherwise the probe pins to a saved record that lacks that style. */}
<StyleProbeImage
universe={draft}
onUniverseChange={(updated) => updateDraft({ styleImageRefs: updated?.styleImageRefs || [] })}
onPreview={onPreview}
onRenderComplete={() => onStyleProbeRenderComplete?.()}
+ styleDirty={styleProbeDirty}
/>
</div>
</section>