From db87e83aedd4936cd1aee9ffe665415e83af3e04 Mon Sep 17 00:00:00 2001 From: Shirone Date: Sat, 24 Jan 2026 18:34:46 +0100 Subject: [PATCH] fix: Address PR feedback for structured output fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Throw error immediately when JSON extraction fails in generate-features-from-spec.ts to avoid redundant parsing attempt (feedback from Gemini Code Assist review) - Emit spec_regeneration_error event before throwing for consistency - Fix TypeScript cast in sync-spec.ts by using double cast through unknown 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../app-spec/generate-features-from-spec.ts | 17 ++++++++++++++--- apps/server/src/routes/app-spec/sync-spec.ts | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/server/src/routes/app-spec/generate-features-from-spec.ts b/apps/server/src/routes/app-spec/generate-features-from-spec.ts index e614113a..95e550e0 100644 --- a/apps/server/src/routes/app-spec/generate-features-from-spec.ts +++ b/apps/server/src/routes/app-spec/generate-features-from-spec.ts @@ -286,9 +286,20 @@ Your entire response should be valid JSON starting with { and ending with }. No contentForParsing = JSON.stringify(extracted); logger.info('✅ Pre-extracted JSON from text response'); } else { - // Fall back to raw text (let parseAndCreateFeatures try its extraction) - contentForParsing = rawText; - logger.warn('⚠️ Could not pre-extract JSON, passing raw text to parser'); + // If pre-extraction fails, we know the next step will also fail. + // Throw an error here to avoid redundant parsing and make the failure point clearer. + logger.error( + '❌ Could not extract features JSON from model response. Full response text was:\n' + + rawText + ); + const errorMessage = + 'Failed to parse features from model response: No valid JSON with a "features" array found.'; + events.emit('spec-regeneration:event', { + type: 'spec_regeneration_error', + error: errorMessage, + projectPath: projectPath, + }); + throw new Error(errorMessage); } } diff --git a/apps/server/src/routes/app-spec/sync-spec.ts b/apps/server/src/routes/app-spec/sync-spec.ts index d36b6808..d1ba139d 100644 --- a/apps/server/src/routes/app-spec/sync-spec.ts +++ b/apps/server/src/routes/app-spec/sync-spec.ts @@ -261,7 +261,7 @@ CRITICAL INSTRUCTIONS: if (techResult.structured_output) { // Use structured output from Claude/Codex models - const structured = techResult.structured_output as TechStackExtractionResult; + const structured = techResult.structured_output as unknown as TechStackExtractionResult; if (Array.isArray(structured.technologies)) { parsedTechnologies = structured.technologies; logger.info('✅ Received structured output for tech analysis');