Skip to content

feat(relay): additive account_id re-keying for GitHub + Linear integrations#821

Merged
arul28 merged 6 commits into
mainfrom
ade/accounts-integration-rekey-0ce031df
Jul 15, 2026
Merged

feat(relay): additive account_id re-keying for GitHub + Linear integrations#821
arul28 merged 6 commits into
mainfrom
ade/accounts-integration-rekey-0ce031df

Conversation

@arul28

@arul28 arul28 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Integration re-keying under the Clerk account (additive / dual-key)

Keys the GitHub-App install + Linear workspace to the Clerk account so any signed-in machine auto-subscribes and revocation is single-place. Strictly additive — the live webhook relay's behavior is unchanged for every existing caller.

  • New nullable account_id on github_app_repositories / github_events / linear_organizations / linear_events (additive migrations; existing rows → NULL = legacy, routes exactly as today).
  • Account path added alongside the legacy path (dual-key): the relay verifies an optional x-ade-account-token (jose JWKS, RS256, exact issuer, exp, sub — same as the feat(account-directory): Clerk-verified machine directory Worker #814 directory Worker) and authorizes listing repos/orgs whose stored account_id matches the token's sub — layered on top of the unchanged assertGitHubRepoAuthorized / Linear token↔org gates. Either path authorizes.
  • Stamping: on register/status with an account token, account_id is stamped on the mapping via coalesce (never nulls an existing association).
  • Revocation: clears an account's mappings → removes account-path access for all the user's machines at once; the legacy per-machine path is unaffected.
  • Desktop/headless ingress sends the account token as a separate header, preserving the provider Authorization exactly.

Legacy safety: no existing route, PK, token shape (ade_proj_…), signing secret, webhook verification, cursor, or fan-out model was replaced; the ade_proj_ scheme is retained, not retired. 43 legacy relay tests unchanged + a byte-identical NULL-legacy-path test prove delivery is unaffected.

Tests: 46/46 relay (JWKS verify, byte-identical NULL legacy, stamping, isolation, dual-key access, listing, revocation) + 91/91 desktop ingress + 13/13 account + wrangler dry-run + typechecks green.

Deploy (pending): the relay needs three Clerk config values set as Worker vars (documented in apps/webhook-relay/README.md); no deploy performed here.

🤖 Generated with Claude Code

ADE   Open in ADE  ·  ade/accounts-integration-rekey-0ce031df branch  ·  PR #821

Summary by CodeRabbit

  • New Features
    • Added account-based authentication for GitHub and Linear integrations.
    • Added account-scoped integration access, event visibility, and integration unlinking.
    • GitHub and Linear relay requests can now use signed-in account credentials.
  • Bug Fixes
    • Improved integration access when legacy authorization credentials are unavailable.
    • Preserved support for existing project and legacy authentication flows.
  • Documentation
    • Added setup guidance for account authentication and local relay builds.

Greptile Summary

This PR adds account-based relay access for GitHub and Linear integrations. The main changes are:

  • Adds nullable account_id fields and unlink tombstones for GitHub and Linear mappings.
  • Verifies Clerk account tokens with JWKS, issuer, audience, subject, and expiration checks.
  • Allows relay status, event polling, integration listing, and unlinking through the account path.
  • Forwards x-ade-account-token from desktop and headless clients without replacing provider Authorization headers.
  • Keeps legacy ade_proj_, GitHub, and Linear authorization paths available.

Confidence Score: 5/5

Safe to merge with low risk.

The account path is additive and the legacy provider/project-token paths remain intact. The previously reported expiration and mapping overwrite issues are addressed by required exp claims and null-only account stamping with unlink tombstones. No new blocking correctness or security issues were found in the reviewed changes.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • Captured the before-scope webhook relay test log to verify the verbose relay test command and the 47/47 pass result.
  • Captured the after-scope webhook relay test log to verify the same verbose relay test command and the 47/47 pass result.
  • Verified that typechecking completed with exit code 0 for both before- and after-scope runs.
  • Verified that Wrangler dry-run builds completed with exit code 0 for both before- and after-scope runs.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
apps/webhook-relay/src/relay.ts Implements additive Clerk account authentication, account-scoped GitHub/Linear event reads, mapping stamping, listing, and unlink revocation.
apps/webhook-relay/test/account.test.ts Adds account re-keying tests for JWT validation, legacy-null behavior, dual-key access, isolation, and unlink tombstones.
apps/webhook-relay/migrations/0005_account_integration_rekey.sql Adds nullable account_id columns and indexes for GitHub and Linear mappings/events.
apps/webhook-relay/migrations/0006_account_integration_unlink_tombstones.sql Adds nullable unlink tombstone columns used to prevent immediate restamping after account revocation.
apps/desktop/src/main/services/automations/automationIngressService.ts Allows hosted GitHub relay polling via account token when GitHub app user auth is unavailable.
apps/desktop/src/main/services/automations/linearIngressService.ts Adds optional account token header support for Linear registration and polling.
apps/desktop/src/main/services/github/githubRelayConfig.ts Defines the account relay header and includes it on hosted GitHub status requests when available.
apps/ade-cli/src/services/account/accountAuthService.ts Adds a helper that returns a trimmed account access token or null while preserving legacy auth on failures.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Client as ADE desktop/headless
participant Account as AccountAuthService
participant Relay as Webhook Relay
participant Clerk as Clerk JWKS
participant DB as D1 mappings/events
participant Provider as GitHub/Linear API

Client->>Account: getSignedInAccountAccessToken()
Account-->>Client: Clerk access token or null
Client->>Relay: Relay request + provider Authorization and/or x-ade-account-token
Relay->>Provider: Verify legacy GitHub/Linear authorization when present
Provider-->>Relay: Authorized repo or org, or auth error
alt account token present
    Relay->>Clerk: Verify RS256 JWT via JWKS
    Clerk-->>Relay: Valid sub, audience, issuer, and exp
    Relay->>DB: Match or stamp account_id on repo/org mapping
end
Relay->>DB: Read account-scoped or legacy events/listings
DB-->>Relay: Matching integrations/events
Relay-->>Client: Status, events, integrations, or unlink result
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Client as ADE desktop/headless
participant Account as AccountAuthService
participant Relay as Webhook Relay
participant Clerk as Clerk JWKS
participant DB as D1 mappings/events
participant Provider as GitHub/Linear API

Client->>Account: getSignedInAccountAccessToken()
Account-->>Client: Clerk access token or null
Client->>Relay: Relay request + provider Authorization and/or x-ade-account-token
Relay->>Provider: Verify legacy GitHub/Linear authorization when present
Provider-->>Relay: Authorized repo or org, or auth error
alt account token present
    Relay->>Clerk: Verify RS256 JWT via JWKS
    Clerk-->>Relay: Valid sub, audience, issuer, and exp
    Relay->>DB: Match or stamp account_id on repo/org mapping
end
Relay->>DB: Read account-scoped or legacy events/listings
DB-->>Relay: Matching integrations/events
Relay-->>Client: Status, events, integrations, or unlink result
Loading

Reviews (6): Last reviewed commit: "ship: iteration 5 — contain account cred..." | Re-trigger Greptile

…ations

Keys the GitHub-App install + Linear workspace to the Clerk account so any
signed-in machine auto-subscribes and revocation is single-place. Strictly
additive: nullable account_id columns (NULL = legacy, routes as today); an
optional JWKS-verified x-ade-account-token authorizes when the mapping's
account_id matches the token sub, layered on top of the unchanged
assertGitHubRepoAuthorized / Linear token-org gates (dual-key, either
authorizes); coalesce stamping never nulls an association; account-scoped
revocation leaves the legacy path untouched. No route/PK/token/secret/
fan-out replaced; ade_proj_ retained. 43 legacy tests unchanged + a
byte-identical NULL-legacy test; 46/46 relay + 91/91 ingress + 13/13
account green. Deploy needs 3 Clerk Worker vars (README).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored Preview Jul 15, 2026 7:02am

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds signed-in account-token retrieval, propagates account credentials through CLI and desktop relay clients, and enables Clerk-authenticated account ownership, authorization, listing, unlinking, and persistence in the webhook relay while preserving legacy authentication paths.

Changes

Account-token integration

Layer / File(s) Summary
Account token retrieval and wiring
apps/ade-cli/src/services/account/*, apps/ade-cli/src/bootstrap.ts, apps/ade-cli/src/headlessLinearServices.ts, apps/desktop/src/main/main.ts
Adds signed-in account-token resolution and injects it into GitHub, Linear, automation, and headless services.
Desktop relay credential selection
apps/desktop/src/main/services/automations/*, apps/desktop/src/main/services/github/*
Adds conditional x-ade-account-token handling alongside existing relay authorization headers.
Relay account authentication and persistence
apps/webhook-relay/src/relay.ts, apps/webhook-relay/migrations/*, apps/webhook-relay/package.json, apps/webhook-relay/README.md
Adds Clerk JWT verification, account mappings and indexes, account-aware GitHub and Linear authorization, and /account/integrations listing and unlinking.
Account integration validation
apps/webhook-relay/test/account.test.ts
Tests JWT validation, legacy compatibility, account re-keying, isolation, and revocation.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • arul28/ADE#684: Related hosted-relay authentication changes in desktop GitHub and automation polling.
  • arul28/ADE#815: Related shared AccountAuthService wiring used by the new account-token callbacks.

Suggested labels: desktop

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: additive account_id re-keying for GitHub and Linear integrations in the relay.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ade/accounts-integration-rekey-0ce031df

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.

@arul28

arul28 commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@copilot review but do not make fixes

Comment thread apps/webhook-relay/src/relay.ts Outdated
@arul28

arul28 commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d6c8bd553

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/webhook-relay/src/relay.ts Outdated
@arul28

arul28 commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Comment thread apps/webhook-relay/src/relay.ts
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 59649aacce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/webhook-relay/src/relay.ts`:
- Around line 1318-1323: The account-authenticated event and cursor queries in
apps/webhook-relay/src/relay.ts lines 1318-1323 and 1931-1935 must retain the
fallback account ID and filter by account_id; preserve unfiltered queries only
for successful legacy authorization. Update the fake database in
apps/webhook-relay/test/account.test.ts lines 109-135 to enforce account
predicates, and extend lines 436-458 with same-repository/organization events
owned by another account, asserting those events are excluded.
- Around line 2016-2028: Make account unlinking durable across all affected
sites: in apps/webhook-relay/src/relay.ts lines 2016-2028, persist an unlink
tombstone or use an explicit unlink operation when handling DELETE; in relay.ts
lines 1560-1562 and 1770-1775, prevent automatic GitHub repository and Linear
registration from reclaiming explicitly unlinked accounts; in
apps/webhook-relay/README.md lines 94-96, document the durable unlink behavior;
and in apps/webhook-relay/test/account.test.ts lines 479-498, repeat status and
registration with both credentials after DELETE and assert ownership remains
revoked.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66bb24aa-d608-4781-8b3c-254cea0ba5aa

📥 Commits

Reviewing files that changed from the base of the PR and between de10485 and 59649aa.

⛔ Files ignored due to path filters (1)
  • apps/webhook-relay/package-lock.json is excluded by !**/package-lock.json, !**/package-lock.json
📒 Files selected for processing (17)
  • apps/ade-cli/src/bootstrap.ts
  • apps/ade-cli/src/headlessLinearServices.ts
  • apps/ade-cli/src/services/account/accountAuthService.test.ts
  • apps/ade-cli/src/services/account/accountAuthService.ts
  • apps/desktop/src/main/main.ts
  • apps/desktop/src/main/services/automations/automationIngressService.test.ts
  • apps/desktop/src/main/services/automations/automationIngressService.ts
  • apps/desktop/src/main/services/automations/linearIngressService.test.ts
  • apps/desktop/src/main/services/automations/linearIngressService.ts
  • apps/desktop/src/main/services/github/githubRelayConfig.ts
  • apps/desktop/src/main/services/github/githubService.test.ts
  • apps/desktop/src/main/services/github/githubService.ts
  • apps/webhook-relay/README.md
  • apps/webhook-relay/migrations/0005_account_integration_rekey.sql
  • apps/webhook-relay/package.json
  • apps/webhook-relay/src/relay.ts
  • apps/webhook-relay/test/account.test.ts

Comment thread apps/webhook-relay/src/relay.ts
Comment thread apps/webhook-relay/src/relay.ts
@arul28

arul28 commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ea7b8c7c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/webhook-relay/src/relay.ts
@arul28

arul28 commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a54da5222

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/webhook-relay/src/relay.ts
Comment thread apps/desktop/src/main/services/automations/automationIngressService.ts Outdated
@arul28

arul28 commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 1370601839

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@arul28
arul28 merged commit 0c93b5a into main Jul 15, 2026
32 checks passed
@arul28
arul28 deleted the ade/accounts-integration-rekey-0ce031df branch July 15, 2026 13:12
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