Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): the Welcome page offers repositories you only worked on in worktrees #33923

Mergeddominikzabcik(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/33923/headmerged by juliusmarminge View on GitHub

Problem

The Welcome page scan drops every session whose cwd is a linked git worktree of a normal checkout. A repository where all recent sessions ran in worktrees (one worktree per task) is never offered, so its root has to be added by hand before that history can be imported. On my machine that hid nfctron-api: all 38 of its recent conversations ran in 8 worktrees.

Change

The scan now counts a linked worktree's sessions toward its main checkout's project and reports the checkout's remote. Only a common dir named .git sits inside a checkout, so worktrees of bare repositories are still offered on their own, and a worktree whose repository config can't be read is left out as before, because it could be bare. A main checkout that is missing, excluded, or reached through a symlink into an excluded folder keeps its worktrees out.

This is the discovery remainder of #33401, split out as suggested when it was closed. Importing those sessions into the offered project is #18198. The two merge cleanly and pass the scanner and importer tests together.

Scope and approval

A maintainer invited this smaller PR when closing #33401 as a duplicate of #18198. It changes only what the scan offers. Import behavior and the symlinked-home exclusion (#23728) are untouched.

Verification

Proof: the existing scanner test for linked worktrees now expects a worktree session to count toward its checkout (threadCount: 2). It also expects a repository whose only session ran in a worktree to be offered with its remote. Both fail on main and pass here. The same test covers a worktree whose repository has no readable config and a main checkout symlinked into T3's state folder; neither is offered, and removing either guard fails it. The existing bare-repository and blocked-config tests still pass, including the one where an unreadable bare config must not offer the parent folder. vp run check:changed passes, except excludes sandboxes reached through a symlink into the worktrees dir, which also fails on main on macOS (/var vs /private/var) and is covered by #23728. Linux CI is unaffected.

On real data, before this change the Welcome page didn't offer nfctron-api. With the discovery part applied, it offered it with 38 conversations.

Created with Claude Opus 5.5 and Claude Fable 5.2 in Claude Code (T3 Code).

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. @@ -923,5 +928,11 @@
      923928 );
      924929 for (const { directory, gitDir, linkedWorktree } of repositories) {
      925930 const configText = configTexts.get(path.join(gitDir, "config")) ?? "";
      931+ const originUrl = parseOriginUrlFromGitConfig(configText);
      932+ const git: AgentSessionProjectGit = {
      933+ remoteKey:
      934+ originUrl === null ? null : sourceControlDefinitions.repositoryKeyFromRemote(originUrl),
      935+ repository: repositoryPathFromRemoteUrl(originUrl),
      936+ };
      926937 // Bare repositories have no main checkout, so offer their linked worktrees independently.
      927938 if (linkedWorktree && !isBareGitConfig(configText)) {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium project/AgentSessionScanner.ts:938

      When a linked worktree's common Git directory is named .git and its config cannot be read, this branch treats the empty fallback as non-bare and sets mainCheckout to the parent, merging independent worktrees into one project. Since readGitFiles uses "" for unreadable files, preserve that unknown state by leaving mainCheckout null instead of inferring a checkout from the basename.

      +      if (linkedWorktree && configText.length === 0) {
      +        identities.set(directory, { _tag: "Worktree", mainCheckout: null, git: null });
      +        continue;
      +      }
      
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/project/AgentSessionScanner.ts around line 938:
      
      When a linked worktree's common Git directory is named `.git` and its `config` cannot be read, this branch treats the empty fallback as non-bare and sets `mainCheckout` to the parent, merging independent worktrees into one project. Since `readGitFiles` uses `""` for unreadable files, preserve that unknown state by leaving `mainCheckout` null instead of inferring a checkout from the basename.

      Fixed in 844485c. A linked worktree whose repository config is empty or unreadable now keeps mainCheckout null, so it is left out as on main. The scan test has a worktree of a repository with no config, and it fails without the guard.

      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

      @@ -1568,12 +1582,17 @@
      15681582
      15691583 for (const candidate of raw) {
      15701584 const expanded = expandHomePath(candidate.cwd.trim(), homeDir);
      15711585 if (!path.isAbsolute(expanded)) continue;
      15721586 const resolved = path.resolve(expanded);
      15731587 const stats = directories.get(resolved);
      15741588 if (stats === undefined || Option.isNone(stats)) continue;
      1575- let key = directoryKeys.get(resolved);
      1576- if (key === undefined) {
      1589+ let project = directoryProjects.get(resolved);
      1590+ if (project === undefined) {
      15771591 const gitIdentity = directoryGitIdentities.get(resolved);
      1578- if (gitIdentity === undefined || gitIdentity._tag === "Worktree") {
      1579- key = "";
      1592+ if (gitIdentity === undefined) {
      1593+ project = null;
      1594+ } else if (gitIdentity._tag === "Worktree") {
      1595+ // A linked worktree's sessions count toward its main checkout's project.
      1596+ const { mainCheckout } = gitIdentity;
      1597+ const mainStats =
      1598+ mainCheckout === null || isExcludedProjectPath(mainCheckout)
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium project/AgentSessionScanner.ts:1598

      A worktree candidate whose mainCheckout resolves into ~/Downloads is still offered as a project, exposing a root that the scanner excludes for direct candidates. This branch checks only the lexical path; resolve mainCheckout and apply isExcludedProjectPath to its real path before adding the project.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/project/AgentSessionScanner.ts around line 1598:
      
      A worktree candidate whose `mainCheckout` resolves into `~/Downloads` is still offered as a project, exposing a root that the scanner excludes for direct candidates. This branch checks only the lexical path; resolve `mainCheckout` and apply `isExcludedProjectPath` to its real path before adding the project.

      Fixed in 844485c. The main checkout's real path now goes through isExcludedProjectPath too, like direct candidates. The scan test has a main checkout symlinked into T3's state folder, and it fails without the check.

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    3. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — Worktree activity now makes main checkouts eligible for the Welcome page’s default-checked project suggestions. Human confirmation is needed for this broader onboarding import default; users can still uncheck projects.

      Needs human approval because:

      • 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The scanner now records linked-worktree metadata and associates eligible worktree sessions with their main checkout project. Tests cover worktree-only sessions and Git configuration and path edge cases. The Projects documentation describes linked-worktree discovery.

      Changes: Linked-worktree session discovery

      Layer / File(s)Summary
      Validate directories and read Git identity
      apps/server/src/project/AgentSessionScanner.ts
      Directory validation rejects excluded paths, missing paths, non-directories, and symlink targets that resolve to excluded paths. Git identities include repository metadata and a main checkout path when the linked-worktree configuration supports one.
      Resolve worktree sessions to projects
      apps/server/src/project/AgentSessionScanner.ts, apps/server/src/project/AgentSessionScanner.test.ts, docs/user/welcome-page.md
      The scanner caches resolved project identities, maps eligible worktree sessions to their main checkout, and merges matching project records. Tests cover worktree-only repositories and invalid checkout cases. The documentation describes linked-worktree discovery.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: Minimal · up to ad500

      Welcome-page scanning now counts linked-worktree sessions toward the main checkout and offers worktree-only repositories for import. Only an unusual Git configuration can attribute sessions to the wrong directory, and no merge-blocking risk remains.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: the Welcome page now offers repositories whose only recent sessions ran in linked git worktrees. It uses the conventional fix(server) prefix. The changeset matches thi…
      Description checkPassedThe description follows the template's sections: Problem, Change, Scope, and Verification. The Problem section gives the bug, the reproduction context, and an example repository. The Change section ex…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the main change: the Welcome page now offers repositories whose only recent sessions ran in linked git worktrees. It uses the conventional fix(server) prefix. The changeset matches this: the scanner attributes linked-worktree sessions to their main checkout and reports the checkout's remote. The title is 81 characters, slightly long but still clear.

      Full details: Description check

      Explanation

      The description follows the template's sections: Problem, Change, Scope, and Verification. The Problem section gives the bug, the reproduction context, and an example repository. The Change section explains the fix and why bare repositories and unreadable configs are excluded. The Scope section links #33401 and #18198 and says a maintainer invited the PR. The Verification section lists focused tests, observed results, and a known unrelated failure. It also states the model and harness used. The description does not include a link to a bug issue for this specific fix, and it does not include a screenshot. The UI-change screenshot requirement may not apply, since the change affects scan results shown on the Welcome page. The description is complete enough to pass.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 844485cfe6a9c110dcc1db79ad59e12cb8e9f845 and ad50076bb0fddaba83ecbbedfbaa0ffceae09d74.

      Files selected for processing: 2

      • apps/server/src/project/AgentSessionScanner.test.ts
      • apps/server/src/project/AgentSessionScanner.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

    5. tanstack-source added labelsbug

    6. Evidence

      Created an ordinary checkout with an origin remote and linked worktree, then supplied three recent synthetic Claude conversations only in the linked worktree. Opened Welcome → Projects → Review all on both commits. A control repository retained the Projects section on base.

      Real web app, Chromium, 1280×800, light theme, fresh isolated state. Temporary parent paths are redacted; repository labels, checkout names and counts remain visible.

      BeforeAfter
      5cff012416ad50076bb0
      Before: only the control repository appearsAfter: demo/wt main checkout appears with count 3
      Worktree-only repository absent.Main checkout worktree-only appears under demo/wt with count 3.
      Before recordingAfter recording

      Scenario and seed driver · Harness patch · Reproduction instructions · Sanitized run records

      scenarios:prove exited 0: failed on base, passed on head. The visible Claude CLI warning is intentional; the harness enables transcript discovery while preventing live provider calls.

      AI-assisted; verified with the tests and tools listed above.

      Not shown:

      • Importing worktree conversations was not exercised; this proof covers discovery only.
      • Codex-format sessions and repositories with mixed main-checkout/worktree conversation histories were not captured.
    7. juliusmarminge merged thisd46b90c

    8. juliusmarminge closed this

Sign in to join this conversation.