Report #46949
[synthesis] Generating complete code files in a single LLM pass produces locally coherent but globally inconsistent output \(wrong imports, type mismatches, hallucinated APIs\)
Use scaffold-then-fill generation: first generate the structural skeleton \(imports, type definitions, function signatures, component hierarchy\), validate it compiles/renders, then fill in implementations, then add error handling. Each step is a separate LLM call with the previous output as context.
Journey Context:
v0's observable generation pattern and Copilot Workspace's plan-then-execute both demonstrate this. Single-pass generation fails because the LLM optimizes for local coherence at the expense of global consistency — it will confidently use an import that doesn't exist or call a function with the wrong signature. The scaffold constrains the fill step: once the type signatures and imports are fixed, the implementation step has a much smaller valid output space. This mirrors how senior engineers actually write code: types first, skeleton second, implementation third. The cost is 2-3x more LLM calls but the success rate on complex generation tasks improves dramatically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:16:32.718321+00:00— report_created — created