Node Pull Request
Stored records, pure decisions, and the background check behind the draft pull request of a task worktree's branch, from its push to its restack and its checks.
Node pull request records and the decisions around them hold the draft pull request of one generation of a task worktree's branch, and a session's decision to publish. ag-store keeps the records, ag-session the pure decisions, ag-git the history read and the lease push, and ag-forge the pull request. A background check decides for each session whether its node worktrees may be published, pushes those that may, opens or adopts their draft pull requests, restacks their branches, links them into forge stacks, and follows up on their checks. Nothing records the user's decision yet, so no worktree gets that far.
Lifecycle🔗
stateDiagram-v2
[*] --> publishing: intent recorded
publishing --> pushed: remote holds it
pushed --> open: found
pushed --> merged: found finished
pushed --> closed: found finished
open --> merged
open --> closed
merged --> [*]
closed --> [*]merged and closed are final; a later attempt starts the next generation.
Records🔗
- Node pull request: keyed by session, worktree, and generation from 1, with the graph node, its state, the remote, head, and base branches, the base worktree when it stacks on one, the intended and pushed commits, the forge's identifier, kind, address, title (at most 256 characters), and draft flag, and a problem of at most 300 characters that says why publishing is stuck. A forge stack number is stored once the host links a stack and the forge answers one. The store reads the latest generation or any earlier one. It outlives its worktree and is deleted with its session.
- What the host last read: while the latest generation is open, whether the forge shows it as a draft, when, and a summary of its checks of at most 300 characters. An older read never replaces a newer one.
- Follow-up ledger: each open generation keeps the fixes started and the findings handled, replaced only from the ledger its caller read, so of two callers only one raises the count.
- Publish decision: one per session, naming the remote, the normalized repository URL, and the commit identity (
commit_nameandcommit_email) the user's confirmation named, and whether they allowed it. Consent covers only that remote and repository, and a decision without an identity allows nothing. - Session's Git directory:
session.repository_common_dir, the common Git directory the host resolved from the project's stored path, never from the session folder. It is recorded when the session makes its first node worktree, or, for an older session, the first time the check reads one, and then stands. A session folder leading to another repository makes no node worktree. - Session's remote:
session.remote_fetch_urlandsession.remote_push_urls, the addresses oforiginread from the project's checkout when the session's worktree is made, before any agent works in it, and at no other time: no push, poll, or read writes them. The first record stands. The publish decision's repository comes from it, every push and remote read names it, and a node folder whoseoriginnames another address is not published. - Confirmed remote:
session.remote_confirmed_at, set when the user confirms the session's addresses, or when the session records the addresses the project already confirmed inproject_remote; see Confirming the remote. A recorded remote that is not confirmed is never pushed to or fetched from, and the node worktrees of such a session reportRemoteNotConfirmed. Theproject_remoterow also holds the only addresses the project's own branch sync and background fetch reach; they never read the liveoriginfor them. - Why there is no remote:
session.remote_unavailable, the reason the host kept no remote when it made the worktree: noorigin, a local path where agents write, or a failed read. A session with neither a remote nor a reason started before the record. Neither takes a remote from the repository's configuration later, and the node worktrees of such a session reportRemoteNotRecorded.
Guarantees🔗
- Every transition names the generation the caller read and is a compare-and-set on its stored state and commits: a push is recorded only for the commit the host intended, a lookup only after the push, and a new intent replaces only the intent it read, so a restart repeats no step and a late answer about an earlier generation changes nothing.
- A merged or closed generation is never opened again; the next generation expects the remote branch to hold the commit the last one pushed. An intent that builds on another session's work is refused.
- A finished generation's unresolved intent is accepted only until the next generation has pushed.
Decisions Around the Records🔗
| Item | Crate | Decides |
|---|---|---|
ExecutionGraph::worktree_settled | ag-session | Whether the owner succeeded and no node of the worktree waits or runs |
NodePublishCheck | ag-session | The first wait or problem, in the stages below |
NodePublishStep::next, NodePushNext::after_remote_read | ag-session | The next step from the record, the local head, a push, and the remote's head |
NodePullRequestChoice::choose | ag-session | Whether a lookup's pull requests are adopted, final, or leave a create to make |
reword_plan, GitClient::reword_commits | ag-session, ag-git | Which commits of a branch are rebuilt with cleaned messages, and the rebuild in one compare-and-set |
NodePullRequestText::compose | ag-session | The title and body: host lines, then the cleaned commit message |
node_stacks, plan_restacks, recover_restack, settle_restack_fix | ag-session | Which pull requests form a stack, which branches move onto a new base, and how a crash ends one |
plan_node_follow_up, fixer_node | agentty | What the host does about a pull request's checks, and the fixer node it starts |
GitClient::push_commit_with_lease, remote_refusal, remote_branch_head | ag-git | One exact commit pushed against an explicit expected value, and which remotes qualify |
GitClient::is_ancestor | ag-git | Whether a restacked branch's history reaches its new base, for restack recovery |
GitClient::read_commit_range, fetch_branch_tip, object_store_refusal, tracks_lfs_files | ag-git | A worktree's history as a push would send it, the target branch's tip, the object store, and LFS use |
GitClient::commit_node_changes, global_commit_identity | ag-git | The identity node commits are written and committed under |
AppServices::check_node_publishing | agentty | Runs the stages for one session in the background, keeps what it found in memory, and acts |
App::follow_up_node_checks | agentty | Stores a poll's follow-up ledger, then adds the fixer, asks for the rerun or ready, or writes the notice |
NodePublishCheck goes through its stages in one order, each reached only through the one before: an admitted forge (GitHub only in this version), a remote Git pushes to, consent for that remote and repository and under a commit identity, the worktree, and its base. A host stops at the first stage that holds a worktree back, so on a remote Agentty cannot publish to it never reads or asks for consent. AppServices::check_node_publishing runs after a dispatch pass settles nodes of a graph with a worktree of its own, and at startup, reading the remote's configuration first, then the decision, then each worktree under its Env gate for reading, in its own folder. A worktree found ready keeps the base, head, and identity it was read at, and a later run does not read that history again while all three are the same.
The worktree is publishable once it is ready and settled, clean, on its own branch, and holds commits whose messages, from its base commit on, are all in their cleaned form (the host rewords its own unclean ones first) and that the decision's identity alone wrote and committed. A worktree waits instead while another host step holds its Env gate, while its repository is shallow, or while its folder pushes to a remote the decision does not cover. Its base must be the session's base branch, the published session branch holding its base commit, or a worktree whose pull request is open on its pushed commit; one closed, merged, or pushed again stops it, and a stacked one waits while the pull request below it is not open on its pushed commit. A new intent is never begun over one not yet resolved against the remote, so a push the host made but did not record is never read as someone else's.
GitClient::read_commit_range reads a worktree's history from its base commit to its branch's head by their IDs, as the objects a push would send: the host hashes each commit and requires it to match its ID, and every parent to be in the range or the base. A commit whose headers are not those Git writes, or whose message is empty, holds a NUL byte, or is not UTF-8, is unclean. A range of more than MAX_RANGE_COMMITS (1,000) commits, a commit larger than MAX_COMMIT_BYTES (64 KiB), or history reaching below the base another way waits with its own wording. A commit another identity wrote or committed waits with a wording that names it.
Node commits are written and committed under the decision's identity through GitClient::commit_node_changes, which an amend resets the author to. Before the user decides, they go under the identity the user's global Git configuration sets, when it names one (GitClient::global_commit_identity), never the repository's, which an agent can write; a commit made without one waits at the check.
clean_forge_title removes hidden characters and breaks mentions, issue references, and CI skip markers, keeping a title's markup as plain text, within 120 characters; it also drops leading draft markers such as Draft: and [WIP]. clean_forge_markdown also breaks or escapes markup that could hide text, within 4,000: HTML, images, definitions, and quick actions, with the info string of every code fence dropped. The header of forge_text.rs lists every rule and what they leave uncovered.
Rewording🔗
A cleaner that changed since a node's commits were made leaves messages a forge could show as a mention or an issue reference. When the publishing check finds one, and only then, reword_plan decides from the messages of the range, oldest first, what to do. A commit is the host's own when its message ends with Agentty's trailer after a blank line. From the first unclean commit up, every commit is rebuilt, so every one must be the host's own: the unclean messages are cleaned, a message that cleans to nothing becomes Update node with the start of the worktree's id, and the rest keep their messages. An unclean commit that is not the host's own, or one that is not above the first unclean commit, makes the plan foreign and the worktree waits with ForeignUncleanCommit.
GitClient::reword_commits rebuilds the commits from objects the host hashed, copying each tree, author, and committer line, changing only the parent and the message, and dropping a signature; commits below the first change keep their IDs. It moves the branch with one compare-and-set update-ref, so a crash or a concurrent writer leaves the old head or the new one, and a branch that moved since the head was read stays as it is. A merge commit, a root commit, odd headers, a head the base already holds, or a range larger than the host reads are refused, and the worktree waits with UnrewordableCommitHistory; the whole range is checked, so a merge below the first unclean commit refuses too. The checkout keeps the same trees, so a worktree on the branch stays clean.
The host takes the worktree's Env gate for writing, reads again that the worktree is settled, clean, and on its own branch with no restack stored, and that its object store is still the one recorded. It rewords only when the pull request is not merged or closed, which would begin another generation for finished work, and no other worktree built on the branch lacks a pull request, since a restack moves only branches that have one; the worktree waits with UncleanCommitMessage or UncleanCommitUnderDependents. Then it rewords, writes one notice for the new head, and gives the gate up; the check then reads the worktree once more and goes on from the new head. A branch already pushed goes out as it does after any new head, under the lease of the commit pushed before, so its pull request stays, and a branch built on it restacks onto the new head. A second run finds every message clean and changes nothing. A commit written while the project leaves out the trailer is not the host's own, so an unclean message in it waits with ForeignUncleanCommit.
Push🔗
A worktree found publishable is pushed in the same hold of its gate, once the session's stages, read again, still allow it at the address and under the identity the worktree was compared with.
- A record already on the worktree's head reaches no remote.
- Otherwise its head must store no file through LFS (
tracks_lfs_files, by the.gitattributesfiles of the commit pushed alone, never the repository's own attribute files or configuration), and the branch its pull request targets must be on the remote with a tip that reaches its base commit through objects the host hashed: an absent branch or one too far ahead waits, and a tip that does not reach the base is a problem. - Its intent is then recorded, resolved against the remote branch, and pushed by ID under the lease of the last push.
- A problem is stored on the latest unfinished generation, a rejection with the remote's own lines (at most 400 characters), and the same head is not pushed again after a rejection or after its branch was found holding someone else's commit.
- The push and its reads name the worktree's own address, which must be the session's, run no hook, and fix their own options; what the push publishes, such as workflow files, can still run on the forge.
Isolated Git🔗
push_commit_with_lease, remote_branch_head, and fetch_branch_tip run in a host-owned empty bare repository that names the address literally and uses the repository's objects, so nothing the repository configures takes part, such as a credential helper, a proxy, an address rewrite, or a remote helper; the user's global and system configuration still apply.
- They speak only HTTPS, SSH, and local paths, and no user name or token the address carries reaches an error. A push the remote rejects keeps the remote's own lines.
- Their objects come from the session's recorded Git directory. Git still follows a link at
objectsorobjects/infoand reads alternate object directories, which the host trusts none of, so they refuse a store with any of those, andobject_store_refusalnames it for the check, as it does a worktree whose common Git directory is not the recorded one. No alternate directory from the host's environment reaches them. remote_refusalrefuses a remote that is missing, a mirror, has several addresses, pushes elsewhere, names a remote helper, or is at another kind of address.
Pull Request🔗
Once the branch holds the head, the same hold takes the forge's part.
- A pushed record looks up the branch's pull requests in any state, and
NodePullRequestChoice::chooseadopts an open one into its base, records a merged or closed one as final, never opened again in that generation, and leaves out the finished ones of earlier generations. - With none, the host opens the draft from
NodePullRequestText::composeof the head commit's message, only while the record is still the pushed latest generation on the same commits and the worktree is ready. A create that fails is followed by exactly one more lookup, which adopts what it may have opened anyway. - A new head of an open record first reads that pull request: still open, the head is pushed to it in place; merged or closed since, that is recorded and the next generation opens a new draft.
- The stored address is one the forge adapter composes from the remote and the number (
ForgeRemote::review_request_url), never an address the forge answered, and an adopted title is cleaned, or the host's own when nothing is left. - Each record transition that applies hands the reducer one
[Pull Request]notice throughAppEvent::SessionWorkflowNoticeWritten, worded with the forge's own noun and display identifier, so it is written at most once: a later run never repeats it, and an exit before the reducer stores it loses it. A stored problem that changed says so once too.
Polling🔗
An open node pull request is polled beside the scheduled review-request pass, about once a minute, for the active page's sessions only, done ones included. A forced refresh, as after each turn, leaves it to the schedule, since the publisher reads its own pull request after each push.
- Each pass reads its targets from the store, the latest generation of each worktree that is open on a forge, and visits each once per round in a fixed order, at most four forge reads per pass, so five open drafts are read four, then one.
- A read takes the pull request's state and, while it is open on the commit the host pushed last, its checks and conflicts for that commit; another head, or checks of a commit pushed between the two reads, is said as such.
- A target whose reading repeats three times is read every fifth pass unless its checks are running, a failing one backs off exponentially, its third failure in a row is said once, and a forge CLI that is missing or signed out, or a second failed read, ends the pass.
- The reducer drops a reading taken under an earlier sync context and stores the rest by compare-and-set, dated when the read began: an open reading only while its generation is the latest, open, on the commit the poll compared, and not older than what is stored.
- A merged or closed reading finishes the record and is said in one
[Pull Request]notice, as a draft when the record last showed one, whichever of the poll and the publisher's own read saw it first. - The stored summary is the host's wording, the graph view's row text:
ready for reviewfirst when it is not a draft, thenconflicts with <base>, failed and held check counts,checks running, and otherwisechecks passed,checks skipped, orno checks reported. A conflict is said as<base> is not on the remoteorits branch is not on the remotewhen the remote lacks one of them.
Freeing a Merged Worktree🔗
A merge is the one proof that lets Agentty delete a node's commits. The reducer starts a reconcile of the session after it records a merge; reconciliation also runs after nodes settle and at startup, so a worktree kept for now is tried again. For each ready worktree whose latest record is merged, SessionManager::merged_node decides in this order, and keeps the worktree, storing the reason as the record's problem, at the first step that fails:
- The owner node has stopped: succeeded, failed, canceled, or withdrawn. An ended session or a worktree recorded without an owner skips this step; an owner no graph shows keeps the worktree. A worktree its node still works in costs no forge read.
- The forge shows the pull request merged, read by its stored display id, and its head is the commit the host pushed last; a merge from a commit the host did not push is kept, and so is a failed read.
- Under the cleanup lane and both Env gates,
Integrated { merged_head }finds the branch atmerged_head, the checkout on that branch, and the folder clean, and retirement finds no node working in or still to run in the worktree. Clean means no tracked or untracked change; ignored files, such as build output, go with the folder as with every removal.
Then the worktree and its branch go and one [Worktree] notice says Removed the worktree of node "api": draft #12 was merged, with the display id as stored. The record outlives the worktree and its reason clears; the remote branch and the pull request are never touched. A worktree the proof does not cover falls back to the ordinary reasons, which remove it only when it holds nothing.
Inspector Row🔗
The graph inspector draws each record as a row under its node. NodePullRequestLine::of is a pure projection of one record and its place among the graph's stacks, see Pull Request Stacks, in the host's words: the forge's short noun and display identifier, its state, what the host last read of an open one, its stack, and the stored problem, never the forge's title. On a merged record the stored problem is why the worktree was kept, shown after worktree kept:. A worktree without a record has no line. The row is not a node, so selection and the node list's scrolling treat it separately. v opens the stored address only when it equals ForgeRemote::review_request_url for the repository's origin remote and the stored display identifier; the record is not trusted on its own. Discarding a worktree or canceling a node leaves its open pull request open; see Generated Graph Proposals.
Pull Request Stacks🔗
node_stacks reads which node pull requests form a stack from the graph's shape alone. It takes a session's members in graph order, each with its base worktree, its pull request's display identifier, and whether that pull request is open; a worktree listed again counts only once.
- A chain starts at a member that is open and has an identifier whose base is not such a member, and follows the first such dependent in graph order. Another dependent of the same base keeps the base its pull request opened with.
- A member that merged, closed, or has no identifier yet ends the chain below it, and the member above it starts a new chain. A chain of one is no stack.
- The same members always give the same chains, so linking one again repeats the same call.
The host reads each graph's records in the order records_in_graph_order gives and links a chain with ReviewRequestClient::link_stack, on the branch its bottom targets, once a member holds neither a stack number nor the stack-link key in its follow-up ledger: when a dependent's pull request opened on it. A number the forge answers, or one a member already holds, is stored on each member through record_node_pull_request_stack, which writes only the open latest generation. A link without a number, or one the forge did not make, puts the stack-link key in each member's ledger instead, so the chain is offered again only once it gains a member. A link not made also stores stack_unavailable_key of its reason in each ledger, and the chat gets the stack_unavailable_notice only after one such ledger write applied and only while no latest record of the session kept that key before, so it says so once per session and kind of reason. The notice names the pull requests by the addresses the remote composes, and leaves the command out when the branch or an address holds a character a shell could misread. A chain of merge requests on GitLab is never offered. A failed call, such as one without authentication, is offered again by the next run. node_stack_places gives each record its NodeStackPlace from the graph's records and the worktrees whose ledger keeps the link key without a reason: its stored stack, in a stack without a number, base set by hand for an open one, left out of a line, or a forge without stacks.
Restacking🔗
plan_restacks decides which node branches move onto a new base, from facts the host reads in bottom-up order. A branch moves only while it is settled: no node runs there, nothing is uncommitted, no restack of it is stored, its pull request has not merged, and it holds exactly the commit last pushed, so a commit the user added locally is never rebased.
- A branch built on a node moves onto that node's pushed commit once it differs from its base commit, or, once that node's pull request merged, onto the fetched tip of the branch it merged into. The merged node's worktree need not be listed, since the host reads the merge from its record (
RestackBase::MergedNode); a branch that moved onto that branch is built on that branch from then on: on the node it belongs to, which moves it again once that node merges in turn, or else on a repository branch, which restacks it only while the forge reports a conflict, like any branch on one. - A branch built on a repository branch moves onto its remote tip only while the forge reports a conflict, never when it is only behind, and never while that branch is not on the remote.
- Restacks go bottom up: a node that moves or has a stored restack holds everything built on it until a later plan.
recover_restackends a restack a crash interrupted: a rebase under way is abandoned, a branch whose history reaches the new base finishes, one still on its old head is abandoned, and anything else is stuck and left for the user.settle_restack_fixdecides how a restack whose conflicts a fixer node resolves goes on: it waits while the fixer is in the graph and unsettled, finishes for a clean worktree whose branch holds a commit on the new base without conflict markers, and otherwise abandons, as it does for a fixer that never joined the graph. While such a restack is stored, nothing is published from the worktree.
After the plans, the run moves each open pull request whose branch left a merged base to the branch it is built on now. It reads the pull request's target branch through review_request_head and calls retarget_review_request only when the forge shows another one, since the forge may have moved it already, then stores the ledger key retargeted:<base commit> so the read is not repeated, and links the chain that now starts with that node again, GitHub only. A read or a change that fails is a problem on the record and a notice, and the next run tries again. The pull request's text is never edited. When the next push refreshes the open pull request, the publisher's intent takes the branch the worktree is built on as its base only once the forge shows that same target, and the node it is stacked on becomes the one the merged node was stacked on; until then the record keeps the base the forge shows. A merged poll starts that run. The notice reads Rebased node "ui" onto main after draft #12 merged, with the display id as stored.
The run that follows a check applies the plans; see Runtime Flow for the rebase, the lease push after it, a rebase that stops for conflicts, and a restack a crash left. A stored restack is described by Task Worktree.
Checks Follow-up🔗
plan_node_follow_up chooses what the host does about a node's pull request from the forge's report, the generation's follow-up ledger, and what the host knows of its own side. It acts only while the worktree branch, the pushed commit, and the forge's head are one commit, and never about review threads.
- Conflicts, failed checks, and reruns follow a watched review request: each result is attempted once per head commit, checks a fix left failing are rerun once if the forge can, and then left to the user, but not while a fixer of the node has not settled.
- A conflict the forge reports is a notice, once per head commit; the plan does not restack. It is ignored while the node's branch or its base is missing from the remote, so it does not hold the checks back.
- Failed checks start a fix while fewer than three fixers ran for the generation, the worktree exists, the graph is not canceled, and the session's graphs have room for a node; otherwise one notice says no fixer can be added, and the attempt is spent. A paused graph instead gets one notice asking to resume it, and its checks wait for the fix.
fixer_nodebuilds the fixer, a child of the node that owns the worktree, namedfix-<worktree>-<generation>-<attempt>, with the worktree cut to its first 8 characters, which waits for its owner alone. It refuses a fixer the graph already holds, so one started before a crash is not added twice, and an identity another owner's node uses.- A draft whose checks all finished, with no failure, no conflict the plan heeds, and no fixer still to commit, is green when a check succeeded and none is held, cancelled or waiting for a person; skipped and neutral checks beside a success change nothing. A green draft is marked ready for review once per head commit. Held checks, checks that were all skipped, and a head without checks each get one notice instead, and the draft stays a draft. A pull request that is not a draft is left alone. The host never merges.
- The forge lists the checks of a new head over some time, so none of these results is acted on at the first poll that shows finished checks. That poll only stores
settled:<commit>:<succeeded>-<held>-<skipped>in the ledger, the shape of the finished checks it saw: how many succeeded, how many are held, and whether all were skipped. The next poll that shows the same shape acts; a changed shape, such as a second workflow finishing, stores the new key and waits another poll. A check that is queued, running, or failing, or a conflict, drops the key, so the wait starts over. The wait is at least one poll, which the poll schedule spaces, and needs no column beyond the ledger.
After the reducer stores a poll, App::follow_up_node_checks plans from it, the graph's progress as the host projects it, so a graph without a live driver reads as paused, and the worktree's own head.
- The ledger the plan returns is stored first, by compare-and-set, and only then is the action started, so of two deliveries of one poll only one acts. A ledger another writer moved first starts nothing; the next poll plans again. A plan without an action stores its ledger too when it changed, as when a draft's finished checks were seen for the first time.
- A fix appends the fixer to the owner's graph with
expand_graph, under an identity that makes a redelivered addition change nothing, from the graph's own budget, and continues the graph. When the graph cannot run it, the notice says the fixer is added and asks to resume the graph; it is not added again. - A fix the ledger counts whose fixer the graph lacks, as after a crash between the two writes, is added on the next poll of that commit under the same conditions as a new fix: a paused graph is asked once to resume and is not resumed for it, and once no fixer can be added, the plan goes on to a rerun and to the user.
- The fixer's request,
fix_node_checks_prompt.md, fences the forge's check names and addresses and tells it not to commit, push, or run forge commands. Its changes are committed in the worktree, and the publishing check pushes them to the same pull request, whose next poll reads the new checks. - A rerun asks the forge in the background; the worktree's checks are not planned for until it is asked, and a refusal is one notice.
- Marking ready also runs in the background, under the stored
ready:<commit>key. The task asks the forge to mark the draft ready, reads the draft flag back, stores the status a poll would write, and writes one notice, or one notice of the failure, including a forge that still shows a draft. A host that stops after storing the key and before asking leaves the draft for the user, who sees the passed checks in its row; the request is never repeated for the same commit. - Each action is one
[Pull Request]notice in the forge's words, such asFixing 1 failing check: test of draft #12 for node "api" with node "fix-…", orDraft #12 for node "api" passed its checks and is ready for review. Merge it on GitHub.
See Execution Graphs for why the host pushes, restacks, and follows up the way it does. Graph Machinery shows how the graph components fit together.