Skip to content

fix(web): New Chat targets a reachable project copy, keeps worktrees - #12912

Open
macodev00 wants to merge 1 commit into
pingdotgg:mainfrom
macodev00:cursor/fix-new-chat-reachable-copy-ee90
Open

macodev00 wants to merge 1 commit into
pingdotgg:mainfrom
macodev00:cursor/fix-new-chat-reachable-copy-ee90

Conversation

@macodev00

@macodev00 macodev00 commented Sep 21, 2026

Copy link
Copy Markdown

What

  • New Chat targets a reachable project copy (not a down host) while keeping every same-environment worktree checkout visible (no environmentId collapse that drops worktrees); prefers the active worktree.

Why

Fixes #12093

Redo of closed #12731 addressing Macroscope Not-approved / High: smaller picker fix with same-env worktree regression coverage.

UI

New Chat / project picker: reachable copies listed; same-env worktrees not omitted.

Checklist

  • I read CONTRIBUTING.md and kept this small / bug-only
  • What + why explained above
  • Followed AGENTS.md documentation rules (no new docs)
  • No unrelated changes
  • CLA / AI-reviewed standing override for macodev00 auto-contrib

Summary by CodeRabbit

  • New Features

    • The “New thread in…” picker now shows available checkouts across environments, making it easier to choose the right project copy.
    • Reachable environments and the active checkout are prioritized when selecting or focusing a project.
  • Bug Fixes

    • Starting a thread from an unavailable environment now shows a clear error instead of attempting to use it.
    • When possible, new threads automatically switch to a reachable project copy.
    • Workspace-specific branch and worktree settings are safely reset when switching environments.

The New Chat picker collapsed same-repo copies onto the selected chat's
environment. Clicking that row while a remote was reconnecting waited
forever on t3.json.

List every checkout (including same-environment worktrees), skip the
file read unless the target is connected, retarget to a reachable
sibling when one exists, and toast when the only copy is down.

Fixes pingdotgg#12093
@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Sep 21, 2026
candidate.id === requestedProjectRef.projectId &&
candidate.environmentId === requestedProjectRef.environmentId,
);
const requestedLogicalProjectKey = requestedProject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High hooks/useHandleNewThread.ts:104

When the requested project has a stale or missing repositoryIdentity, New Chat reports Environment unavailable even though a reachable sibling for the same repository exists. requestedLogicalProjectKey falls back to the requested project's physical key, while the filter at lines 110–113 derives the sibling's repository key independently, so no sibling reaches resolveAvailableNewThreadProjectRef; use the existing physical-to-logical key map for this lookup instead of deriving the keys independently.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/hooks/useHandleNewThread.ts around line 104:

When the requested project has a stale or missing `repositoryIdentity`, New Chat reports `Environment unavailable` even though a reachable sibling for the same repository exists. `requestedLogicalProjectKey` falls back to the requested project's physical key, while the filter at lines 110–113 derives the sibling's repository key independently, so no sibling reaches `resolveAvailableNewThreadProjectRef`; use the existing physical-to-logical key map for this lookup instead of deriving the keys independently.

Comment on lines +255 to +261
const currentEntry =
input.entries.find((entry) =>
projectRefsMatch(
{ environmentId: entry.targetProject.environmentId, projectId: entry.targetProject.id },
currentProjectRef,
),
) ?? null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium src/sidebarProjectGrouping.ts:255

resolveNewThreadPickerFocusEntry returns null for a valid current thread when its ref remains in group.memberProjectRefs but its stale physical row was removed from memberProjects. Because currentEntry only matches targetProject, the function never reaches the reachable-sibling fallback, so New Chat loses its initial focus. Match the current ref against the group as a fallback.

-  const currentEntry =
-    input.entries.find((entry) =>
-      projectRefsMatch(
-        { environmentId: entry.targetProject.environmentId, projectId: entry.targetProject.id },
-        currentProjectRef,
-      ),
-    ) ?? null;
+  const currentEntry =
+    input.entries.find(
+      (entry) =>
+        projectRefsMatch(
+          { environmentId: entry.targetProject.environmentId, projectId: entry.targetProject.id },
+          currentProjectRef,
+        ) || groupContainsProjectRef(entry.group, currentProjectRef),
+    ) ?? null;
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/sidebarProjectGrouping.ts around lines 255-261:

