Aider-AI / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
20.49k stars 1.89k forks source link

Support multiple instances of aider, for parallel workflow #302

Open mikeslattery opened 11 months ago

mikeslattery commented 11 months ago

I'd like to be able to have multiple instances of aider running at a time so I can work on multiple tasks.

GPT-4 can be slow and I spend a lot of time waiting. I could use that time working on related tasks.

My current workaround is a separate branch in a git worktree, but it's very clunky. I have to merge often.

Currently, problems with running two aider processes are: log files get overwritten, file contents might be stale, and work could get mixed when creating the diff. Possible solutions:

nevercast commented 11 months ago

I've also noticed weird behaviour when I've multiple instances of Aider running, particularly around edits and Git commits (edits and commits would just fail some of the time). It's possible that it's an unrelated bug specific to handling the SEARCH/REPLACE and Git commit steps, however I didn't observe it while using one Aider instance, only when running more than one. Would be good to get some insight if that's your experience too @mikeslattery

nevercast commented 11 months ago

My current workaround is a separate branch in a git worktree, but it's very clunky. I have to merge often.

Aider could very well manage it's own Git refs for each "transaction" and then merge them at the end of the conversation. This would work like branching and merging, but using custom refs instead of branches as to not clutter the user's Git experience. There are probably benefits to doing this separate from the parallel workflow story.

mikeslattery commented 11 months ago

My current workaround is a separate branch in a git worktree, but it's very clunky. I have to merge often.

Aider could very well manage it's own Git refs for each "transaction" and then merge them at the end of the conversation. This would work like branching and merging, but using custom refs instead of branches as to not clutter the user's Git experience. There are probably benefits to doing this separate from the parallel workflow story.

Oh, that's an interesting idea. /add could use git show <commit-id>:<file-path>. After commit run git rev-parse HEAD to get commit-id.

For now, I'm going to refine my bash scripts to make git worktrees solve the problem. I'll post here when done.

  1. aider-tree <path> will create the worktree child directory and add commit hooks, and it will create a dedicated local branch.
  2. The pre-commit hook will merge any changes from the parent path
  3. The post-commit hook will merge the commit to the parent path
  4. aider-tree --delete [path] will remove the hooks, and delete the current branch and worktree (if a child).
paul-gauthier commented 11 months ago

This is an interesting potential enhancement. One thing to keep in mind is that the repo may be dirty when aider sends the files and user request to GPT.

Currently aider only commits a dirty file when it gets a reply from GPT which contains an edit to that file. If aider gets an edit for a dirty file, it commits the dirty changes, applies the edit and then commits again.

There's probably a solution here in a world where aider is directly managing git refs and/or temporary branches, etc. Aider could speculatively commit the dirty repo, note git ref/branch, send the files+request to GPT, get the response and then based on the edits in the response decide whether to (partially) roll back the speculative dirty commit, etc.

This all seems doable, but it's a wrinkle which would need to be considered.

mikeslattery commented 11 months ago

As a workaround, I wrote a sync utility, git-syncr. You can fork off multiple directories from a feature branch.

git syncr add ../worktree2
cd ../worktree2
aider

And within aider you run /git sync or /run git-syncr sync to synchronize the directories.

https://gist.github.com/mikeslattery/48e196a3623608e021e61f6864a3ee74

heijligers commented 7 months ago

@mikeslattery Could you write a little bit more about your workflow here? Thanks!