fix(sandbox): re-point a thread at a live GitHub connection when its own is gone - #5808
Merged
pedrofrxncx merged 1 commit intoAug 6, 2026
Conversation
…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
merged commit Aug 6, 2026
a8de27b
into
fix/sandbox-missing-github-connection
3 checks passed
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.
Stacked on #5807 (merge that first; this PR's base is its branch).
Problem
threads.metadata.githubRepo.connectionIdpins a specific mcp-github connection, but those aren't immortal:VIRTUAL_MCP_DELETEtears down the agent's repo-scoped child connection;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_sUNCH2u3kuYEdSE4mb5Ca→conn_JLu7_P8GYpTVtsx6sUHQ_).Change
getThreadGithubRepo— the single read every consumer goes through (sandbox provisioning, fs tools, dispatch) — now, when the pinned connection is missing:owner/repovia the existingfindReusableRepoConnection(org-shared wins, same rule as import);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
repointedRepoBinding(match, org-shared preference, no match, already-live no-op)bun run check,bun run fmtSummary by cubic
Automatically re-points a thread’s GitHub repo binding to a live connection for the same owner/repo when its pinned
connectionIdno longer exists, and persists the fix. Falls back to the original binding so users still seeGITHUB_CONNECTION_MISSINGwhen no replacement is available.repointedRepoBindingto pick a live repo connection (prefers org-shared viafindReusableRepoConnection) and updategetThreadGithubRepo.GITHUB_CONNECTION_MISSING.repointedRepoBinding(match, org-shared preference, no match, already-live no-op).Written for commit b5dc1a5. Summary will update on new commits.