Skip to content

fix(agent): list every pull request and diff changes from the merge base - #157

Merged
kalaspuff merged 6 commits into
mainfrom
fctl/95-fix-https-github-com-hyperstructure-fctl
Oct 20, 2026
Merged

kalaspuff merged 6 commits into
mainfrom
fctl/95-fix-https-github-com-hyperstructure-fctl

Conversation

@fctl-sh

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

Copy link
Copy Markdown
Contributor

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 fix(web): close a dropdown when you tap it again on iPhone and iPad #151 also opened fix(web): stop Home's composer taking presses in its project list #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: "fix(web): close a dropdown when you tap it again on iPhone and iPad #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, 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 After: Changes lists select.test.tsx and select.tsx with "+34 −0, 1 commit, #151 merged", and Pull requests lists #151 and #152

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" The same as the light after, in the dark theme

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 After: the session page, the header names fctl#151 and fctl#152

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"

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

fctl-sh Bot added 5 commits October 20, 2026 21:15
GitState gains pull_requests, every pull request fctl-agent follows,
whichever branch, worktree or clone it came from, and unmerged, the
commits after a merged pull request's head. pulls::found reads the
list, so the control plane lists them and keeps their state current.
SessionSpec carries the session's pull requests, so an agent in a new
sandbox follows them too. All optional: older agents leave them out,
older hosts drop the spec's.

Refs #155
… base

- Changes are what the branch changed since it left its base, from the
  merge base, so a base that moves on no longer shows its commits as
  the session's, reversed, and a merged branch keeps its changes. Once
  the branch's pull request merged, from the base as it was just
  before, which covers merge commits too.
- fctl-agent follows the pull requests gh pr create prints, and those
  of the branches it looks up, in its state file, and looks them up
  again when a turn ends until they merge.
- It doesn't push a branch whose pull request merged: GitHub deleted
  it, and the new commits stay in the sandbox, with a line that says so.
  A branch whose upstream is gone, or whose pull request was open, is
  looked up before it is pushed again.
- The system prompt says to make another pull request's branch in the
  same checkout rather than in a worktree.

Refs #155
…ranches

ADR 0029 records the decisions in #155, and amends ADR 0027.

Refs #155
fctl pushes only the session branch in the clones in ~/repos, so the
system prompt's line on another pull request's branch says only what
the session shows.

Refs #155
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner October 20, 2026 21:27
main took ADR 0029 (#156): this branch's ADR is now 0030.
@kalaspuff
kalaspuff merged commit e5237d0 into main Oct 20, 2026
5 of 6 checks passed
@kalaspuff
kalaspuff deleted the fctl/95-fix-https-github-com-hyperstructure-fctl branch October 20, 2026 21:39
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.

Session pages miss pull requests from other branches and show wrong changes once main moves

1 participant