Skip to content

Conversation

jif-oai
Copy link
Contributor

@jif-oai jif-oai commented Sep 19, 2025

Summary

Introduces a “ghost commit” workflow that snapshots the tree without touching refs.

  1. git commit-tree writes an unreferenced commit object from the current index, optionally pointing to the current HEAD as its parent.
  2. We then stash that commit id and use git restore --source to roll the worktree (and index) back to the recorded snapshot later on.

Details

  • Ghost commits live only as loose objects—we never update branches or tags—so the repo history stays untouched while still giving us a full tree snapshot.
  • Force-included paths let us stage otherwise ignored files before capturing the tree.
  • Restoration rehydrates both tracked and force-included files while leaving untracked/ignored files alone.

# Conflicts:
#	codex-rs/tui/src/chatwidget.rs
#	codex-rs/tui/src/chatwidget/tests.rs
#	codex-rs/tui/src/slash_command.rs
@jif-oai
Copy link
Contributor Author

jif-oai commented Sep 19, 2025

@codex can you review this deeply ?

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

}

let options = CreateGhostCommitOptions::new(&self.config.cwd);
match create_ghost_commit(&options) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How do you intend on this being used? When should one be created?

Somethings that come to mind are:

  1. Ideally this adds no latency in most cases even though the underlying git operations may be slow. To do this, it may require kicking off the snapshot when a turn starts and awaiting on it before the first exec call which will hopefully be long enough after the turn starts for it to complete
  2. However, some turns won't make filesystem changes so we would do extra throwaway work in those cases but maybe that's fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Yes this is exactly what I'm doing right now
  2. I don't see how to pre-shot those turns unfortunately

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed!

Copy link
Collaborator

Choose a reason for hiding this comment

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

For 1, this isn't using a tokio future so the snapshot runs synchronously on submit message which does add latency, right?

I was thinking we could use a tokio future that we launch at the same time but then await on before the first tool call to avoid the latency hit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the record: it will be tackled in a dedicated PR

@dedrisian-oai
Copy link
Collaborator

This is awesome! One thing to look out for is that unreachable commits get automatically garbage collected by git after a certain point (default is 14 days). Do we know if we need to create a ref/tag for each commit?

# Conflicts:
#	codex-rs/tui/src/chatwidget.rs
#	codex-rs/tui/src/slash_command.rs
@gpeal
Copy link
Collaborator

gpeal commented Sep 22, 2025

This is awesome! One thing to look out for is that unreachable commits get automatically garbage collected by git after a certain point (default is 14 days). Do we know if we need to create a ref/tag for each commit?

I think it's fine (good, actually) that these get garbage collected. The useful lifetime of the snapshot will likely be shorter than that.

@jif-oai jif-oai requested a review from gpeal September 22, 2025 19:48
@jif-oai jif-oai merged commit e0fbc11 into main Sep 23, 2025
19 checks passed
@jif-oai jif-oai deleted the jif/git-tooling branch September 23, 2025 15:59
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants