Repository navigation
feat(agent): select repositories and link session PRs in the Magic Chip - #6303
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughThe change adds an Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Repository-backed Cursor sessions now request pull-request creation and terminal results retain branch and pull-request URLs. The change preserves behavior for repository-less sessions and older results without Git data, with no current merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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. Comment |
32514a4 to
a2c9591
Compare
42239df to
537cb93
Compare
537cb93 to
8f6a1c1
Compare
| ws.addEventListener(WebsocketEvent.Open, invalidatePullRequestMentions); | ||
| onCleanup(() => | ||
| ws.removeEventListener(WebsocketEvent.Open, invalidatePullRequestMentions) | ||
| ); |
There was a problem hiding this comment.
Reconnect refetch can wipe push
Medium Severity
WebsocketEvent.Open always invalidates PR mention queries. That refetch writes null on 404 and does not use the push path's updatedAt latest-wins check. A reconnect after a successful github_pull_request_updated can replace the cached entity with null and snap the chip back to the plain GitHub link, with no polling left to recover.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 1bb7fd7. Configure here.
…run result Thread an open_pull_request flag through the CursorAgents::create_agent port, serialized as Cursor's autoCreatePR (omitted when false). The one caller passes it whenever the session has a repository; a prompt-intent classifier will supply it later. Model the terminal result event's git state (branches with repoUrl, branch, prUrl) as serde types on CursorEvent::Result, defaulting so a result without git never degrades to Unknown.
…n metadata The translator turns a result's git state into one session_info_update carrying _meta.cursor.pullRequestUrl, announced once per url. The fold's Cursor reader lifts it into SessionMetadata.pull_request_url, exported to the web client's generated types.
The status icon, title #N pill, hover preview and split-open, for a surface that already holds the foreign entity and carries no mention node.
recent_for_owner(owner, limit) on AgentSessionRepo, a read model narrower than AgentSession for a classifier prompt that wants to know what this person has worked on lately.
…itory A 4xx from POST /v1/agents whose envelope names repository_access or integration_not_connected becomes RepositoryUnavailable, reaching the client verbatim as "Cursor can't access owner/name. Connect the repository to Cursor's GitHub app, then prompt again." Cursor's raw body stays in the log. The Magic Chip's failed arm now shows the message as its detail.
ReachableRepositoriesService::for_user: the installations this user or their teams installed, an installation-wide metadata:read token per installation, GET /installation/repositories, deduped and cached per user for ten minutes. Shares the pager with the pull-request sweep.
GET /foreign_entity/by_source/{source}/{*foreign_entity_id}, the same
view-access check as the by-id route applied per candidate, first visible
record wins, 404 otherwise. Web client method and a PR-by-github-key query
that reads 404 as not-yet-synced.
…ic Chip The header shows the PR as our GitHub entity once the webhook has synced it, resolving by github key from the url the fold reports; a plain link to GitHub that polls for the entity until then.
RepositoryChooser replaces RepoResolver: at the first prompt a Haiku classifier sees the repositories the user reaches through Macro's GitHub App, their five newest sessions and the prompt, and answers one candidate or none plus whether the work wants a pull request. The choice is written to the session row before the agent is minted, so egress pins git to it; an undecidable prompt fails visibly instead of defaulting. CURSOR_REPO_URL is gone.
Also wraps GET /foreign_entity/by_source in the SDK as ForeignEntityNamespace.bySource.
The rebase landed both a repositories port and a pending-commands handle on CursorContainerManager::new, taking it past clippy's argument limit. The pool and replica always travel together, so they become CursorJournal.
c1ac1a2 to
2f143e9
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5b8df49. Configure here.


Hosted Cursor sessions choose a repository from the owner's GitHub App installations before agent creation. The chooser considers the initial prompt and five recent sessions, persists its choice, and enables automatic PR creation when a repository is selected. Standalone Cursor leaves the repository unset; there is no local Git resolver or repository override. GitHub discovery exposes a single repository-listing operation, with metadata-only token handling private to its adapter.
Macro Internal MCP exposes the session-scoped
set_pull_requesttool. Every harness receives a shared prompt instruction to register PRs; Cursor also registers URLs returned by its provider. The association is a nullableagent_session.pull_request_urlcolumn, separate from conversation history. Registration validates ownership and the URL, conditionally updates the row, and sends a gateway notification that invalidates the shared TanStack session-detail query. Mounted chips consume that cache, without a custom metadata listener registry. There is no PR protocol event, fold state, or history-replay compatibility path.The chip links directly to GitHub until webhook sync resolves the PR entity. Existing GitHub gateway events keep its open/merged/closed status current. Reconnect invalidates session metadata and PR lookups. Older snapshot fetches are cancelled before invalidation, and guarded query reads keep the surrounding editor visible while loading.
Repository lookup, recent-session lookup, Haiku decision, and PR registration have correlated spans with counts and outcomes. The shared GenAI instrumentation captures model usage and content according to its configured policy. Credentials and raw model reasoning are not added to ordinary span fields.
Validation:
just checkstill reports existing SDK formatting findings; scoped changes are formatted and type-checked.Deployment: apply the nullable session-column migration before deploying the harness and web changes. Macro Internal MCP uses the existing harness egress listener; no Pulumi change is required.
Note
Medium Risk
Changes span agent egress auth, Cursor agent creation (repo/PR), and new persisted session fields plus realtime sync; misconfiguration could block git or show stale PR links, but ownership checks and guarded cache updates limit exposure.
Overview
Cursor-hosted sessions now pick a GitHub repository before the first agent is created: reachable repos from the user’s GitHub App, the prompt, and recent sessions feed a fast-model chooser that writes
repo_urlon the session (or leaves it unset). When a repo is chosen, Cursor can auto-open a PR;pull_request_urlis stored separately and surfaced on the harness GET response.Agents are told to register PRs via a new
macro_internalMCP server (set_pull_request). Cursor also reports PR URLs from the provider. Egress treats the repository as optional so MCP-only sessions work; git credentials require a stored repo. External runtimes get the internal MCP server when they bind, with egress token rotation on attach.On the web, the Magic Chip header shows the session PR—plain GitHub link until webhook sync, then the rich PR entity—with websocket-driven cache updates for
agent_session_updatedandgithub_pull_request_updated. Session metadata loading moves to a shareduseAgentSessionQuery(replacing chip-local polling). Storage adds lookup by source id (owner/repo/pull/N). Failed turns now show the runtime error message in the chip activity detail.Reviewed by Cursor Bugbot for commit 0428fe2. Bugbot is set up for automated code reviews on this repo. Configure here.