Repository navigation
Receive GitHub App webhooks (installation, repositories, authorization revoked) - #643
Merged
Merged
Conversation
…orizations POST <mount>/api/github_app/webhooks verifies X-Hub-Signature-256 under github_app_webhook_secret (falling back to GITHUB_APP_WEBHOOK_SECRET; 404 when neither is set), records the X-GitHub-Delivery id so a redelivery is a no-op, answers 202 and applies the delivery in GithubWebhookJob: - installation deleted / suspend / unsuspend / new_permissions_accepted update the linked installation's removed_at, suspended_at and permissions - installation_repositories removed drops repositories from the owner's selection; added needs nothing stored (the picker lists live) - github_app_authorization revoked deletes the user's stored connection when connections authorize through the App's client id Deliveries for installations no owner linked, and other events, are accepted and ignored. Ships migration 029 for the delivery table. Closes #641 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PCEJHsJpjXpDa9Kuq9i4Yg
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PCEJHsJpjXpDa9Kuq9i4Yg
TonsOfFun
pushed a commit
that referenced
this pull request
Oct 27, 2026
Both Unreleased entries are kept: the CLI and its facade tools, then #643's GitHub App webhooks. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RSuPEbVwjxwJub8eAmGM9N
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #641
What
An engine endpoint,
POST <mount>/api/github_app/webhooks(Api::GithubAppWebhooksController, anActionController::APIlike the other signed/token endpoints: no session, no CSRF, none of the host's controller concerns).Signature:
X-Hub-Signature-256must equalsha256=+ HMAC-SHA256 of the raw body underActionAgent.github_app_webhook_secret(new accessor, falls back toGITHUB_APP_WEBHOOK_SECRET), compared withActiveSupport::SecurityUtils.secure_compare. Bad, malformed or missing signature: 401. No secret configured: 404. The secret is not part ofgithub_app_configured?, so an App without a webhook keeps working as before.Answer: 202 right away; the delivery is applied in
ActionAgent::GithubWebhookJob. JSON bodies and GitHub's form-encodedpayload=bodies are both read; the job gets a slice of the payload (action, installation id/permissions/selection/suspended_at, added/removed repo ids, sender id), not the whole delivery.Idempotency: a new table,
github_webhook_deliveries(delivery id unique, event, action, installation id, created_at; no payload). The delivery is inserted before the job is enqueued; a duplicate insert (RecordNotUnique, inside a savepoint) answers202 {"status":"duplicate"}and does nothing. If enqueueing fails the row is removed so a redelivery is processed. Rows older than 7 days are pruned on each insert. I went with a table overRails.cachebecause the unique index makes check-and-record one atomic insert across every web process whatever cache store the host runs (Cloud Run runs several instances; a memory or null store would dedupe nothing). Handlers also set state from the payload rather than toggling it, so a job run twice gives the same result.Events:
installationdeletedremoved_atset (if unset)installationsuspendsuspended_atset from the payload (or now)installationunsuspendsuspended_atclearedinstallationnew_permissions_acceptedpermissionsreplaced from the payloadinstallation_repositoriesremovedrepository_selectionrefreshedinstallation_repositoriesaddedrepository_selectionrefreshed; nothing else to store, since the repository picker lists what the installation reaches from GitHub each time it opensgithub_app_authorizationrevokedGithubConnections deleted, only whengithub_client_id == github_app_client_id(see below)ping,push, ...)202 {"status":"ignored"}, nothing recordedDeliveries for an
installation_idno owner linked are ignored (aninstallation createdis never auto-linked; linking stays the Settings flow with its admin check).Migration
Ships the way the engine ships others: numbered template
029_create_active_agent_github_webhook_deliveries.rb.erb(emitted byrails g action_agent:install), the same migration intest/dummy/db/migrate, and the dummyschema.rb(version 29). Index names are short (index_<prefix>webhook_deliveries_on_*) to stay under the 63/64-char limits with longer prefixes. Hosts: run the generator anddb:migratewhen upgrading.Docs
docs/framework/dashboard.mdgains a "GitHub App webhooks" section (setup + event table) and no longer says "no webhook"; the initializer template and CHANGELOG mention the new setting.Deviation from the issue: revoked authorization
The App's own user tokens are never stored (the installation callback holds them in-method only), and
GithubConnectionis the separate OAuth App flow (github_client_id). Agithub_app_authorization: revokeddelivery is about the App's grant, not that OAuth App's, so deleting an OAuth App connection on it would remove a token that still works. The job therefore deletes the sender's connection only when the OAuth connection flow is configured with the App's own client id (i.e. the connection's token is an App user token). On activeagents.ai today, where the OAuth App is separate, the event changes nothing. If you want it to delete regardless, that's a one-line change.Tests
actionagent/test/github_app_webhooks_test.rb(19 tests) against payload fixtures inactionagent/test/fixtures/files/github_webhooks/with signatures computed in the test; no network (a WebMock stub only for the picker listing check). Covers valid/invalid/missing signatures, no secret = 404, ENV fallback, CSRF exemption, redelivery no-op (suspend, unsuspend, then a redelivered suspend leaves it unsuspended), enqueue failure not recorded, pruning, each event, unlinked installations, ignored events, form-encoded bodies, and both revoke cases.install_generator_test.rb: the 029 migration builds the same table shape as the dummy schema, with a unique delivery index, and reverses.bin/test actionagent/test/*_test.rb, Ruby 3.3.8, rails8 gemfile): 1840 runs, 13800 assertions, 0 failures, 0 errors, 7 skips. RuboCop clean on changed Ruby files.Host follow-up (activeagents/activeagents), after this ships
https://activeagents.ai/dashboard/api/github_app/webhooks, check Active, subscribe to Installation and Installation repositories (GitHub App authorization is sent automatically). Same for the staging App withhttps://staging.activeagents.ai/dashboard/api/github_app/webhooks.GITHUB_APP_WEBHOOK_SECRET(orconfig.github_app_webhook_secret), keeping the Terraform/env files in sync; staging needs its own secret.db:migratefor the new table on repin.docs/infrastructure/gcp-cicd-setup.mdstep 1 ("leave Active unchecked until a receiver exists").Not done here
Create GitHub Appfor self-hosters) still creates an App with no webhook; addinghook_attributesand showing the returnedwebhook_secreton the created page is a possible follow-up.🤖 Generated with Claude Code
https://claude.ai/code/session_01PCEJHsJpjXpDa9Kuq9i4Yg