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 (claude): stamp proposal order from index + pin schema looseness

Adam Eivy3d01d29983aa
diff --git a/server/lib/identityValidation.js b/server/lib/identityValidation.js
index 4c650fc72f..0375954193 100644
--- a/server/lib/identityValidation.js
+++ b/server/lib/identityValidation.js
@@ -140,9 +140,11 @@ export const acceptDecompositionInputSchema = z.object({
//
// Intentionally looser than the accept schemas: `targetDate` is a free string
// here (the LLM commonly emits a near-miss date the user fixes in review; the
-// strict validCalendarDate check still runs at accept), `order` is optional (the
-// service fills it from the array index), and unknown keys are stripped. The
-// strictness is on structural shape — title present, tasks well-formed.
+// strict validCalendarDate check still runs at accept) and unknown keys are
+// stripped. The strictness is on structural shape — title present, tasks
+// well-formed. `order` is optional on each element but the array-level transform
+// below stamps it from the index when absent, so the proposal the review UI
+// hands back always satisfies the accept route's required `order` field.
export const goalPhaseProposalSchema = z.object({
title: z.string().min(1).max(500),
description: z.string().max(5000).optional().default(''),
@@ -150,13 +152,17 @@ export const goalPhaseProposalSchema = z.object({
order: z.number().int().min(0).optional()
});
-export const goalPhasesProposalSchema = z.array(goalPhaseProposalSchema).min(1).max(50);
+// Fill a missing `order` from the array index so generation output is always
+// accept-ready (the accept route requires `order`); an LLM-supplied order wins.
+const stampOrder = (arr) => arr.map((el, i) => ({ ...el, order: el.order ?? i }));
+
+export const goalPhasesProposalSchema = z.array(goalPhaseProposalSchema).min(1).max(50).transform(stampOrder);
export const goalDecompositionMilestoneProposalSchema = goalPhaseProposalSchema.extend({
tasks: z.array(decomposedTaskSchema).max(50).optional().default([])
});
-export const goalDecompositionProposalSchema = z.array(goalDecompositionMilestoneProposalSchema).min(1).max(50);
+export const goalDecompositionProposalSchema = z.array(goalDecompositionMilestoneProposalSchema).min(1).max(50).transform(stampOrder);
// --- Goal Progress Log Schemas ---
diff --git a/server/services/identity/goals.test.js b/server/services/identity/goals.test.js
index 3577f74190..d0d3c946ea 100644
--- a/server/services/identity/goals.test.js
+++ b/server/services/identity/goals.test.js
@@ -204,6 +204,26 @@ describe('proposal validation (raw LLM output)', () => {
]);
await expect(decomposeGoal('goal-1', {})).rejects.toMatchObject({ status: 502, code: 'AI_PARSE_ERROR' });
});
+
+ it('stamps a missing order from the array index so the proposal stays accept-ready', async () => {
+ // No `order` keys → the array-level transform fills them from position.
+ h.aiText = JSON.stringify([
+ { title: 'First', tasks: [] },
+ { title: 'Second', tasks: [] }
+ ]);
+ const proposal = await decomposeGoal('goal-1', {});
+ expect(proposal.map(m => m.order)).toEqual([0, 1]);
+ });
+
+ it('keeps the intentional looseness — a free-form targetDate survives generation', async () => {
+ // The proposal schema is deliberately looser than the strict accept schema:
+ // a non-calendar date the user fixes in review must NOT be rejected here.
+ h.aiText = JSON.stringify([
+ { title: 'Outline', targetDate: 'next quarter', order: 0, tasks: [] }
+ ]);
+ const proposal = await decomposeGoal('goal-1', {});
+ expect(proposal[0].targetDate).toBe('next quarter');
+ });
});
describe('re-plan guard — orphaned scheduledEvents', () => {