## TL;DR

Every macro edit must be followed by `dbt parse` before anything else. The agent should diff its edit, parse, smoke-test the macro with `run-operation`, and keep the change revertible (git stash or a backup) so a bad edit is one command away from undone.

## Error

```text
agent failed to compile the model after its own macro edit broke jinja
```

## Steps

1. Diff the macro edit: `git diff macros/[FILE].sql`. Expected: you see exactly what the agent changed.
2. Run `dbt parse` immediately. Expected: either clean, or an error pointing at the edit.
3. If parse fails, first try fixing the obvious issue (usually a brace or a variable name). Expected: a quick, targeted correction.
4. If the fix is not obvious in one try, revert the edit (`git checkout -- [FILE]`) and re-plan the change. Expected: the project compiles again.
5. Smoke-test the corrected macro with `dbt run-operation [MACRO] --args '{...}'`, then compile the affected models. Expected: green parse and compile.

## When to use

- An agent edited a macro and compilation now fails.
- Any automated macro edit workflow.

## When not to use

- The macro was already broken before the agent touched it (fix the original bug).
- The failure is in model SQL, not a macro.

## Tool compatibility

- dbt Core 1.0 and later, all adapters, git for revert.

## Variant phrasings

### Agent edit broke YAML, not Jinja

Same discipline: validate (YAML parse) immediately after every edit.

### Compile broke two edits later

Parse after every single edit, not after a batch; the culprit is then obvious.

## Why it happens

Agents batch edits and test at the end, so a Jinja mistake hides among several changes. Validating after each edit makes the failing change obvious and the revert trivial.

## Edge cases

- `run-operation` needs representative args; testing with empty args can miss the real failure.
- Parse-time vs run-time macro behavior differs; a clean parse does not guarantee a clean run.
- Keep edits small: one logical change per parse cycle.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_zDMd0ljTNC6y_xs2WSd5hQ
