Skip to content

fix(sandbox): tell the user the GitHub connection is gone, not unauthenticated - #5807

Open
pedrofrxncx wants to merge 5 commits into
mainfrom
fix/sandbox-missing-github-connection
Open

fix(sandbox): tell the user the GitHub connection is gone, not unauthenticated#5807
pedrofrxncx wants to merge 5 commits into
mainfrom
fix/sandbox-missing-github-connection

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Problem

A thread whose metadata.githubRepo.connectionId points at a deleted connection fails SANDBOX_START with GITHUB_NOT_AUTHENTICATEDbuildCloneInfo just finds no downstream token and assumes auth. The UI then shows "This agent's GitHub repo isn't authenticated. Reconnect it in Connections", which is wrong advice: reconnecting mints a new connection id, the thread still points at the dead one, and the sandbox stays broken forever.

Hit in prod on demo-storefront (thread thrd_sUNCH2u3kuYEdSE4mb5Caconn_JLu7_P8GYpTVtsx6sUHQ_, row gone). 152 threads prod-wide currently reference a connection id that no longer exists.

Change

  • New GITHUB_CONNECTION_MISSING sandbox-start error code.
  • buildCloneInfo checks the connection row exists before looking for a token, and throws the new code when it doesn't.
  • The error state card renders a distinct message ("The GitHub connection this chat used was removed. Link the repository again…") with a Link repository action instead of Reconnect GitHub. en + pt-br.

UI feedback only — no data repair, no deletion-guard change. Threads already pointing at a dead connection still need the repo re-linked; they just now say so.

Testing

  • bun test packages/shared/src/sandbox-start-errors.test.ts (added a case for the new code)
  • bun run check, bun run fmt

Summary by cubic

Detect deleted GitHub connections, auto-repoint threads to a live org connection for the same repo, and show the right guidance when none exists. Also block deleting a repo connection if any thread still references it to avoid stranded sandboxes.

  • Bug Fixes
    • Auto-repoint: getThreadGithubRepo uses repointedRepoBinding to switch to a live connection for the same owner/repo (org-shared preferred) and persists it to metadata.githubRepo.
    • Missing-connection: buildCloneInfo checks for the connections row and throws GITHUB_CONNECTION_MISSING; the error card says “Link repository” (en, pt-br).
    • Deletion guard: VIRTUAL_MCP_DELETE calls connections.isReferencedByThread and skips deleting a repo connection when any thread points at it.

Written for commit 2ee494d. Summary will update on new commits.

Review in cubic

…enticated

A thread whose metadata.githubRepo.connectionId points at a deleted
connection failed SANDBOX_START with GITHUB_NOT_AUTHENTICATED, so the UI
told the user to reconnect GitHub — which mints a new connection id and
never fixes the thread. Detect the missing row in buildCloneInfo and
surface a distinct GITHUB_CONNECTION_MISSING code asking to link the
repository again.
Pedro França and others added 4 commits August 6, 2026 12:06
…own is gone (#5808)

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.

Co-authored-by: Pedro França <pedrofrxncx@deco.cx>
* fix(sandbox): re-point a thread at a live GitHub connection when its 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.

* fix(virtual): keep a repo connection a thread still points at

VIRTUAL_MCP_DELETE tore down the agent's repo-scoped child connection
whenever no other AGENT held it, ignoring threads pinned to it via
metadata.githubRepo.connectionId — which stranded 152 prod threads on a
sandbox that can never boot. Treat a referencing thread as a holder.

---------

Co-authored-by: Pedro França <pedrofrxncx@deco.cx>
…ithub-connection

# Conflicts:
#	apps/api/src/tools/sandbox/thread-repo.test.ts
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