Skip to main content

Enabling the governed git read + write capability on a tenant

github.commit_files is the first UpsQuad action that can change a customer's source of truth. It ships catalogued but authorised nowhere: nothing in the platform seeds a policy for it, so on every tenant a call that reaches it fails closed until an operator writes an explicit grant.

Since ADR-0038 (core#4635) the write lives in a first-party MCP server behind the team gateway — cmd/upsquad-github-mcp, registry name github — and the agents+gates runtime reaches it as github.<tool>. The retiring Temporal tool_action arm (cmd/agent-orchestrator/github_commit.go) runs the same six fences from the same code (internal/mcp/github/fences.go) until #4444 deletes it. §0 is the MCP path; §1–§8 still describe the shared fences and the governance grant, which are the same on both paths.

Issue: #2568 (design, founder-approved 2026-08-12, countersigned and re-homed 2026-11-18) · ADR-0038 (docs/adrs/ADR-0038-governed-git-write-first-party-mcp.md, supersedes the issue-only ADR #2595) · related: #2566, #2564, #2397.


0. The MCP path (ADR-0038) — what has to be true, in order​

A github.commit_files call from an orchestrated session succeeds only when every layer below admits it. Each is independent; each fails closed.

The write grant needs a deployment that carries S3 (#4634)

Since #4634 the bridge's ADR-0038 D5 overlay ships: every allowed github.commit_files call from an orchestrated session runs with idempotency_key = the bridge's own hop key and, from a coder session, base_commit = the platform's record of the checkout — both replacing any model-supplied value (orchrt.overlayCommit) — and a coder's GitHub write naming any repository but its workspace's is denied before the Governor (ReasonCoderRepoMismatch). On a deployment that predates #4634 the key is still caller-supplied: do not grant the write there.

#LayerWhereEnabled by
1Bridge clearance floor: a GitHub write tool from a run below clearance 4 is denied before the Governor is askedinternal/workflow/orchrt/bridge.go (ReasonGitWriteClearanceFloor)the run's clearance (never a model value)
2Governor verdict on tool:github.<tool> (tool_action, fail-closed on no match)governance cascade§4 grant (deploy/sql/github_mcp_governance_grant.sql)
3Gateway edge floor: mcp_servers.min_clearance = 4 on the github server — server-wide, so it floors the reads toointernal/gateway/mcpproxy/edge_policy.go; audited mcp_clearance_floor_deniedthe first-party seed (forces 4)
4Team audience: the agent's token must be for /mcp/team/{unit}; another team's token is HTTP 401gateway terminatorthe team the agent belongs to
5Server identity: the forwarded token must carry aud = <base>/mcp/upsquad-github; otherwise 401 / JSON-RPC -32001internal/auth/mcpidentityTOKEN_AUDIENCE (required at boot)
6Repo pin = the calling team's source grant: repo_registry (team) → repo_source_grants enabled → repo_map_bindings active + access_confirmed → repo_map_credentials activeinternal/githubmcp/authority.gothe repo-map registration + source grant (#4152)
7Credential: the team's SCM credential from the repo-map vault, resolved per call, never cached, never logged (a GitHub App credential is minted into an installation token narrowed to the one repository)samethe team credential (VAULT_PASSPHRASE on the server)
8The six fences (§2) and the CAS, plus branch creation at expected_head_sha when the branch is absent (ADR-0038 D4)internal/mcp/github/fences.go—

0a. Onboard the server for a team (once per team)​

(Write grant: see the S3 caution in §0 first.)

  1. Deploy upsquad-github-mcp (dev compose: docker compose -f docker-compose.dev.yml up -d upsquad-github-mcp) and set MCP_BUILTIN_GITHUB_ENDPOINT on context-engine (dev compose default: http://upsquad-github.mcp.internal:9103/). With the variable empty the github builtin target is unresolvable and every call fails closed.

  2. Seed it for the team (plan → apply → verify; the seed forces min_clearance = 4 and refuses a stored schema that is not exactly the ruled surface):

    go run ./cmd/tools/first-party-seed -mode=plan -memory-endpoint=... -knowledge-endpoint=... \
    -github-endpoint=http://upsquad-github.mcp.internal:9103/ -github-pinned-cidr=<compose subnet> \
    -org=<ORG> -unit=<TEAM> -actor=<MEMBER>
    go run ./cmd/tools/first-party-seed -mode=apply -receipt=/path/receipt.json ...same flags...
  3. Register the repository to the team and enable its source grant (repo-map registration UI / RepositorySourceManagement), with a team credential that has write scope (fine-grained PAT with Contents + Pull requests + Issues write and Checks read on that one repository, or a GitHub App installation granting the same). A classic PAT (ghp_…) is refused: it cannot be narrowed to one repository.

  4. Write the governance grant (§4).

0b. Error identities the server returns​

Every refusal after authentication is a tool error whose structuredContent is {"error":{"code","message","retryable"}}. The codes a reviewer and an operator will see:

CodeMeaning
protected_branch_namea conventional protected name (main, master, …), no network call
default_branchthe repository's own default branch
github_protected_branchGitHub reports the branch protected
path_under_dot_github / path_under_dot_gita path under .github/ / .git/ (case/dot variants folded)
cas_conflict (retryable: true)the branch moved; nothing was written
reserved_trailer_in_messagethe author message tried to write Upsquad-Idempotency-Key: / Upsquad-Base-Commit:
idempotency_key_required / idempotency_key_invalidno replay marker / not a single [A-Za-z0-9:@#._-] line
expected_head_sha_not_founda new branch requested at a commit that does not exist
repo_not_grantedthe repository is not in the calling team's source grant
caller_not_in_teamthe token's team is not the calling agent's team
credential_unavailablethe team credential could not be resolved or minted
too_many_files, file_too_large, total_too_large, message_too_large, path_invalid, path_duplicate, file_mode_unsupported, bad_argumentsinput bounds and grammar

The full closed set is the Fence* codes in internal/mcp/github/fences.go (enumerated in githubtest.AllFenceCodes) plus the Code* constants in internal/githubmcp.


1. What the three actions are​

ActionClassClearance floorWhat it can do
github.get_file_contentsread0Read one file, at a ref, from the pinned repo (Temporal arm: the node's literal pin; MCP path: the team's source grant). Capped at 128 KiB, truncation and binary flagged.
github.get_branchread0Read a branch's head SHA, its protected flag and the repo's default branch.
github.commit_fileswrite4Commit a set of file contents to a non-default, unprotected branch of the pinned repo (Temporal arm: the node's literal pin; MCP path: the team's source grant), compare-and-swap'd on expected_head_sha.
github.create_pull_requestwrite (PR)4Open a PR from a same-repository head into a base. Never merges: there is no merge or enqueue tool anywhere (ruling 3, "a human lands").
github.create_issue_commentwrite (comment)4Comment on an issue/PR (how reviewer agents record a verdict).
github.get_issue / github.get_pull_request / github.get_check_runsread0 at the Governor, 4 at the gateway edge in Stage 2Read an issue, a PR, the check runs for a ref.

On the MCP path, "the node's pinned repo" is the team's source grant (§0 layer 6): repo is model-produced, so the pin moved from a definition literal to an operator-written grant (ADR-0038 D3a). The read floor at the edge is server-wide in Stage 2 (§0 layer 3); a per-tool edge floor is the filed follow-up (#4642).

The floor is enforced at save: a commit_files step declaring required_clearance < 4 is rejected by the definition validator.

2. What is fenced without any policy at all​

These hold on a tenant with zero governance rows, and they hold if the guardrails store is unreachable. They are not what authorises the action — they are what bounds it once it is authorised.

  1. Repo pin. with.repo must be an author-committed literal (no ${...}), and the invoker denies any resolved repo outside it before resolving the credential.
  2. Protected-ref deny, three independent arms: a conventional integration-branch name (main, master, trunk, develop, release, production, staging, …) with no network call; the repository's live default_branch; and GitHub's own protected flag on the branch.
  3. Path fence. Traversal / absolute / URL-metacharacter paths are refused, and no commit may touch .github/ or .git/ — a workflow file committed to a branch executes with the repository's CI credentials, which is a strictly larger capability than the commit.
  4. Compare-and-swap. expected_head_sha is required; there is no blind-write mode. The ref update additionally sends force: false, so GitHub rejects a non-fast-forward. There is no force-push capability and no way to compose one.
  5. Bounds. ≤ 50 files, ≤ 256 KiB per file, ≤ 1 MiB total, ≤ 8 KiB message.
  6. Idempotency. The commit message carries an Upsquad-Idempotency-Key: run:step@lap trailer and the arm reads the branch's recent history for its own trailer before writing, so an at-least-once retry returns the prior commit instead of landing a second one.
The T5 guardrails are NOT the authorisation for this action

guardrails.Engine.EvaluateArguments is fail-open — it allows when no policy matches. What authorises a commit_files node is the node's entry Govern, where action_type = tool_action is in governance.FailsClosedOnNoMatch, so a cascade matching no policy at any layer resolves to deny. Never reason about this capability from a guardrail rule.

The agent's committed code can execute in your CI on the next push

The .github/ fence stops the agent committing new workflow definitions, but it does not stop the code it commits from being run by workflows you already have. A repository with an existing on: push or (worse) pull_request_target workflow executes the agent's committed content — build scripts, Makefiles, test files, package.json lifecycle hooks — with whatever credentials that workflow carries, the moment commit_files moves the branch. pull_request_target runs on the base repository's secrets and is the classic privilege-escalation surface.

Before enabling commit_files on a repo, audit its .github/workflows/ for triggers that run on the branches this agent will target, and prefer a branch-scoped or manual-approval CI posture for agent-authored branches. This capability grants "may land a commit", and on a repo with automatic CI that is transitively "may run code in CI" — which is exactly the escalation the .github/ write-fence is designed to keep narrow, not to eliminate.

3. Before you grant: the pre-enablement audit​

Check for a blanket wildcard first. cascade_query.go returns target = '*' rows for every target, so a tenant that already carries a tool_action / * / allow row has the write enabled the moment it ships, with no per-target decision by anyone. The platform never seeds such a row (the provisioner is deliberately per-target), so it can only have arrived by hand.

-- Any wildcard tool_action grant on this org? Expect ZERO rows.
SET LOCAL app.org_id = '<ORG_ID>';
SELECT id, target, effect, min_clearance
FROM org_governance_policies
WHERE org_id = '<ORG_ID>' AND action_type = 'tool_action' AND target = '*';

Also check the tighter layers (org_unit_governance_policies, member_governance_policies) for target = '*'. If a wildcard exists, narrow it before granting anything here — otherwise the per-target grant below is decoration.

Then confirm the rest of the prerequisites:

  • The tenant's SCM credential has write scope. The token comes from the vault resolution chain (member → team → org). A read-only token fails at the ref update with a GitHub 403; that is a legible failure, not a silent one, but it is a wasted run. Check before granting.
  • The target repo is the one you think. The grant is per action, not per repo. On the MCP path the repo bound is the calling team's source grant (§0 layer 6): list the team's granted repositories before enabling. On the retiring Temporal arm it is the node's literal pin — read the definition's with.repo.
  • The branch strategy produces non-protected branches. A flow that ships to main cannot be made to work by granting harder; it has to open a PR instead.

4. Writing the grant​

The governance target strings are exactly tool: + each name in internal/mcp/github.RuledPlatformTools:

tool:github.commit_files (min_clearance 4)
tool:github.create_pull_request (min_clearance 4)
tool:github.create_issue_comment (min_clearance 4)
tool:github.get_issue
tool:github.get_pull_request
tool:github.get_check_runs
tool:github.get_branch
tool:github.get_file_contents

For the SDLC roster on one org, apply the checked-in grant (idempotent; org scope, for the reason in §4a):

psql "$DATABASE_URL" -v org_id=<ORG_UUID> -f deploy/sql/github_mcp_governance_grant.sql

TestGovernanceGrantSQLIsTheRuledSurface holds that file to the ruled set and the write floor. The hand-written variants below remain valid for a narrower grant.

(TestGitCapability_GovTargetIsTheStringAnOperatorGrants pins these against the runtime's own derivation, so a typo here is a grant that is written and never read.)

Governance keys on the triggering human's identity: the org_unit layer only matches units on that member's ancestor path, so a unit-scoped grant is invisible to every run triggered from outside that unit (this is the core#2564 finding, measured on the live tenant). For a capability the whole tenant is meant to have, grant at org scope.

There is no PutOrgPolicy RPC today — GovernanceService exposes PutOrgUnitPolicy and PutMemberPolicy only — so an org-scope grant is a direct, RLS-scoped upsert:

BEGIN;
SET LOCAL app.org_id = '<ORG_ID>'; -- required: FORCE ROW LEVEL SECURITY

INSERT INTO org_governance_policies (org_id, action_type, target, effect, min_clearance)
VALUES
('<ORG_ID>', 'tool_action', 'tool:github.get_file_contents', 'allow', 0),
('<ORG_ID>', 'tool_action', 'tool:github.get_branch', 'allow', 0),
('<ORG_ID>', 'tool_action', 'tool:github.commit_files', 'allow', 4)
ON CONFLICT (org_id, action_type, target)
DO UPDATE SET effect = EXCLUDED.effect,
min_clearance = EXCLUDED.min_clearance,
updated_at = now();

COMMIT;

min_clearance = 4 on the write mirrors the catalog floor: the node presents its declared required_clearance, and the engine denies when the presented clearance is below the policy's minimum. Raise it above 4 to require a higher-clearance node; never lower it below the floor, which would be a policy the validator makes unreachable.

Grant the reads without the write to get a genuinely read-only agent posture: omit the third row. Per-target scoping is enforced in SQL (AND (target = $4 OR target = '*')), so a read grant does not reach the write.

4b. Unit or member scope — for a single team or a single person​

Use the RPCs (both require guardrails.edit on the target scope):

PutOrgUnitPolicy { org_unit_id, action_type: "tool_action",
target: "tool:github.commit_files", effect: "allow", min_clearance: 4 }
PutMemberPolicy { member_id, action_type: "tool_action",
target: "tool:github.commit_files", effect: "allow", min_clearance: 4 }

⚠ Remember the cascade rule: an org_unit grant only applies to runs triggered by a member on that unit's ancestor path. If the person who triggers the run is not in that unit, the grant is dead and the run fails closed.

5. Verifying​

EvaluateDryRun renders the full cascade trace without mutating anything, and since core#2565 its no-match default is derived from the same FailsClosedOnNoMatch the enforcement path uses, so preview and enforcement agree:

EvaluateDryRun { org_id, member_id: <the human who triggers the run>,
action_type: "tool_action",
target: "tool:github.commit_files", clearance: 4 }

Expect verdict = allow with the matching layer named in the trace. Before the grant, expect verdict = deny with platform default deny.

On the MCP path, check the server directly through the team gateway with an agent token (tools/call github.get_branch on the granted repo must succeed; on any other repo it must return repo_not_granted), then run the flow on the disposable fixture repository (upsquad-ai/dogfood-sandbox, the #2568 authorisation) first.

On the Temporal arm, run the flow end to end on a sandbox repo first, and check:

  • workflow_actions.output for the step carries commit_sha, previous_head_sha and idempotent: false;
  • coordinator_audit_log carries a tool_result hop for the step whose detail holds commit_sha, previous_head_sha and idempotency_key;
  • the branch in GitHub has exactly ONE new commit, and its message ends with the Upsquad-Idempotency-Key: trailer.

6. Revoking​

Set the row's effect to deny rather than deleting it — a deny is explicit and survives a later re-seed, whereas a deleted row simply returns the target to "no match", which is also a deny today but relies on the fail-closed default staying in place.

BEGIN;
SET LOCAL app.org_id = '<ORG_ID>';
UPDATE org_governance_policies
SET effect = 'deny', updated_at = now()
WHERE org_id = '<ORG_ID>' AND action_type = 'tool_action'
AND target = 'tool:github.commit_files';
COMMIT;

Revocation takes effect on the next Govern check. A run already past its entry Govern for that node is not interrupted; a run parked at a gate re-governs when it resumes.

7. Failure modes and what they mean​

SymptomCauseAction
Run fails GovernanceDenied at the tool nodeNo allow policy at any layer, or a deny at a tighter layerGrant per §4, or find the tighter deny
refusing to write to branch "X"Protected-ref deny (name, default branch, or GitHub protection)Ship to a feature branch and open a PR
repo_not_granted (MCP)The repo is not registered to the calling team, its source grant is disabled, or its binding is not access_confirmedRegister/confirm the repo and enable the team's source grant
mcp_clearance_floor_denied audit rowThe calling agent's clearance is below the github server's edge floor (4)Run the roster agent at clearance 4; the floor is server-wide in Stage 2
HTTP 401 / JSON-RPC -32001Wrong team audience at the gateway, or a forwarded token not bound to /mcp/upsquad-githubUse the agent's own team gateway; check TOKEN_AUDIENCE
ToolCASConflict … branch movedAnother writer moved the head since get_branchRetries automatically (3 attempts); if persistent, the branch has a concurrent writer
path … is under ".github"The agent tried to write a workflow/action definitionDeliberate fence — widening it is a separate review
github 403 on the ref updateThe tenant SCM credential has no write scopeRe-issue the credential with write scope
requires required_clearance >= 4 at saveThe node declares a clearance below the floorRaise the node's required_clearance
  • internal/workflow/tool_catalog.go — the catalog rows and the "membership is not authorisation" note.
  • internal/mcp/github/fences.go — the six fences, in the order they run (shared by both arms).
  • internal/mcp/github/surface.go — RuledPlatformTools, the one declaration of the surface.
  • internal/githubmcp/ + cmd/upsquad-github-mcp/ — the first-party server (ADR-0038).
  • deploy/sql/github_mcp_governance_grant.sql — the SDLC roster grant.
  • cmd/agent-orchestrator/github_commit.go — the retiring Temporal arm (thin caller of fences.go).
  • cmd/agent-orchestrator/github_repo_read.go — why neither read is observation-safe.
  • internal/goldenflow/git_capability_seed_2568_test.go — the test that fails if any provisioner path ever starts seeding these targets.