Skip to content

Sign-in redirects at once: GitHub's repository listing moves to a queued job on its own queue (callback 6.3 s → under 1 s) - #175

Merged
ndbroadbent merged 3 commits into
mainfrom
signin-async-sync
Dec 4, 2026
Merged

ndbroadbent merged 3 commits into
mainfrom
signin-async-sync

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Nathan's sign-in on 4 Dec 2026 took about 20 s before app.visualci.com loaded. In the cluster (Envoy's access log, via talira infra), GET /auth/github/callback alone took 6,316 ms: it listed every installation's repositories one page at a time (Nathan can reach about 650), rewrote user_repositories a row at a time, and applied memberships, all before redirecting.

What changes

  • The callback reads who they are and signs them in. It reads /user/emails only for a GitHub account no user has yet, so it makes at most 3 GitHub calls (the code exchange, /user, and that). Its counted budget drops from 22 to 1. It logs sign-in callback with elapsed_ms and github_calls.
  • SyncGithubAccess (new, forge/sign_in_sync.rs) runs on the sign-in queue:
  • Workers: talira infra has already deployed queue:work --queue=sign-in,default for the 3 workers, and a dedicated worker-sign-in running --queue=sign-in (infra cfb7b5f), so a backlog of builds can't hold a sign-in up. The journeys, CI's visual job and the self-hosting docs use the same arguments.
  • State: the migration adds users.github_sync_requested_at, github_synced_at and github_sync_error. sign_in_sync::state reads them as done, syncing, failed or sign_in_again; a listing still unfinished after 90 s counts as failed.
    • Picker (sync in its JSON):
      • while it loads, the last sign-in's repositories stay listed with "Loading your repositories from GitHub…", and the picker polls every second;
      • when it fails, "Couldn't load your repositories from GitHub." with Try again (POST /api/ui/github/sync, 6 a minute);
      • when the token has expired, Sign in with GitHub again.
    • Checklist: setup's github_sync shows "Looking for your GitHub installations…", and the org query polls while syncing.
    • /github/setup?refreshed=1 (the App-install round trip) shows "Finding your GitHub repositories…" with <meta refresh> until the listing has the installation, or an error with Try again.
  • Signing in again redirects at once. What the previous sign-in listed stays until the new listing replaces it in one transaction.
  • /status reports oldest_sign_in_sync_seconds.
  • docs/design.md is updated.

Tests

  • github_calls.rs:
    • the callback stays under 1 s with every repository page delayed 300 ms, makes only /user/emails (none when signing in again), and queues one job;
    • the listing's caps, run inline: 1 + SIGN_IN_SYNC_BUDGET calls, the per-installation counts, state done;
    • a failed listing reads as failed and keeps the last one;
    • the retry answers 409 sign_in_again without a token.
  • New journey sign-in-redirects-at-once-and-lists-after:
    • with the stub's /user/installations slowed by 3 s, the callback takes under 1 s and makes at most 3 GitHub calls, timed against the stub's new request log;
    • the picker shows the stored repositories while "Loading…";
    • a 502 from GitHub shows the error with the last list kept, and Try again lists them.
  • Run on a pool box: clippy, plus the github_calls, installations, setup, auth, abuse, oauth and mcp tests. The frontend's tsc and vitest pass too.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@visualci-com

visualci-com Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #458 · 400 unchanged · no changes

This PR vs base: 6 changed, 8 added since #407, across 3 builds

docspring/visualci · journeys · build #454 · 1 changed, 5 added, 29 unchanged · approved by visualci features agent for Nathan Broadbent

visualci subdomains: rebase of #175; the same 1 changed + 5 added as build 433, reviewed and approved there (sign-in redirects at once, listing shown after).

This PR vs base: nothing since #405, across 3 builds

Snapshot Before After
journeys/sign-in-from-the-site/02-dashboard (changed)
journeys/sign-in-redirects-at-once-and-lists-after/01-site (added) –
journeys/sign-in-redirects-at-once-and-lists-after/02-site (added) –
journeys/sign-in-redirects-at-once-and-lists-after/03-picker-refreshing (added) –
journeys/sign-in-redirects-at-once-and-lists-after/04-site (added) –
journeys/sign-in-redirects-at-once-and-lists-after/05-picker-listing-failed (added) –

Updated as builds change. Agents can review with VisualCI's MCP tools.

… GitHub calls) and a queued job on the sign-in queue lists their installations and repositories

The callback took 6.3 s for Nathan on 4 Dec 2026, listing every installation's repositories one page at a time before it redirected. Now:
- the callback reads the verified addresses only for a GitHub account no user has yet, signs them in and redirects (budget 1 counted call, plus the code exchange and /user); it logs 'sign-in callback' with elapsed_ms and github_calls
- SyncGithubAccess (queue sign-in, which workers take first and one worker takes alone) lists with the token kept from the sign-in, records installations and repositories in one statement each, and fires SignedIn for memberships
- users.github_sync_* says how it's going: the picker and checklist show the last sign-in's repositories while it loads, a failure or a listing over 90 s says so with Try again (POST /api/ui/github/sync, or Sign in with GitHub again when the token expired), and /github/setup waits on a self-reloading page until the listing has the installation
- /status reports oldest_sign_in_sync_seconds
- tests: the callback under 1 s with slow repository pages and at most 1 counted call; the listing's caps; a failed listing keeps the last one; a journey times the callback (< 1 s, <= 3 GitHub calls) and covers the failed listing and Try again
- The job has a 60 s timeout and gives up its listing after 45 s, recording a failure, so a killed run can't leave the person waiting; /status counts only listings asked for in the last 15 minutes, so one lost job doesn't alert for good
- Two listings for one person serialise: the writes, the listing counts and the done mark happen in one transaction under the person's advisory lock, and only when no newer listing has finished; SignedIn follows only the latest
- A token GitHub refuses (401) is forgotten and reads as sign_in_again, so the picker offers a new sign-in, not a Try again that can't work
- The checklist shows a failed listing with Try again too, and a failed retry says why (one GithubSyncNotice for both)
- The waiting-listings index covers only the waiting rows; docs/deploy.md names both worker commands
- The journey allows 1.5 s in the browser with the listing slowed to 8 s
@ndbroadbent
ndbroadbent merged commit 542e1ed into main Dec 4, 2026
16 checks passed
@ndbroadbent
ndbroadbent deleted the signin-async-sync branch December 4, 2026 06:36
ndbroadbent added a commit that referenced this pull request Dec 4, 2026
ndbroadbent added a commit that referenced this pull request Dec 4, 2026
ndbroadbent added a commit that referenced this pull request Dec 4, 2026
…ete (#172)

* Repository picker: the pick stays as it was, with the button on Adding…, until the importer shows

* App logo: back to the app's home, and from the app's home on to the site

* Organization settings page; setup steps can be shown again once complete

* MCP goldens show the checklist's shown state; a too-long name is the refused one

* Settings: no sideways scroll on a phone; the getting started box follows the click

* Journey: the Projects heading by its exact name

* Org page: members live in Settings, no Show setup steps link, the gear alone on a phone; Leave's reason on its own line

* Settings: an installation's kind and repositories under its account, so the table fits a phone

* MCP goldens after rebasing onto #175: github_sync beside the checklist's shown state
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