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): don't clear inline feedback if the federated split threw; listCommissions falls back to inline pre-migration

[._.]/ Adam Eivycb9229083978
diff --git a/server/services/creativeCommissions/store.js b/server/services/creativeCommissions/store.js
index 9e932f61ef..5e39534c53 100644
--- a/server/services/creativeCommissions/store.js
+++ b/server/services/creativeCommissions/store.js
@@ -315,7 +315,15 @@ export async function listCommissions() {
// any un-migrated legacy inline feedback is split lazily by getCommission /
// backfillAllCommissionFeedback, not on this hot list path.
const byId = await listFeedbackByCommissionIds(recs.map((r) => r.id)).catch(() => new Map());
- for (const r of recs) r.feedback = byId.get(r.id) || [];
+ // Prefer the federated view; fall back to the record's own (sanitized) inline
+ // feedback only when NO federated reaction exists for it yet — the transient
+ // pre-migration window before getCommission / backfillAllCommissionFeedback has
+ // split its legacy inline reactions. `byId.has` (not `|| []`) distinguishes
+ // "federated store has this commission's reactions" (authoritative, even if the
+ // array is non-empty) from "not yet migrated" (show the legacy inline so the
+ // list page doesn't transiently under-report), without ever double-counting
+ // (post-migration the inline array is empty).
+ for (const r of recs) r.feedback = byId.has(r.id) ? byId.get(r.id) : r.feedback;
return recs;
}
@@ -328,8 +336,16 @@ export async function getCommission(id) {
// route GET always see the federated feedback even before the boot backfill
// runs. Idempotent (deterministic ids, never-clobber upsert).
if (rec.feedback.length > 0) {
- await backfillInlineFeedback(id, rec.feedback).catch(() => {});
- await clearInlineFeedback(id).catch(() => {});
+ // Clear the inline array ONLY if the split SUCCEEDED. A mid-batch DB failure
+ // in backfillInlineFeedback (after ≥1 reaction was federated) must leave the
+ // inline array intact so a later read/boot can retry — clearing on a swallowed
+ // throw would permanently drop the un-migrated reactions. Gate on "didn't
+ // throw", NOT on the boolean return (which is legitimately false on an
+ // idempotent re-run where everything is already federated — clearing is still
+ // correct then).
+ let split = false;
+ try { await backfillInlineFeedback(id, rec.feedback); split = true; } catch { /* leave inline for retry */ }
+ if (split) await clearInlineFeedback(id).catch(() => {});
}
rec.feedback = await listFeedbackForCommission(id).catch(() => []);
return rec;
@@ -501,7 +517,10 @@ export async function backfillAllCommissionFeedback() {
for (const r of raw) {
const rec = sanitizeCommission(r);
if (!rec || rec.feedback.length === 0) continue;
- await backfillInlineFeedback(rec.id, rec.feedback).catch(() => {});
+ // Same non-atomic guard as getCommission: clear the inline array only after
+ // the split succeeded, so a transient failure mid-batch leaves the un-migrated
+ // reactions in place for the next boot/read instead of silently dropping them.
+ try { await backfillInlineFeedback(rec.id, rec.feedback); } catch { continue; }
await clearInlineFeedback(rec.id).catch(() => {});
migrated += 1;
}
diff --git a/server/services/creativeCommissions/store.test.js b/server/services/creativeCommissions/store.test.js
index 9ae1ede0df..a7594e421d 100644
--- a/server/services/creativeCommissions/store.test.js
+++ b/server/services/creativeCommissions/store.test.js
@@ -32,8 +32,10 @@ const {
updateCommission,
deleteCommission,
getCommission,
+ listCommissions,
recordCommissionRun,
submitCommissionFeedback,
+ backfillAllCommissionFeedback,
ERR_VALIDATION,
ERR_NOT_FOUND,
} = await import('./store.js');
@@ -243,6 +245,48 @@ describe('sanitizeCommission (feedback)', () => {
});
});
+describe('legacy inline feedback → federated split (#2686)', () => {
+ // Seed a pre-#2686 record that still carries INLINE feedback (Phase 2 storage),
+ // written straight into the machine-local commission map.
+ const seedLegacy = () => {
+ records.set('commission-legacy', {
+ id: 'commission-legacy', name: 'Legacy', enabled: true, targetAbility: 'video',
+ brief: {}, schedule: { kind: 'DAILY', atLocalTime: '02:00' }, generation: {},
+ runs: [{ id: 'run-A', status: 'started' }],
+ feedback: [{ id: 'feedback-old', runId: 'run-A', rating: 'up', note: 'legacy like', at: '2026-01-01T00:00:00.000Z' }],
+ createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z',
+ });
+ };
+
+ it('listCommissions falls back to inline feedback before migration (no under-report)', async () => {
+ seedLegacy();
+ const list = await listCommissions();
+ const legacy = list.find((c) => c.id === 'commission-legacy');
+ expect(legacy.feedback).toHaveLength(1);
+ expect(legacy.feedback[0]).toMatchObject({ runId: 'run-A', rating: 'up', note: 'legacy like' });
+ });
+
+ it('getCommission migrates inline → federated and clears the inline array', async () => {
+ seedLegacy();
+ const rec = await getCommission('commission-legacy');
+ expect(rec.feedback).toHaveLength(1);
+ expect(rec.feedback[0]).toMatchObject({ runId: 'run-A', rating: 'up', note: 'legacy like' });
+ // Inline array on the machine-local record is now cleared; a federated record exists.
+ expect(records.get('commission-legacy').feedback).toEqual([]);
+ expect([...feedbackRecords.values()].some((f) => f.commissionId === 'commission-legacy')).toBe(true);
+ });
+
+ it('backfillAllCommissionFeedback splits every commission idempotently', async () => {
+ seedLegacy();
+ const first = await backfillAllCommissionFeedback();
+ expect(first.migrated).toBe(1);
+ // Re-running is a no-op (inline already cleared).
+ const second = await backfillAllCommissionFeedback();
+ expect(second.migrated).toBe(0);
+ expect(records.get('commission-legacy').feedback).toEqual([]);
+ });
+});
+
describe('submitCommissionFeedback', () => {
it('appends a reaction keyed to an existing run and returns the updated commission', async () => {
const created = await createCommission(validInput());