Skip to content

feat(webhooks): scope a delivery to the workspace it belongs to - #263

Merged
imshashank merged 6 commits into
mainfrom
feat/webhook-delivery-workspace
Aug 9, 2026
Merged

imshashank merged 6 commits into
mainfrom
feat/webhook-delivery-workspace

Conversation

@imshashank

@imshashank imshashank commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

#260 surfaced why a GitHub delivery changed nothing, but webhook_delivery had no workspace column, so the list could only be gated on integration:manage and still showed every workspace's traffic to whoever could read it. On a deployment with many workspaces that is both noisy and wrong.

The design decision

The obvious move is to attribute a delivery by its repository, since that is what applyGithubEvent already resolves. That is exactly backwards for diagnostics: repository_not_connected is the single most useful reason to show a workspace, and repository-based attribution cannot produce it by definition, because there is no repository row to attribute through.

So attribution goes through the installation. Every GitHub App payload carries installation.id, and github_installation maps it to a workspace.

Case Attributed Visible to the workspace
Repository connected here yes yes
Repository not connected, installation is ours yes yes, with the reason
Installation belongs to another workspace no no
Payload with no installation, or unparseable no no

Does this work for everybody, not just this deployment

This is the part I went back and checked properly, because Orbit is installed by other people in other places.

Both documented install paths apply the column. The repository now has two, and the docs describe only one:

  • bun run db:push, which is what README.md, CONTRIBUTING.md, docs/getting-started.md and docs/self-hosting.md all tell people to run. Push applies the schema directly, so the column lands.
  • bun run db:migrate, which is what CI exercises since Refuse to build against a database that is behind the schema #256 and what a fresh clone needs. This PR adds 0003_productive_quicksilver.sql so that path lands too.

I verified the second the way CI does rather than assuming: built a database from nothing but the committed migrations and ran the drift check against it.

$ createdb orbit_from_migrations && bun run --filter '@orbit/db' migrate
[OK] migrations applied successfully!
$ bun run db:check-drift
localhost/orbit_from_migrations has every table and column the schema declares.

The migration is additive and safe on an existing install. A nullable text column, its foreign key, and an index. No table rewrite, no backfill, no default to compute. On Postgres 11 and later ADD COLUMN without a volatile default is O(1). The foreign key validates existing rows, but every existing row is null, so there is nothing to check. Retention already bounds the table: #253 added a 30 day prune after it reached 23,000 rows.

Old rows degrade in the safe direction. Deliveries recorded before this carry no workspace and stop appearing, rather than appearing under the wrong one.

A deployment with no github_installation rows loses nothing. Its deliveries are unattributed and the list is empty, but that install is already told plainly what is wrong: the integrations page says GitHub is not connected. No diagnostic disappears, it moves somewhere better.

Tests

2 new against a real database: a delivery for an unconnected repository is stamped with the workspace behind its installation and still records repository_not_connected, and a delivery whose installation belongs elsewhere stays unattributed. 28 pass on that route.

bun run verify green.

One thing worth deciding separately

Every install doc still says bun run db:push, including against a production database. Since #256 the repository also carries committed migrations and CI refuses a schema they do not build. Both work today, so nothing is broken, but a self-hoster following the docs will never run db:migrate. That belongs with whoever owns #256 rather than in this PR.

🤖 Generated with Claude Code

Greptile Summary

The PR attributes GitHub webhook deliveries to workspaces through GitHub App installations and displays workspace-scoped delivery diagnostics.

  • Adds nullable workspace attribution to webhook deliveries, including migrations and an index.
  • Resolves and records the workspace before processing signed GitHub webhook payloads.
  • Loads the latest workspace-scoped deliveries for integration administrators.
  • Adds delivery-list UI and database-backed route/component tests.

Confidence Score: 4/5

The PR is not yet safe to merge because the delivery summary can report that every recent webhook changed Orbit even when one failed or completed without a state change.

The existing summary branch still treats every non-ignored delivery as a successful mutation, while current webhook processing can persist failed deliveries and processed deliveries with no synchronization actions.

Files Needing Attention: apps/web/src/features/settings/github-deliveries.tsx

Important Files Changed

Filename Overview
apps/web/src/app/api/webhooks/github/route.ts Resolves the signed payload's installation and stamps the corresponding workspace onto the delivery before event handling.
apps/web/src/features/settings/integrations-data.ts Adds permission-gated, workspace-scoped loading of the 20 latest GitHub deliveries.
apps/web/src/features/settings/github-deliveries.tsx Adds the recent-deliveries presentation and human-readable reason labels.
packages/db/src/schema/comms.ts Adds nullable workspace attribution and its lookup index to the webhook-delivery schema.
packages/db/drizzle/0004_clear_mandroid.sql Migrates persisted webhook deliveries with the nullable workspace foreign key and composite index.

Sequence Diagram

