Skip to main content

ADR-0038 — The governed git write is re-homed as a first-party GitHub MCP server behind the team gateway

  • Status: Accepted — records founder ruling 3 (own account, upsqdvb, user.type=User, #4578 comment 6980541294, 2026-11-18), which countersigns the 2026-08-12 approval of github.commit_files with its binding fences as #2595 records it, and re-homes it. Supersedes the issue-only "ADR-0031" (#2595) as the design of record for the write; the number 0031 on main belongs to the embedding ADR, and the ruling says the re-home "takes a fresh ADR number". Every fence and every review correction of #2595 is carried forward verbatim — nothing is loosened; what changes is the home, the source of the repo pin, the home of the idempotency key, and the removal of the human-landing step from the tool surface. Implementation: S0 #4631 (this ADR, the fixture correction, the one-declaration surface), S3 #4634 (bridge: floor-4 check and the key overlay), S4 #4635 (the server). No further founder sign-off required: the write capability is approved (own account) and the one new write surface the ruling considered — a merge tool — it declined.
  • Date: 2026-11-20 (Consequences amended 2026-11-20 in #4635: migration 297, BuiltinGitHub, MCP_BUILTIN_GITHUB_ENDPOINT)
  • Deciders: Founder (ruling 3 — countersignature, re-home, "no merge or enqueue tool; a human lands"). Principal Architect (the design under it). backend-security reviews S0, S3 and S4 as the independent lane (credential, authz, effect boundary).
  • Refs: #2568 (the design issue; this discharges its ask 1, the markdown ADR; the issue closes when S4 lands) · #2595 (the issue-only ADR this supersedes; its §1–§8 remain the rationale record) · PR #2594 (the Temporal-arm implementation and its adversarial review corrections) · #4538 (fixture vs seed naming of a merge tool — closed by construction here: no merge tool exists to name) · #4444 (Temporal retirement; deletes the old arm) · #4152 (team source grant — the new source of the repo pin) · #2397 (lap-scoped idempotency anchor) · ADR-0024 (MCP governance surfaces, D6 clearance floor at the edge) · ADR-0025 (MCP egress) · ADR-0037 (the workspace the coder edits; the only way bytes leave it is this write) · docs/runbooks/governed-git-write-grant.md (updated in S4 for the MCP path)
  • Numbering note: see ADR-0037. 0038 was unclaimed on 2026-11-20.

Context​

What exists, and where it lives​

The composite write exists and is correct — on the wrong path.

FactWhere
commit_files is implemented as a Temporal tool_action arm with six fences, size caps, the trailer-based idempotency scan and the forge refusalcmd/agent-orchestrator/github_commit.go — fence order :19-36; trailer :114-115; caps :121-137 (50 files / 256 KiB / 1 MiB / 8 KiB message / scan depth 30); static names :160; .github/.git root deny :197; commitFiles :249; forge refusal :277-281; key grammar :292-303; denyProtectedBranchName :473-491; fenceCommitFiles :505-577; commitMessageWithTrailer :593; trailer-block-only match :629
The Git Data client has no force capability and cannot grow one by accidentinternal/mcp/github/client_gitdata.go:23-34 (doc), CreateBlob :286, CreateTree :330, CreateCommit :355, UpdateRef :382 (force:false unconditionally), GetBranch :173, GetRepo :132, GetGitCommit :266
The REST client already has the other catalogued actionsinternal/mcp/github/client.go: GetIssue :266, CreateIssueComment :284, CreatePR :195, GetCheckRuns :406, GetPullRequest :428, GetFile :143 — and also MergePR :217, Push :239, CreateBranch :170, which this ADR does not expose
The old GovernedTool set (github.push, github.merge_pr, github.create_branch, github.create_pr, …) has no production registrarinternal/mcp/github/tools.go:74 RegisterTools — grep of cmd/ and internal/ finds only the definition; tool names :131-464
The catalogued GitHub actions are eight: get_issue, get_pull_request, create_issue_comment, create_pull_request, get_check_runs, get_file_contents, get_branch, commit_files (floor 4)internal/workflow/tool_catalog.go:120-250 (ClearanceFloor: 4 at :203; code_exec.run floor 4 at :223)
The agents+gates runtime reaches a tool only through the team gateway, which mints the platform name ServerName.RawName into _meta["upsquad.platform_tool"]; gates, allowlists and governance targets match that name and nothing elseinternal/gateway/mcpproxy/dispatch.go:94,104-114; runtime.proto:1255-1264 (OrchestratorToolCall.platform_tool); orchrt/hook.go:85-93
The gateway edge enforces a clearance floor per server (mcp_servers.min_clearance vs the calling agent's clearance), audited as mcp_clearance_floor_denied; there is no per-tool floor at the edgeinternal/gateway/mcpproxy/edge_policy.go:152-169, dispatch.go:302, mcpproxy.go:96
A first-party MCP server is onboarded to a team through mcpserver.FirstPartySeed with a registry name (upsquad-knowledge, upsquad-memory), reaches the team through /mcp/team/{unit}, and inherits the gateway's edge floor rather than filtering by clearance itselfinternal/mcpserver/firstparty_seed.go:54-72; cmd/tools/first-party-seed/main.go:183-189; cmd/upsquad-knowledge-mcp/main.go:16-19
The upstream identity the gateway presents to a first-party server carries org, agent, unit and provenance claims — no clearanceinternal/auth/oauth/agent_token.go:182-204; first_party.go:31-38
The bridge can replace a tool call's input before it runs (updated_input), and already does so for gated allowsorchrt/hook.go:143-147; runtime.proto:1314-1327 (OrchestratorPermissionDecision.updated_input)
The Temporal engine is being retired without migration#4444

The SDLC agents+gates fixture (internal/workflow/agentsgates/testdata/sdlc_workflow.json) still models the loop's end as release calling github.merge_pull_request behind a before_tool landing gate, and reviewers writing github.create_pull_request_review — neither is in the ruled set.

The ruling, verbatim​

I countersign the 2026-08-12 approval of the composite github.commit_files write with its binding fences (fail-closed authorisation outside the guardrail path, clearance floor 4, PinnedLiteral repo, protected-ref deny, required expected_head_sha CAS, lap-scoped idempotency) as #2595 records it, and I rule that it leaves the retired Temporal tool_action path and is re-homed as a first-party MCP server behind the team gateway together with create_pull_request and get_check_runs — branch-only, never a protected ref, no merge or enqueue tool. Alternative: a governed merge_pull_request under a human landing gate — a new write surface I am not approving now; a human lands.

Decision​

D1 — Home: cmd/upsquad-github-mcp, first-party, behind the team gateway, registry name github​

A new first-party server, built on the cmd/upsquad-knowledge-mcp pattern (binary, healthcheck, deployments/upsquad-github-mcp/base/* cloned from deployments/upsquad-knowledge-mcp/base/*, compose service on dev), seeded to a team through mcpserver.FirstPartySeed with a new oauth.BuiltinTarget and the registry name github. The platform names the gateway mints are therefore github.commit_files, github.get_branch, … — the vocabulary the fixture, the gates, the allowlists and the tool: governance targets already use. The server package is internal/githubmcp; the fences and the client it reuses stay in internal/mcp/github.

D2 — Surface: exactly the eight catalogued actions, declared once​

Tool (raw name)ClassFloorSource of truth today
commit_fileswrite (repository)4github_commit.go (moved, D3)
create_pull_requestwrite (PR)4client.go:195
create_issue_commentwrite (comment)4 at the edge in Stage 2 (D6)client.go:284
get_issueread—client.go:266
get_pull_requestread—client.go:428
get_check_runsread—client.go:406
get_branchread—client_gitdata.go:173
get_file_contentsread—client_gitdata.go:434 (GetFileRead, the fenced read path)

Nothing else. No merge_*, no push, no update_ref, no create_branch as a tool (branch creation is a fenced side-effect of commit_files, D4), no create_pull_request_review (not in the ruled set; a reviewer agent returns its verdict as text and the orchestrator records it with create_issue_comment), no delete_*, no release, no workflow dispatch. The old GovernedTools in internal/mcp/github/tools.go are not revived; #4444 deletes them with the Temporal arm.

One declaration. S0 adds internal/mcp/github/surface.go:

// RuledPlatformTools is the complete governed GitHub tool surface (ADR-0038 D2),
// spelled as platform names. The first-party server's tools/list, the SDLC
// fixture's allowlists and gates, and the governance seed read THIS slice; a
// name that is not here is not a tool, whatever a client advertises.
var RuledPlatformTools = []string{
"github.commit_files", "github.create_pull_request", "github.create_issue_comment",
"github.get_issue", "github.get_pull_request", "github.get_check_runs",
"github.get_branch", "github.get_file_contents",
}

The server's tools/list golden (S4, pattern internal/context/knowledgemcp/tools.go + testdata/tools_list.golden.json) is generated from it, and TestSDLCFixtureGitHubVocabularyIsRuled (S0) fails when the fixture names a github.* tool outside it. Adding a member means editing one line and watching both tests go red — the WR2 retro class 6 shape, not a hand-maintained list in three places. This is also how #4538 closes: the fixture no longer names a merge tool, so there is no second spelling to reconcile.

D3 — The six fences move verbatim to internal/mcp/github/fences.go and are shared until the Temporal arm is deleted​

In the order they run, all before any byte is written, the first three without a network call (from github_commit.go:19-36):

  1. Repo pin — see D3a: the pin's source changes, its predicate does not.
  2. Static protected-name deny (denyProtectedBranchName, case-folded; main, master, trunk, develop, release/*-style conventional names).
  3. Path + size fence (fenceCommitFiles): read-path grammar per segment, .github/.git root deny with confusable-root folding, 50 files / 256 KiB per file / 1 MiB total / 8 KiB message, modes 100644/100755 only (no symlink, no gitlink).
  4. Default-branch deny — the repository's live default_branch (GetRepo), EqualFold.
  5. GitHub-protection deny — BranchInfo.Protected (classic protection; rulesets are not reported by this flag, which is why there are four ref fences and GitHub's own push-time refusal remains the last authority — #2595 §4).
  6. Compare-and-swap — explicit expected_head_sha comparison (legible refusal naming both SHAs, no write), then force:false on the ref update so GitHub rejects a non-fast-forward the comparison could not see. ToolCASConflict is its own error identity and is retryable.

Plus the two review corrections that are part of the approval (#2595 "Review corrections binding"): the trailer channel is runtime-owned (an author message containing Upsquad-Idempotency-Key: — or, new here, Upsquad-Base-Commit: — is refused, :277-281), and the marker match is trailer-block-only (:629). cmd/agent-orchestrator/github_commit.go becomes a thin caller of fences.go in S4 so that, until #4444 deletes it, the two arms cannot drift; the S4 tests drive each fence through both callers with the same table.

D3a — the repo pin on the MCP path. There is no DSL PinnedLiteral on an MCP call: the repo argument is model-produced. The pin becomes the team source grant (#4152): the server resolves the calling token's (org, unit) to the team and refuses a repo that is not in that team's granted repository set — before resolving any credential, exactly where fence 0 ran before (:254-259). The predicate #2595 §4 cared about — "author-committed, never a ${...} template attacker-controlled data could steer" — is preserved because grants are operator-written rows, not run inputs. A second, in-definition belt stays available: a roster entry's tools_allowlist cannot pin arguments, but the SDLC definition's repo input is what ADR-0037's workspace was acquired for, and the bridge's overlay (D5) stamps base_commit from that workspace — a commit_files whose repo disagrees with the overlaid workspace's repo is refused by the server (repo ≠ workspace repo is a distinct error identity).

D4 — Branch creation at expected_head_sha when the branch is absent​

get_branch is the only way to obtain expected_head_sha today, which made a brand-new branch unauthorable (a 404 has no head). The MCP server closes that gap inside the same fenced call, with no new tool:

  • If GetBranch(branch) returns 404: expected_head_sha must name an existing commit of the repository (GetGitCommit 200) and the branch name must pass fences 1 and 3 (static deny, default-branch deny; fence 4 is vacuous for a ref that does not exist). The server then POST /git/refs refs/heads/<branch> at expected_head_sha (GitHub returns 422 if a concurrent writer created it first → surfaced as ToolCASConflict, retryable), and proceeds with the ordinary CAS write against that head. The ref creation is atomic on GitHub's side; there is no window in which the branch exists with a head other than expected_head_sha.
  • If the branch exists, behaviour is unchanged: CAS against its head.
  • On a replay (D5) where the branch now exists with our trailer at its head, the call returns the prior commit_sha and writes nothing — the scan runs before the CAS, as before (github_commit.go:59-66).

Branch names are fenced to the ref grammar already applied to branch (tool_catalog.go:187) and may not be a protected name. create_branch as a standalone tool stays unexposed: a branch that nothing is committed to is not a governed outcome.

D5 — Idempotency on the MCP path: the key is hook-overlaid updated_input, required by the server, and never trusted for attribution​

The trailer value stays the agents+gates hop key run_id:step@ordinal (grammar [A-Za-z0-9:@#._-], github_commit.go:292-303; distinct per lap, stable within a lap, prefixed by the run id — #2397). Who supplies it changes. On the Temporal arm it came from the activity's anchor. On the MCP path:

  • The bridge's PreToolUse overlays idempotency_key and base_commit onto the tool input of every allowed github.commit_files call (Decision.UpdatedInput, orchrt/hook.go:143-147 → wire updated_input). The overlay replaces any model-supplied value for these two keys; it does not merge. The model therefore cannot choose its key, and cannot forge another run's (the #2594 B1 concern, closed one layer earlier).
  • The server requires idempotency_key (a call without it is refused with its own error identity), validates the grammar, and runs the trailer scan before the CAS as today. It also requires base_commit for a call arriving from an orchestrated session (the overlay always sets it), and records it as a second runtime-owned trailer Upsquad-Base-Commit: <sha>; the author message may not contain either prefix.
  • Attribution never comes from the key. The audit row's actor is the gateway-validated identity (EdgeToolCall.AgentID, the token's org/unit — edge_policy.go:159-162), the step name and run id in the tool_result hop come from the bridge's own ToolCall.Key, and commit_sha / previous_head_sha / idempotency_key are recorded on the hash-chained audit hop as #2595 §8 requires. A key is an idempotency marker that happens to be human-readable in git log; it is not evidence of who wrote the commit.

A caller that is not an orchestrated session (a seat token through the gateway) supplies its own key; its provenance is its token, and in Stage 2 such a caller is floored at the edge (D6).

D6 — Clearance floor 4, where it is actually enforceable​

Ruling 5 makes 4 the one floor for run-code, write-branch and dispatch-coder. On this path it is enforced at two layers, and the ADR is explicit about what each covers:

  1. The bridge (orchestrated sessions — every Stage 2 caller): call.PlatformTool ∈ {github.commit_files, github.create_pull_request, github.create_issue_comment} and RunScope.Clearance < 4 ⇒ deny with its own reason constant, beside the coder-dispatch floor check and before the Governor call (bridge.go:150-157). This is the same RunScope.Clearance the run row carries (hook.go:239-247) — never a model- or worker-supplied value.
  2. The gateway edge (every other caller class): the github server is registered with mcp_servers.min_clearance = 4. The edge floor is per server (edge_policy.go:152-169), so this floors the server's reads too for agents below L4 — accepted in Stage 2, where the SDLC roster agents on the pilot team are seeded at clearance 4 (S5) and the reads a lower-clearance agent needs exist on the third-party GitHub MCP server under another registry name. A per-tool floor at the edge is the right end state and is filed from S4 as a follow-up owned by backend-sme (ADR-0024 D6 widening); until it lands, the server-level floor is the honest statement of what the edge enforces, and this ADR does not claim more.

The server itself cannot enforce the floor: the upstream token carries no clearance claim (agent_token.go:182-204), and inventing one is a token-contract change this ADR does not make.

D7 — Credential and egress​

The server resolves the team's SCM credential per call from the vault (RepoMapCredentialStore.Resolve, repo_map_credentials.go:221), scoped by the token's (org, unit) → team and by provider/host — never cached across calls, never logged, zeroed after use (the store's own discipline). Its egress to api.github.com goes through the MCP egress guard (internal/mcp/egress, ADR-0025). The sandbox the coder runs in has no route to GitHub (ADR-0037 D7): the credential and the egress live in this server, which is the whole point of the re-home — the ruling's rejected alternative for the workspace ("hands the sandbox an SCM credential and an egress grant") is the same alternative here, rejected for the same reason.

Authorisation remains fail-closed outside the guardrail path (#2595 §2): for an orchestrated session the Governor's tool_action verdict on tool:github.commit_files (FailsClosedOnNoMatch) is the grant; the gateway's CEL/guardrail layer stays a secondary argument filter that can only deny. "Catalogued is not authorised": enabling the write on a tenant is still the operator grant in docs/runbooks/governed-git-write-grant.md, updated in S4 for the tool: target spelling and the server-level edge floor.

D8 — No merge or enqueue tool: a human lands​

The surface has no merge_pull_request, no merge-queue enqueue, no update_ref on a protected ref, and no deploy.release (#2598 stays awaiting-approval, outside Stage 2). The SDLC definition ends its automated part by raising the landing gate (an on_request approval gate, clearance 4) that names the pull request and the base commit; a human lands through the repository's protected mechanism; the run completes reporting the PR URL. The governance seed row targeting github.merge_pr (deploy/seeds/platform_governance_policies.yaml:55) governs a tool that no server exposes; #4538's reconciliation is moot and the issue closes with S0.

Rejected​

  • A governed merge_pull_request under a human landing gate — the ruling's named alternative, declined by the founder as a new write surface. Recorded so it is not re-asked.
  • Reviving internal/mcp/github/tools.go's GovernedTools (push, merge_pr, create_branch, …). They have no production registrar, no fences, no CAS and no trailer; two of them are merges or force-capable pushes. #4444 deletes them.
  • Using a third-party GitHub MCP server for the write (push_files / create_or_update_file). No CAS, no trailer, no .github deny, no size caps, and the credential would have to live in the gateway's upstream config rather than the vault.
  • Letting the coder git push from the sandbox. Needs the credential and an SCM egress grant inside the sandbox — ADR-0037's rejected alternative.
  • A standalone create_branch tool. Recomposable into a write surface nobody reviewed (#2595's reason for rejecting option A); folded into commit_files as a fenced side-effect instead (D4).
  • Trusting a model-supplied idempotency_key. The key would then be a forgeable replay channel (#2594 B1); the overlay replaces it.
  • Two registry servers to get a per-tool floor (github reads at 0, a write server at 4). Breaks the github.* vocabulary the gates and governance targets use; the per-tool edge floor is the right fix and is filed as one.

Consequences​

  • Positive. One write surface, one declaration, one audit record per write, the same six fences on both arms until the old arm dies; the coder needs no credential and no egress to GitHub; the SDLC loop reaches "PR open, CI green, human lands" with no merge authority anywhere in the platform; #4538 closes by construction.
  • Size caps bind real changes (50 files / 1 MiB). Stage 2 picks an acceptance change inside them; launcher-side diff extraction feeding the same governed write is the follow-up, not a cap raise (plan risk 7).
  • The edge floor is server-wide in Stage 2. Reads through the github server need L4 until the per-tool floor lands; the follow-up is filed from S4 and named here so the limitation is not mistaken for a design choice.
  • Two trailers on every commit (Upsquad-Idempotency-Key, Upsquad-Base-Commit) — visible in git log on purpose (#2595's "a commit message has no hidden channel").
  • create_pull_request_review leaves the SDLC vocabulary. Reviewer agents post verdicts as issue comments through the orchestrator; a PR "review" object is not created by an agent.
  • Until #4444 lands there are two callers of fences.go. Every fence test runs through both; a change to one caller that the other cannot see is the drift this arrangement exists to prevent.
  • No proto change. Amended 2026-11-20 (S4, #4635): the original line read "no migration, no new flag", which the build disproved — migration 282 closed mcp_builtin_registrations.target to ('memory','knowledge'), so the github builtin target needs migration 297 (CHECK widened), a new oauth.BuiltinGitHub target with its own audience oauth.GitHubAudienceURI, and the context-engine deployment setting MCP_BUILTIN_GITHUB_ENDPOINT (empty disables the target, fail-closed). None is a behaviour flag or a new authority. New governance target rows (tool:github.commit_files, tool:github.create_pull_request, tool:github.create_issue_comment) and the first-party seed are deployment data (S4/S5).

References​

Founder ruling 3 — #4578 comment 6980541294 · design #2568 (ask 1 discharged here) · superseded issue-only ADR #2595 · implementation PR #2594 and its review corrections · fixture/seed naming #4538 · Temporal retirement #4444 · source grant #4152 · idempotency anchor #2397 · ADR-0024, ADR-0025, ADR-0037 · runbook docs/runbooks/governed-git-write-grant.md · S0 #4631 · S3 #4634 · S4 #4635