`resolveNewThreadPickerFocusEntry` returns `null` for a valid current thread when its ref remains in `group.memberProjectRefs` but its stale physical row was removed from `memberProjects`. Because `currentEntry` only matches `targetProject`, the function never reaches the reachable-sibling fallback, so New Chat loses its initial focus. Match the current ref against the group as a fallback.

contextualRefBelongsToGroup
? contextualProjectRef
: scopeProjectRef(project.environmentId, project.id),
const environment = environments.find(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High components/CommandPalette.tsx:1331

Selecting an enabled offline row in the expanded new-thread picker shows “Environment unavailable” and does not create a thread, even when the group has a reachable sibling checkout. The guard returns before handleNewThread, which already resolves the requested checkout to a reachable logical-project sibling; remove the guard so the rendered row follows that fallback path.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/CommandPalette.tsx around line 1331:

Selecting an enabled offline row in the expanded new-thread picker shows “Environment unavailable” and does not create a thread, even when the group has a reachable sibling checkout. The guard returns before `handleNewThread`, which already resolves the requested checkout to a reachable logical-project sibling; remove the guard so the rendered row follows that fallback path.

@macroscopeapp

macroscopeapp Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes production New Chat routing, picker presentation, connectivity gating, and workspace context across several components rather than making a small isolated fix. Unresolved findings identify concrete cases where reachable-copy fallback or picker focus can fail.

Not approved because:

  • 3 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. You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8017b586-c5bb-4b81-b740-091392b79989

📥 Commits

Reviewing files that changed from the base of the PR and between 1de563c and 3b70150.

📒 Files selected for processing (7)
  • apps/web/src/components/CommandPalette.tsx
  • apps/web/src/environmentGrouping.test.ts
  • apps/web/src/hooks/useHandleNewThread.test.ts
  • apps/web/src/hooks/useHandleNewThread.ts
  • apps/web/src/lib/chatThreadActions.test.ts
  • apps/web/src/lib/chatThreadActions.ts
  • apps/web/src/sidebarProjectGrouping.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

New Chat now lists grouped project copies by environment, prioritizes reachable copies, retargets thread creation when needed, clears incompatible workspace options, and reports unavailable environments instead of proceeding silently.

Changes

New Chat reachability

Layer / File(s) Summary
Target and workspace resolution
apps/web/src/lib/chatThreadActions.ts, apps/web/src/lib/chatThreadActions.test.ts
Added helpers that select reachable project copies and clear branch or worktree options when the target environment changes.
Expanded project picker
apps/web/src/sidebarProjectGrouping.ts, apps/web/src/components/CommandPalette.tsx, apps/web/src/environmentGrouping.test.ts
The New Chat picker renders environment copies as separate entries, orders reachable entries first, and focuses a reachable sibling when the current copy is unavailable.
Environment-aware thread creation
apps/web/src/hooks/useHandleNewThread.ts, apps/web/src/hooks/useHandleNewThread.test.ts
New thread creation resolves reachable targets, avoids unavailable project-file reads, propagates resolved workspace options, and shows an “Environment unavailable” error when no target is reachable.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CommandPalette
  participant PickerGrouping
  participant ThreadHandler
  participant Toast
  CommandPalette->>PickerGrouping: Build reachable environment-copy entries
  PickerGrouping-->>CommandPalette: Return ordered picker entries and focus target
  CommandPalette->>ThreadHandler: Start thread for selected project
  ThreadHandler->>Toast: Show "Environment unavailable" when no reachable copy exists
Loading

Suggested reviewers: shivamhwp, maria-rcks

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: New Chat selects a reachable project copy while preserving worktrees.
Description check ✅ Passed The description explains what changed, why it changed, and the UI impact. It includes a checklist and remains focused on the bug fix. It does not include the requested before/after screenshots for the…
Linked Issues check ✅ Passed The implementation meets the coding requirements in [#12093] and [#12731]. CommandPalette.tsx expands New Chat entries to reachable and unreachable copies across environments, keeps separate checkou…
Out of Scope Changes check ✅ Passed The changes stay within the linked New Chat targeting scope. The modified production files implement picker expansion, reachability checks, retargeting, workspace-option handling, and unavailable-envi…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: New Chat project picker is scoped to the selected chat and a disconnected remote copy does nothing

1 participant