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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): fail the fire on unreadable feedback; tombstone feedback pre-prune
[._.]/ Adam Eivy272336cd1f33
diff --git a/server/services/creativeCommissions/feedbackStore.js b/server/services/creativeCommissions/feedbackStore.jsindex 408e422fe5..094de83149 100644--- a/server/services/creativeCommissions/feedbackStore.js+++ b/server/services/creativeCommissions/feedbackStore.js@@ -366,17 +366,20 @@ export async function deleteCommissionFeedback(id) {}/**- * Tombstone every live feedback record for a commission. Called when the+ * Tombstone every live feedback record for a commission. Called BEFORE the* commission's own tombstone is hard-pruned: past that point no peer can* resurrect the commission, but its feedback rows would otherwise stay live* forever — enumerated by the sync listers and pushed to every new peer, with* no GC path (tombstone GC only prunes rows that are already tombstoned).+ * Deliberately throws on failure: the caller runs pre-prune, so a throw leaves+ * the commission tombstone in place and the next sweep retries — swallowing+ * here would let the prune proceed and orphan the remaining rows permanently.*/export async function tombstoneFeedbackForCommission(commissionId) {const raw = await feedbackStore().listRawByCommission(commissionId);let tombstoned = 0;for (const rec of raw) {- const res = await deleteCommissionFeedback(rec.id).catch(() => ({ deleted: false }));+ const res = await deleteCommissionFeedback(rec.id);if (res.deleted) tombstoned += 1;}return { commissionId, tombstoned };diff --git a/server/services/creativeCommissions/store.js b/server/services/creativeCommissions/store.jsindex 9a462fbbdc..a0dd08d87d 100644--- a/server/services/creativeCommissions/store.js+++ b/server/services/creativeCommissions/store.js@@ -505,7 +505,12 @@ export async function getCommission(id) {try { await backfillInlineFeedback(id, inlineLegacy); split = true; } catch { /* leave inline for retry */ }if (split) await clearInlineFeedback(id).catch(() => {});}- const federated = await listFeedbackForCommission(id).catch(() => []);+ // No catch: a FAILED federated read must not collapse into "no feedback" —+ // the scheduler's pre-fire read would spend generation budget ignoring the+ // user's ratings. Let it throw: the route surfaces the error, the scheduler+ // aborts the fire and retries next tick. (listCommissions keeps its display+ // fallback — a degraded list page is fine; a mis-directed generation is not.)+ const federated = await listFeedbackForCommission(id);// Union with the legacy inline reactions so a PARTIAL migration (backfill wrote// a prefix then threw, inline retained for retry) never hides the un-migrated// tail from the scheduler directive or the UI. After a full migration the inline@@ -777,14 +782,18 @@ export async function mergeCommissionsFromSync(remoteRecords, { source = { via:/** Hard-remove tombstoned commissions older than the cutoff; evicts each base hash. */export async function pruneTombstonedCommissions(olderThanMs) {- const result = await commissionStore().pruneTombstoned(olderThanMs);- for (const id of result.ids || []) {- await deleteSyncBaseHash(CREATIVE_COMMISSION_KIND, id).catch(() => {});- // The commission is gone everywhere its tombstone aged out — tombstone its- // feedback too, so the rows GC through the normal path instead of staying- // live (and peer-pushed) forever with no owner.- await tombstoneFeedbackForCommission(id).catch(() => {});+ // Tombstone each stale commission's feedback BEFORE hard-pruning the+ // commission. Once the prune removes the record there is nothing left for a+ // later sweep to rediscover, so a failure after the prune would leave the+ // feedback live (and peer-pushed) forever. In this order a failure throws,+ // the commission tombstone stays put, and the next sweep retries both halves.+ if (Number.isFinite(olderThanMs)) {+ const stale = (await commissionStore().listRaw({ includeDeleted: true }))+ .filter((r) => r?.deleted === true && isStr(r.deletedAt) && Date.parse(r.deletedAt) < olderThanMs);+ for (const r of stale) await tombstoneFeedbackForCommission(r.id);}+ const result = await commissionStore().pruneTombstoned(olderThanMs);+ for (const id of result.ids || []) await deleteSyncBaseHash(CREATIVE_COMMISSION_KIND, id).catch(() => {});return result;}diff --git a/server/services/creativeCommissions/store.test.js b/server/services/creativeCommissions/store.test.jsindex b309c465c7..48d6ecc977 100644--- a/server/services/creativeCommissions/store.test.js+++ b/server/services/creativeCommissions/store.test.js@@ -53,6 +53,7 @@ const {mergeCommissionRecord,getCommissionForSync,mergeCommissionsFromSync,+ pruneTombstonedCommissions,ERR_VALIDATION,ERR_NOT_FOUND,} = await import('./store.js');@@ -266,6 +267,29 @@ describe('deleteCommission', () => {});});+describe('pruneTombstonedCommissions', () => {+ it('tombstones the commission\'s feedback BEFORE the hard-prune so it GCs instead of staying live', async () => {+ const created = await createCommission(validInput());+ await recordCommissionRun(created.id, { id: 'run-A', status: 'completed' });+ await submitCommissionFeedback(created.id, { runId: 'run-A', rating: 'up', note: 'more Magritte' });+ await deleteCommission(created.id);+ // Age the commission tombstone past the cutoff.+ const rec = records.get(created.id);+ records.set(created.id, { ...rec, deletedAt: '2020-01-01T00:00:00.000Z' });++ const result = await pruneTombstonedCommissions(Date.parse('2021-01-01T00:00:00.000Z'));++ expect(result.pruned).toBe(1);+ expect(records.has(created.id)).toBe(false); // commission hard-pruned+ // The orphan-prevention contract: every feedback row for the pruned+ // commission is now a tombstone (not live, not hard-deleted), so it+ // federates its removal and ages out through normal tombstone GC.+ const rows = [...feedbackRecords.values()].filter((f) => f.commissionId === created.id);+ expect(rows.length).toBeGreaterThan(0);+ for (const f of rows) expect(f.deleted).toBe(true);+ });+});+describe('sanitizeFeedbackEntry', () => {it('normalizes an up/down reaction and mints an id', () => {const e = sanitizeFeedbackEntry({ runId: 'run-1', rating: 'up', note: 'more Magritte' });