-
Notifications
You must be signed in to change notification settings - Fork 4
Skip live PR/MR provider detection during bulk import #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexeyzimarev
merged 4 commits into
main
from
worktree-issue-232-import-provider-detection-latency
Jul 5, 2026
+155
−14
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a396470
perf(import): skip live PR/MR provider detection during bulk import
realtonyyoung 042c8b2
fix(import): keep PR detection for Cursor import (it emits pr_* in it…
realtonyyoung 6a858e1
Merge remote-tracking branch 'origin/main' into worktree-issue-232-im…
realtonyyoung d226393
docs(import): document the provider-detection skip rationale (#232)
realtonyyoung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Import provider (PR/MR) detection latency | ||
|
|
||
| Tracking: [#232](https://github.com/kurrent-io/kcap-cli/issues/232) (AI-1122). | ||
|
|
||
| ## Question | ||
|
|
||
| `ImportCommand`'s bulk loop calls `RepositoryDetection.DetectRepositoryAsync` per session/cwd, | ||
| which can spawn a live `gh pr view` / `glab api` per unique repo (bounded by a ~2 s best-effort | ||
| cap each). The per-host memo in `GitProviderRouter` stops the `gh auth status` **probe** from | ||
| multiplying, but the **detection call** still runs per cwd — and GitLab's `glab api` is a network | ||
| round-trip rather than gh's local resolution. Does this hurt large multi-repo imports, and if so, | ||
| should we cache per `(repo, branch)` or skip detection during import? | ||
|
|
||
| ## Finding: the PR/MR detection is *dead work* on the import paths | ||
|
|
||
| The decisive observation is not a latency number — it's that **every bulk-import path discards the | ||
| PR fields**, so the `gh`/`glab` round-trip produces a result that is never used: | ||
|
|
||
| - **Scope-picker resolution** and the **"Scanning repositories"** step use only `Owner`/`RepoName`. | ||
| - **Per-session ingest** (`ImportCommand`) builds its `repository` node manually with | ||
| `user_name`/`user_email`/`remote_url`/`owner`/`repo_name`/`branch` — **no `pr_*` fields**. | ||
| - **Classification** (`TranscriptFileClassification`) uses the detected repo only for the | ||
| owner/repo exclusion key. | ||
| - The **Copilot / Pi / Kiro** import sources use their repo detector only for the same exclusion | ||
| key. | ||
|
|
||
| The **live/hook path** (`EnrichWithRepositoryInfo` → `BuildRepositoryNode`) *does* emit | ||
| `pr_number`/`pr_title`/`pr_url`/`pr_head_ref`, so PR detection genuinely matters there — just not | ||
| during import. | ||
|
|
||
| ## Decision | ||
|
|
||
| Add a `detectPullRequest` flag (default `true`, preserving every live/hook caller) to | ||
| `DetectRepositoryAsync` and pass `detectPullRequest: false` on the bulk-import paths. This removes | ||
| the provably-unused `gh pr view` / `glab api` round-trip per cwd while still resolving base repo | ||
| info from local git. It is **behaviour-preserving**: imported payloads never carried PR fields on | ||
| those paths, so nothing observable changes — only the discarded network calls are dropped. | ||
|
|
||
| Because the result is discarded, this is a stronger justification than a wall-clock measurement: | ||
| the work is unnecessary regardless of its per-call cost. A representative "large multi-repo import" | ||
| benchmark was **not** run — it needs live `gh`/`glab` authentication, many real repositories with | ||
| open PRs/MRs, and network access that isn't reproducible in the dev/CI sandbox — and would not | ||
| change the conclusion. | ||
|
|
||
| ### Exception: Cursor import keeps PR detection | ||
|
|
||
| `CursorImportSource` is the one import source whose synthetic `session-start/cursor` payload carries | ||
| a `repository` node built via `RepositoryDetection.BuildRepositoryNode`, which **does** emit `pr_*` | ||
| when populated (AI-1152). It therefore keeps live PR detection (its default detector is *not* | ||
| flipped) so imported Cursor sessions retain their PR tagging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/Capacitor.Cli.Tests.Unit/ImportProviderDetectionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| using Capacitor.Cli; | ||
| using Capacitor.Cli.PrDetection; | ||
|
|
||
| namespace Capacitor.Cli.Tests.Unit; | ||
|
|
||
| /// <summary> | ||
| /// Import discards PR/MR fields on every path, so running the live `gh pr view` / `glab api` | ||
| /// provider round-trip per cwd during a bulk import is wasted latency (AI-1122). These tests pin | ||
| /// the `detectPullRequest` switch on RepositoryDetection.DetectRepositoryAsync via an injected | ||
| /// command runner: import (false) resolves owner/repo with git only and never spawns a provider | ||
| /// CLI, while the default (live) path still does. | ||
| /// </summary> | ||
| public class ImportProviderDetectionTests { | ||
| // Records every command the detector spawns; answers git probes with a GitHub remote so | ||
| // owner/repo/host resolve, and answers `gh pr view` with a PR so the live path can populate it. | ||
| static CommandRunner Recording(List<string> log) => (cmd, args, _, _) => { | ||
| log.Add($"{cmd} {args}"); | ||
| if (cmd == "git" && args.StartsWith("remote get-url")) return Task.FromResult<string?>("https://github.com/foo/bar"); | ||
| if (cmd == "git" && args.StartsWith("branch")) return Task.FromResult<string?>("main"); | ||
| if (cmd == "git") return Task.FromResult<string?>(""); | ||
| if (cmd == "gh") return Task.FromResult<string?>("""{"number":7,"title":"t","url":"https://github.com/foo/bar/pull/7","headRefName":"main"}"""); | ||
| return Task.FromResult<string?>(null); | ||
| }; | ||
|
|
||
| [Test] | ||
| public async Task Import_detection_resolves_repo_without_spawning_a_provider_cli() { | ||
| var log = new List<string>(); | ||
|
|
||
| var repo = await RepositoryDetection.DetectRepositoryAsync( | ||
| "/fake/import/skip-pr", budget: null, detectPullRequest: false, run: Recording(log)); | ||
|
|
||
| // Base repo info still resolves from git alone… | ||
| await Assert.That(repo!.Owner).IsEqualTo("foo"); | ||
| await Assert.That(repo.RepoName).IsEqualTo("bar"); | ||
| await Assert.That(repo.PrNumber).IsNull(); | ||
| // …but no `gh` / `glab` round-trip was made. | ||
| await Assert.That(log.Any(c => c.StartsWith("gh") || c.StartsWith("glab"))).IsFalse(); | ||
| await Assert.That(log.Any(c => c.StartsWith("git"))).IsTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Live_detection_still_runs_provider_detection() { | ||
| var log = new List<string>(); | ||
|
|
||
| var repo = await RepositoryDetection.DetectRepositoryAsync( | ||
| "/fake/live/do-pr", budget: null, detectPullRequest: true, run: Recording(log)); | ||
|
|
||
| await Assert.That(log.Any(c => c.StartsWith("gh pr view"))).IsTrue(); // provider detection ran | ||
| await Assert.That(repo!.PrNumber).IsEqualTo(7); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.