fix(jobs): keep a connection syncing when one of its accounts cannot be read

Open
#761 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
nextjs, react, supabase, typescript

Research direction

Read src/lib/jobs/sync-connection.ts and its account loop, then trace the reconnect flow in src/lib/connections/connect.ts and the adapter errors named in the issue. The work spans account level persistence, several adapters, GitHub installation checks, the connection page, and unit and Playwright tests. Done means the listed acceptance criteria pass, including the specified typecheck, lint, database tests, and connections end to end spec.

Written by the indexing model from the issue text.

Description

area: connections area: jobs bug impact: medium priority: P1 size: M

Context

Do after #760: it changes the same loop in src/lib/jobs/sync-connection.ts.

Found by the Fable pre-production review on 2026-12-02 (main at cedc1914; every line reference below re-checked on main at cde5aa3b). Source: provider connect readiness report, N5.

One account that cannot be read stops every account on its connection:

  • The account loop has no per-account handling (src/lib/jobs/sync-connection.ts:206-288): any throw goes to handleFailure for the whole connection (:113-114).
  • A 404 is invalid_response (src/lib/adapters/errors.ts:164), which a deleted Supabase project hits on its first request (src/lib/adapters/supabase/index.ts:826-834).
  • An account the credential no longer covers throws a plain Error (src/lib/adapters/vercel/index.ts:1025, src/lib/adapters/stripe/index.ts:1096, src/lib/adapters/digitalocean/index.ts:1329), which counts as internal_error (sync-connection.ts:386) and is retried every hour.
  • A reconnect upserts the accounts the new grant lists and never retires the rest (src/lib/connections/connect.ts:184-196), so an account the grant dropped stays included.
  • GitHub's sync never checks that the account belongs to the installation it mints a token for (src/lib/adapters/github/index.ts:475-495), so after a reconnect that grants another installation, the new account's figures can be stored under the old account.

Impact: one deleted Supabase project, an unshared Railway workspace, or a reconnect that grants another team stops the whole connection, with "did not answer" copy that points at the provider (sync-connection.ts:357). Every other account on it goes stale. #529 covers the simulated case only.

Plan

  1. Catch an account's failure inside the loop: record it on that account (a new external_accounts column for the last error code and reference), log it with a reference, and continue with the next account.
  2. Fail the connection only when every account failed, or when the error is connection wide (auth_revoked, permission_missing, rate limit).
  3. On reconnect, mark an included account the new grant no longer lists as not covered (skip it in sync, show it on the page) instead of leaving it included.
  4. Replace the plain Errors for an uncovered account with a typed adapter error, so it is classified as "account not covered", not internal_error.
  5. GitHub: refuse an externalAccountId that is not the installation's account before minting a token.
  6. The connection page names a failing or uncovered account and what to do.

Acceptance criteria

  • A failing account is named on the connection page with a reference, and the other accounts still sync (unit test).
  • After a reconnect, an included account the grant no longer lists is skipped and marked on the page (unit test).
  • GitHub refuses an account id that is not its installation's (unit test).
  • The Vercel, Stripe, and DigitalOcean "not covered" errors are typed and not retried as internal_error.
  • Playwright e2e covers the connection page notice, with an axe scan and a keyboard pass.

Files and areas

src/lib/jobs/sync-connection.ts, src/lib/connections/connect.ts, src/lib/adapters/errors.ts, the three adapters named above, src/lib/adapters/github/index.ts, a migration for the account level error, src/app/w/[workspace]/connections/[connectionId]/page.tsx, their tests.

Non-goals: the sync deadline (#{n4}), the connection level failure copy (separate issue), simulated reconnects (#529).

Verification

npm run typecheck, npm run lint, npx vitest run src/lib/jobs src/lib/connections src/lib/adapters, npm run test:db, the connections e2e spec.


Branch: <issue-number>-account-failure-isolation

Model: anthropic/claude-opus-5-5 | Reasoning effort: unknown

Dominant language
TypeScript
Stars
13
Forks
2
Avg merge
5h 20m
Merged PRs (30d)
287

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from eddiejaoude/StackDash

All issues in eddiejaoude/StackDash

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.