git: coalesce remote fetches per repository and window - #370
Conversation
Background refresh paths (project switches, panel opens, watcher-driven reloads) each ran their own 'git fetch --prune', and a fetch's own ref writes fed back into the workspace watcher as git_dirty — bursts turned into sustained remote traffic. sync_remote now runs through a per-repository slot keyed by --git-common-dir (linked worktrees share refs/remotes, so they share a slot): callers arriving while a fetch is in flight share its result, and a successful fetch younger than 60s satisfies later callers outright. Explicit Fetch operations still contact the remote every time but coalesce with an in-flight run; a completed pull stamps freshness so the next background sync skips its fetch. Failures reach queued callers but are never freshness-stamped, so retries are unaffected.
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99195ab1fb
ℹ️ 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
- 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 address that feedback".
- Include the resolved fetch remote (branch.<name>.remote, default origin) in the fetch-slot key so linked worktrees tracking different remotes can't share a stale success. - Count callers blocked on the slot condvar so the in-flight-sharing test releases the leader only once all waiters are actually queued.
Summary
Modeled on pingdotgg/t3code#14673, which cut background GitHub polling ~74% by coalescing calls: every refresh path that syncs remote refs ran its own
git fetch --prune, and bursts turned into sustained remote traffic. The triggers —Inspect { sync_remote }from project switches and the four panel-open actions,WorkspaceChanged { git_dirty }reloads (a fetch's own ref writes feed the watcher back asgit_dirty), and per-worktreeGitOperation::Fetchcalls — all funnel throughthreadlane_git::sync_remote/fetch, so the fix lives there and covers daemon and local mode alike.RemoteFetchSlotper repository, keyed bygit rev-parse --git-common-dir: linked worktrees sharerefs/remotes/*, so sessions in sibling worktrees of one repo now share a single fetch pipeline.run_remote_fetchgives each slot two behaviors: callers arriving while a fetch isin_flightwait and share its result (success or error) instead of racing a second process on.gitlocks; and a completedOkyounger thanREMOTE_SYNC_TTL(60s) satisfies later callers outright.sync_remoteuses the 60s window — background refreshes collapse to ≤1 remote call per repo per minute.fetch(the panel's Fetch action,worktree_bases) passesttl = ZERO: explicit requests still contact the remote every time, but coalesce with an in-flight run and re-arm the window for the background path.pullcallsnote_remote_fetchedon success — a pull already fetched, so the next background sync skips its own.Testing
cargo nextest run -p threadlane-git— 88 tests pass, including new coverage: TTL skip, explicit-fetch bypass/re-arm, cross-worktree slot sharing, retry-after-failure, and queued waiters sharing one in-flight run (REMOTE_FETCH_RUNScounts real fetch spawns).cargo check -p threadlane-gpuiandgit diff --checkclean.Link to Devin session: https://app.devin.ai/sessions/922c096109634db8a2b783534aa62196
Open in Devin Desktop: https://app.devin.ai/desktop/session/922c096109634db8a2b783534aa62196?variant=devin
Requested by: @wheregmis