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: keep unsent nested Code Animation project settings on PATCH (#12434)

[._.]/ Adam Eivy002f42bc3691
diff --git a/server/lib/codeAnimationProjects.js b/server/lib/codeAnimationProjects.js
index f5d987b5aa..a7cce512ce 100644
--- a/server/lib/codeAnimationProjects.js
+++ b/server/lib/codeAnimationProjects.js
@@ -24,18 +24,26 @@ const localSettingsSchema = z.object({
substitution: z.enum(['pinned', 'allowed']).default('pinned'),
}).strict();
+const referenceIntentSchema = z.object({
+ universeId: z.string().max(128).nullable().default(null),
+ moodBoardId: z.string().max(128).nullable().default(null),
+ notes: z.string().max(16000).default(''),
+}).strict();
+
export const codeAnimationProjectSchema = z.object({
manifest: codeAnimationManifestSchema,
budgets: codeAnimationBudgetsSchema.prefault({}),
localSettings: localSettingsSchema.prefault({}),
- referenceIntent: z.object({
- universeId: z.string().max(128).nullable().default(null),
- moodBoardId: z.string().max(128).nullable().default(null),
- notes: z.string().max(16000).default(''),
- }).strict().prefault({}),
+ referenceIntent: referenceIntentSchema.prefault({}),
}).strict();
-export const codeAnimationProjectPatchSchema = partialWithoutDefaults(codeAnimationProjectSchema);
+// Nested objects get their own defaults-free partials: the top-level partial
+// does not recurse into them, and a filled-in default would overwrite stored fields.
+export const codeAnimationProjectPatchSchema = partialWithoutDefaults(codeAnimationProjectSchema).extend({
+ budgets: partialWithoutDefaults(codeAnimationBudgetsSchema).optional(),
+ localSettings: partialWithoutDefaults(localSettingsSchema).optional(),
+ referenceIntent: partialWithoutDefaults(referenceIntentSchema).optional(),
+}).strict();
// POST /projects/:id/stage-runs. Starting is an explicit user action; the body
// can only name which stored revision to work from or which stopped run to resume.
diff --git a/server/services/codeAnimation/projectStore.js b/server/services/codeAnimation/projectStore.js
index 8a6b9a1785..db444af9e5 100644
--- a/server/services/codeAnimation/projectStore.js
+++ b/server/services/codeAnimation/projectStore.js
@@ -38,7 +38,14 @@ export async function patchProjectRecord(id, patch) {
return withTransaction(async client => {
const { rows } = await client.query(`SELECT ${columns} FROM code_animation_projects WHERE id = $1 FOR UPDATE`, [id]);
if (!rows[0]) throw missing();
- const settings = { ...rows[0].data, ...patch };
+ const stored = rows[0].data;
+ // Nested objects merge field by field: a partial PATCH names only the fields it changes.
+ const settings = {
+ ...stored, ...patch,
+ budgets: { ...stored.budgets, ...patch.budgets },
+ localSettings: { ...stored.localSettings, ...patch.localSettings },
+ referenceIntent: { ...stored.referenceIntent, ...patch.referenceIntent },
+ };
if (patch.budgets) {
const used = await client.query("SELECT COALESCE(SUM((data->>'reservedBytes')::bigint), 0) AS bytes FROM code_animation_project_runs WHERE project_id = $1", [id]);
if (Number(used.rows[0].bytes) > settings.budgets.diskBytes) {
diff --git a/server/services/codeAnimation/stages.db.test.js b/server/services/codeAnimation/stages.db.test.js
index af79749226..684713d719 100644
--- a/server/services/codeAnimation/stages.db.test.js
+++ b/server/services/codeAnimation/stages.db.test.js
@@ -639,4 +639,25 @@ describe.skipIf(!ready)('Production stage runs', () => {
expect(unfreeze).not.toHaveBeenCalled();
expect(render).not.toHaveBeenCalled();
});
+
+ it('keeps unsent nested project settings when a partial PATCH names one field of each nested object', async () => {
+ const created = await createProductionProject({
+ manifest: manifest(),
+ budgets: { iterations: 3, diskBytes: 2 * 1024 * 1024 },
+ localSettings: { providerId: 'example-provider', connectionId: 'example-connection', mode: 'api', model: 'example-model', effort: 'medium', substitution: 'allowed' },
+ referenceIntent: { universeId: 'example-universe', moodBoardId: 'example-board', notes: 'keep me' },
+ });
+ ids.push(created.id);
+ await patchProductionProject(created.id, { budgets: { renderSeconds: 60 } });
+ await patchProductionProject(created.id, { localSettings: { model: 'other-model' } });
+ await patchProductionProject(created.id, { referenceIntent: { notes: 'new notes' } });
+ const saved = await getProductionProject(created.id);
+ expect(saved.budgets).toEqual({ iterations: 3, timeSeconds: 900, tokens: 128000, renderSeconds: 60, diskBytes: 2 * 1024 * 1024 });
+ expect(saved.localSettings).toMatchObject({ providerId: 'example-provider', connectionId: 'example-connection', mode: 'api', model: 'other-model', effort: 'medium', substitution: 'allowed' });
+ expect(saved.referenceIntent).toEqual({ universeId: 'example-universe', moodBoardId: 'example-board', notes: 'new notes' });
+ await patchProductionProject(created.id, { localSettings: { model: null }, referenceIntent: { universeId: null } });
+ const cleared = await getProductionProject(created.id);
+ expect(cleared.localSettings).toMatchObject({ model: null, providerId: 'example-provider' });
+ expect(cleared.referenceIntent).toMatchObject({ universeId: null, moodBoardId: 'example-board', notes: 'new notes' });
+ });
});