Skip to main content

M9: Single Agent Coding — Bead to PR Pipeline

2026-02-21T13:38:38Z by Showboat 0.6.0

M9 verifies that a live dev agent on Mimas can receive a bead, navigate to a test repo, fix a bug, run tests, create a GitHub PR, and close the bead with the PR link. Two phases: 9.1 (local edit, no PR) and 9.2 (full PR workflow).

Prerequisites

Test repos cloned on Mimas, git identity set, gh auth working for b4arena org.

ssh openclaw@mimas "ls /home/openclaw/b4arena/repos/"
test-calculator
test-greeter
ssh openclaw@mimas "git config --global user.name && git config --global user.email"
b4-dev
b4-dev@b4arena.dev
ssh openclaw@mimas "gh repo view b4arena/test-calculator --json name,url"
{"name":"test-calculator","url":"https://github.com/b4arena/test-calculator"}

Phase 9.1: Local Code Edit (no PR)

Create a bead asking the agent to fix the division-by-zero bug in calc.sh. No branch or PR — just prove the agent can edit code and verify with tests.

ssh openclaw@mimas "cd /home/openclaw/b4arena/repos/test-calculator && bash test.sh 2>&1; echo EXIT:\$?"
FAIL: 10 / 0 → exit=1 (expected 1), output='/home/openclaw/b4arena/repos/test-calculator/calc.sh: line 14: NUM1 / NUM2: division by 0 (error token is "NUM2")'
Tests: 4 passed, 1 failed
EXIT:1

Bug confirmed: division-by-zero test fails. Create the bead:

ssh openclaw@mimas "BEADS_DIR=/home/openclaw/b4arena/beads/.beads BD_ACTOR=demo bd create \"Fix division-by-zero crash in test-calculator\" --labels dev -d \"calc.sh crashes when dividing by zero. Add proper error handling that prints an error message to stderr and exits with code 1. The repo is at /home/openclaw/b4arena/repos/test-calculator. Run test.sh to verify your fix. Do NOT create a branch or PR. Close the bead with a summary of what you changed.\" --json 2>/dev/null"
{
"id": "beads-2b4",
"title": "Fix division-by-zero crash in test-calculator",
"description": "calc.sh crashes when dividing by zero. Add proper error handling that prints an error message to stderr and exits with code 1. The repo is at /home/openclaw/b4arena/repos/test-calculator. Run test.sh to verify your fix. Do NOT create a branch or PR. Close the bead with a summary of what you changed.",
"status": "open",
"priority": 2,
"issue_type": "task",
"owner": "b4-dev@b4arena.dev",
"created_at": "2026-02-21T13:39:35.187156263Z",
"created_by": "demo",
"updated_at": "2026-02-21T13:39:35.187156263Z"
}

Trigger the agent via watcher+dispatcher pipeline. The agent processes the bead (output is the full JSON response, trimmed to final payload):

ssh openclaw@mimas "BEADS_DIR=/home/openclaw/b4arena/beads/.beads bd show beads-2b4 --json 2>/dev/null" | jq ".[0] | {status, assignee, close_reason}"
{
"status": "closed",
"assignee": "dev-agent",
"close_reason": "Added division-by-zero guard in calc.sh: before evaluating the division, the '/' case now checks if NUM2 is 0, prints 'Error: division by zero' to stderr, and exits with code 1. All 5 tests pass (including the new check_error test for divide-by-zero)."
}

Verify the fix — git diff and tests:

ssh openclaw@mimas "cd /home/openclaw/b4arena/repos/test-calculator && git diff HEAD~1 -- calc.sh"
diff --git a/calc.sh b/calc.sh
index 979cac4..2dc7864 100755
--- a/calc.sh
+++ b/calc.sh
@@ -11,6 +11,7 @@ case "$OP" in
+) echo $((NUM1 + NUM2)) ;;
-) echo $((NUM1 - NUM2)) ;;
x) echo $((NUM1 * NUM2)) ;;
- /) echo $((NUM1 / NUM2)) ;;
+ /) if [[ "$NUM2" -eq 0 ]]; then echo "Error: division by zero" >&2; exit 1; fi
+ echo $((NUM1 / NUM2)) ;;
*) echo "Unknown operator: $OP" >&2; exit 1 ;;
esac
ssh openclaw@mimas "cd /home/openclaw/b4arena/repos/test-calculator && bash test.sh"
Tests: 5 passed, 0 failed

