dotFactory

Growing a software factory

When I build software factories, I usually go through the same progression. The first version has a simple job. Take a ticket, write the code that would close it, and open a pull request.

A straight line from ticket opened to coding agent to opening a PR.

I start there because I want to see what comes back. Can the agent find the right part of the codebase? Is the diff small enough to review? Can I tell from the PR what it changed?

In dotFactory, follow the values down the page. The issue trigger emits a ticket. The coding step reads that ticket and produces a revision. The PR step takes both.

trigger issue_opened:
  kind: article_issue_opened
  out: { ticket: Ticket }

step implement:
  runner: coding_agent
  in: { ticket: issue_opened.ticket }
  out: { revision: Revision }

step open_pr:
  runner: repository
  config: { action: "open_or_find_pr" }
  in: { ticket: issue_opened.ticket, revision: implement.revision }
  out: { pr: int }

Then CI goes red, and I find myself copying a test failure into another agent session. The factory got me to a PR. Getting from a failing test to a revised patch was still my job.

Run the tests before opening the PR

I add a test step while the agent still has the checkout. When a test fails, the agent gets the output, revises the patch, and tries again. If the tests pass, it opens the PR. If it runs out of attempts, I get the patch and the failure it couldn’t resolve.

Tests run before the PR opens. A failure goes back to the coding agent, with a handoff to a maintainer if attempts run out.

Read the loop in two directions. The agent sends its revision forward to test_patch. If the test fails, the two prev bindings send that revision and the failure output back to the agent. The loop allows two retries after the first attempt, and open_pr waits for a passing result.

loop tested_patch:
  in: { ticket: Ticket, starting_revision?: Revision, base_sha?: text, ci_output?: text }
  out:
    revision: Revision = implement.revision
    tests: TestResult = test_patch.result

  step implement:
    runner: coding_agent
    in:
      ticket: inputs.ticket
      starting_revision?: inputs.starting_revision
      base_sha?: inputs.base_sha
      ci_output?: inputs.ci_output
      prev candidate?: test_patch.revision if not test_patch.result.passed and implement.attempt < 3
      prev test_feedback: test_patch.result.output if not test_patch.result.passed and implement.attempt < 3
    out: { revision: Revision }

  step test_patch:
    runner: test_runner
    in: { repo: inputs.ticket.repo, revision: implement.revision }
    out: { result: TestResult, revision: Revision }

step build:
  use: tested_patch
  in: { ticket: issue_opened.ticket }

step open_pr:
  runner: repository
  config: { action: "open_or_find_pr" }
  when: build.tests.passed
  in: { ticket: issue_opened.ticket, revision: build.revision }
  out: { pr: int }

The difference shows up the next time I open the PR list. There’s a patch to review, and the routine work of fixing a failing test has already happened.

That works until another PR lands while mine is waiting.

Feed CI back into the factory

The agent’s tests passed against the checkout it started with. Another PR had also passed its checks, and it merged first. Now CI tests my PR against the updated base and finds a failure that neither PR showed on its own.

I’m copying output into an agent session again. This time, the output alone won’t do. The agent needs the updated base so it can reproduce what CI saw.

A failed CI check on the merge candidate sends the failure and updated base back to the coding agent.

The CI adapter emits a failure for the current merge candidate. That starts a repair run through the same tested_patch loop, with the failed PR revision, the updated base, and the CI output as inputs.

trigger ci_failed:
  kind: article_merge_ci_failed
  out: { ticket: Ticket, pr: int, revision: Revision, base_sha: text, output: text }

step repair:
  use: tested_patch
  in:
    ticket: ci_failed.ticket
    starting_revision: ci_failed.revision
    base_sha: ci_failed.base_sha
    ci_output: ci_failed.output

step update_pr:
  runner: repository
  config: { action: "update_pr_if_head_matches" }
  when: repair.tests.passed
  in:
    ticket: ci_failed.ticket
    pr: ci_failed.pr
    expected_head: ci_failed.revision.sha
    revision: repair.revision
  out: { updated: bool }

If the repair passes its tests and the PR head still matches the revision that failed, the factory updates the same PR. CI checks the new merge candidate.

Split the ticket before writing the patch

At some point, a PR comes back green and I still can’t review it in one sitting. The ticket covers several changes, the diff mixes them together, and I’m trying to work out which parts have to ship together. I end up writing the outline I wish the agent had started with.

That’s where I add a step before coding. It reads the ticket and the codebase and asks whether the work can be implemented and reviewed as one change.

A scope check sends small tickets straight to the coding agent and turns larger tickets into a proposal for smaller tickets.

The triage step produces a typed choice. The two when conditions show where it goes. A single change enters the test loop. A split produces a proposal with a clear outcome, acceptance criteria, and dependencies for each smaller ticket.

type Scope = choice { single {}, split { tickets: [ChildTicket] } }

step triage:
  runner: coding_agent
  config: { action: "inspect_scope" }
  in: { ticket: issue_opened.ticket }
  out: { scope: Scope }

step propose_split:
  runner: repository
  config: { action: "propose_child_tickets" }
  when: triage.scope is split
  in: { ticket: issue_opened.ticket, proposed: triage.scope.split.tickets }
  out: { reported: bool }

step build:
  use: tested_patch
  when: triage.scope is single
  in: { ticket: issue_opened.ticket }

Once those tickets are ready, each one goes through the workflow we already built. Each gets its own patch, test loop, and CI feedback. A reviewer can take them one at a time.

The next small ticket still takes the short route. The difference is what happens when a test fails, another change lands first, or the ticket turns out to be bigger than it looked. I used to step in at each of those points. That’s where the factory grew.

The excerpts show the workflow wiring. The full definitions and host adapter contracts cover the ticket and CI events, checkout, test execution, and PR operations.