Repository navigation
fix(github): single-source repo attachment + enforce repo-child 1:1 - #4370
Merged
Merged
Conversation
The GitHub save/publish header could vanish entirely when the repo's "is a connection attached?" state was interpreted inconsistently across call sites, or when a repo-scoped github child was aggregated under more than one agent (the 1:1 invariant lived only in code and drifted). 1. Single source of truth: new resolveGithubAttachment() derives one discriminated status (none | public-clone | attached | detached) from metadata.githubRepo + live connections. getActiveGithubRepo and the agent-capabilities gates now all go through it instead of each re-interpreting the two fields independently. 2. SQL-enforced invariant (migration 125): a BEFORE INSERT trigger rejects attaching a repo-scoped github child (metadata.repoScope) to a second parent. Pre-existing violations are deduped first (keep the claiming parent, else oldest) so the last edge is never removed and the trigger installs cleanly. Verified against real Postgres. 3. Graceful degrade: a detached repo now renders a "Reconnect GitHub" pill instead of nothing, so a stale/mid-mutation aggregation never leaves the header blank with no recovery path. Also registers 123-drop-thread-projected-seq (committed in #4179 but forgotten from the migrations index, so it never ran) as 124, resolving the duplicate-123 collision and the red migration-index guardrail.
decocms Bot
pushed a commit
that referenced
this pull request
Jul 8, 2026
PR: #4370 fix(github): single-source repo attachment + enforce repo-child 1:1 Bump type: patch - decocms (apps/mesh/package.json): 3.103.3 -> 3.103.4 Deploy-Scope: both
pedrofrxncx
pushed a commit
that referenced
this pull request
Aug 4, 2026
Migration 125 rejects attaching a repo-scoped github child to a second agent. Reuse makes that legal by design — the second import of a repo now aggregates the existing connection — so the trigger fails the import (and the new e2e). The bug 125 defended against was fixed in the same PR (#4370) by resolveGithubAttachment + the detached reconnect pill, neither of which needs 1:1: the gate cross-checks against THIS agent's own aggregation rows and virtualMcps.update rewrites edges scoped to one parent. Teardown's 1:1 assumption is now an explicit other-holder check in virtual/delete.ts, with the ON DELETE RESTRICT FK still behind it.
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.
Why
A user reported the GitHub save/publish button (top-right header) missing on an agent that clearly had a repo linked and a live preview. Investigation found the header's "is a GitHub connection attached?" decision was made independently in several places from two fields that can drift (
metadata.githubRepo.connectionIdvs the liveconnections/aggregation edges). It also surfaced a real data anomaly: one repo-scopedmcp-githubchild connection aggregated under two agents — the 1:1 invariant ("one github child per agent") lived only in code and had drifted. When such an aggregation mutates, the gate flips off and the header renders nothing (no error, no recovery path).What
1. Single source of truth — new
resolveGithubAttachment()derives one discriminated status (none | public-clone | attached | detached) frommetadata.githubRepo+ liveconnections.getActiveGithubRepoand theagent-capabilitiesgates now all go through it instead of each re-interpreting the two fields.2. SQL-enforced invariant (
migration 125) — aBEFORE INSERTtrigger onconnection_aggregationsrejects attaching a repo-scoped github child (identified bymetadata.repoScope) to a second parent. Existing violations are deduped first (keep the parent that claims the child viametadata.githubRepo.connectionId, else the oldest edge) so a child's last edge is never deleted and the trigger installs cleanly. Normal (non-github) children can still be shared across agents. All JSON access goes through a defensivetry_parse_jsonbso one malformed metadata row can't abort the migration/trigger.3. Graceful degrade — a
detachedrepo now renders a disabled "Reconnect GitHub" pill (with tooltip) instead ofnull, so a stale/mid-mutation aggregation never leaves the header blank.Also (housekeeping, opted-in)
Registers
123-drop-thread-projected-seq— committed in #4179 but forgotten from the migrations index, so it never ran (the exact incident the index guardrail test exists to catch; that test is currently red onmain). Renumbered to124to resolve the duplicate-123collision; our new migration is125. Confirmed no live code referencesthreads.projected_seqbefore enabling the drop.Testing
resolveGithubAttachment/getActiveGithubRepostatus matrix +agent-capabilitiesgates (incl. detached → header shows) — 27 pass.23505), allows normal shared children;threads.projected_seqdropped.bun run fmt,oxlint(0 errors on changed files),tsc --noEmit(mesh) — clean.Note
This does not fully rule out the original report being a "clean tracked branch showed Up to date" case (branch/working-tree state, not attachment) — but these three changes remove the whole silent-vanish bug class and give a recovery path regardless.
🤖 Generated with Claude Code
Summary by cubic
Fixes the disappearing GitHub save/publish header by unifying repo-attachment logic and enforcing a 1:1 repo-child rule in the DB. If a repo is detached, the header now shows a disabled “Reconnect GitHub” pill instead of vanishing.
Bug Fixes
resolveGithubAttachment()returningnone | public-clone | attached | detached; all gates now use it (getActiveGithubRepo, header actions, capabilities).detachedrepos; git tab only appears forattachedrepos.Migration
125-github-child-single-parent: dedupes existing multi-parent edges (prefer claiming parent, else oldest) and adds aBEFORE INSERTtrigger blocking a second parent for repo-scoped GitHub children; usestry_parse_jsonbfor safe JSON access.124-drop-thread-projected-seqand updates the migrations index.Written for commit 9a55abc. Summary will update on new commits.