Skip to content

fix(github): single-source repo attachment + enforce repo-child 1:1 - #4370

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/github-header-attachment-integrity
Jul 8, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/github-header-attachment-integrity

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

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.connectionId vs the live connections/aggregation edges). It also surfaced a real data anomaly: one repo-scoped mcp-github child 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) from metadata.githubRepo + live connections. getActiveGithubRepo and the agent-capabilities gates now all go through it instead of each re-interpreting the two fields.

2. SQL-enforced invariant (migration 125) — a BEFORE INSERT trigger on connection_aggregations rejects attaching a repo-scoped github child (identified by metadata.repoScope) to a second parent. Existing violations are deduped first (keep the parent that claims the child via metadata.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 defensive try_parse_jsonb so one malformed metadata row can't abort the migration/trigger.

3. Graceful degrade — a detached repo now renders a disabled "Reconnect GitHub" pill (with tooltip) instead of null, 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 on main). Renumbered to 124 to resolve the duplicate-123 collision; our new migration is 125. Confirmed no live code references threads.projected_seq before enabling the drop.

Testing

  • Unit: resolveGithubAttachment / getActiveGithubRepo status matrix + agent-capabilities gates (incl. detached → header shows) — 27 pass.
  • Migration verified against real Postgres (fresh container, full chain):
    • trigger blocks a 2nd parent for a repo-scoped child (23505), allows normal shared children;
    • dedupe keeps the claiming parent even when the spurious edge is older; unclaimed → oldest;
    • post-migrate: trigger present, threads.projected_seq dropped.
  • bun run fmt, oxlint (0 errors on changed files), tsc --noEmit (mesh) — clean.
  • Migration-index guardrail test now green.

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

    • Added resolveGithubAttachment() returning none | public-clone | attached | detached; all gates now use it (getActiveGithubRepo, header actions, capabilities).
    • Header renders a reconnect pill for detached repos; git tab only appears for attached repos.
    • Tests cover attachment matrix and header gating.
  • Migration

    • 125-github-child-single-parent: dedupes existing multi-parent edges (prefer claiming parent, else oldest) and adds a BEFORE INSERT trigger blocking a second parent for repo-scoped GitHub children; uses try_parse_jsonb for safe JSON access.
    • Registers the previously missed 124-drop-thread-projected-seq and updates the migrations index.

Written for commit 9a55abc. Summary will update on new commits.

Review in cubic

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.
@pedrofrxncx
pedrofrxncx merged commit 3dcc154 into main Jul 8, 2026
21 of 22 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/github-header-attachment-integrity branch July 8, 2026 16:33
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.
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