## TL;DR

The agent wrote the file without checking for local changes. Recover the colleague's work from git (stash, reflog, or their branch), re-apply the agent's fix on top via a real merge, and make agents pull and check git status before editing shared files.

## Error

```text
agent overwrote a colleague in-progress model edit with no merge
```

## Steps

1. Stop the agent and assess: ask the colleague what was lost, and check git status, git stash list, and their branches for the work.
   Expected: You locate the colleague's changes in git history, a stash, or their branch.

2. Restore the colleague's version to a branch, then re-apply the agent's fix on top of it (cherry-pick or manual re-application), resolving properly.
   Expected: Both changes exist in one branch, merged intentionally.

3. Run dbt compile and dbt run --select the affected models to verify the merged result.
   Expected: Build succeeds on the merged code.

4. Change the agent workflow: git pull and git status before any edit, never overwrite a dirty working tree, and work on branches, not main.
   Expected: Agents stop clobbering in-progress work.

## When to use

- an agent overwrote a colleague's uncommitted model edits
- a human's work vanished after an agent ran in the same repo
- the agent edited files with a dirty git status

## When not to use

- a normal merge conflict between two branches (resolve it normally)
- the colleague's work was already committed and pushed (then it is recoverable trivially)
- the agent and human edited different files (no conflict)

## Tool compatibility

- git status, stash list, reflog, and branches for recovery
- branches for agent work instead of main
- dbt compile/run to verify the merge

## Variant phrasings

### agent overwrote a pushed branch
Force-push damage: recover from the colleague's local clone or the reflog, then re-apply. Protect branches against force push.

### agent and human edited the same file concurrently
Same recovery, but expect a real content merge, not just re-application. Review the merged file carefully.

## Why it happens

Agents treat the working tree as their scratch space and do not check git status first. A human's uncommitted edits are invisible to the agent and get overwritten by a blind file write. Branching plus a pre-edit status check prevents the whole class.

## Edge cases

- Uncommitted work with no backup anywhere may be partially unrecoverable; the lesson is commit early and push often.
- Consider giving agents their own working copies or worktrees so they never share a working tree with humans.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_zzwJ_7TfJ0lXy-bpfrGftQ
