Skip to content

feat(control)!: workspaces connect GitHub accounts with a GitHub sign-in - #156

Merged
kalaspuff merged 3 commits into
mainfrom
fctl/94-currently-a-workspace-owner-that-connect
Oct 20, 2026
Merged

kalaspuff merged 3 commits into
mainfrom
fctl/94-currently-a-workspace-owner-that-connect

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Why

On an instance that hosts more than one team (app.fctl.sh), a workspace
owner who connected a GitHub account needed an instance admin to approve
it, and an instance admin could connect any installed account to any
workspace. Both are wrong: connecting an account should be the workspace's
own decision, and nobody — instance admins included — should be able to
point one person's workspace at another person's organization and have that
workspace's agents write to repositories its people never had access to.
The instance's one GitHub App can mint a writing token for every account it
is installed on, so the only thing standing between a workspace and someone
else's code was an admin's judgement.

The reason the old flow leaned on an admin: GitHub's setup redirect carries
an installation_id that anyone can forge, so naming an installation proved
nothing. The fix is to ask GitHub, as the person, instead of trusting a
redirect or an admin.

What changed

Workspaces connect GitHub accounts themselves, with a GitHub sign-in.
A workspace's admin who connects an account is sent to GitHub to sign in
with the app (OAuth, PKCE). fctl trades the code for a short-lived user
access token, reads what that person may grant, uses it once and revokes
it — no refresh token, nothing stored, the token never leaves the control
plane. fctl_domain::github::grant turns what GitHub reports into the
connection:

  • Your own account, or an organization whose every repository the app
    reaches and you administer all of
    (as its owners do): every repository,
    also those the app reaches there later.
  • Otherwise: the repositories you administer, by name, at the moment you
    connect. --repo/named repositories are kept only where you both see them
    through the installation and administer them.

The installation is found among those the token can see
(GET /user/installations), never by id alone, so connecting reveals
nothing about where else the app is installed, and a forged installation_id
finds nothing. Instance admins approve nothing and connect nothing — they
see the app's installations and the workspaces using each, and can take an
account away from a workspace (a brake, not a way in). See
ADR 0029.

A session's tokens go only to the runner it runs on. Found while
investigating cross-workspace leakage: the fleet answered any connected
runner's credential request for any session, and took any runner's start
result and Claude sign-in update. A runner serves only the workspaces its
owner added it to, so a runner of one workspace could ask for the GitHub
installation tokens or the Claude credential of a session in another
workspace and get them. The fleet now mints a session's credentials only
for the runner it is assigned to (as the session uplink already checked),
ignores a start result from a runner the session is not assigned to, and
takes a Claude sign-in update only from the runner the sign-in was sent to.

What the GitHub App needs (instance operators)

Answering the question in the session — to connect accounts after this
change, the instance's GitHub App needs:

  1. A client secret (GITHUB_CLIENT_SECRET) — the client ID was already
    configured; the secret signs workspace admins in to GitHub.
  2. A Callback URL registered: {FCTL_PUBLIC_URL}/api/v1/github/authorized.
    Leave "Request user authorization (OAuth) during installation" off —
    fctl starts the sign-in itself.

No new GitHub App permissions: reading a user's installations and their
repositories (with the per-repo permissions.admin flag) needs only
Metadata, which the app already has. Without the client secret a workspace
keeps the accounts it has but connects no new one, and its GitHub tab says
so. app.fctl.sh's admins must set GITHUB_CLIENT_SECRET and the callback
URL
(an instance-admin action this session's token can't do) before anyone
can connect a new account there.

BREAKING CHANGE: connecting a GitHub account now requires the app's client
secret (GITHUB_CLIENT_SECRET) and a callback URL
(…/api/v1/github/authorized); existing connections keep working without
them. fctl workspaces connect now opens a GitHub sign-in in the browser
instead of connecting in one call, and fctl admin github approve is gone
(instance admins no longer approve or connect). The migration drops GitHub
connections still waiting for approval; their admins reconnect them.

How verified

  • cargo xtask check (full) and cargo xtask dev --smoke pass — the smoke
    run confirms normal session start still works with the runner-credential
    change on the hot path.
  • Unit tests for fctl_domain::github::grant (own account, org owner,
    member with some admin repos, nobody-administers, named-repo refusals,
    more-than-a-connection-lists) and the new cookie.
  • Web tests for the workspace GitHub tab (the sign-in connect flow, the
    returned banners, the member view, the no-client-secret state) and the
    admin tab; web/ npm run check and vitest green.
  • The real GitHub OAuth round-trip can't run against cargo xtask dev (no
    GitHub App); the screenshots below render the real components against the
    dev stack with the GitHub API responses mocked (injected data, no
    secrets).

