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): split create/update featureAreas schemas; omit untouched override on save

[._.]/ Adam Eivy282b63be7550
diff --git a/client/src/components/goals/GoalDetailPanel.test.jsx b/client/src/components/goals/GoalDetailPanel.test.jsx
index ee87bfdf18..a7775c8391 100644
--- a/client/src/components/goals/GoalDetailPanel.test.jsx
+++ b/client/src/components/goals/GoalDetailPanel.test.jsx
@@ -190,11 +190,12 @@ describe('GoalDetailPanel Daily Driver feature-area override (issue #2679)', ()
);
});
- it('preserves forward-unknown ids when editing an unrelated field (no data loss on federated installs)', async () => {
- // A goal synced from a newer peer carries a feature-area id this install
- // doesn't know. Editing an unrelated field must round-trip that id intact —
- // dropping it would LWW-propagate a truncated array back and erase the newer
- // peer's config. The (non-strict) server schema accepts the unknown id.
+ it('omits featureAreas when the selector was untouched (no stale-snapshot clobber of a concurrent peer edit)', async () => {
+ // The editor sends a startEdit snapshot of every field. Re-sending an
+ // untouched featureAreas would let that stale value win the whole-record LWW
+ // merge and erase a featureAreas change a federated peer made while the editor
+ // was open. Omitting the field lets the service preserve whatever is stored —
+ // including any forward-unknown id from a newer peer, which is never dropped.
await renderPanel({ ...baseGoal, featureAreas: ['someFutureAreaFromANewerPeer'] });
fireEvent.click(screen.getByText('Edit'));
// Change only the title; never touch the feature-area buttons.
@@ -205,7 +206,7 @@ describe('GoalDetailPanel Daily Driver feature-area override (issue #2679)', ()
await Promise.resolve();
});
const [, payload] = api.updateGoal.mock.calls[0];
- expect(payload.featureAreas).toEqual(['someFutureAreaFromANewerPeer']);
+ expect(payload).not.toHaveProperty('featureAreas');
expect(payload.title).toBe('Master the craft, revised');
});
diff --git a/client/src/hooks/useGoalDetail.js b/client/src/hooks/useGoalDetail.js
index 067a6769cc..88d1d4bc7a 100644
--- a/client/src/hooks/useGoalDetail.js
+++ b/client/src/hooks/useGoalDetail.js
@@ -68,17 +68,35 @@ export function useGoalDetail({ goal, allGoals, onClose, onRefresh }) {
};
const saveEdit = async () => {
- // `form.featureAreas` carries the full override, INCLUDING any forward-unknown
- // ids preserved from `startEdit` (issue #2679). The multi-select only toggles
- // ids this install knows; unknown ids ride along untouched. We send the whole
- // array so those unknown ids are never dropped — the (now non-strict) server
- // schema accepts them and `getGoalFeatureAreas` filters them at read time.
- await api.updateGoal(goal.id, {
- ...form,
+ // featureAreas handling (issue #2679):
+ // - When the user did NOT touch the selector, OMIT featureAreas from the
+ // PATCH. The whole editor sends a startEdit snapshot, so re-sending an
+ // untouched featureAreas would let a stale value win the whole-record LWW
+ // merge and clobber a concurrent featureAreas edit from a federated peer.
+ // Omitting it lets the service preserve whatever is currently stored. (The
+ // pre-#2679 editor never sent this field at all, so this restores that
+ // immunity for the untouched case.)
+ // - When the user DID change it, send the full array — INCLUDING any
+ // forward-unknown ids preserved from startEdit (the known-id-only
+ // multi-select leaves them untouched). The update schema accepts unknown
+ // ids and getGoalFeatureAreas filters them at read time, so they are never
+ // dropped.
+ const { featureAreas, ...rest } = form;
+ const original = goal.featureAreas || [];
+ const current = featureAreas || [];
+ const featureAreasChanged =
+ current.length !== original.length ||
+ current.some((id, i) => id !== original[i]);
+ const payload = {
+ ...rest,
parentId: form.parentId || null,
targetDate: form.targetDate || null,
timeBlockConfig: form.timeBlockConfig || null
- });
+ };
+ if (featureAreasChanged) {
+ payload.featureAreas = current;
+ }
+ await api.updateGoal(goal.id, payload);
setEditing(false);
onRefresh();
};
diff --git a/server/lib/identityValidation.js b/server/lib/identityValidation.js
index 86bfcd155d..0d720b2f56 100644
--- a/server/lib/identityValidation.js
+++ b/server/lib/identityValidation.js
@@ -1,21 +1,27 @@
import { z } from 'zod';
+import { FEATURE_AREA_IDS } from './goalFeatureMap.js';
// Per-goal feature-area override (issue #2666): an ordered list of feature-area
// ids the Daily Driver deep-links to for this goal, overriding the category
// default. Absent/empty → the goal falls back to its category's default map.
//
-// Forward-compat (issue #2679): this is deliberately NOT `z.enum(FEATURE_AREA_IDS)`.
-// Goals sync between federated peers as whole records (no schema-version gate),
-// so an older install can receive — and store, via dataSync's direct file write
-// which bypasses this route validation — a goal carrying a feature-area id a
-// newer peer introduced. If the edit path rejected those ids, saving that goal
-// would 400; if the client stripped them, the truncated array would LWW-propagate
-// back and erase the newer peer's config. So we accept any non-empty string id
-// here and let `getGoalFeatureAreas` filter ids this install doesn't know at read
-// time — unknown ids are preserved in storage, ignored when resolving areas. The
-// cap stays generous (not tied to this install's FEATURE_AREA_IDS.length) so a
-// goal pinning more areas than this version knows still validates.
-const featureAreasSchema = z.array(z.string().min(1)).max(64);
+// Two schemas, because create and update have different forward-compat needs
+// (issue #2679):
+// - CREATE stays strict (`z.enum(FEATURE_AREA_IDS)`): a brand-new goal is
+// authored on THIS install, so an id outside this version's set is a typo or
+// a bug worth rejecting — `getGoalFeatureAreas` would silently discard it.
+// - UPDATE is lenient (any non-empty string): goals sync between federated
+// peers as whole records (no schema-version gate), so an older install can
+// receive — and store, via dataSync's direct file write which bypasses this
+// route validation — a goal carrying a feature-area id a newer peer
+// introduced. If the edit path rejected those ids, saving that goal would
+// 400; so we accept unknown ids on update and let `getGoalFeatureAreas`
+// filter ids this install doesn't know at read time (preserved in storage,
+// ignored when resolving areas). The cap stays generous (not tied to this
+// install's FEATURE_AREA_IDS.length) so a goal pinning more areas than this
+// version knows still validates.
+const createFeatureAreasSchema = z.array(z.enum(FEATURE_AREA_IDS)).max(FEATURE_AREA_IDS.length);
+const updateFeatureAreasSchema = z.array(z.string().min(1)).max(64);
export const sectionStatusEnum = z.enum(['active', 'pending', 'unavailable']);
@@ -87,7 +93,7 @@ export const createGoalInputSchema = z.object({
tags: z.array(z.string().min(1).max(50)).max(20).optional().default([]),
targetDate: validCalendarDate.optional(),
timeBlockConfig: timeBlockConfigSchema.optional(),
- featureAreas: featureAreasSchema.optional()
+ featureAreas: createFeatureAreasSchema.optional()
});
export const updateGoalInputSchema = z.object({
@@ -101,7 +107,7 @@ export const updateGoalInputSchema = z.object({
tags: z.array(z.string().min(1).max(50)).max(20).optional(),
targetDate: validCalendarDate.nullable().optional(),
timeBlockConfig: timeBlockConfigSchema.nullable().optional(),
- featureAreas: featureAreasSchema.optional()
+ featureAreas: updateFeatureAreasSchema.optional()
});
export const addMilestoneInputSchema = z.object({
diff --git a/server/lib/identityValidation.test.js b/server/lib/identityValidation.test.js
index c9e6997ce8..a647bca8fc 100644
--- a/server/lib/identityValidation.test.js
+++ b/server/lib/identityValidation.test.js
@@ -167,6 +167,16 @@ describe('identityValidation', () => {
});
expect(r.success).toBe(false);
});
+
+ it('accepts a known featureAreas override', () => {
+ expect(createGoalInputSchema.safeParse({ title: 'x', featureAreas: ['universes', 'tribe'] }).success).toBe(true);
+ });
+
+ it('rejects an unknown featureAreas id on create (strict — catches typos/bugs)', () => {
+ // Create happens on THIS install, so an id outside this version's set is a
+ // mistake worth rejecting (issue #2679 keeps create strict).
+ expect(createGoalInputSchema.safeParse({ title: 'x', featureAreas: ['someBogusArea'] }).success).toBe(false);
+ });
});
describe('updateGoalInputSchema', () => {
@@ -181,6 +191,18 @@ describe('identityValidation', () => {
it('rejects bad status value', () => {
expect(updateGoalInputSchema.safeParse({ status: 'paused' }).success).toBe(false);
});
+
+ it('accepts a forward-unknown featureAreas id on update (lenient — federated forward-compat)', () => {
+ // A goal synced from a newer peer can carry an id this install doesn't know
+ // yet; the edit path must not 400 on it (issue #2679). getGoalFeatureAreas
+ // filters unknown ids at read time, so storing them is harmless.
+ const r = updateGoalInputSchema.safeParse({ featureAreas: ['universes', 'someFutureAreaFromANewerPeer'] });
+ expect(r.success).toBe(true);
+ });
+
+ it('rejects a non-string featureAreas entry on update', () => {
+ expect(updateGoalInputSchema.safeParse({ featureAreas: [123] }).success).toBe(false);
+ });
});
describe('addMilestoneInputSchema', () => {