fix(web): always run a repo-backed editor on a thread (#6667 follow-up) - #6680
Merged
Conversation
After #6667 started addressing destinations by path, a repo-backed agent editor could open with no thread in the URL (`?thread=` absent — a deep link, choose-editor, or any navigation that didn't carry it, since the shell deliberately doesn't retain `thread`). The branch is a thread field, so a threadless editor stranded the branch picker on "Select branch…" with selecting and "New" both silently no-op (setCurrentTaskBranch is gated on an active thread), and the adopt/auto-fresh effects never fired. AgentInsetProvider now guarantees a thread for repo-backed agents: when the URL names none it mints one into `?thread=` before mounting, reusing the user's idle empty "New chat" for that agent when one exists — exactly what useNavigateToAgent does (findReusableNewChat ?? fresh id). This restores the pre-#6667 behavior where the client minted the thread id and the ensure fallback created the row on landing. Scoped to repo-backed agents; the Super Agent keeps its lazy threadless composer. Complements #6639: with a thread guaranteed, adopt-branch mints a fresh (unmaterialized, non-stale) branch and the auto-fresh-stale check evaluates correctly instead of sitting dead on a threadless entry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
After #6667 started addressing destinations by path, a repo-backed agent editor could open with no thread in the URL (
?thread=absent — a deep link,choose-editor, or any navigation that didn't carry it, since the shell deliberately doesn't retainthreadacross navigations).The branch is a thread field (
activeTask.branch), so a threadless editor left the branch picker stranded on "Select branch…", with both selecting a branch and New silently doing nothing (setCurrentTaskBranchis gated on an active thread), and the adopt / auto-fresh-stale effects never firing.AgentInsetProvidernow guarantees a thread for repo-backed agents: when the URL names none it mints one into?thread=before mounting, reusing the user's idle empty "New chat" for that agent when one exists — exactly whatuseNavigateToAgentdoes (findReusableNewChat ?? fresh id). This restores the pre-#6667 behavior where the client minted the thread id and the ensure-fallback created the row on landing.Scoped to repo-backed agents on purpose — the Super Agent (no repo, no branch pill) keeps its lazy threadless empty composer that #6667 designed.
Why it happens
resolveRouteThreadIdreturnsnullon a destination with no?thread=→currentBranch = activeTask?.branch ?? null→ picker falls back to "Select branch…".setCurrentTaskBranchisif (effectiveTaskId) …→ no-op without a thread → selecting/Newdo nothing.VmEventsBridge's adopt-branch and auto-fresh-stale both requireactiveTask, so neither runs.Relationship to #6639
Complementary, not conflicting (same file, different function —
AgentInsetProvidervsVmEventsBridge; #6639 is already an ancestor). With a thread guaranteed, adopt mints a fresh unmaterialized (non-stale) branch and #6639's auto-fresh-stale check evaluates correctly instead of sitting dead on a threadless entry. No double-switch:isBranchStale(null)isfalseand both effects are one-shot per thread/tab.Testing
bun run --cwd=apps/web check✅bun run lint✅bun run fmt✅thread-route.test.ts+use-layout-state.test.ts→ 57 pass / 0 failNot yet added: an e2e that enters a repo-backed destination without
?thread=and asserts the URL gains?thread=+ a real branch (reusing an idle empty chat when present). Happy to add if wanted.🤖 Generated with Claude Code
Summary by cubic
Fixes repo-backed agent editors opening without a thread in the URL, which stranded the branch picker on “Select branch…” and made selecting a branch or New silently do nothing.
AgentInsetProvidernow guarantees a thread before mounting by minting?thread=into the URL, reusing the user’s idle empty chat for that agent when one exists. Scoped to repo-backed agents, the Super Agent keeps its lazy threadless composer.Written for commit 50380be. Summary will update on new commits.