interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / scripts / pipeline-proofs / 17-claims-exclusive.sh

34 lines · 2343 bytes Raw Blame History
1#!/usr/bin/env bash
2# 17: two worktrees cannot hold conflicting active claims. Agent A claims a target from worktree 1;
3# agent B's claim on the same target from a linked worktree 2 exits 2 (BLOCKED); B may claim another
4# target; after A closes, B's claim on the first target succeeds. Records claim/close latency.
5# The coordination plane is the clone's own common git dir, so nothing touches the real repository's store.
6here="$(cd "$(dirname "$0")" && pwd)"; . "$here/lib.sh"
7proof_begin 17 "claims are exclusive across linked worktrees" "${1:-}"
8clone_repo "$TMP/a"
9git -C "$TMP/a" worktree add -q "$TMP/wt2" -b proof17-other || { echo "worktree add failed" >&2; exit 1; }
10L=$(leaf_crumb_dir "$TMP/a") || L=docs
11OTHER=$(crumb_dirs "$TMP/a" | grep -v '^\.$' | grep -v "^$L\$" | head -1); [ -n "$OTHER" ] || OTHER=README.md
12num "target=$L"; num "other_target=$OTHER"
13
14cd "$TMP/a" || exit 1
15measure claim_A $CRUMB claim agent-A . "$L" "proof 17: agent A" 600
16check "A claims $L from worktree 1 (rc 0)" [ "$RC" -eq 0 ]; check "A's claim prints CLAIMED" grep -q '^CLAIMED' <<<"$OUT"
17cd "$TMP/wt2" || exit 1
18measure claim_B_conflict $CRUMB claim agent-B . "$L" "proof 17: agent B" 600
19check_eq "B's claim on the same target from worktree 2 exits 2" "$RC" 2
20check "B's refusal names the holder" grep -q 'BLOCKED .*held by agent-A' <<<"$OUT"; note "$(echo "$OUT" | head -1 | cut -c1-120)"
21measure sniff_B $CRUMB sniff agent-B .
22check "sniff from worktree 2 shows A's lock" grep -q 'agent-A' <<<"$OUT"
23measure claim_B_other $CRUMB claim agent-B . "$OTHER" "proof 17: agent B elsewhere" 600
24check "B claims a different target (rc 0)" [ "$RC" -eq 0 ]
25cd "$TMP/a" || exit 1
26measure close_A $CRUMB close agent-A . "$L" modify "proof 17: A done"
27check "A closes (rc 0)" [ "$RC" -eq 0 ]
28cd "$TMP/wt2" || exit 1
29measure claim_B_after_close $CRUMB claim agent-B . "$L" "proof 17: agent B after A closed" 600
30check "B claims the released target (rc 0)" [ "$RC" -eq 0 ]
31$CRUMB close agent-B . "$L" modify "proof 17: B done" >/dev/null; $CRUMB close agent-B . "$OTHER" modify "proof 17: B done" >/dev/null
32check_eq "no locks remain" "$($CRUMB list . | grep -ci 'lock.*agent-' || true)" 0
33check_eq "git status in both worktrees untouched by claims" "$(git -C "$TMP/a" status --porcelain | wc -l)$(git -C "$TMP/wt2" status --porcelain | wc -l)" "00"
34proof_end