Screenshots

At 9fd96fe, light theme, 1280 px wide (data injected — the dev stack has no
GitHub App).

Workspace GitHub tab

Before (approval flow) After (GitHub sign-in)
Before: workspace GitHub tab, waiting for an instance admin After: workspace GitHub tab, Connect with GitHub

Before, a named account waits "for an instance admin" and the button is a
plain "Connect". After, each connection shows who connected it and the
GitHub account they signed in as, and the button is "Connect with GitHub".

After, dark, and the banner when GitHub limited the connection to the
repositories you administer:

After (dark) After signing in (limited to repos you administer)
After: workspace GitHub tab, dark After: banner saying it connected the repositories you administer

Admin → GitHub

Before (approve/connect) After (read-only, can remove)
Before: admin GitHub tab with an approval request and Connect to a workspace After: admin GitHub tab listing installations and the workspaces using each

Before, instance admins approve requests, connect accounts to workspaces and
install on other accounts. After, the tab is read-only: installations and
the workspaces using each, with the option to take an account away.

Companion PR

Privacy policy, which must merge together with this: hyperstructure/fctl-site#33

Session: https://app.fctl.sh/s/ses_01M5DG4B4WDKV44T5E9H9HY0AC

fctl-sh Bot added 3 commits October 20, 2026 21:01
…gn-in

A workspace's admin who connects an account signs in to GitHub with the
instance's GitHub App, and the workspace gets what GitHub says they may
give it: every repository of their own account, or of an organization
whose every repository the app reaches and they are an admin of;
otherwise the repositories they are an admin of. Nobody approves
requests any more, and instance admins connect nothing: they see the
app's installations and can take an account from a workspace.

The installation is looked up among those GitHub shows the person, so
that connecting doesn't reveal where else the app is installed, and the
GitHub sign-in is revoked once used.
The fleet answered any connected runner's credential request for any
session, and took any runner's start result and Claude sign-in update.
A runner serves only the workspaces its owner added it to, so a runner
of one workspace could ask for the GitHub installation tokens or Claude
credential of a session in another workspace and get them.

Now the fleet mints a session's credentials only for the runner the
session is assigned to (as the session uplink already checks), ignores a
start result from a runner the session is not assigned to, and takes a
Claude sign-in update only from the runner the sign-in was sent to.
ADR 0029, and the architecture, security, self-hosting, getting-started
and CLI guides: a workspace's admin connects an account by signing in to
GitHub, which shows fctl what they may give the workspace; instance
admins approve nothing and connect nothing, only take accounts away; the
instance needs the GitHub App's client secret and a callback URL; and a
session's tokens go only to the runner it runs on. The standalone server
passes GITHUB_CLIENT_SECRET through, and the roadmap item is done.
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner October 20, 2026 21:19
kalaspuff pushed a commit to hyperstructure/fctl-site that referenced this pull request Oct 20, 2026
)

Matches the GitHub-connection change in hyperstructure/fctl: a
workspace's
admin now connects a GitHub account by **signing in to GitHub** with the
instance's GitHub App, instead of an instance admin approving a request.
GitHub tells fctl which of the account's repositories that person may
give
the workspace.

The privacy policy is updated to match what app.fctl.sh now does:

