Repository navigation
Description
Problem Statement
When I shape a big piece of work into a Spec with Tickets as its sub-issues (like #109 and its five Tickets), thirdshift can only take one issue at a time. I have to work out by hand which Tickets are unblocked, start a Run for each, wait for it to merge, look again at the graph, and start the next ones. That is exactly the kind of bookkeeping the factory should do overnight while the day shift is away. The implement-spec skill can drive a Spec, but it puts an agent in charge of work that is really deterministic (which Ticket is ready, what landed, what failed) and it produces no single outcome thirdshift stands behind.
Solution
Given a Spec's Issue URL, thirdshift starts a Spec run: it reads the Spec's Tickets and their GitHub "blocked by" links, and works through them in dependency order, several at once when the graph allows. Each Ticket gets its own Run, a Merge run into the Spec branch (the Spec's own Issue branch). When a Ticket lands, the Tickets it was blocking can start.
Once every Ticket is done, a Spec review session reviews the whole Spec branch against the Spec and fixes what it finds, and the Spec PR from the Spec branch into the Base branch goes through the same Repair loop a Run's pull request does: conflicts with the Base branch and red CI are repaired by agents until the PR is mergeable and green. It is then left ready for review, or, with merge (or merge.always), merged by thirdshift's Self-merge.
The Spec run goes as far as it can. A Ticket that fails stops only the Tickets it blocks, and Unready Tickets (labelled ready-for-human, needs-info, wontfix or needs-triage) are skipped along with anything they block. If any Ticket isn't done, the Spec run is a Failed spec run: it leaves a draft Spec PR and a per-Ticket summary, and running it again picks everything up where it stopped.
The command doesn't change: thirdshift [merge] <Issue URL> is a Spec run whenever the issue has sub-issues. parallel <n> sets how many Tickets run at once for one Spec run, and spec.parallel in the User config sets the default (3).
User Stories
- As a user, I want
thirdshift <Spec URL>to implement the whole Spec, so that I don't have to start a Run for each Ticket by hand. - As a user, I want thirdshift to recognise a Spec by its having sub-issues, so that I don't need a separate command or word for it.
- As a user, I want
thirdshift <Issue URL>on an issue with no sub-issues to behave exactly as it does today, so that single-issue Runs are unaffected. - As a user, I want the order of work to come from GitHub's native "blocked by" links between the Tickets, so that the graph I see in GitHub is the graph thirdshift follows.
- As a user, I want Tickets whose blockers are all done to start straight away, so that the Spec gets done as fast as the graph allows.
- As a user, I want several unblocked Tickets to run at once, so that independent work happens in parallel.
- As a user, I want at most 3 Tickets running at once by default, so that a wide graph doesn't exhaust Repair budgets or API rate limits.
- As a user, I want to set that limit with
spec.parallelin my User config, so that each machine can run as many as it can handle. - As a user, I want
parallel <n>/--parallel <n>to override the limit for one Spec run, so that I can go wider or narrower without editing the config. - As a user, I want
parallel 0, a non-number, orspec.parallel = 0rejected as an error, so that a typo can't stall a Spec run. - As a user, I want
parallelon an issue that isn't a Spec rejected before any work, so that a mistaken command doesn't quietly ignore it. - As a user, I want Tickets that are already closed to count as done, so that a Spec with some Tickets finished only runs the rest.
- As a user, I want an open Ticket with no triage label to be taken, so that I don't have to label every Ticket before a Spec run.
- As a user, I want an open Ticket labelled
ready-for-human,needs-info,wontfixorneeds-triagenever to be run, so that the factory respects an explicit "not for an agent" label. - As a user, I want a Spec run to take every Ticket it can reach even when some Tickets are unready, so that it gets as far as it can.
- As a user, I want a Ticket blocked by an Unready Ticket to wait rather than run, so that the dependency graph is always respected.
- As a user, I want a Ticket whose Run fails to stop only the Tickets it blocks, so that the rest of the Spec keeps moving.
- As a user, I want a failed Ticket not to be retried within the same Spec run, so that a Ticket that just failed doesn't burn more time failing again.
- As a user, I want the graph re-read from GitHub whenever a Ticket's Run ends, so that labelling a Ticket
ready-for-agent, adding a Ticket, or closing one by hand takes effect during a Spec run. - As a user, I want a Ticket blocked by an open issue outside the Spec to wait, and one blocked by a closed issue outside the Spec to be free, so that outside dependencies are respected.
- As a user, I want Tickets in a dependency cycle never to run, and the cycle named in the summary, so that I can fix the graph.
- As a user, I want a Ticket that has sub-issues of its own treated as unready, so that thirdshift never tries to implement a nested Spec as a single Ticket.
- As a user, I want each Ticket's work to land on a Spec branch rather than the Base branch, so that half a Spec never reaches
main. - As a user, I want the Spec branch to be the Spec's own Issue branch (
issue-<n>, numbered like any Issue branch), so that its name is predictable. - As a user, I want each Ticket's Run to branch off the Spec branch and open its pull request against it, so that Tickets build on each other's work.
- As a user, I want each Ticket's Run to be a Merge run into the Spec branch whatever my
mergeword ormerge.alwayssays, so that the graph can move on without me. - As a user, I want each Ticket's Run to do everything a Run does (the implement session, code review, Repairs, CI, Self-merge), so that each Ticket meets the same bar a standalone Run does.
- As a user, I want Tickets that collide to be handled by the Run's existing conflict Repairs, so that parallel work doesn't need special handling.
- As a user, I want a Ticket closed when it lands on the Spec branch, with thirdshift's usual closing comment naming the pull request and the Spec branch, so that I can see which Tickets are done.
- As a user, I want a draft Spec PR opened as soon as the first Ticket lands, so that I can watch the Spec's progress on GitHub while the Spec run goes.
- As a user, I want the Spec PR to carry a Tickets checklist that thirdshift ticks as each Ticket lands, with each Ticket's pull request, so that the PR shows where the Spec stands.
- As a user, I want the Spec PR body to include
Closes #<spec>, so that merging it closes the Spec. - As a user, I want CI to run on the Spec PR as Tickets land, so that cross-Ticket breakage shows up early.
- As a user, I want a Spec review session once every Ticket is done, reviewing the whole Spec branch against the Base branch and the Spec on both Standards and Spec axes, so that problems between Tickets, which no single Ticket's review sees, are found.
- As a user, I want the Spec review to fix the findings it agrees with and list the rest as Unaddressed findings in the Spec PR, so that I can decide on them.
- As a user, I want the Spec review to write the Spec PR's description, and thirdshift to keep the Tickets list in it, so that the description is useful and the list is exact.
- As a user, I want the Spec PR marked ready for review once the Spec review is done, so that I know it's for me.
- As a user, I want the Spec PR to go through the same Repair loop as a Run's pull request (merging the Base branch in, conflict Repairs, CI-fix Repairs, going round again when the Base branch moves, the same budgets), so that the Spec PR ends mergeable and green.
- As a user, I want a Declined CI fix and a Policy refusal to apply to the Spec PR as they do to a Run's, so that the Spec run doesn't loop on a problem it can't fix.
- As a user, I want
thirdshift merge <Spec URL>to end with the Spec PR merged into the Base branch by a Self-merge, so that a whole Spec can ship unattended. - As a user, I want
merge.always = trueto make a Spec run merge its Spec PR, andno-mergeto stop it at ready for review, so that the goal words mean the same for a Spec as for an issue. - As a user, I want the Spec PR's Self-merge to delete the Spec branch and close the Spec, as a Run's does for its issue, so that nothing is left behind.
- As a user, I want the Base branch for the Spec PR to be the branch checked out in the Launch directory, so that a Spec run from a
maincheckout lands onmain. - As a user, I want a Spec run with any Ticket not done to end as a Failed spec run with exit code 1, so that scripts can tell it didn't finish.
- As a user, I want a Failed spec run to leave its Spec PR as a draft, listing what is missing, so that the progress stays visible on GitHub.
- As a user, I want a Spec run to print a summary with one line per Ticket (merged with its PR, failed with its cause and session log, blocked by which Ticket, unready with which label, in a cycle), so that I know what happened without opening GitHub.
- As a user, I want a complete Spec run to print the Spec PR URL on stdout and exit 0, and a Failed spec run to print the draft Spec PR URL if there is one, so that the output matches a Run's.
- As a user, I want to rerun a Spec URL after a Failed spec run and have it pick up the existing Spec branch, draft Spec PR and each failed Ticket's Issue branch as Continuations, so that nothing is redone and nothing is lost.
- As a user, I want a Spec whose Tickets are all closed and which has no Spec branch to stop with "every Ticket is closed and there is no Spec branch; nothing to do", without closing the Spec, so that a Spec implemented some other way isn't touched.
- As a user, I want a Spec whose Tickets are all done and whose Spec branch exists to go straight to the Spec review and the Spec PR, so that a rerun after the last Ticket landed finishes the job.
- As a user watching the terminal, I want each Ticket Run's progress lines prefixed with its Ticket number (
#113: CI red; starting Repair 1 of 5), so that I can follow parallel Runs in one terminal. - As a user watching the terminal, I want Spec-level progress lines when a Ticket starts, lands, fails or unblocks others (
starting #114, unblocked by #113), so that I can follow the graph. - As a user, I want each Ticket's Run to keep its own session logs, so that I can look into any one Ticket.
- As a user, I want one Run notification when a Spec run ends, with every Ticket's outcome in it, so that I get one email per Spec, not one per Ticket.
- As a user, I want the Ticket Runs inside a Spec run never to send a Run notification of their own, so that my inbox isn't flooded.
- As a user, I want Ctrl-C, SIGTERM or a closed terminal to stop every Ticket Run, each going through its usual Failed run path, and the Spec run to end as an interrupted Failed spec run, so that interrupting is safe.
- As a user, I want the Spec run's preflight (Origin match, the Base branch, the User config, the notification checks) done once before any Ticket starts, so that a setup problem stops everything before any work.
- As a user with
launch.pull = true, I want the Launch directory's Base branch fast-forwarded once at the start of the Spec run, not by each Ticket Run, so that parallel Runs don't race on it. - As a user, I want a crash in one Ticket's Run not to take down the other Tickets or the Spec run, so that one bad Ticket can't lose everyone's work.
- As a user, I want
thirdshift setupto writespec.parallelat its default with a comment, like every other setting, so that I can see it can be changed. - As a user, I want help and the README to explain Spec runs,
parallel,spec.paralleland what makes an Unready Ticket, so that I can use the feature without reading the source.
Implementation Decisions
- Domain terms. Spec, Ticket, Spec run, Spec branch, Spec PR, Unready Ticket, Spec review and Failed spec run are defined in
CONTEXT.md; Run is narrowed to one issue that isn't a Spec, and Base branch, Merge run and Repair are updated. Use these terms in code, help text, messages and PR bodies. The design is recorded in ADR 0006. - Detecting a Spec. After argument parsing and preflight, the issue's sub-issues are read. Any sub-issue, open or closed, makes the issue a Spec. No sub-issues means an ordinary Run, unchanged.
- Reading the graph. One GraphQL query reads the Spec's sub-issues with, for each: number, state, labels, whether it has sub-issues of its own, and its
blockedByissues with their numbers and states. The body's "Blocked by" text is never read. The graph is read at the start and again whenever a Ticket's Run ends. - The frontier. A deterministic function of the graph and what the Spec run has seen: a Ticket is ready when it is open, not an Unready Ticket, has no sub-issues, has every blocker closed, is not running, and hasn't failed in this Spec run. Unready Tickets, failed Tickets, open outside blockers and cycles make the Tickets downstream of them unreachable. The Spec run starts ready Tickets (lowest issue number first) up to the parallel limit, and ends the Ticket phase when nothing is running and nothing is ready.
- Parallel limit.
[spec] parallelin the User config (a positive integer, default 3) is a new known section and key;thirdshift setupwrites it with its default and a comment, and does not ask about it.parallel <n>/--parallel <n>takes the next token as the number, follows the flag-once rule, and wins over the config. A non-positive or non-numeric value is an argument error (exit 2) or config error.parallelon an issue that turns out not to be a Spec is a preflight failure before any work. - Spec branch. Chosen like any Issue branch for the Spec issue (
issue-<n>, orissue-<n>-branch-<k>, with an existing one meaning continue, per ADR 0002), branched off the Launch directory's Base branch, and pushed to origin before any Ticket starts. The Spec run keeps a worktree on it. - Ticket Runs as child processes. Each Ticket's Run is a child process of the same
thirdshiftbinary, a Merge run on the Ticket's Issue URL from the same Launch directory, told through a hidden argument to use the Spec branch as its Base branch and not to send a Run notification or fast-forward the Launch directory. The hidden argument is not in help. The child's Base branch is the Spec branch in its prompts and review fixed point, so it branches off and targets the Spec branch. The Spec run reads each child's exit code and the PR URL it prints on stdout; stderr lines are relayed with a#<n>:prefix. Children share the Spec run's process group, so an interrupt reaches them all; the Spec run waits for every child to finish its Failed run path before it ends. - After a Ticket lands. The Ticket's own Self-merge closes it with its usual comment. The Spec run fetches the Spec branch, opens the draft Spec PR if there isn't one yet (title from the Spec, body with
Closes #<spec>and the Tickets checklist), or updates the checklist in it, then re-reads the graph and starts whatever became ready. - The Tickets checklist in the Spec PR body is written by thirdshift between fixed markers, so it can be replaced without touching the prose the Spec review writes around it. Each line is a Ticket with its state (done with its PR, failed, blocked, unready).
- Spec review. Once every Ticket is done, a new prompt, shaped like the Continuation prompt, starts a session in the Spec branch worktree:
/thirdshift:code-reviewof the Spec branch with the Base branch as the fixed point and the Spec issue as the spec, fix the Standards and Spec findings it agrees with, commit, push, and update the Spec PR through/thirdshift:prwith a body covering the whole Spec, an "Unaddressed findings" section, andCloses #<spec>. No new Factory skill. thirdshift then re-writes the Tickets checklist into the body and marks the Spec PR ready. - The Spec PR's Repair loop and Self-merge reuse the Run's Repair loop, budgets, Declined CI fix, Policy refusal, ready-and-mergeable check, Self-merge and post-merge steps unchanged, with the Spec as the issue and the Spec branch as the Issue branch. Repair prompts name the Spec. The goal (
merge,no-merge,merge.always) applies here only. - Outcomes. Complete: the Spec PR ready (or merged), its URL on stdout, exit 0. Failed spec run (any Ticket not done, or the Spec PR phase failed, or interrupted): the draft Spec PR URL on stdout if there is one, exit 1, the per-Ticket summary on stderr. A Spec PR that ends up failing after being marked ready follows the Failed run rules for its pull request (back to draft unless only the Self-merge could not happen).
- Nothing to do. Every Ticket closed and no Spec branch: stop with the "nothing to do" message, exit 1, touching nothing.
- Preflight and config (Origin match, Base branch checks, User config, notification preflight,
launch.pull) run once in the Spec run before any Ticket starts; children skip the notification andlaunch.pullsteps. - Run notification. A Spec run sends at most one, when it ends, under the same rules as a Run (
--email,email.always,--no-email). Subject:[thirdshift] <owner>/<repo>#<spec> <title>: <outcome>. The body adds one line per Ticket with its outcome to what a Run's notification holds. - Progress output. The Spec run's own lines go through the existing progress output. Lines relayed from a child keep their order within that child; lines from different children may interleave.
Testing Decisions
- What makes a good test here. Tests drive the compiled binary from outside, as a user would: the command line, the User config, the GitHub state in the fake
gh, the branches on the bare origin, the Resend stand-in, stdout/stderr and the exit code. They never call internal functions or assert on internal types. One seam only: the existing end-to-end harness. - Extending the fake
gh. It learns a Spec's sub-issues, each Ticket's labels andblockedBylinks, and nested sub-issues, served through the GraphQL query thirdshift uses. A test helper sets up a Spec and its graph. Because parallel child Runs call it at the same time, reads and writes of its state file take a file lock. Fake agents and tests can change the graph mid-run (e.g. label a Ticket), throughgh fake …as today. - Extending the fake
claude. Scripts are chosen by the issue a session is for (the Issue URL in its prompt) and that issue's session count, not by global call order, which parallel Runs make nondeterministic. A helper sets "the agent does X for Ticket #n", and one for the Spec review. - Behaviour to cover:
- An issue with no sub-issues is still an ordinary Run.
- A linear Spec runs its Tickets in order, each a Merge run into the Spec branch, each Ticket's PR targeting the Spec branch; the Spec PR ends ready for review, targeting the Base branch, with
Closes #<spec>and the Tickets checklist; exit 0 and the Spec PR URL on stdout. mergeandmerge.alwaysend with the Spec PR merged into the Base branch, the Spec branch deleted and the Spec closed;no-mergestops at ready.- Two independent Tickets run at the same time (both Ticket sessions are started before either Ticket lands), and a Ticket blocked by both starts only after both land.
parallel 1runs them one at a time;spec.parallelsets the default; bad values are rejected;parallelon a non-Spec issue fails before any work.- Closed Tickets aren't run; Unready Tickets and the Tickets they block aren't run, and the Spec run ends failed naming them.
- A failed Ticket stops only its dependents; independent Tickets still land; the Spec run ends failed with a draft Spec PR and the per-Ticket summary.
- Labelling a Ticket mid-run lets it run in the same Spec run.
- Open and closed outside blockers, a cycle, and a Ticket with its own sub-issues behave as decided.
- The draft Spec PR appears after the first Ticket lands and its checklist updates as Tickets land.
- The Spec review session gets a prompt naming the Spec and the Base branch, and the Spec PR is marked ready after it.
- Conflicts and red CI on the Spec PR start Repairs as for a Run.
- A rerun after a Failed spec run continues the Spec branch and the failed Ticket's Issue branch, and doesn't re-run closed Tickets.
- Every Ticket closed with no Spec branch stops with "nothing to do", touching nothing.
- Relayed child lines carry the
#<n>:prefix. --emailsends exactly one notification for the whole Spec run, listing each Ticket's outcome; the Ticket Runs send none.- An interrupt stops every Ticket Run and ends the Spec run as interrupted.
- Prior art:
tests/merge_run.rs,tests/fresh_run.rs,tests/failed_run.rs: Run outcomes through the fakestests/continuation.rs,tests/numbered_branches.rs: picking up existing Issue branchestests/ci.rs,tests/mergeable.rs: the Repair looptests/progress_lines.rs: what reaches the terminaltests/run_notification.rsand the Resend stand-in: notificationstests/user_config.rs,tests/command_surface.rs: config keys and argument errorstests/support/mod.rsandtests/fakes/: the harness this extends
Out of Scope
- A strict mode that refuses a Spec run up front when any Ticket is unready.
- Retrying a failed Ticket within the same Spec run.
- Nested Specs: a Ticket with sub-issues of its own is never run, and there is no recursion.
- Reading dependencies from the "Blocked by" text in issue bodies.
- Keeping Tickets open until the Spec PR merges; a Ticket closes when it lands on the Spec branch, and rejecting a Spec PR means reopening its Tickets by hand.
- Ticket Runs that stop at ready for review for a human to merge.
- Running Tickets across several machines, or sharing the parallel limit across concurrent Spec runs.
- Label-gating standalone Runs; they keep ignoring triage labels.
- A new Factory skill for the Spec review; it is a prompt over the existing skills.
Further Notes
- Grew out of make way for thirdshift to implement a spec #28 and a grilling session; decisions are recorded in
CONTEXT.mdanddocs/adr/0006-spec-runs-merge-tickets-into-a-spec-branch.md. - The
implement-specskill inspired the orchestration (frontier, parallel implementers, merging into one branch, a final review), which here becomes deterministic Rust. Agents remain only in the Ticket sessions, their Repairs, the Spec review and the Spec PR's Repairs. - Parallel child Runs share one Launch directory, each creating its own worktree. Concurrent
git worktree addand fetches in one repository can contend for git's lock files; the implementation should make that safe (e.g. by serialising worktree creation, or retrying on a lock), and a test with two Tickets starting together should cover it. - Ticket PRs into the Spec branch get CI only if the repository's workflows run on pull requests into any branch; this repository's CI does (
pull_request:with no branch filter). With no CI, a Merge run treats the checks as absent. - Run notifications by email, and a User config for per-machine defaults #109 is fully merged, so it can't serve as a live trial; a new Spec is needed to try this for real.
Activity
JacobStephens2 commentedon Oct 1, 2026
works!