GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(core): significantly speed up slow revert functionality by natewill · Pull Request #20551 · anomalyco/opencode

Conversation

@natewill

@natewill natewill commented Apr 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #20550

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR speeds up Snapshot.revert for large revert operations.

Currently, revert handles files one at a time. In the worst case, that means up to 2n git subprocesses for n files: one git checkout per file, and one git ls-tree per file when checkout fails. Because each subprocess has overhead (10-20ms per file), revert gets very slow as file count grows.

This change batches files by snapshot hash and processes them in chunks. In the common case, that reduces the work from 2n git subprocesses to two batched git ls-tree and git checkout calls per 100 file chunks, while preserving the existing single-file path as a fallback if a batched operation fails.

In local testing on my machine, Snapshot.revert for a 300-file revert dropped from 8.72s to 96ms, which is about a 90x speedup.

This improves the file rollback portion of revert specifically. The remaining time in full session revert is still dominated by diff generation after rollback, which can be lengthy.

How did you verify your code works?

  • Verified locally with mixed revert scenarios covering modified existing files, deleted existing files, newly created files, and overlapping files across patches.
  • Verified the real session revert flow restores the worktree correctly for mixed file changes.
  • Ran bun typecheck in packages/opencode.

Screenshots / recordings

Not UI change

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Nate added 9 commits April 1, 2026 14:10
Nate Nate
fix(opencode): batch snapshot revert checkout
f0fb09f
Nate Nate
refactor(opencode): clarify snapshot revert naming
82b0843
Nate Nate
refactor(opencode): clarify single-file revert path
042462c
Nate Nate
refactor(opencode): clarify grouped file naming
3bd9964
Nate Nate
refactor(opencode): clarify file chunk naming
a426048
Nate Nate
refactor(opencode): clarify checkout file naming
37028d6
Nate Nate
refactor(opencode): clarify chunk path naming
4cc2a39
Nate Nate
refactor(opencode): clarify file chunk path naming
8687240
Nate Nate
refactor(opencode): polish snapshot batching flow
921c809
@github-actions github-actions Bot added the needs:title label Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title perf(core): significantly speed up slow revert functionality doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the contributor label Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, the current PR (#20551) appears to be the primary result in most searches. The other related PRs found are:

  • refactor(opencode): parallelize git snapshot operations on finish-step #16103 - "refactor(opencode): parallelize git snapshot operations on finish-step" - Related to batching git operations for snapshot performance
  • feat: add conversation-only revert capability #16447 - "feat: add conversation-only revert capability" - Related to revert functionality
  • fix(opencode): improve message filtering for summary update during revert and unrevert #13489 - "fix(opencode): improve message filtering for summary update during revert and unrevert" - Related to revert operations
  • fix(snapshot): make /redo targeted to only restore files from reverted turn #15611 - "fix(snapshot): make /redo targeted to only restore files from reverted turn" - Related to snapshot restoration

However, none of these appear to be duplicates addressing the same optimization (batching by snapshot hash to speed up Snapshot.revert). PR #16103 touches on parallelizing git operations, but that's a different scope.

No duplicate PRs found

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@natewill natewill changed the title perf(core): significantly speed up slow revert functionality refactor(core): significantly speed up slow revert functionality Apr 1, 2026
@github-actions github-actions Bot removed the needs:title label Apr 1, 2026
@thdxr thdxr assigned kitlangton Apr 1, 2026
@natewill
natewill force-pushed the revert-batching-dev branch from 0badd89 to 921c809 Compare April 1, 2026 21:03
natewill
natewill commented Apr 1, 2026
View reviewed changes
Comment thread packages/opencode/src/snapshot/index.ts
}
}

const revertSingle = Effect.fnUntraced(function* (hash: string, file: string) {

@natewill natewill Apr 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revertSingle is the same functionality as the revert function that is in the current code. We use this as a fallback if the batching doesn't work for some reason or the snapshot hash only has one reverted file in it

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
natewill
natewill commented Apr 1, 2026
View reviewed changes
Comment thread packages/opencode/src/snapshot/index.ts
}
continue
}

@natewill natewill Apr 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we only checkout files that exist in this snapshot; files missing from the tree should be removed. The old code did the same thing but individually.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@natewill natewill mentioned this pull request Apr 1, 2026
fix(desktop): fix revert race condition for sessions with many files #20518
Closed
3 of 6 tasks
Nate and others added 4 commits April 1, 2026 17:31
Nate Nate
Merge upstream/dev into revert-batching-dev
d4fb8a0
@natewill
Update comments in snapshot index.ts
8222e72
Refactor comments for clarity and consistency in index.ts.
Nate Nate
refactor(opencode): simplify file path naming
06f5cce
@natewill
Merge branch 'dev' into revert-batching-dev
9eaac9d
@kitlangton kitlangton mentioned this pull request Apr 1, 2026
fix(opencode): batch snapshot revert without reordering #20564
Merged
@natewill natewill mentioned this pull request Apr 2, 2026
refactor(core): speed up diff calculation significantly #20731
Closed
3 of 6 tasks
@github-actions github-actions Bot mentioned this pull request Apr 3, 2026
fix(core): fix restoring earlier messages in a reverted chain #20780
Merged
3 of 6 tasks
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@github-actions github-actions Bot mentioned this pull request Apr 29, 2026
feat: add conversation-only revert capability (resolved conflicts) #24957
Closed
2 of 3 tasks
@rekram1-node

rekram1-node commented May 15, 2026

Copy link
Copy Markdown
Member

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node rekram1-node closed this May 15, 2026
@rekram1-node rekram1-node added the automated-pr-cleanup label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@kitlangton kitlangton

Labels

automated-pr-cleanup contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG} revert is very slow

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@natewill @rekram1-node @kitlangton
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.