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: degrade an unshipped subject-family id instead of stranding the record (#3485)

[._.]/ Adam Eivye2825f3dcafa
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 98b4deab6e..b9c9bc28a4 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -155,4 +155,4 @@
- **[issue-3507] Opening the Brain graph's search box no longer walks every record on disk.** The graph search index returns nothing but a name and a type per node, but it was building that list by loading the *full* body of every person, project, idea, admin item and memory entry — plus every Daily Log day — and then discarding the summaries, tags and status it had just parsed. Since Brain keeps one file per record, focusing a search input meant thousands of file reads for a dropdown of labels. The index now reads the same in-memory field projections unified search uses, so it costs a scan of memory rather than a walk of the disk, and a Daily Log entry contributes only "is this day non-empty?" instead of its whole text — the biggest body in the Brain never enters the cache at all. The two graph views that genuinely need bodies (the overview and a node's neighborhood) still load them; only the label list changed, and it derives its labels and its skip rules from the same helpers the full-record path uses so the two cannot drift. Nodes come back in the same order as before: the projections are read unranked, so the memory entries in the dropdown stay in store order rather than silently re-sorting themselves newest-first.
-- **[issue-3485] Three.js model generation can now be narrowed to a subject family, so the model is judged against a checklist it did not write itself.** The assembly-coverage gate has always carried an honest limit: it proves a spec built everything it promised, never that it promised enough — a component nobody noticed is never inventoried, never specified, and passes every check clean. Picking one of five coarse families (character, vehicle, weapon, building, device) on the create form or the workspace splices a curated checklist into the generation prompt — the components a reconstruction of that family is usually judged on, the material zones worth separating, the axes to judge the result on, and the orbit views that expose the usual failures — and lets the coverage gate warn on a required component the spec never mentions anywhere. That warning feeds the unsteered refinement pass, so "you never accounted for the trigger guard" becomes something the next run is actually told. The checklist is deliberately framed as a floor rather than a ceiling, in the prompt and in the panel: it names the limitations escape hatch for a component the reference genuinely does not show, and it says outright that a spec inventorying only the checklist has under-observed its reference — a thin taxonomy that teaches the model to stop early would be worse than none. Family is optional and defaults to General, which splices nothing at all: an existing model, and anyone who does not pick a family, gets the byte-identical prompt that shipped before this. The workspace renders the chosen family's checklist under the coverage panel with each component marked accounted-for or not, so the orbit views worth checking are next to the preview you would check them in. The field is additive on the record, so no migration is needed and a model generated before this reads back as General; a family id this install does not recognize — from a peer running a newer taxonomy — degrades to no checklist rather than failing the record.
+- **[issue-3485] Three.js model generation can now be narrowed to a subject family, so the model is judged against a checklist it did not write itself.** The assembly-coverage gate has always carried an honest limit: it proves a spec built everything it promised, never that it promised enough — a component nobody noticed is never inventoried, never specified, and passes every check clean. Picking one of five coarse families (character, vehicle, weapon, building, device) on the create form or the workspace splices a curated checklist into the generation prompt — the components a reconstruction of that family is usually judged on, the material zones worth separating, the axes to judge the result on, and the orbit views that expose the usual failures — and lets the coverage gate warn on a required component the spec never mentions anywhere. That warning feeds the unsteered refinement pass, so "you never accounted for the trigger guard" becomes something the next run is actually told. The checklist is deliberately framed as a floor rather than a ceiling, in the prompt and in the panel: it names the limitations escape hatch for a component the reference genuinely does not show, and it says outright that a spec inventorying only the checklist has under-observed its reference — a thin taxonomy that teaches the model to stop early would be worse than none. Family is optional and defaults to General, which splices nothing at all: an existing model, and anyone who does not pick a family, gets the byte-identical prompt that shipped before this. The workspace renders the chosen family's checklist under the coverage panel with each component marked accounted-for or not, so the orbit views worth checking are next to the preview you would check them in. The field is additive on the record, so no migration is needed and a model generated before this reads back as General. A family id this build does not ship — a record written by a build with a larger taxonomy, then downgraded or restored from a backup — degrades to no checklist everywhere rather than failing the record: the picker shows General instead of pinning itself to a value it has no option for, and the server coerces rather than rejecting the refine request, which would otherwise have left that model permanently un-refinable.
diff --git a/client/src/components/threejsModels/SubjectFamilySelect.jsx b/client/src/components/threejsModels/SubjectFamilySelect.jsx
index 2d3fc20050..172479f89a 100644
--- a/client/src/components/threejsModels/SubjectFamilySelect.jsx
+++ b/client/src/components/threejsModels/SubjectFamilySelect.jsx
@@ -1,3 +1,5 @@
+import { resolveFamilyId } from '../../hooks/useThreejsModelFamilies';
+
/**
* Subject-family picker, shared by the create form and the workspace so the two
* cannot drift on labelling or on what an empty taxonomy does. Renders nothing
@@ -7,7 +9,7 @@
export default function SubjectFamilySelect({
id,
families,
- value,
+ value: requestedValue,
onChange,
disabled = false,
optional = false,
@@ -18,6 +20,8 @@ export default function SubjectFamilySelect({
// this element: a caller's own margin div would leave a visible gap where the
// picker isn't.
if (families.length === 0) return null;
+ // Never hand the select a value it has no option for — see resolveFamilyId.
+ const value = resolveFamilyId(families, requestedValue);
const description = families.find((option) => option.id === value)?.description;
return (
<div className={className}>
diff --git a/client/src/hooks/useThreejsModelFamilies.js b/client/src/hooks/useThreejsModelFamilies.js
index 969d2a3990..d4409468a1 100644
--- a/client/src/hooks/useThreejsModelFamilies.js
+++ b/client/src/hooks/useThreejsModelFamilies.js
@@ -8,6 +8,27 @@ import { listThreejsModelFamilies } from '../services/api';
*/
export const GENERAL_FAMILY_ID = 'general';
+/**
+ * A family id the served taxonomy actually offers, or `general`.
+ *
+ * A record can hold a family this install no longer ships — written by a build
+ * with a larger taxonomy, then downgraded or restored from a backup. Feeding
+ * that id to a `<select>` leaves the control with no matching option, so what is
+ * on screen stops agreeing with the state behind it and picking the option it
+ * appears to be showing fires no change event at all. Both the rendered value
+ * and the value submitted go through here so they cannot disagree.
+ *
+ * An empty list means the taxonomy has not resolved (or failed): the stored id
+ * is passed through untouched rather than being flattened to `general`, since
+ * there is no picker on screen to disagree with and the record's own family
+ * should survive a refine.
+ */
+export const resolveFamilyId = (families, value) => (
+ families.length === 0 || families.some((option) => option.id === value)
+ ? value
+ : GENERAL_FAMILY_ID
+);
+
/**
* The Three.js subject-family options. A failed fetch yields an empty list, and
* callers hide the picker rather than rendering an empty select — generation
diff --git a/client/src/pages/ThreejsModelDetail.jsx b/client/src/pages/ThreejsModelDetail.jsx
index b40e39e896..beebc00ddd 100644
--- a/client/src/pages/ThreejsModelDetail.jsx
+++ b/client/src/pages/ThreejsModelDetail.jsx
@@ -8,7 +8,7 @@ import ThreejsModelPreview from '../components/threejsModels/ThreejsModelPreview
import PageSkeleton from '../components/ui/PageSkeleton';
import InlineConfirmRow from '../components/ui/InlineConfirmRow';
import useProviderModels from '../hooks/useProviderModels';
-import useThreejsModelFamilies, { GENERAL_FAMILY_ID } from '../hooks/useThreejsModelFamilies';
+import useThreejsModelFamilies, { GENERAL_FAMILY_ID, resolveFamilyId } from '../hooks/useThreejsModelFamilies';
import {
deleteThreejsModel,
generateThreejsModel,
@@ -240,7 +240,9 @@ export default function ThreejsModelDetail() {
effort,
// Always sent so switching back to General turns the checklist OFF for
// this pass instead of silently re-applying the record's stored family.
- family,
+ // Resolved against the served taxonomy so what is sent is what the picker
+ // is showing, even for a record holding a family this install dropped.
+ family: resolveFamilyId(families, family),
prompt: record.prompt || '',
feedback: feedback.trim(),
}, { silent: true }).catch((error) => {
@@ -301,8 +303,12 @@ export default function ThreejsModelDetail() {
: null;
// The record's own family, not the coverage snapshot's — the header should
// read the current setting even before the next generation re-runs the gate.
- const familyLabel = record.family && record.family !== GENERAL_FAMILY_ID
- ? (families.find((option) => option.id === record.family)?.label || record.family)
+ // Resolved like the picker is, so a record holding a family this install no
+ // longer ships does not have the header and the picker naming two different
+ // things; the coverage panel below still reports the checklist that ran.
+ const activeFamily = resolveFamilyId(families, record.family);
+ const familyLabel = activeFamily && activeFamily !== GENERAL_FAMILY_ID
+ ? (families.find((option) => option.id === activeFamily)?.label || activeFamily)
: '';
return (
diff --git a/client/src/pages/ThreejsModelDetail.test.jsx b/client/src/pages/ThreejsModelDetail.test.jsx
index cf79dfab35..450c742698 100644
--- a/client/src/pages/ThreejsModelDetail.test.jsx
+++ b/client/src/pages/ThreejsModelDetail.test.jsx
@@ -250,4 +250,26 @@ describe('ThreejsModelDetail subject family', () => {
{ silent: true },
));
});
+
+ it('falls back to General for a family this build no longer ships', async () => {
+ // A record written by a build with a larger taxonomy (a downgrade, or a
+ // restored backup). Left as-is, the select would carry a value it has no
+ // option for: what is on screen stops matching the state behind it, and
+ // picking the option it appears to show fires no change event at all.
+ getThreejsModel.mockResolvedValue({ ...baseRecord, family: 'kaiju-mecha-hybrid' });
+ generateThreejsModel.mockResolvedValue({ ...baseRecord, status: 'generating' });
+ renderDetail();
+
+ const picker = await screen.findByLabelText('Subject family');
+ await waitFor(() => expect(picker).toHaveValue('general'));
+ // The header must not name a different family than the picker is showing.
+ expect(screen.queryByText(/kaiju-mecha-hybrid/)).not.toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole('button', { name: /Refine model/ }));
+ await waitFor(() => expect(generateThreejsModel).toHaveBeenCalledWith(
+ 'threejs-example',
+ expect.objectContaining({ family: 'general' }),
+ { silent: true },
+ ));
+ });
});
diff --git a/server/routes/threejsModels.js b/server/routes/threejsModels.js
index b42518c550..403cbb85f8 100644
--- a/server/routes/threejsModels.js
+++ b/server/routes/threejsModels.js
@@ -31,10 +31,21 @@ const effortSchema = z.preprocess(emptyToNull, z.enum(EFFORT_LEVELS).nullable().
// Subject-family checklist. Unlike `effort` there is no "clear" state — the
// picker's General choice submits the real `general` id, so an empty string is
// normalized to it rather than to `null`.
-const familySchema = z.preprocess(
- (value) => (value === '' ? GENERAL_FAMILY_ID : value),
- z.enum(THREEJS_MODEL_FAMILY_IDS).optional(),
-);
+//
+// A family id this install does not ship gets the same treatment rather than a
+// 400. The picker can only offer ids the server served, so an unrecognized
+// STRING is never fresh user intent — it is a record written by a build with a
+// larger taxonomy (a downgrade, or a backup restored from a machine ahead of
+// this one), which the detail page reads straight back into its refine request.
+// Rejecting it would make that record permanently un-refinable; coercing it
+// degrades to "no checklist" exactly like every other layer and self-heals the
+// record on the next generate. A non-string is a malformed body, not a stale
+// value, and still falls through to the enum and a 400.
+const familySchema = z.preprocess((value) => {
+ if (typeof value !== 'string') return value;
+ if (value === '') return GENERAL_FAMILY_ID;
+ return THREEJS_MODEL_FAMILY_IDS.includes(value) ? value : GENERAL_FAMILY_ID;
+}, z.enum(THREEJS_MODEL_FAMILY_IDS).optional());
const createSchema = z.object({
name: z.string().trim().min(1).max(120),
diff --git a/server/routes/threejsModels.test.js b/server/routes/threejsModels.test.js
index ff774fc7ce..05c4cc3ef1 100644
--- a/server/routes/threejsModels.test.js
+++ b/server/routes/threejsModels.test.js
@@ -153,14 +153,44 @@ describe('Three.js model routes', () => {
});
});
- it('rejects a family that is not in the shipped taxonomy', async () => {
+ it('degrades a family this build does not ship to general instead of 400-ing', async () => {
+ // A record written by a build with a larger taxonomy (a downgrade, or a
+ // restored backup) reads its stored family straight back into the refine
+ // request. Rejecting it would leave that record permanently un-refinable.
+ models.startGeneration.mockResolvedValueOnce({ id: 'threejs-1', status: 'generating' });
const res = await request(makeApp())
.post('/api/threejs-models/threejs-1/generate')
.send({ providerId: 'codex', family: 'kaiju-mecha-hybrid' });
+ expect(res.status).toBe(202);
+ expect(models.startGeneration).toHaveBeenCalledWith('threejs-1', {
+ providerId: 'codex',
+ family: 'general',
+ feedback: '',
+ });
+ });
+
+ it('still rejects a family that is not a string at all', async () => {
+ // A stale id is a plausible value; a number is a malformed body.
+ const res = await request(makeApp())
+ .post('/api/threejs-models/threejs-1/generate')
+ .send({ providerId: 'codex', family: 42 });
expect(res.status).toBe(400);
expect(models.startGeneration).not.toHaveBeenCalled();
});
+ it('leaves the family key absent when the caller omits it', async () => {
+ // Absent must stay absent — the service reads that as "keep what is stored",
+ // which a preprocess that defaulted to `general` would silently overwrite.
+ models.startGeneration.mockResolvedValueOnce({ id: 'threejs-1', status: 'generating' });
+ await request(makeApp())
+ .post('/api/threejs-models/threejs-1/generate')
+ .send({ providerId: 'codex' });
+ expect(models.startGeneration).toHaveBeenCalledWith('threejs-1', {
+ providerId: 'codex',
+ feedback: '',
+ });
+ });
+
it('serves generated source as a JavaScript attachment', async () => {
models.getModelSource.mockResolvedValueOnce({
filename: 'example-robot.js',