JuliusBrussee/caveman · error

githubapp: installation response identity mismatch

Error message

githubapp: installation response identity mismatch

What it means

After decoding a 200 response, the library verifies the installation is self-consistent: the returned ID equals the requested ID, the account ID is positive, and the account login is non-empty. Any mismatch means the response cannot be trusted to identify the installation, so it fails closed. This guards against confused-deputy bugs where a different installation's data is used.

Solutions

  1. Compare the requested ID to the returned ID in the error context; request the correct installation ID
  2. Fix test fixtures to include a full account object (id > 0, non-empty login)
  3. If GitHub changed the payload shape, update the library / file an issue

Example fix

// before
// test fixture missing account
{"id": 12345}
// after
{"id": 12345, "account": {"id": 987, "login": "my-org"}}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-call: confirm you are passing the intended installation ID, not a stale cached one

Try / catch

inst, err := app.GetInstallation(ctx, wantID)
if err != nil {
	if strings.Contains(err.Error(), "identity mismatch") {
		// refresh installation listing; do not proceed with mismatched identity
	}
	return err
}

Prevention

When it happens

Trigger: App.GetInstallation when GitHub (or a mock) returns an installation whose ID differs from the requested one, or whose account object lacks an ID/login — e.g. stale cached payload, wrong fixture, or a changed response schema.

Common situations: Test doubles returning minimal fixtures without account fields; intermittent proxies serving stale responses; schema drift from GitHub API previews.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/453b0567d4141f0d. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/githubapp/githubapp.go:178

		return out, fmt.Errorf("githubapp: installation id must be positive")
	}
	jwt, err := a.AppJWT()
	if err != nil {
		return out, err
	}
	status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodGet,
		"/app/installations/"+strconv.FormatInt(installationID, 10), nil)
	if err != nil {
		return out, err
	}
	if status != http.StatusOK {
		return out, fmt.Errorf("githubapp: get installation: HTTP %d: %s", status, snippet(raw))
	}
	if err := json.Unmarshal(raw, &out); err != nil {
		return out, fmt.Errorf("githubapp: decode installation: %w", err)
	}
	if out.ID != installationID || out.Account.ID <= 0 || strings.TrimSpace(out.Account.Login) == "" {
		return Installation{}, fmt.Errorf("githubapp: installation response identity mismatch")
	}
	return out, nil
}

// MintInstallationToken POSTs /app/installations/{id}/access_tokens narrowed to
// `repos` and `perms`, returning a ~1h token. Defaults (perms nil) are
// contents:write + pull_requests:write — enough to push a branch and open a draft
// PR, never to merge.
func (a *App) MintInstallationToken(ctx context.Context, installationID int64, repos []string, perms map[string]string) (InstallationToken, error) {
	if installationID <= 0 {
		return InstallationToken{}, fmt.Errorf("githubapp: installation id must be positive")
	}
	if len(repos) != 1 || strings.TrimSpace(repos[0]) == "" {
		return InstallationToken{}, fmt.Errorf("githubapp: exactly one repository is required")
	}
	repository := strings.TrimSpace(repos[0])
	if perms == nil {
		perms = map[string]string{"contents": "write", "pull_requests": "write"}

View on GitHub (pinned to 3ee70a1026)