From f3882f91b7024015f9fa157239bba9041f8d60e9 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Wed, 8 Apr 2026 16:33:02 +0200 Subject: [PATCH] Add status handling in profile extraction and caching logic --- backend/api/src/llm-extract-profile.ts | 10 ++++------ web/components/optional-profile-form.tsx | 3 +++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/api/src/llm-extract-profile.ts b/backend/api/src/llm-extract-profile.ts index f9eac172..cbc9a613 100644 --- a/backend/api/src/llm-extract-profile.ts +++ b/backend/api/src/llm-extract-profile.ts @@ -209,10 +209,7 @@ async function getCachedResult(cacheKey: string): Promise, -): Promise { +async function setCachedResult(cacheKey: string, result: any): Promise { if (!USE_CACHE) return try { await fs.mkdir(CACHE_DIR, {recursive: true}) @@ -285,9 +282,10 @@ async function processAndCache( if (bio) { profile.bio = bio } - await setCachedResult(cacheKey, profile) + await setCachedResult(cacheKey, {profile, status: 'success'}) } catch (error) { log('Async LLM processing failed', {cacheKey, error}) + await setCachedResult(cacheKey, {profile: {}, status: 'error'}) } finally { await clearProcessing(cacheKey) } @@ -589,7 +587,7 @@ export const llmExtractProfileEndpoint: APIHandler<'llm-extract-profile'> = asyn const cached = await getCachedResult(cacheKey) if (cached) { log('Returning cached profile', {cacheKey: cacheKey.substring(0, 8)}) - return {profile: cached, status: 'success'} + return cached as {profile: Partial; status: 'success' | 'error' | 'pending'} } // Check if already processing diff --git a/web/components/optional-profile-form.tsx b/web/components/optional-profile-form.tsx index 78b254d4..e799e830 100644 --- a/web/components/optional-profile-form.tsx +++ b/web/components/optional-profile-form.tsx @@ -131,6 +131,9 @@ export const OptionalProfileUserForm = (props: { } extractedProfile = response.profile } + if (status !== 'success') { + throw new Error('Failed to extract profile') + } extractedProfile = removeNullOrUndefinedProps(extractedProfile) for (const data of Object.entries(extractedProfile)) { const key = data[0] as keyof ProfileWithoutUser