Skip to content

git: coalesce remote fetches per repository and window - #370

Merged
wheregmis merged 2 commits into
mainfrom
devin/1790899722-coalesce-git-fetch
Oct 2, 2026
Merged

wheregmis merged 2 commits into
mainfrom
devin/1790899722-coalesce-git-fetch

Conversation

@wheregmis

Copy link
Copy Markdown
Owner

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 as git_dirty), and per-worktree GitOperation::Fetch calls — all funnel through threadlane_git::sync_remote/fetch, so the fix lives there and covers daemon and local mode alike.

  • RemoteFetchSlot per repository, keyed by git rev-parse --git-common-dir: linked worktrees share refs/remotes/*, so sessions in sibling worktrees of one repo now share a single fetch pipeline.
  • run_remote_fetch gives each slot two behaviors: callers arriving while a fetch is in_flight wait and share its result (success or error) instead of racing a second process on .git locks; and a completed Ok younger than REMOTE_SYNC_TTL (60s) satisfies later callers outright.
  • sync_remote uses the 60s window — background refreshes collapse to ≤1 remote call per repo per minute.
  • fetch (the panel's Fetch action, worktree_bases) passes ttl = 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.
  • pull calls note_remote_fetched on success — a pull already fetched, so the next background sync skips its own.
  • Failed fetches are returned to queued callers but never freshness-stamped, so the next sync retries immediately.

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_RUNS counts real fetch spawns). cargo check -p threadlane-gpui and git diff --check clean.

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

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.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T00:14:04.423704Z 99195ab PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 8e688ae9-320e-4f05-b308-d37eef8a0dd2

📥 Commits

Reviewing files that changed from the base of the PR and between 0da8d34 and 196f3f4.

📒 Files selected for processing (2)
  • crates/threadlane-git/src/git.rs
  • crates/threadlane-git/src/tests.rs
 __________________________________________________________________________________________________________
< Minimize coupling between modules. Avoid coupling by writing 'shy' code and applying the Law of Demeter. >
 ----------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Copy link
Copy Markdown

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 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".

Comment thread crates/threadlane-git/src/git.rs Outdated
Comment thread crates/threadlane-git/src/git.rs Outdated
- 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.
@wheregmis
wheregmis merged commit a0e5173 into main Oct 2, 2026
8 of 9 checks passed
@wheregmis
wheregmis deleted the devin/1790899722-coalesce-git-fetch branch October 2, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant