Skip to content

feat(agent): select repositories and link session PRs in the Magic Chip - #6303

Merged
404Wolf merged 31 commits into
mainfrom
wolf/cursor-pr-magic-chip
Sep 14, 2026
Merged

404Wolf merged 31 commits into
mainfrom
wolf/cursor-pr-magic-chip

Conversation

@404Wolf

@404Wolf 404Wolf commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

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_request tool. Every harness receives a shared prompt instruction to register PRs; Cursor also registers URLs returned by its provider. The association is a nullable agent_session.pull_request_url column, 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:

  • Session/fold/service tests, including duplicate registration, ownership, history independence, and gateway failure recovery.
  • Mounted chip regressions for registration, reconnect, and stale fetch responses; Chromium verification with controlled session responses.
  • Generated API/protocol/fold types and SQLx cache refreshed against an isolated database.
  • Rustls patched to 0.23.45; cargo deny passes. Earlier CI test blockers were corrected.
  • just check still 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_url on the session (or leaves it unset). When a repo is chosen, Cursor can auto-open a PR; pull_request_url is stored separately and surfaced on the harness GET response.

Agents are told to register PRs via a new macro_internal MCP 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_updated and github_pull_request_updated. Session metadata loading moves to a shared useAgentSessionQuery (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.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: d55bf457-b885-4e02-b31e-600778ed469a

📥 Commits

Reviewing files that changed from the base of the PR and between f7f1842 and 2b2f7fd.

📒 Files selected for processing (13)
  • crates/agent_harness/src/outbound/cursor/manager.rs
  • crates/cursor_cloud_agents/src/api.rs
  • crates/cursor_cloud_agents/src/api/wire.rs
  • crates/cursor_cloud_agents/src/api/wire/test.rs
  • crates/cursor_cloud_agents/src/domain/event.rs
  • crates/cursor_cloud_agents/src/domain/event/test.rs
  • crates/cursor_cloud_agents/src/domain/journal.rs
  • crates/cursor_cloud_agents/src/domain/journal/test.rs
  • crates/cursor_cloud_agents/src/domain/ports.rs
  • crates/cursor_cloud_agents/src/domain/service.rs
  • crates/cursor_cloud_agents/src/domain/service/test.rs
  • crates/cursor_cloud_agents/src/inbound/acp/test.rs
  • crates/cursor_cloud_agents/src/testing.rs

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


📝 Summary

Summary by CodeRabbit

  • New Features
    • Agents working with a repository can now automatically create a branch and open a pull request.
    • Repository-free agents continue to run without pull-request creation.
    • Completed agent results now include branch and pull-request links when available.
  • Bug Fixes
    • Results without repository changes continue to be processed correctly, including older event formats.
  • Tests
    • Added coverage for pull-request creation and reporting branch and pull-request details.

Walkthrough

The change adds an open_pull_request option to agent creation. Repository-backed agents serialize autoCreatePR: true; repository-less agents omit the field. Result events now carry optional Git branch and pull-request data through GitState and GitBranch. Polling, test doubles, service fixtures, journal fixtures, and ACP tests were updated for the new event field and agent-creation argument.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 2b2f7

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)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title uses valid conventional commit syntax with the feat(agent) prefix, is 71 characters long, and accurately describes repository selection and session PR linking.
Description check ✅ Passed The description directly explains repository selection, automatic PR creation, PR linking, persistence, UI behavior, testing, and deployment requirements covered by the pull request.

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.

❤️ Share

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

@404Wolf 404Wolf changed the title feat(cursor): ask Cursor for a pull request and read its url off the run result feat(cursor): sessions pick a repository, open a PR, and link it from the Magic Chip Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread crates/agent_harness/src/outbound/cursor/repository_chooser.rs Outdated
@404Wolf
404Wolf force-pushed the wolf/cursor-pr-magic-chip branch from 32514a4 to a2c9591 Compare September 10, 2026 21:30

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread crates/cursor_cloud_agents/src/domain/journal.rs Outdated
@404Wolf
404Wolf force-pushed the wolf/cursor-pr-magic-chip branch 3 times, most recently from 42239df to 537cb93 Compare September 11, 2026 22:07

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread crates/cursor_cloud_agents/src/domain/service.rs
Comment thread crates/agent_harness/src/outbound/cursor/repository_chooser.rs Outdated
@404Wolf
404Wolf force-pushed the wolf/cursor-pr-magic-chip branch from 537cb93 to 8f6a1c1 Compare September 11, 2026 23:23

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread crates/cursor_cloud_agents/src/domain/journal.rs Outdated

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

ws.addEventListener(WebsocketEvent.Open, invalidatePullRequestMentions);
onCleanup(() =>
ws.removeEventListener(WebsocketEvent.Open, invalidatePullRequestMentions)
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1bb7fd7. Configure here.

@404Wolf 404Wolf changed the title feat(cursor): sessions pick a repository, open a PR, and link it from the Magic Chip feat(agent): select repositories and link session PRs in the Magic Chip Sep 14, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread crates/cursor_cloud_agents/src/domain/service.rs
…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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread crates/agent_harness/src/domain/service/deliver.rs
@404Wolf
404Wolf force-pushed the wolf/cursor-pr-magic-chip branch from c1ac1a2 to 2f143e9 Compare September 14, 2026 20:50

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread crates/agent_harness/src/domain/service/deliver.rs
@404Wolf
404Wolf requested a review from a team as a code owner September 14, 2026 21:54

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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).

Fix All in Cursor

❌ 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.

@404Wolf
404Wolf merged commit 6106355 into main Sep 14, 2026
33 checks passed
@404Wolf
404Wolf deleted the wolf/cursor-pr-magic-chip branch September 14, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant