mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Defer Git worktree status until the turn starts (#62437)
## Why A turn interrupted during setup can be discarded before it runs. Starting the worktree scan during setup can spend time scanning for a turn that will never send a model request. ## What changed Collect `HEAD` and remote URLs in the background after turn setup, and start the worktree status scan only after the turn is admitted to run. Model requests use the latest available Git metadata while collection continues, and later requests can include the worktree status once it is available. Use shared background Git root discovery for the memory extraction change probe and pass the resolved root into the probe. ## Testing Regression tests cover requests proceeding while status is blocked, later requests carrying the updated `HEAD`, remote URL, and dirty status, and an interrupted wake skipping the worktree scan. GitOrigin-RevId: 00f465a5621d672d8b6d9063c384fb62e493c79f
This commit is contained in:
@@ -13,7 +13,6 @@ use futures::future::BoxFuture;
|
||||
use futures::future::WeakShared;
|
||||
|
||||
use crate::GitSha;
|
||||
use crate::get_git_repo_root;
|
||||
use crate::info::detect_local_fsmonitor_override;
|
||||
use crate::info::run_git_command_with_timeout_from;
|
||||
|
||||
@@ -82,8 +81,11 @@ pub async fn get_worktree_status_in_repo(
|
||||
/// Returns a positive change observation from a few recently modified root
|
||||
/// directories. A clean, failed, or incomplete probe cannot establish that the
|
||||
/// complete worktree is clean and returns `None`.
|
||||
pub async fn probe_worktree_changes(cwd: &Path) -> Option<(PathBuf, GitWorktreeStatus)> {
|
||||
let root = get_git_repo_root(cwd)?;
|
||||
pub async fn probe_worktree_changes(
|
||||
cwd: &Path,
|
||||
repo_root: &Path,
|
||||
) -> Option<(PathBuf, GitWorktreeStatus)> {
|
||||
let root = repo_root.to_path_buf();
|
||||
let probe_root = root.clone();
|
||||
let cwd = cwd.to_path_buf();
|
||||
// Relative Git environment paths can resolve differently in sibling cwds.
|
||||
|
||||
@@ -214,15 +214,17 @@ async fn change_probe_only_returns_git_verified_positive_status() {
|
||||
crate::ensure_git_baseline_repository(root)
|
||||
.await
|
||||
.expect("create initial commit");
|
||||
let cwd = root.join("nested");
|
||||
std::fs::create_dir(&cwd).expect("create nested cwd");
|
||||
let head = crate::get_head_commit_hash(root).await.expect("read HEAD");
|
||||
assert_eq!(probe_worktree_changes(root).await, None);
|
||||
assert_eq!(probe_worktree_changes(&cwd, root).await, None);
|
||||
|
||||
// The pathspec must treat names containing Git pathspec syntax literally.
|
||||
let candidate = root.join("[recent]");
|
||||
std::fs::create_dir(&candidate).expect("create candidate directory");
|
||||
std::fs::write(candidate.join("leaf"), "new file").expect("create untracked leaf");
|
||||
assert_eq!(
|
||||
probe_worktree_changes(root).await,
|
||||
probe_worktree_changes(&cwd, root).await,
|
||||
Some((
|
||||
root.to_path_buf(),
|
||||
GitWorktreeStatus {
|
||||
@@ -240,7 +242,7 @@ async fn change_probe_only_returns_git_verified_positive_status() {
|
||||
.expect("configure hidden untracked files")
|
||||
.success()
|
||||
);
|
||||
assert_eq!(probe_worktree_changes(root).await, None);
|
||||
assert_eq!(probe_worktree_changes(&cwd, root).await, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user