PASS. Agent read the bead, claimed it, navigated to the repo, added a zero-check guard in calc.sh, verified all 5 tests pass, and closed the bead with a descriptive reason. No branch or PR created (as instructed).

Phase 9.2: Full PR Workflow

Reset the repo to re-introduce the bug, clear the agent session, then create a bead asking for branch + PR.

ssh openclaw@mimas "cd /home/openclaw/b4arena/repos/test-calculator && git checkout main && git reset --hard origin/main && rm -f /home/openclaw/.openclaw/agents/b4-dev/sessions/sessions.json && echo RESET_DONE"
M	calc.sh
Your branch is up to date with 'origin/main'.
Already on 'main'
HEAD is now at c1daf80 test: add division-by-zero test case
RESET_DONE
ssh openclaw@mimas "BEADS_DIR=/home/openclaw/b4arena/beads/.beads BD_ACTOR=demo bd create \"Fix division-by-zero crash in test-calculator\" --labels dev -d \"calc.sh crashes when dividing by zero. Add proper error handling. The repo is at /home/openclaw/b4arena/repos/test-calculator. Create a branch, fix the bug, run tests, create a PR, then close this bead with the PR URL.\" --json 2>/dev/null"
{
"id": "beads-ttd",
"title": "Fix division-by-zero crash in test-calculator",
"description": "calc.sh crashes when dividing by zero. Add proper error handling. The repo is at /home/openclaw/b4arena/repos/test-calculator. Create a branch, fix the bug, run tests, create a PR, then close this bead with the PR URL.",
"status": "open",
"priority": 2,
"issue_type": "task",
"owner": "b4-dev@b4arena.dev",
"created_at": "2026-02-21T13:41:44.559163367Z",
"created_by": "demo",
"updated_at": "2026-02-21T13:41:44.559163367Z"
}

Run the full pipeline (watcher → dispatcher → agent):

ssh openclaw@mimas "export BEADS_DIR=/home/openclaw/b4arena/beads/.beads && cd /home/openclaw/b4arena && bash scripts/beads-watcher.sh 2>/dev/null | bash scripts/agent-openclaw.sh --label dev --timeout 300 2>&1" 2>/dev/null | grep -E "^(Processing|OK:|{)" | head -3
Processing bead beads-ttd via agent b4-dev (actor: dev-agent)...
OK: bead beads-ttd processed by b4-dev
{

Verify: PR exists on GitHub, bead closed with PR URL, tests pass on PR branch.

ssh openclaw@mimas "gh pr list --repo b4arena/test-calculator --json number,title,url,headRefName"
[{"headRefName":"fix/beads-ttd-division-by-zero","number":3,"title":"Fix: handle division by zero with error message (beads-ttd)","url":"https://github.com/b4arena/test-calculator/pull/3"}]
ssh openclaw@mimas "BEADS_DIR=/home/openclaw/b4arena/beads/.beads bd show beads-ttd --json 2>/dev/null" | jq ".[0] | {status, assignee, close_reason}"
{
"status": "closed",
"assignee": "dev-agent",
"close_reason": "Fixed division-by-zero crash in calc.sh by adding a zero-check before division: prints 'division by zero' to stderr and exits 1. All 5 tests pass. PR: https://github.com/b4arena/test-calculator/pull/3"
}
ssh openclaw@mimas "cd /home/openclaw/b4arena/repos/test-calculator && git checkout fix/beads-ttd-division-by-zero 2>/dev/null && bash test.sh"
Your branch is up to date with 'origin/fix/beads-ttd-division-by-zero'.
Tests: 5 passed, 0 failed

PASS. Agent created branch fix/beads-ttd-division-by-zero, committed the fix, pushed via the multi-org gh wrapper, created PR #3 on GitHub, and closed the bead with the PR URL. All 5 tests pass on the PR branch. No manual token workarounds needed.

Summary

PhaseTestResult
9.1Local code edit (no PR)PASS
9.2Full PR workflow (branch → push → PR → close)PASS

Key observations:

  • Agent uses git push and gh pr create transparently — multi-org wrapper handles token routing.
  • Fresh session (no bleed-through from prior beads) keeps the agent focused and efficient.
  • Bead close reasons include actionable detail (commit hash, PR URL, test count).