Skip to content

feat(control-plane): route incoming GitHub webhooks to hosted ORB tenants - #8078

Merged
loopover-orb[bot] merged 1 commit into
mainfrom
orb-webhook-routing
Jul 22, 2026
Merged

feat(control-plane): route incoming GitHub webhooks to hosted ORB tenants#8078
loopover-orb[bot] merged 1 commit into
mainfrom
orb-webhook-routing

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

Implements #7181, the last unbuilt piece of #7173's ORB side (AMS's own cron-wake orchestration, #7182, already shipped).

  • orb-webhook-router.ts: a request-time routing layer for POST /v1/orb/webhook — verifies an incoming GitHub webhook's HMAC-SHA256 signature (a hosted-fleet-specific secret, ORB_WEBHOOK_SECRET, independent of the main app's own ORB_GITHUB_WEBHOOK_SECRET, since control-plane is a separate Worker with no D1 access), extracts the installation ID, looks up the owning tenant, and proxies the still-unmodified request straight through to that tenant's own container.
  • @cloudflare/containers' Container.fetch() already wakes a sleeping container and waits for its HTTP port before resolving — no manual wake/poll loop needed here (unlike ams-wake.ts's one-shot CLI orchestration, which has no persistent HTTP server to wait on).
  • The tenant's container re-verifies the same signature independently (it runs the main app's own self-host image, completely unmodified) — this layer only changes where a verified webhook gets dispatched, not how it's authenticated.
  • tenant-registry.ts gains getByOrbInstallationId, backed by a new installation:${id} KV secondary index kept in sync on every upsert (handles re-linking and unlinking, not just first-link).
  • POST /v1/tenants gains an optional orbInstallationId field (ORB-only, rejecting a duplicate claim by another active tenant with 409); GET /v1/tenants surfaces it back, mirroring Cloudflare Cron Trigger wake scheduling for hosted AMS containers #7182's amsSchedule field exactly.

Test plan

  • npm run build (typecheck) clean
  • npm run cf:typecheck clean
  • npm run test:node — 159/159 passing
  • node ../scripts/control-plane-coverage.mjs — every touched file 100%/100%/100%/100%; only gap is the pre-existing, untouched settlement-backend-driver.ts
  • npx wrangler deploy --dry-run clean, both container images build, all bindings resolve
  • npm audit --audit-level=moderate — pre-existing findings only, no dependency changes in this PR

Closes #7181

