Skip to content

fix(workflows): ensure all PR-creating workflows target $BASE_BRANCH#1479

Merged
Wirasm merged 1 commit intocoleam00:devfrom
ericsoriano:archon-fix-pr-base-targeting
Apr 29, 2026
Merged

fix(workflows): ensure all PR-creating workflows target $BASE_BRANCH#1479
Wirasm merged 1 commit intocoleam00:devfrom
ericsoriano:archon-fix-pr-base-targeting

Conversation

@ericsoriano
Copy link
Copy Markdown
Contributor

@ericsoriano ericsoriano commented Apr 29, 2026

Summary

  • Problem: Several bundled default workflows produce PRs targeting the GitHub repo default branch instead of the configured worktree.baseBranch. The engine substitutes $BASE_BRANCH correctly; the bug is that some prompts/commands fail to instruct the AI to pass --base $BASE_BRANCH to gh pr create.
  • Why it matters: Users configuring worktree.baseBranch in .archon/config.yaml get PRs filed against the wrong base, requiring manual gh pr edit cleanup. Superseded PR fix: ensure all PR-creating workflows target $BASE_BRANCH #1453 is itself an example — it was opened against the wrong base because the workflow that created it hit this exact bug.
  • What changed: Added --base $BASE_BRANCH to gh pr create invocations in archon-architect, archon-refactor-safely, and archon-implement-issue. Added a defensive verify-pr-base bash node to all 9 PR-creating bundled workflows that auto-corrects via gh pr edit if the AI ever drops the flag.
  • What did NOT change (scope boundary): No code in packages/*/src/** is modified. The engine-layer substitution and fail-fast guard at `executor-shared.ts:287-310` and the bash-node substitution path at `dag-executor.ts:1252-1268` are already correct and intentionally not touched.

UX Journey

Before

```
User Archon AI agent GitHub
──── ────── ──────── ──────
runs workflow ────▶ resolves $BASE_BRANCH from worktree.baseBranch
builds prompt
streams to AI ──────▶ runs `gh pr create --title ... --body ...`
(no --base flag) ──────────────────▶ PR opens against repo
default branch
(WRONG base)
sees PR ◀──────────────────────────────────────────────────────────────────── manual gh pr edit
required
```

After

```
User Archon AI agent GitHub
──── ────── ──────── ──────
runs workflow ────▶ resolves $BASE_BRANCH from worktree.baseBranch
builds prompt
streams to AI ──────▶ runs `gh pr create [--base $BASE_BRANCH] ...` ◀── *** changed
──────────────▶ PR opens against
configured base ✅
[verify-pr-base node] ──▶ `gh pr view --json baseRefName` ◀── *** new
if mismatch:
`gh pr edit --base $EXPECTED` ◀── *** new
sees correctly-targeted PR ◀──────────────────────────────────────────────────
```

Architecture Diagram

Before

```
DAG (per PR-creating workflow):

... ──▶ create-pr ──▶ (downstream nodes)
```

After

```
DAG (per PR-creating workflow):

... ──▶ create-pr ──▶ [+] verify-pr-base ──▶ (downstream nodes)

└─ `gh pr view --json baseRefName`
if mismatch: `gh pr edit --base $EXPECTED`
```

Connection inventory:

From To Status Notes
`create-pr` `verify-pr-base` new New downstream guard node (9 workflows)
`verify-pr-base` downstream review/notify nodes modified `depends_on` rewired through verify-pr-base in workflows that had downstream consumers

Label Snapshot

  • Risk: `risk: low`
  • Size: `size: M`
  • Scope: `workflows`
  • Module: `workflows:defaults`

Change Metadata

  • Change type: `bug`
  • Primary scope: `workflows`

Linked Issue

Validation Evidence (required)

```bash
bun run validate
```

  • ✅ `check:bundled` passes
  • ✅ `type-check` passes (all packages)
  • ✅ `lint` passes (0 errors, 0 warnings)
  • ✅ `format:check` passes
  • ✅ Test suite passes (per-package isolated)

Evidence provided: `bun run validate` exit code 0 on commit `283a978b`.

Security Impact (required)

  • New permissions/capabilities? No
  • New external network calls? No (verify-pr-base node uses `gh` already required by all PR-creating workflows)
  • Secrets/tokens handling changed? No
  • File system access scope changed? No

Compatibility / Migration

  • Backward compatible? Yes — existing workflows continue to work; `--base` substitution falls back to git-detected default when `worktree.baseBranch` is unset (existing engine behavior).
  • Config/env changes? No
  • Database migration needed? No

Human Verification (required)

End-to-end verified by running `archon-architect` against a project whose `.archon/config.yaml` set `worktree.baseBranch` to a non-default branch.

  • Verified scenarios:
    • `gh pr create` correctly received `--base `
    • Resulting PR's `baseRefName` matched the configured value (not the GitHub repo default)
    • `verify-pr-base` bash node executed (`duration_ms: 540`) and emitted `PR base verified: `
  • Edge cases checked:
    • Workflow ran on a fork clone (head pushed to fork, base referenced configured branch on fork)
    • `gh repo set-default` fork-pinning kept verify and create steps consistent within the same repo context
  • What was not verified:
    • Auto-correct path (`gh pr edit` rewrite when AI omits `--base`) — happy path covered all 3 fixed prompts; the verify node's correction branch is exercised only when the AI mis-targets, which the prompt rewrites now prevent. The correction branch is a defense-in-depth guard, not the primary fix.

Side Effects / Blast Radius (required)

  • Affected subsystems/workflows: 9 bundled PR-creating workflows (`archon-architect`, `archon-feature-development`, `archon-fix-github-issue`, `archon-idea-to-pr`, `archon-issue-review-full`, `archon-piv-loop`, `archon-plan-to-pr`, `archon-ralph-dag`, `archon-refactor-safely`) plus the `archon-implement-issue` command file.
  • Potential unintended effects:
    • Each affected workflow run gains one extra ~500ms bash node (`verify-pr-base`). Negligible vs. the PR-creating step itself.
    • Workflows that already have downstream consumers of `create-pr` had their `depends_on` rewired through `verify-pr-base`; topological order is preserved.
  • Guardrails/monitoring for early detection: `verify-pr-base` emits to stderr if it has to correct (`Base mismatch on PR #N: expected=... actual=... — re-targeting`), making any future regression visible in the workflow log.

Rollback Plan (required)

  • Fast rollback command: `git revert 283a978` — single commit, no schema or interface changes.
  • Feature flags or config toggles: None needed — change is in bundled defaults and is opt-in via running the workflows.
  • Observable failure symptoms: PRs landing on the GitHub repo default branch instead of `worktree.baseBranch` — same symptom as the bug being fixed, would be a clean signal that rollback is needed.

Risks and Mitigations

  • Risk: Bundled defaults file (`bundled-defaults.generated.ts`) drifts if someone edits a workflow YAML without running `bun run generate:bundled`.
    • Mitigation: `bun run validate` (and CI) run `check:bundled` and fail loudly if the generated bundle is stale. Already enforced; this PR's commit was validated against it.
  • Risk: `verify-pr-base` node assumes `gh` is authenticated in the workflow's execution environment.
    • Mitigation: All PR-creating workflows already require `gh` for the `create-pr` step; the new node uses the same authentication. No new auth surface.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced pull request creation to explicitly specify the target base branch across all automation workflows.
    • Added automatic verification and correction mechanism: if a PR's base branch doesn't match the expected configuration, the system automatically retargets it to the correct branch.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

Pull request creation now explicitly specifies a base branch via the --base $BASE_BRANCH flag, with new verification steps added across workflows to detect and correct mismatches between the PR's actual base and the expected target, automatically re-targeting via gh pr edit when necessary.

Changes

Cohort / File(s) Summary
PR Creation Command
.archon/commands/defaults/archon-implement-issue.md
Updates gh pr create to include explicit --base $BASE_BRANCH flag for base branch targeting.
Workflow Base Verification
.archon/workflows/defaults/archon-architect.yaml, archon-feature-development.yaml, archon-fix-github-issue.yaml, archon-idea-to-pr.yaml, archon-issue-review-full.yaml, archon-piv-loop.yaml, archon-plan-to-pr.yaml, archon-ralph-dag.yaml, archon-refactor-safely.yaml
Introduces verify-pr-base step that fetches the PR's current baseRefName, compares it to $BASE_BRANCH, and re-targets via gh pr edit when mismatched. Re-wires dependent nodes (review-scope, report, etc.) to execute after verification completes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops with glee through branches fair,
Base targets now receive our care,
Verify, redirect, all aligned,
No stray PR left behind!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: ensuring PR-creating workflows target the configured base branch instead of relying on defaults.
Description check ✅ Passed The PR description is comprehensive and follows the template structure with all required sections filled out, including Summary, UX Journey, Architecture Diagram, Security Impact, Validation Evidence, and Rollback Plan.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 10 minutes and 40 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@Wirasm
Copy link
Copy Markdown
Collaborator

Wirasm commented Apr 29, 2026

Review Summary

Verdict: minor-fixes-needed

This PR fixes a regression where bundled workflows creating PRs silently ignored the configured worktree.baseBranch, causing PRs to target the GitHub repo default branch instead. The fix is clean — --base $BASE_BRANCH added to 10 files, defensive verify-pr-base guard nodes added to 9 workflows, and error handling uses set -euo pipefail correctly throughout. Two documentation gaps need addressing before merge.

Blocking issues

None. Code and error handling are solid.

Suggested fixes

  • archon-implement-issue command undocumented: This is a new user-facing command that executes implementation plans and creates PRs. Add it to:

    • packages/docs-web/src/content/docs/getting-started/overview.md — workflows table
    • packages/docs-web/src/content/docs/guides/index.md — workflows index

    Entry text: | archon-implement-issue | Execute an implementation plan from /investigate-issue, create PR and run self-review |

  • CHANGELOG.md missing entry: The $BASE_BRANCH fix warrants a changelog line under [Unreleased] ### Fixed:

    PRs from bundled workflows now correctly target the configured worktree.baseBranch instead of the GitHub repo default.
    

Minor / nice-to-have

  • None.

Compliments

  • Consistent pattern applied across all 12 files — the same fix repeated cleanly with no drift.
  • Defensive verify-pr-base guard with self-healing (gh pr edit) is a well-designed fail-safe.
  • PR body is thorough: UX Journey, Architecture Diagram, Connection Inventory, Validation Evidence, and Rollback Plan all present.

Reviewed via maintainer-review-pr workflow (Pi/Minimax). Aspects run: code-review, error-handling, comment-quality, docs-impact.

- Add --base $BASE_BRANCH to gh pr create in archon-architect,
  archon-refactor-safely, and archon-implement-issue
- Add verify-pr-base bash node to all 9 PR-creating workflows
  that auto-corrects via gh pr edit if the AI mis-targets
- Rewire downstream depends_on edges through verify-pr-base
- Regenerate bundled-defaults.generated.ts
@Wirasm Wirasm force-pushed the archon-fix-pr-base-targeting branch from 283a978 to 64aad61 Compare April 29, 2026 09:42
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.archon/workflows/defaults/archon-refactor-safely.yaml (1)

449-495: ⚠️ Potential issue | 🟠 Major

Use the repo PR template verbatim here.

This still hand-rolls the PR body. Repo policy says every PR must copy .github/PULL_REQUEST_TEMPLATE.md into the body and fill every section explicitly; otherwise this workflow can drift from the required format.

Suggested adjustment
-      4. Create the PR targeting `$BASE_BRANCH` as the base branch:
-         `gh pr create --base $BASE_BRANCH --title "..." --body "..."`, then format
-         title/body per the template below
+      4. Create the PR targeting `$BASE_BRANCH` as the base branch:
+         Copy `.github/PULL_REQUEST_TEMPLATE.md` into the PR body, fill every section,
+         then invoke `gh pr create --base $BASE_BRANCH --title "..." --body "..."`.

Based on learnings: All PRs must use the template at .github/PULL_REQUEST_TEMPLATE.md — fill in every section; when opening via gh pr create, copy the template into the body explicitly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.archon/workflows/defaults/archon-refactor-safely.yaml around lines 449 -
495, The PR body in the workflow currently hand-rolls a refactor template
instead of using the repo's required PR template; update the step that runs `gh
pr create` (the block that writes the PR body/title and saves
`$ARTIFACTS_DIR/.pr-url`) to read and insert the contents of
`.github/PULL_REQUEST_TEMPLATE.md` into the `--body` argument and ensure every
section is filled before creating the PR (keep using `$BASE_BRANCH` and preserve
saving the PR URL to `$ARTIFACTS_DIR/.pr-url`), so the workflow always copies
the canonical template verbatim and populates its fields rather than using the
inline markdown shown in the current PR Format section.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In @.archon/workflows/defaults/archon-refactor-safely.yaml:
- Around line 449-495: The PR body in the workflow currently hand-rolls a
refactor template instead of using the repo's required PR template; update the
step that runs `gh pr create` (the block that writes the PR body/title and saves
`$ARTIFACTS_DIR/.pr-url`) to read and insert the contents of
`.github/PULL_REQUEST_TEMPLATE.md` into the `--body` argument and ensure every
section is filled before creating the PR (keep using `$BASE_BRANCH` and preserve
saving the PR URL to `$ARTIFACTS_DIR/.pr-url`), so the workflow always copies
the canonical template verbatim and populates its fields rather than using the
inline markdown shown in the current PR Format section.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d3ef2f1-48cf-4748-b8e2-e11be2ad3715

📥 Commits

Reviewing files that changed from the base of the PR and between 283a978 and 64aad61.

📒 Files selected for processing (11)
  • .archon/commands/defaults/archon-implement-issue.md
  • .archon/workflows/defaults/archon-architect.yaml
  • .archon/workflows/defaults/archon-feature-development.yaml
  • .archon/workflows/defaults/archon-fix-github-issue.yaml
  • .archon/workflows/defaults/archon-idea-to-pr.yaml
  • .archon/workflows/defaults/archon-issue-review-full.yaml
  • .archon/workflows/defaults/archon-piv-loop.yaml
  • .archon/workflows/defaults/archon-plan-to-pr.yaml
  • .archon/workflows/defaults/archon-ralph-dag.yaml
  • .archon/workflows/defaults/archon-refactor-safely.yaml
  • packages/workflows/src/defaults/bundled-defaults.generated.ts
✅ Files skipped from review due to trivial changes (1)
  • .archon/commands/defaults/archon-implement-issue.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • .archon/workflows/defaults/archon-plan-to-pr.yaml
  • .archon/workflows/defaults/archon-piv-loop.yaml
  • .archon/workflows/defaults/archon-fix-github-issue.yaml
  • .archon/workflows/defaults/archon-issue-review-full.yaml
  • .archon/workflows/defaults/archon-ralph-dag.yaml
  • .archon/workflows/defaults/archon-architect.yaml
  • .archon/workflows/defaults/archon-idea-to-pr.yaml

@Wirasm Wirasm merged commit 5d0a90d into coleam00:dev Apr 29, 2026
4 checks passed
@Wirasm Wirasm mentioned this pull request Apr 29, 2026
@ericsoriano ericsoriano deleted the archon-fix-pr-base-targeting branch April 29, 2026 17:19
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.

2 participants