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
review: absorb synchronous embedder throws in semantic dedup too (#2262)
Adam Eivy1dc9fdd263be
diff --git a/server/services/layeredIntelligence.js b/server/services/layeredIntelligence.jsindex aa2655da65..e38912df3a 100644--- a/server/services/layeredIntelligence.js+++ b/server/services/layeredIntelligence.js@@ -579,16 +579,20 @@ export async function checkSemanticDuplicate({ proposal, existingIssues = [], no.slice(0, SEMANTIC_DEDUP_MAX_CANDIDATES);if (candidates.length === 0) return unavailable;- // A rejected/throwing embed (transient provider blip, malformed response) must- // degrade to the available:false sentinel — NOT reject through processApp and- // mark the whole app run 'error'. `.catch(() => null)` mirrors this file's- // fetchHttpSource / jira-search failure idiom (no non-boundary try/catch).- const proposalRes = await embed(issueEmbedSeed({ title: proposal.title, body: proposal.body })).catch(() => null);+ // A failing embed (transient provider blip, malformed response) must degrade to+ // the available:false sentinel — NOT reject through processApp and mark the+ // whole app run 'error'. Deferring the call into a promise chain then catching+ // absorbs BOTH an async rejection AND a synchronous throw from the (injectable)+ // embedder, mirroring this file's fetchHttpSource / jira-search failure idiom+ // (no non-boundary try/catch).+ const safeEmbed = (text) => Promise.resolve().then(() => embed(text)).catch(() => null);++ const proposalRes = await safeEmbed(issueEmbedSeed({ title: proposal.title, body: proposal.body }));if (!proposalRes?.success || !Array.isArray(proposalRes.embedding)) return unavailable;const embedded = [];for (const c of candidates) {- const res = await embed(issueEmbedSeed({ title: c.title, body: c.body })).catch(() => null);+ const res = await safeEmbed(issueEmbedSeed({ title: c.title, body: c.body }));if (res?.success && Array.isArray(res.embedding)) {embedded.push({ slug: c.slug || null, number: c.number ?? null, title: c.title || '', embedding: res.embedding });}diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.jsindex 9a096e04c5..b71db0b8a4 100644--- a/server/services/layeredIntelligence.test.js+++ b/server/services/layeredIntelligence.test.js@@ -883,11 +883,15 @@ describe('checkSemanticDuplicate — I/O wrapper', () => {expect(res.duplicate).toBe(false);});- it('degrades to unavailable (never rejects) when the embedder throws', async () => {- const embed = vi.fn(async () => { throw new Error('provider down'); });+ it('degrades to unavailable (never rejects) on an async rejection OR a synchronous throw', async () => {const existing = [{ number: 3, title: 'Add widget', body: 'x', state: 'open' }];- const res = await checkSemanticDuplicate({ proposal, existingIssues: existing, now: NOW, embed });- expect(res).toEqual({ available: false, duplicate: false, match: null });+ const asyncThrow = vi.fn(async () => { throw new Error('provider down'); });+ expect(await checkSemanticDuplicate({ proposal, existingIssues: existing, now: NOW, embed: asyncThrow }))+ .toEqual({ available: false, duplicate: false, match: null });+ // A non-async embedder that throws synchronously must also degrade, not reject.+ const syncThrow = vi.fn(() => { throw new Error('sync boom'); });+ expect(await checkSemanticDuplicate({ proposal, existingIssues: existing, now: NOW, embed: syncThrow }))+ .toEqual({ available: false, duplicate: false, match: null });});it('flags a near-duplicate when a candidate embedding is close enough', async () => {