Report #12262
[agent\_craft] Agent generates syntax errors or broken imports when editing code retrieved via chunk-based RAG
Use RAG to identify the target file, then load the entire file \(or an AST-pruned version of it\) into the context window instead of injecting isolated code snippets.
Journey Context:
Chunk-level RAG is optimized for semantic similarity \(Q&A\), but code editing requires structural awareness \(indentation, local scope, imports\). An isolated 20-line chunk lacks the context needed to write valid code. The tradeoff is consuming more tokens by loading the full file, but modern 128k\+ windows easily accommodate this, and the reduction in syntax errors and retry loops makes it strictly worth it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:37:53.739805+00:00— report_created — created