…ants (#7181)

Adds orb-webhook-router.ts: a request-time routing layer for POST /v1/orb/webhook
that verifies an incoming GitHub webhook's HMAC-SHA256 signature (a hosted-fleet-
specific secret, independent of the main app's own ORB_GITHUB_WEBHOOK_SECRET,
since control-plane is a separate Worker with no D1 access), extracts the
installation ID, looks the owning tenant up via a new KV secondary index
(tenant-registry.ts's getByOrbInstallationId, kept in sync on every upsert), and
proxies the still-unmodified request straight through to that tenant's own
container. @cloudflare/containers' Container.fetch() already wakes a sleeping
container and waits for its HTTP port before resolving, so no manual wake/poll
loop is needed the way ams-wake.ts's one-shot CLI orchestration required.

The tenant's container re-verifies the same signature independently (it runs the
main app's own self-host image, completely unmodified) -- this layer only changes
WHERE a verified webhook gets dispatched, not how it's authenticated.

POST /v1/tenants gains an optional orbInstallationId field (ORB-only, rejecting a
duplicate claim by another active tenant with 409) to link a hosted tenant to the
GitHub App installation its container should answer for; GET /v1/tenants surfaces
it back for admin visibility, mirroring #7182's amsSchedule field exactly.

Closes #7181
@JSONbored JSONbored self-assigned this Jul 22, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 22, 2026
@loopover-orb

loopover-orb Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-22 20:43:29 UTC

10 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR implements #7181's request-time webhook router: HMAC-SHA256 verification against a separate control-plane secret, a KV-backed `installation:${id}` secondary index on tenant-registry.ts kept in sync on every upsert (including re-link/unlink), and proxying through Container.fetch() to the owning tenant. The wiring is traced end-to-end (worker.ts → http-app.ts → orb-webhook-router.ts → tenant-registry.ts) and is exhaustively tested, including the KV secondary-index cleanup paths and stale-index tolerance. This closes the explicitly linked, maintainer-authorized issue #7181 and matches the stated description precisely.

Nits — 7 non-blocking
  • control-plane/src/tenant-registry.ts upsert() reads the previous record to clean the stale installation index before writing the new one, which is a benign read-then-write race under concurrent upserts of the same tenant — worth a one-line comment noting KV's own eventual consistency already bounds this risk, but not a reachable defect in this single-writer-per-tenant deploy model.
  • control-plane/src/http-app.ts and orb-webhook-router.ts inline several raw HTTP status codes (400/401/404/409/502/503) — consider naming a few as constants purely for readability, though this matches the rest of the codebase's existing style.
  • control-plane/test/orb-webhook-router.test.ts's WEBHOOK_SECRET constant is a hardcoded test string, not a real credential — worth double-checking no CI secret-scanner false-positives on it, but no rotation is actually needed.
  • Consider whether GitHub's installation ID space could ever exceed Number.MAX_SAFE_INTEGER in practice; if so, parseOrbInstallationId (http-app.ts) and the payload.installation.id check (orb-webhook-router.ts) might want a bigint-safe path, though this is speculative given GitHub's current ID scheme.
  • The header comment in orb-webhook-router.ts is quite long (relative to the code it documents) — could be trimmed once the pattern is established, but it's consistent with this package's existing verbose-rationale convention.
  • PR author also opened the linked issue — Link an issue that was opened by a different contributor, or provide a rationale for why this self-authored issue represents genuine discovery work.
  • Possible secret-shaped assignment in the diff (generic_secret_assignment) — Verify the value is not a real credential.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #7181
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 16 registered-repo PR(s), 14 merged, 255 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 16 PR(s), 255 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: significant
Linked issue satisfaction

Addressed
The PR adds a new orb-webhook-router.ts that verifies the GitHub HMAC signature, looks up the installation ID against a new KV-backed tenant registry index (getByOrbInstallationId), and forwards the request via Container.fetch() (which wakes sleeping containers), satisfying installation→tenant lookup, request forwarding with wake-on-request, and leaving src/orb/webhook.ts and src/orb/installations

Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, Ruby, Go, JavaScript, MDX, Shell, Solidity
  • Official Gittensor activity: 16 PR(s), 255 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Treat this as maintainer-lane context rather than normal contributor-lane activity.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit dd9b6ed into main Jul 22, 2026
12 checks passed
@loopover-orb
loopover-orb Bot deleted the orb-webhook-routing branch July 22, 2026 20:43
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.46%. Comparing base (1026fb3) to head (f1d9160).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8078      +/-   ##
==========================================
- Coverage   91.98%   91.46%   -0.52%     
==========================================
  Files         748      749       +1     
  Lines       76617    76855     +238     
  Branches    23239    23277      +38     
==========================================
- Hits        70474    70297     -177     
- Misses       5041     5503     +462     
+ Partials     1102     1055      -47     
Flag Coverage Δ
control-plane 99.82% <100.00%> (+0.02%) ⬆️
shard-1 52.78% <ø> (-0.70%) ⬇️
shard-2 54.95% <ø> (-0.63%) ⬇️
shard-3 53.92% <ø> (-0.62%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
control-plane/src/http-app.ts 100.00% <100.00%> (ø)
control-plane/src/index.ts 100.00% <100.00%> (ø)
control-plane/src/orb-webhook-router.ts 100.00% <100.00%> (ø)
control-plane/src/tenant-registry.ts 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Route incoming GitHub webhooks to the correct tenant's hosted ORB container

1 participant