sequenceDiagram
    participant GitHub
    participant Webhook as GitHub webhook route
    participant Installations as github_installation
    participant Deliveries as webhook_delivery
    participant Settings as Integration settings
    GitHub->>Webhook: Signed event with installation.id
    Webhook->>Installations: Resolve installation globally
    Installations-->>Webhook: organizationId or null
    Webhook->>Deliveries: Stamp organizationId
    Webhook->>Webhook: Process event and record status
    Settings->>Deliveries: Query latest rows by organizationId
    Deliveries-->>Settings: Workspace-scoped deliveries
Loading

Reviews (3): Last reviewed commit: "Merge main, and take the migration slot ..." | Re-trigger Greptile

imshashank and others added 4 commits August 9, 2026 11:45
The reason a delivery was ignored was recorded and then never shown, so
a workspace watching hundreds of accepted webhooks had no way to learn
that every one of them named no issue.

List the recent deliveries under Integrations with the reason in words,
and count the ones that arrived and changed nothing. Reading them needs
integration:manage, because the delivery table is not scoped to a
workspace.

Also cover the whole path in tests, from a signed delivery to a row on
the pulls page, including a merged pull request showing as merged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The delivery log had no workspace, so the recent deliveries list could
only be gated on a permission and still showed every workspace's traffic
to whoever could read it.

Stamp each delivery with the workspace behind its installation, which
also covers the most useful diagnostic case: a repository that is not
connected here still resolves through the installation, so the workspace
sees why its own deliveries changed nothing. A delivery no installation
here owns stays unattributed and invisible.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@imshashank
imshashank requested a review from pulkitxm as a code owner August 9, 2026 06:50
@vercel

vercel Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview Aug 9, 2026 7:03pm

Request Review

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: web The Next.js app and its UI area: database Schema, migrations, queries, seed area: integrations GitHub, Slack and webhooks labels Aug 9, 2026
@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@imshashank, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 14 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f4ba2713-0770-4ad7-a38c-33ecf395c437

📥 Commits

Reviewing files that changed from the base of the PR and between 22eb19a and fcd7792.

📒 Files selected for processing (11)
  • apps/web/src/app/(app)/settings/integrations/page.tsx
  • apps/web/src/app/api/webhooks/github/route.ts
  • apps/web/src/features/settings/github-deliveries.tsx
  • apps/web/src/features/settings/integrations-data.ts
  • apps/web/tests/app/api/webhooks/github/route.test.ts
  • apps/web/tests/features/settings/github-deliveries.test.tsx
  • packages/db/catchup/webhook-delivery-workspace-catchup.sql
  • packages/db/drizzle/0004_clear_mandroid.sql
  • packages/db/drizzle/meta/0004_snapshot.json
  • packages/db/drizzle/meta/_journal.json
  • packages/db/src/schema/comms.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The schema change alone only reaches a database someone pushes to. A
fresh install runs the committed migrations, and CI refuses a schema the
migrations do not build, so the column needs a migration of its own.

The migration is additive: a nullable column, its foreign key and an
index. Nothing is rewritten and nothing is backfilled, so an existing
install takes it without downtime and its old rows simply carry no
workspace.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
main landed 0003_cute_sway while this branch was open, so both claimed
drizzle slot 0003 and the journal conflicted on index 3. Two migrations
cannot share a slot: drizzle orders by the journal, so whichever applied
first would leave the other permanently unapplied and the deploy guard
would keep refusing to build.

main's history is the one already applied everywhere, so it wins.
0003_productive_quicksilver is dropped and the same schema change is
regenerated from the merged schema as 0004_clear_mandroid. The generated
SQL is the same three statements: the nullable column, its cascading
foreign key, and the composite index the panel query needs. No drop, no
rewrite, no backfill.

Adds packages/db/catchup/webhook-delivery-workspace-catchup.sql so a
database that is already live can take the same change by hand, which is
how this repository applies schema to production. Every statement guards
itself, so running it twice is safe.
@imshashank

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@imshashank
imshashank merged commit c594023 into main Aug 9, 2026
13 checks passed
@imshashank
imshashank deleted the feat/webhook-delivery-workspace branch August 9, 2026 19:20
imshashank added a commit that referenced this pull request Aug 9, 2026
#263 landed first and scoped the delivery query to one workspace. This
branch was written before that column existed, so its copy of
loadGithubDeliveries still filtered on provider alone, and git offered
both sides. Taking this branch's version would have quietly put the
cross workspace read back, which is the whole reason #263 went first.

main wins for the query. This branch wins for the summary, since #263
predates the outcome fix and carries the sentence that called a failed
delivery one that changed nothing.

Two tests now hold the scoping down rather than trusting the next merge
to resolve it the same way: a second workspace must not see the first
one's deliveries, and a delivery nobody could attribute belongs to no
workspace at all. Removing the organization predicate turns both red.

The delivery fixture attributes to the caller's workspace by default,
which it could not do before the column existed.
@imshashank imshashank mentioned this pull request Aug 15, 2026

This branch was successfully deployed

1 active deployment
Preview — fcd7792f Deployed Aug 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: database Schema, migrations, queries, seed area: integrations GitHub, Slack and webhooks area: web The Next.js app and its UI tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant