Skip to content

Make code-producing flows open a best-effort PR and derive branch handoff from run target - #169

Merged
adamw merged 20 commits into
masterfrom
best-effort-pr-unified-branch
Sep 16, 2026
Merged

adamw merged 20 commits into
masterfrom
best-effort-pr-unified-branch

Conversation

@adamw

@adamw adamw commented Sep 11, 2026

Copy link
Copy Markdown
Member

Summary

Every code-producing built-in flow now ends with a best-effort PR step: when the repository is on GitHub and gh can reach it, the flow pushes the branch and opens a PR; when it can't—no remote, not GitHub, gh unreachable—the flow reports why in one line and finishes successfully without a PR.

The per-flow returnToStartBranch flag is gone. The run now decides where to leave the checkout: a NewBranch run that opened a PR hands you back the branch you started on (the work is on the PR); every other run stays put.

What changed

Tools: Added gh.availability(), a read-only probe answering whether a PR can be opened as a GitHubAvailability enum (Available / NoRemote / NoHost / NotGitHub / Unreachable). Made PrHandle carry the host as its first field so PR creation, lookup, and writes work on GitHub Enterprise Server. Derived the host from the origin remote URL via the existing remoteHost parser.

Flow runtime: Extracted the three stages of openPrFromBranch (push → summarise → create) into private helpers. Added openPrIfGitHub, which probes first and either runs those stages or emits one Step naming the reason and returns None. Added a small explicit door on FlowControl—recordOpenedPr—so a flow that opens its PR with a bare gh.createPr can tell the lifecycle. Added BranchHandoff.of(target, worktree, openedPr) to compute the checkout location: ReturnToStart only for NewBranch runs outside a worktree that opened a PR; everything else stays put.

Built-in flows: Appended openPrIfGitHub(codingAgent.cheap) to implement.sc, implement-interactive.sc, and simple.sc. Switched implement-enhanced.sc from openPrFromBranch to openPrIfGitHub. Kept openPrFromBranch in issue-pr.sc (those flows require GitHub); added recordOpenedPr to issue-pr-bugfix.sc so the lifecycle learns about its tentative PR. Removed returnToStartBranch arguments and updated flow headers to describe the new behavior.

Docs: Updated README to document gh.availability, the new PR helper signatures, the host-aware PrHandle, and the target-derived branch handoff rule. Added a dated amendment to ADR 0018 R3. Updated AGENTS.md to list the new test fakes.

The PR step runs outside a worktree by construction; orca create/orca fork run simple.sc in a sandbox with no remote, so the step skips cleanly there.

@adamw

adamw commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

review.sc now fails instead of skipping

Test

@adamw

adamw commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Comment from Tulip's PR explanation, for the category: GitHub availability probe and host-aware PrHandle

Test2

Require the outside-a-stage evidence on both PR helpers. Fail the
no-code check open when git cannot measure the branch. Return the
default base as an Either. Classify gh failures as hard or transient
and retry only the transient ones. Refuse ported hosts instead of
mis-linking. Split the availability enum into Available and
Unavailable with one explanation per cause, so the flows no longer
spell out each case. Probe review.sc's host inside its stage.
The flow context held the handle in a var, which a resumed run lost
unless it reached the recording call again — hence the rule to call it
outside the stage that opened the PR. The log survives replay, so put
it there: the call now takes WorkspaceWrite and belongs inside that
stage, where the stage's own commit carries it.

Also make an unreadable log path read as corrupt rather than throw,
which load() already promised.
Reading the log folded every failure into "corrupt", which let setup
overwrite a run it could not read, and let teardown delete a branch
whose PR is open. Split absent, corrupt and unreadable apart: setup
aborts on unreadable, and teardown deletes only on a log that loaded
and records no PR.
The progress log and the branch policy are git-level, but both named a
PrHandle to answer a question neither asks in GitHub terms: only its
presence was ever read. Record a plain reference instead, so a flow
that publishes to something other than GitHub can set it without
touching the log schema or the handoff rule. The PR-facing door keeps
its name and signature and translates.

The closing summary now names where the work went.
@adamw
adamw merged commit e87d70f into master Sep 16, 2026
6 checks passed
@adamw
adamw deleted the best-effort-pr-unified-branch branch September 16, 2026 15:31
adamw added a commit that referenced this pull request Sep 16, 2026
#170)

## Summary

The whole-run final review in the built-in flows allowed three fix
rounds, and the flows discarded the loop's result. A run could end with
findings still open and open a PR that said nothing about them.

## Changes

- The final review loop in `implement.sc`, `implement-interactive.sc`,
`implement-enhanced.sc`, `issue-pr.sc` and `issue-pr-bugfix.sc` now
allows five rounds. The per-task loop and the library default stay at
three.
- New `renderOpenFindings` renders the loop's unfixed findings as a
markdown section, verbatim, omitted when there are none.
- `openPrFromBranch` takes a required `openFindings` parameter and
appends that section to the PR body. No default, so a flow cannot drop
the loop's result by omission.
- The PR-opening flows pass the final review's result through. The
bugfix flow appends the section when it updates its tentative PR.

## Limitation

The loop returns only a title and reason per finding. Reviewer, location
and suggestion are not retained, so they are not listed.

## Note

Touches the same helper signature that #169 extends. Whichever lands
second needs the pass-through added to `openPrIfGitHub`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant