agent failed: misread the compiled sql and fixed the wrong model in the dag
Teaches an agent to map compiled SQL back to its source model via the manifest before editing, so fixes land on the right file. Use when an agent edits the wrong model after reading compiled output. Not for correct-model wrong-fix situations.
TL;DR
Compiled SQL does not say which source file produced it, and the agent guessed wrong. Before editing, the agent must map the compiled output to its source: find the node ID, look up original_file_path (or patch_path) in the manifest, and edit that file. Then recompile and confirm the right model changed.
Error
agent failed to misread the compiled sql and fixed the wrong model in the dagSteps
- Stop editing. Identify the node: match the compiled SQL to a node via the filename or by searching node metadata. Expected: the correct node ID.
- Look up the node's source file in the manifest (
original_file_path). Expected: the exact file to edit. - Revert the wrong edit (
git checkout -- [WRONG FILE]) if it was committed to the working tree. Expected: the mistaken change is undone. - Apply the fix to the correct source file. Expected: the edit lands where it belongs.
- Recompile and verify with
git diffthat only the intended file changed. Expected: a clean, targeted diff.
When to use
- An agent fixed the wrong model after reading compiled SQL.
- Any workflow that goes from compiled output back to source.
When not to use
- The right file was edited but the fix was wrong (re-diagnose, do not remap).
- The agent works from source files directly (no mapping needed).
Tool compatibility
- dbt Core 1.0 and later; manifest.json for the mapping; git for revert.
Variant phrasings
Agent edited the compiled file in target/
Never edit target/ output; it is regenerated and the fix is lost.
Two models with similar names confused the agent
The manifest lookup disambiguates; names alone do not.
Why it happens
Compiled SQL is detached from its source: CTEs from ephemeral models, similar model names, and generated filenames all mislead. Agents that skip the manifest lookup guess, and guesses hit the wrong file.
Edge cases
- Ephemeral models have no compiled file of their own; their SQL appears inside downstream compiled files.
- Always verify with
git diff --statafter an agent edit; a surprising file list means a mapping error. - Keep a node-ID to file-path cheat sheet for the models the agent touches most.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_bXxlAuOYwvmdqYzrMnyzEA