2 Commits

Author SHA1 Message Date
Paul O'Reilly
91f69282cf feat(agent-repo): opt-in AR-42 archive-and-reset of a stale task branch (f910e2ba)
init.sh now archives and resets an existing task/<uuid> branch to the current
base when AGENT_BRANCH_RESET_ON_START=true. Default off: all nodes of a
workflow share the branch, so only the workflow's first node may set it.

Claude-Session: https://claude.ai/code/session_01N218bERyNeLhbLmDRDvbWF
2026-10-09 14:13:37 +13:00
Paul O'Reilly
65fc400fcd fix(gitea-ssh-hatchmate): correct account_ref space id (hatchmate, not platform)
The accelerators/ai-enablement precedent uses the literal 'platform' space
id — those credentials happen to live in the platform-owned CP accounts.
For hatchmate the credentials live in a CP account owned by the hatchmate
space, so the ref must be 'hatchmate.space:hatchmate'. Misnamed ref caused
the dispatcher's account resolver to fail with 'no active account for
AccountRef(name=hatchmate, scope=space:platform)', failing every review
task in the W4 vertical slice within seconds of dispatch.

After this lands and the next CRS sync (~5 min) refreshes the concepts
PVC, the next auto-advance fire on dfc4358c should resolve the account
and proceed through the working-repo clone with the per-org hatchmate key.
2026-09-18 14:18:17 +12:00
2 changed files with 36 additions and 1 deletions

View File

@@ -65,6 +65,41 @@ if [ -n "${AGENT_REPO_URL:-}" ] && [ -n "${AGENT_BRANCH:-}" ]; then
echo "Cloning agent working repo: $AGENT_REPO_URL (branch: $AGENT_BRANCH)"
if git clone --depth 1 --branch "$AGENT_BRANCH" "$AGENT_REPO_URL" /workspace/project 2>/dev/null; then
echo "Cloned existing branch $AGENT_BRANCH (continuing prior work)"
# AR-42: archive the stale task branch and reset it to the current base.
# Opt-in per node (AGENT_BRANCH_RESET_ON_START=true, set by the workflow
# template on its FIRST node only): every node of a workflow shares this
# one branch, so an unconditional reset would wipe earlier nodes' commits.
if [ "${AGENT_BRANCH_RESET_ON_START:-}" = "true" ]; then
mkdir -p /workspace/.agent-output
AR42_TOOL=/opt/agent/agent_repo_base.py
AR42_FAIL() {
echo "ERROR: AR-42 $1" >&2
printf '{"error": "ar42_archive_and_reset_failed", "detail": %s}\n' \
"$(printf '%s' "$1" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()[:500]))')" \
> /workspace/.agent-output/init-error.json
exit 1
}
AR42_SEL=$(python3 "$AR42_TOOL" select-base \
--workdir /workspace/project \
--branch "$AGENT_BRANCH" \
--upstream-url "${AGENT_UPSTREAM_REPO_URL:-}" \
--upstream-branch "${AGENT_UPSTREAM_BRANCH:-main}" \
--reference-dir /workspace/reference/main \
--out /workspace/.agent-output/branch_base.json 2>&1) \
|| AR42_FAIL "select-base failed: $AR42_SEL"
AR42_SHA=$(printf '%s\n' "$AR42_SEL" | sed -n 's/^sha=//p' | head -1)
[ -n "$AR42_SHA" ] || AR42_FAIL "select-base returned no sha: $AR42_SEL"
AR42_OUT=$(python3 "$AR42_TOOL" archive-and-reset \
--workdir /workspace/project \
--branch "$AGENT_BRANCH" \
--base-sha "$AR42_SHA" \
--fork-url "$AGENT_REPO_URL" \
--archive-prefix archive \
--base-metadata /workspace/.agent-output/branch_base.json \
--out /workspace/.agent-output/branch_base.json 2>&1) \
|| AR42_FAIL "archive-and-reset failed: $AR42_OUT"
echo "AR-42: $AGENT_BRANCH reset to base $AR42_SHA"
fi
else
echo "Branch $AGENT_BRANCH does not exist — seeding fresh branch from upstream reference"
# Full clone (not --depth 1) so we get a working remote for finalize.sh push.

View File

@@ -23,6 +23,6 @@ scripts:
secrets_required:
- name: gitea-ssh-hatchmate
account_ref: "hatchmate.space:platform"
account_ref: "hatchmate.space:hatchmate"
mount_path: /run/agent/secrets/gitea-ssh-hatchmate
mode: "0400"