Skip to content

fix(github): follow the installation on GitHub and drop dead company-wide paths - #391

Merged
artempartos merged 1 commit into
developfrom
fix/github-installation-lifecycle
Oct 1, 2026
Merged

artempartos merged 1 commit into
developfrom
fix/github-installation-lifecycle

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

A GitHub connection's state now follows what happens on GitHub, and the dead company-wide GitHub paths are gone. Six problems from the integration docs review, each checked against the code first.

What was wrong, and what changed

1. Dead "Link to project" and company-wide branches. The Link action (IntegrationsContent.tsx, canLink) only showed for company-wide rows. The company-wide branches of Integration.find_or_build_github_for_pat/_for_installation (app/models/integration.rb:55-77) only ran for project: nil. Migration 20260808000001_remove_company_wide_github_integrations deleted every company-wide GitHub row, and nothing creates one now, so none of this could run.

  • Removed the Link button and handler, the installationId it read from IntegrationResource, the non-PAT branch of IntegrationsController#create_github, IntegrationService#create's via_setup: and its "held by the company" check, and Integration.github_installation_held_by?.
  • Github::IntegrationService now requires project:. The model lookups are project-only.
  • A non-PAT POST provider=github now creates nothing and answers with an alert. App installations arrive only through GithubSetupController.
  • Left in place: the Integration.company_wide scope. Nothing calls it any more, but a parallel branch might still use it.

2. The availability check was incomplete. github_props and github_app_install checked only GITHUB_APP_ID/GITHUB_APP_SLUG (integrations_controller.rb:238,307). The dialog's own text names a private key as required too.

  • New Github::TokenService.app_configured? also requires GITHUB_APP_PRIVATE_KEY, or a GITHUB_APP_PRIVATE_KEY_PATH file that exists. It backs both the dialog prop and the install endpoint.

3. An expired setup link showed the wrong message. After 10 minutes Oauth::State.decode returns nil, so the callback said "Connect a GitHub integration from within a project." (github_setup_controller.rb:31).

  • New Oauth::State.expired? is true when the signature is ours (MessageVerifier#valid_message?) but the state no longer verifies.
  • The callback now says "The GitHub setup link expired — open the project's Integrations page and connect GitHub again." A state that is not ours still gets the misroute message.

4. Uninstalls were invisible.

  • Webhooks::GithubController now handles installation events through the new Github::InstallationEvents. GitHub sends these to every App without a subscription.
    • deleted and suspend set every connection on that installation to error, in every company, with a reason.
    • unsuspend brings back only the connections the suspension took down. A connection in error for another reason stays in error.
  • GitHub rows (App and token) now have Test connection, via a new Github::IntegrationService#test wired into test_connection:
    • A connection GitHub accepts is repaired in place.
    • A suspended installation is reported as suspended.
    • A 404 now reads "…it was uninstalled".
    • A GitHub 5xx raises the new TokenService::UnavailableError and leaves the status alone.
  • Why a GitHub connection is failing now shows on its row (IntegrationResource#github_error).
  • Removing in Flow does not uninstall on GitHub. I chose the confirm-dialog option over calling GitHub's installation DELETE. One installation can serve several projects, and several companies when installation ownership is enforced, so uninstalling from one project's row would cut off all of them. The dialog says the app stays installed and links to the installation.

5. Failed clones were silent. record_failed_repo (session_context_service.rb:683) wrote only to metadata["failed_repos"].

  • New TerminalSessionResource#failed_repositories exposes the list, only to viewers who may see the session.
  • SessionShowContent shows an alert with each repository and the reason. This covers GitHub, GitLab, Azure and public clones alike.

6. Wrong trigger example. create_workflow_trigger's event_type description offered 'github.push', which nothing emits. It now names events that exist (slack.message, an inbound webhook's webhook.<token>) and points GitHub at kind=webhook.

Docs: docs/user-guide/github.md and its bundled copy are updated:

  • "Limits" no longer says there is no connection test.
  • New sections cover the installation lifecycle, the installation events, the full configuration requirement, the removal note and failed clones.
  • New troubleshooting rows: expired link, uninstalled, suspended, GitHub outage.

gitlab.md (both copies) gets the failed-clone note. The docs/design/task-tracker-integrations.md row that cited the removed link path is updated.

How it is tested

Targeted local runs through the test runner; the full suite is left to CI:

  • rails test on the GitHub services, the new installation_events_test, the token service contract tests (WebMock: suspended, 404, 502, app_configured?), the webhook, setup and integrations controllers, the Integration model, the TerminalSessionResource resource, Oauth::State, plus neighbours: session context, context builders, repositories, personal MCP triggers, oauth controller. All green except 12 SessionContextServiceTest MCP-config cases. Those fail locally on "Url cannot point to private or internal network addresses": the local runner's DNS makes the URL-safety check reject the MCP hosts. They do not touch this change.
  • rubocop on every changed Ruby file and brakeman: clean.
  • vitest on the integrations, session-show and onboarding tests, plus yarn tsc, yarn lint and yarn fsd: clean.

Neighbouring work

Other open branches edit nearby code:

  • One adds Test connection for GitLab/Coder/Slack, in the same test_connection hash and row actions.
  • One unregisters repository hooks on removal.

The diff in the shared files (integrations_controller.rb, IntegrationsContent.tsx, integration.rb) is kept to the GitHub lines.

🤖 Generated with Claude Code

…wide paths

A GitHub connection read Active after the app was uninstalled or suspended
on GitHub: nothing handled the `installation` webhook and the row had no
connection test. Clone failures were recorded only in session metadata, so
a repository silently dropped out of the agent's context.

- Webhook: apply `installation` deleted / suspend / unsuspend to every
  connection on the installation (Github::InstallationEvents). Unsuspend
  restores only what the suspension took down.
- Test connection for GitHub rows (App and token). A GitHub 5xx no longer
  reads as a bad credential (TokenService::UnavailableError), and a 404
  says the installation was uninstalled.
- The App counts as configured only with id, slug and a private key, so a
  deployment without a key no longer offers an install that can only end
  as a "GitHub (unverified)" row in error.
- An expired setup link says it expired instead of "Connect a GitHub
  integration from within a project." (Oauth::State.expired?).
- Removing an App connection says the app stays installed and links to the
  installation; uninstalling from Flow would also cut off every other
  project and company on the same installation.
- The session page lists repositories that did not clone, with the reason
  (GitHub, GitLab, Azure and public clones alike).
- Remove "Link to project" and the company-wide branches of
  find_or_build_github_for_*: migration 20260808000001 deleted every
  company-wide GitHub row, so neither could run.
- create_workflow_trigger no longer offers 'github.push', which nothing
  emits, as an example event.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit ac39dab into develop Oct 1, 2026
7 checks passed
artempartos added a commit that referenced this pull request Oct 1, 2026


Reuse the in-file danger Text for dialog errors instead of a new Alert
import, keep the test_connection provider hash in the layout #391 uses, and
leave Integration.find_or_build_gitlab_for_token for a follow-up so the
model does not collide with #391's edit next to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
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