- **Receives**: the GitHub sign-in gives fctl a short-lived token that
says
which repositories the person may grant; fctl uses it once to read that
and then revokes it. It does not sign you in to GitHub or keep the
token.
- **Stores**: each GitHub connection records who connected it and the
  GitHub account they signed in as (replacing "who asked for it and who
  approved it").
- **Sets**: a fourth cookie, `__Host-fctl-github`, protects the GitHub
  sign-in for the 10 minutes it may take.
- **Drops**: the GitHub-approval email to admins and the "asking the
admins
  to approve a GitHub account" processing purpose.

Must merge together with the fctl pull request (it alters what
app.fctl.sh
receives and stores). The fctl docs CI pins this repository when `docs/`
changes on `main`; this is a `legal/` change, unaffected by that.

fctl PR: hyperstructure/fctl#156
Session: https://app.fctl.sh/s/ses_01M5DG4B4WDKV44T5E9H9HY0AC

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
@kalaspuff
kalaspuff merged commit 166238b into main Oct 20, 2026
7 checks passed
@kalaspuff
kalaspuff deleted the fctl/94-currently-a-workspace-owner-that-connect branch October 20, 2026 21:26
fctl-sh Bot added a commit that referenced this pull request Oct 20, 2026
main took ADR 0029 (#156): this branch's ADR is now 0030.
kalaspuff pushed a commit that referenced this pull request Oct 20, 2026
…ase (#157)

Session pages missed pull requests opened from other branches, and
showed the wrong changes once `main` moved. Three causes in fctl-agent's
git state (#155), all fixed here, with the decisions from the issue.

## What was wrong

1. **Pull requests were looked up only for the checked-out branch** (`gh
pr view <branch>`). The session behind #151 also opened #152, from a
branch in a worktree, and its page never listed it.
2. **Changes were a diff against the moving tip of `origin/<base>`.**
After a squash merge the diff was empty ("No changes yet." over "+0 −0 ·
1 commit"). Once someone else's commits reached `main`, they showed
among the session's changes, reversed.
3. **A merged branch was pushed again after a resume.** `git fetch
--prune` removed the branch GitHub had deleted, `pushed` turned false,
and the next turn's push brought the branch back on GitHub.

## What changed

- **fctl-agent follows every pull request of its session**
(`crates/fctl-agent/src/followed.rs`). It follows the pull requests of
the branches it looks up, those whose URL `gh pr create` printed
(`Refresh` reads the tool's result), and those the session lists when a
sandbox starts (a new `SessionSpec.pull_requests`). Only repositories
the session may use count. The list lives in the agent's `state.json`,
so it survives restarts. fctl-agent looks each pull request up by URL
when a turn ends, until it is merged, and reports them all in a new
`GitState.pull_requests`. `fctl_domain::pulls::found` reads that list,
so the control plane lists every pull request with its current state.
- **Changes are what the branch changed since it left its base:** the
diff from `git merge-base origin/<base> HEAD`, for both `--numstat` and
`--name-status`. Uncommitted and untracked work counts as it is now, and
the empty tree stays the fallback when there is no base, or no merge
base. `GitState::files`'s doc now says so. Once the branch's pull
request is merged, the diff starts from the base as it was just before
the merge (the pull request's `baseRefOid`), so a merge commit, which
puts the branch's commits on `main`, still shows the merged work.
- **A branch whose pull request merged isn't pushed again.** If GitHub
deleted the branch after it was pushed (its upstream is `[gone]`), or
its pull request was open at the last lookup, fctl-agent looks the pull
request up when a turn ends, before it pushes. If the pull request is
merged, the commits stay in the sandbox and the transcript says `Didn't
push <branch>: its pull request #N is merged`, once per new head. A new
`unmerged` count holds the commits after the merged head.
- **Changes say a merged branch is merged:** "#151 merged" in place of
"not pushed yet", with "1 commit since, not pushed" when the agent
committed again (`whereCommits` in `web/src/lib/git.ts`).
- **The system prompt** now says fctl pushes the branch "until its pull
request is merged", and tells agents to make another pull request's
branch where the repository is checked out (`git switch -c`), not in a
worktree or another clone.
- Docs: `docs/architecture.md` (Repositories), `docs/cli.md`,
`docs/getting-started.md`, and [ADR
0030](docs/adr/0030-sessions-follow-every-pull-request-their-agent-opens.md),
which amends ADR 0027: a pull request that isn't merged is looked up
each turn, wherever it came from.

## The decisions in the issue

- *Worktrees and clones outside the checkout* ("use your recommended
approach"): fctl lists their pull requests, from `gh pr create`'s
output, and the system prompt asks agents to keep their branches in the
checkout, where Changes follows them. Changes doesn't scan worktrees:
their branches are neither shown nor pushed by fctl, and telling agents
where to work is the simpler fix.
- *New commits on a merged, deleted branch* ("It should likely be shown
if possible"): I read this as "leave them unpushed and say so". fctl
doesn't push them. The transcript says why, and Changes shows them as "N
commits since, not pushed". If you meant pushing them to bring the
branch back, that is a small change in `Run::publish`.
- *Changes once merged* ("shown as merged … with the merged work"):
Changes lists the merged work and says "#N merged".

What fctl still can't see: a pull request opened without `gh pr create`
printing its URL into the transcript (output sent elsewhere, or `gh
api`) is found only while its branch is checked out, as before.

## Compatibility

Every new field is optional. The control plane takes
`GitState.pull_requests` and `unmerged` before agents send them; older
agents leave them out and report as before. Older hosts drop
`SessionSpec.pull_requests`, and then the agent follows only what it
finds. `gh` versions without `headRefOid`/`baseRefOid` get asked again
with the fields fctl-agent asked for before, so pull requests are still
found, just without the merged-work diff base and the `unmerged` count.
Old sessions in the web app read as before. There is no migration.
Agents reach sandboxes with hosts' releases.

## Screenshots

At 41b72fc, from `cargo xtask dev`; merging `main` (#156) changed
nothing they show. Dev projects have no GitHub repository, so their
sessions never get pull requests. For these screenshots, Playwright
replaced the session's git state and pull requests in the browser with
what each version of fctl-agent reports in the issue's case: #151
squash-merged and its branch deleted, the session resumed, and #152
opened from a worktree. The page itself is the real app: `main` on the
left, this branch on the right.

The session's sidebar, light theme:

| Before | After |
|---|---|
| ![Before: Changes says "No changes yet." over "+0 −0, 1 commit, not
pushed yet", and Pull requests lists only
#151](https://app.fctl.sh/api/v1/published/buVTqu01848iLrRYX3UUj49jtmmJ7QhO7Xxs0vXdT6x/rail-before.png)
| ![After: Changes lists select.test.tsx and select.tsx with "+34 −0, 1
commit, #151 merged", and Pull requests lists #151 and
#152](https://app.fctl.sh/api/v1/published/37Md9MuKPAM15sVrVsRgVO7COhOp8QWETx1X5xr7pi2/rail-after.png)
|

After, once the agent committed again on the merged branch (left), and
in the dark theme (right):

| Commits after the merge | Dark |
|---|---|
| ![Changes says "+36 −0, 2 commits, #151 merged" and "1 commit since,
not
pushed"](https://app.fctl.sh/api/v1/published/fph75kYbfeoZvuXGMrveBXsZ4rJiQTXCDpUf6de3UAE/rail-after-more.png)
| ![The same as the light after, in the dark
theme](https://app.fctl.sh/api/v1/published/MiusrJZONhFEL3TbQM7wYsJvixso0RcsYM6Uc8kuiiF/rail-after-dark.png)
|

The whole page, 1440 px wide: the header lists both pull requests, and
the transcript's line counts the merged files.

| Before | After |
|---|---|
| ![Before: the session page, the header names fctl#151
alone](https://app.fctl.sh/api/v1/published/2bBWDb5zUrgvLmxbteJfXwzRs13SuzGPmxUTvIqN3fe/before-light.png)
| ![After: the session page, the header names fctl#151 and
fctl#152](https://app.fctl.sh/api/v1/published/WTuCtMcgyoZt1qkjUn86XuOTlP7Hgvk643c8WMftWdj/after-light.png)
|

On a phone (390 px), the details sheet, where the line after "#151
merged" wraps:

![The details sheet on a phone: Pull requests lists #151 and #152;
Changes says "+36 −0, 2 commits, #151 merged" and "1 commit since, not
pushed"](https://app.fctl.sh/api/v1/published/FvlJHmdViaxAjsI8rTdoBbPuwMrlHAqpWZCwmmAPaj6/after-more-390.png)

## How I verified it

- The issue's reproductions are now tests in
`crates/fctl-agent/src/workspace.rs`, with a stand-in `gh` that answers
from the pull requests each test gives it. They assert the fixed
behavior: after the squash merge and a resume, `files` lists `a.txt` and
the branch shows merged; the next turn's end doesn't push, and the
branch stays deleted on the fake GitHub; a new commit stays unpushed,
the transcript says why once, and `unmerged` is 1; after `main` moved
on, only `a.txt`, plus uncommitted and untracked work; the worktree's
pull request is found, and its state follows when it merges, then
lookups stop. More tests cover a branch the agent pushed without an
upstream, a merge-commit merge, and an older `gh`. With main's diff and
push code put back, three of them fail.
- Unit tests: `fctl_domain::pulls` (reading URLs from `gh pr create`
output, `found` with the list), `refresh.rs` (URLs from `gh pr create`
results only), `followed.rs` (repositories the session may use, a
branch's open or latest pull request, older `gh` output, what is due
when), the supervisor (a printed URL is reported and survives a
restart), the prompt, and `whereCommits` in the web app.
- `cargo xtask check --quick` passes.
- `cargo xtask dev --smoke` passes, and so does the same session through
`cargo xtask serve` (the control plane on workerd), since `spec.rs`
changed.

Fixes #155

Session: https://app.fctl.sh/s/ses_01M5DGT18535H8SAX2DYXH3PQV

---------

Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant