Skip to content

fix(sandbox): re-point a thread at a live GitHub connection when its own is gone - #5808

Merged
pedrofrxncx merged 1 commit into
fix/sandbox-missing-github-connectionfrom
fix/thread-repo-repoint-dead-connection
Aug 6, 2026
Merged

fix(sandbox): re-point a thread at a live GitHub connection when its own is gone#5808
pedrofrxncx merged 1 commit into
fix/sandbox-missing-github-connectionfrom
fix/thread-repo-repoint-dead-connection

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #5807 (merge that first; this PR's base is its branch).

Problem

threads.metadata.githubRepo.connectionId pins a specific mcp-github connection, but those aren't immortal:

  • VIRTUAL_MCP_DELETE tears down the agent's repo-scoped child connection;
  • re-importing a repo mints a new connection id.

Either way every thread pinned to the old id is permanently un-startable, even when the org still has a perfectly good connection for the same repository. Prod today: 152 threads reference a connection id that no longer exists (e.g. thrd_sUNCH2u3kuYEdSE4mb5Caconn_JLu7_P8GYpTVtsx6sUHQ_).

Change

getThreadGithubRepo — the single read every consumer goes through (sandbox provisioning, fs tools, dispatch) — now, when the pinned connection is missing:

  1. looks for a live connection granting the same owner/repo via the existing findReusableRepoConnection (org-shared wins, same rule as import);
  2. returns the re-pointed binding and persists it to the thread metadata;
  3. falls back to the dead binding untouched when nothing matches, so the user still gets GITHUB_CONNECTION_MISSING (fix(sandbox): tell the user the GitHub connection is gone, not unauthenticated #5807) telling them to link the repo again.

Best-effort: any failure logs and returns the original binding. The choice itself is a pure function, repointedRepoBinding.

Note: the sandbox branch embeds the connection id (threadBranch), so a repoint yields a fresh sandbox — the old one was unusable anyway.

Testing

  • 4 new unit tests on repointedRepoBinding (match, org-shared preference, no match, already-live no-op)
  • bun run check, bun run fmt

Summary by cubic

Automatically re-points a thread’s GitHub repo binding to a live connection for the same owner/repo when its pinned connectionId no longer exists, and persists the fix. Falls back to the original binding so users still see GITHUB_CONNECTION_MISSING when no replacement is available.

  • Bug Fixes
    • Added repointedRepoBinding to pick a live repo connection (prefers org-shared via findReusableRepoConnection) and update getThreadGithubRepo.
    • Persist the new binding in thread metadata so sandbox, fs tools, and dispatch all use the same live connection; repointing yields a fresh sandbox branch.
    • Best‑effort behavior: on errors or no match, keep the old binding and surface GITHUB_CONNECTION_MISSING.
    • Added 4 unit tests for repointedRepoBinding (match, org-shared preference, no match, already-live no-op).

Written for commit b5dc1a5. Summary will update on new commits.

Review in cubic

…own is gone

Repo connections aren't immortal — deleting the owning agent tears one
down, re-importing mints a new id — but threads pin the id in
metadata.githubRepo, so the thread is stuck on a dead connection forever.
When the pinned connection is missing, reuse the org's live connection
for the same owner/repo (org-shared wins) and persist the repoint.
@pedrofrxncx
pedrofrxncx merged commit a8de27b into fix/sandbox-missing-github-connection Aug 6, 2026
3 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/thread-repo-repoint-dead-connection branch August 6, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant