From 74fbd0414547e88d82f2dd2681c17a534ffd9894 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 19:10:13 +0100 Subject: [PATCH 01/10] feat: ytstack-frontier owner --pr N names the lane that holds a PR and its last commit (#91) Shares claimed_at and last_commit with check, so both read one clock. Co-Authored-By: Claude Opus 5.5 --- bin/ytstack-frontier | 56 +++++++++++++++++++++++++++++----- tests/ytstack-frontier.test.sh | 21 +++++++++++++ 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/bin/ytstack-frontier b/bin/ytstack-frontier index 39954fe..f895719 100755 --- a/bin/ytstack-frontier +++ b/bin/ytstack-frontier @@ -7,6 +7,7 @@ # ytstack-frontier [-C DIR] set [--status S] [--next TEXT] [--pr N] [--head SHA] [--round N] [--branch B] [--worktree W] # ytstack-frontier [-C DIR] release # ytstack-frontier [-C DIR] check [--minutes N] +# ytstack-frontier [-C DIR] owner --pr N # ytstack-frontier [-C DIR] peer set --repo R --address A [--contact UTC] # ytstack-frontier [-C DIR] peer list # @@ -46,6 +47,11 @@ # a ready lane of `list` that nobody claimed for --minutes since a # check first saw it ready. First sights are kept outside the # tree, under a lock: /repos//frontier-seen. +# owner the lane whose PR cell names pull request N (12 or #12), one line, +# with the clock of check: the holder, the status and the age of the +# last commit on its branch, or of the claim when that is newer: +# lane M004-S03 held by impl-S03 (running), last commit 52 min ago on ytstack/M004-S03 +# The PR watch and ytstack-watch put it into their STALL lines. # peer the sessions in other repositories this coordinator works with, # one line each under "## Peers" in LANES.md: # - | |
| @@ -63,6 +69,7 @@ # release 0; 1 the lane has no row # check 0 "lanes ok" or "no lanes file"; 1 one line per problem; 2 the # file is well-formed and some lanes are stale +# owner 0; 1 no lanes file or no row with that pull request # peer 0 # 64 usage, or a cell value with "|" or a newline @@ -78,7 +85,7 @@ KINDS='implement|review|prepare' NL=' ' -usage() { sed -n '5,11p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } +usage() { sed -n '5,12p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } die() { echo "ytstack-frontier: $*" >&2; exit 1; } # listed listed() { case "|$2|" in *"|$1|"*) return 0 ;; esac; return 1; } @@ -93,7 +100,7 @@ DIR="$PWD" if [ "${1:-}" = "-C" ]; then DIR="${2:-}"; shift 2 || true; fi CMD=list case "${1:-}" in - list|claim|set|release|check|peer) CMD=$1; shift ;; + list|claim|set|release|check|owner|peer) CMD=$1; shift ;; -h|--help|help) usage; exit 0 ;; ""|--*) ;; *) usage >&2; exit 64 ;; @@ -202,6 +209,19 @@ new_table() { } # utc : the UTC time to the minute (BSD date, then GNU and BusyBox) utc() { date -u -r "$1" +%Y-%m-%dT%H:%MZ 2>/dev/null || date -u -d "@$1" +%Y-%m-%dT%H:%MZ; } +# claimed_at <"Claimed by" cell>: the epoch of its claim time, or nothing +claimed_at() { + local t=${1##* } + case "$t" in *T[0-9][0-9]:[0-9][0-9]Z) t="${t%Z}:00Z" ;; esac + yt_epoch "$t" +} +# last_commit : the commit time of the branch's newest commit (the +# local branch, else origin/), or nothing +last_commit() { + [ "$1" != - ] && [ "$YT_IS_GIT" = yes ] || return 0 + git -C "$YT_TOPLEVEL" log -1 --format=%ct "$1" -- 2>/dev/null \ + || git -C "$YT_TOPLEVEL" log -1 --format=%ct "origin/$1" -- 2>/dev/null +} # ---- list ------------------------------------------------------------------------ # open_milestone: the highest milestone whose roadmap is still open. @@ -523,8 +543,7 @@ stale() { if [ "$wt" != - ] && [ ! -d "$c" ]; then echo "stale: $lane: running, but its worktree $wt does not exist: the worker ended; read its branch and set the status"; continue fi - t=${by##* }; case "$t" in *T[0-9][0-9]:[0-9][0-9]Z) t="${t%Z}:00Z" ;; esac - since=$(yt_epoch "$t"); [ -n "$since" ] || continue + since=$(claimed_at "$by"); [ -n "$since" ] || continue if [ "$kind" != implement ]; then [ $((now - since)) -gt $((lim * REVIEW_FACTOR)) ] \ && echo "stale: $lane: running $kind lane, no report for $(((now - since) / 60)) minutes (claimed $(utc "$since"))" @@ -532,8 +551,7 @@ stale() { fi # A PR in the row: a fix round. It starts when a check first sees it. if [ "$pr" != - ]; then seen "fix:$lane:$rnd"; [ "$SEEN_AT" -le "$since" ] || since=$SEEN_AT; fi - c="" - [ "$br" = - ] || [ "$YT_IS_GIT" != yes ] || c=$(git -C "$YT_TOPLEVEL" log -1 --format=%ct "$br" -- 2>/dev/null) + c=$(last_commit "$br") [ -z "$c" ] || [ "$c" -le "$since" ] || since=$c [ $((now - since)) -gt "$lim" ] || continue if [ "$br" = - ]; then echo "stale: $lane: running, no branch in its row, claimed $(((now - since) / 60)) minutes ago" @@ -552,6 +570,29 @@ EOF [ "$locked" = no ] || rm -f "$f.lock" } +# ---- owner ----------------------------------------------------------------------- +cmd_owner() { + local n row lane st by br since c now + [ $# -eq 2 ] && [ "$1" = --pr ] || { usage >&2; return 64; } + case "$2" in ''|*[!0-9]*) usage >&2; return 64 ;; esac + n=$((10#$2)) + [ -n "$YT_DIR" ] && [ -f "$LANES" ] || return 1 + row=$(lane_rows | awk -F'\t' -v n="$n" '$7 == n || $7 == "#" n { print; exit }') + [ -n "$row" ] || return 1 + IFS=' ' read -r lane _ st by br _ </dev/null 2>&1 & done; wait eq "after six checks at once: the state file is whole" "fix:M004-S03:2" "$(cut -f1 "$SEEN")" eq "and no temporary or lock file is left" "frontier-seen" "$(ls "$(dirname "$SEEN")" | grep frontier | paste -sd' ' -)" run "$R" check --minutes x; eq "--minutes takes a number: exit 64" 64 "$EC" +# owner --pr N: the lane that holds a pull request and its last sign of life (issue #91) +run "$R" set M004-S02 --pr 21 +run "$R" owner --pr 21 +eq "owner: the lane with PR 21 in its row" 0 "$EC" +like "its holder, status and the age of its last commit" "^lane M004-S02 held by w2 \(running\), last commit 1[01] min ago on work/s02\$" "$OUT" +run "$R" owner --pr 13 +like "a lane without a branch: the claim" "^lane M004-S07 held by r7 \(running\), claimed 2[34][0-9] min ago, no branch in its row\$" "$OUT" +run "$R" set M004-S08 --branch work/s01 --pr '#14' +run "$R" owner --pr 14 +like "a PR cell written as #14; a claim newer than the last commit counts" "^lane M004-S08 held by p8 \(running\), no commit on work/s01 since its claim 6[01] min ago\$" "$OUT" +run "$R" release M004-S08 +run "$R" owner --pr 14 +eq "a released lane: nobody holds it" "0 lane M004-S08 (dropped), nobody holds it" "$EC $OUT" +run "$R" owner --pr 99 +eq "no row with that PR: exit 1, nothing printed" "1 " "$EC $OUT" +run "$R" owner --pr x; eq "owner --pr takes a number: exit 64" 64 "$EC" +run "$R" owner; eq "owner without --pr: exit 64" 64 "$EC" +mkdir -p "$TMP/bare" +run "$TMP/bare" owner --pr 12; eq "owner without .ytstack: exit 1" "1 " "$EC $OUT" sed 's/| running | w1/| working | w1/' "$L" > "$L.x" && mv "$L.x" "$L" run "$R" check eq "a format problem: exit 1, liveness not read" "1" "$EC" From ebdafb7caf2b3fbaa5334ae4e1043c682a6e28d0 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 19:10:14 +0100 Subject: [PATCH 02/10] feat: ytstack-watch --focus and --stall with the holding lane's liveness (#91) Co-Authored-By: Claude Opus 5.5 --- bin/ytstack-watch | 92 +++++++++++++++++++++++++++++++------ tests/ytstack-watch.test.sh | 89 ++++++++++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 16 deletions(-) diff --git a/bin/ytstack-watch b/bin/ytstack-watch index 91f99be..d04bfa6 100755 --- a/bin/ytstack-watch +++ b/bin/ytstack-watch @@ -2,7 +2,7 @@ # ytstack watch: polls pull requests on the host, and a release on its target, # outside the model. # -# ytstack-watch [-C DIR] --pr N[,N...] [--interval SECONDS] [--once] +# ytstack-watch [-C DIR] --pr N[,N...] [--focus N[,N...]] [--interval SECONDS] [--stall MINUTES] [--once] # ytstack-watch release --commit SHA [--timeout SECONDS] [--interval SECONDS] [-C DIR] # release only reads: it runs the "deployed" and "healthy" commands of # RUNTIME.md. It deploys nothing and rolls nothing back. @@ -27,6 +27,19 @@ # ends when every watched pull request is merged or closed. A finished # pull request is not read again. # +# --focus N[,N...] pull requests to follow closely (with or without --pr): +# listed first and, while one of them is open, read every 20 seconds; +# the others are still read every --interval seconds. +# --stall MINUTES (default 15, 0 = off; not with --once) one line when an +# open pull request sat in an actionable state (checks red, a merge +# conflict, or changes requested on the head commit) for that long +# without a new head, and one more after the next window of the same +# length; a new head or a state that is no longer actionable starts +# the clock again. When LANES.md names the lane that holds it, the +# line ends with that lane's last commit (`ytstack-frontier owner`): +# 2026-11-15T14:30:07Z #12 STALL 1: conflict, review changes_requested; no new head for 15 min (head a1b2c3d); lane M004-S03 held by impl-S03 (running), last commit 52 min ago on ytstack/M004-S03 +# The clock starts when this process first saw the state. +# # Output is plain text, one write per line, meant for a process that forwards # new lines to the model (a background shell, a monitor tool). The values are # host facts with their read time: act on them, do not store them in .ytstack/ @@ -39,7 +52,7 @@ # Exit codes # 0 --once: every pull request was read; loop: all are merged or closed # 1 gh is missing; --once: a read failed; loop: three failed polls in a row -# 64 usage (no --pr, a value that is no number, --interval below 20) +# 64 usage (no --pr or --focus, a value that is no number, --interval below 20) # # ---- release ---- # Follows one commit after a merge, from the "Release" section of RUNTIME.md in @@ -84,12 +97,14 @@ # Test only: YTSTACK_WATCH_SLEEP names a command that runs instead of `sleep` # (it gets the interval as its argument). tests/ytstack-watch.test.sh sets it # to move its fixtures on between polls. YTSTACK_WATCH_ATTEMPT_MAX replaces the -# 30 seconds a call of release may take. Nothing else sets them. +# 30 seconds a call of release may take. YTSTACK_WATCH_CLOCK names a command +# that prints the epoch for the STALL clock. Nothing else sets them. set -uo pipefail MIN_INTERVAL=20 -DIR="$PWD"; PRS=""; INTERVAL=60; ONCE=no +FOCUS_INTERVAL=20 +DIR="$PWD"; PRS=""; FOCUS=""; INTERVAL=60; STALL=15; ONCE=no usage() { sed -n '5,8p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } bad_usage() { [ $# -eq 0 ] || echo "ytstack-watch: $*" >&2; usage >&2; exit 64; } @@ -236,21 +251,33 @@ while [ $# -gt 0 ]; do case "$1" in --once) ONCE=yes; shift; continue ;; -h|--help|help) usage; exit 0 ;; - -C|--pr|--interval) [ $# -ge 2 ] || bad_usage "$1 needs a value" ;; + -C|--pr|--focus|--interval|--stall) [ $# -ge 2 ] || bad_usage "$1 needs a value" ;; *) bad_usage "unknown argument '$1'" ;; esac case "$1" in -C) DIR=$2 ;; --pr) PRS=$2 ;; + --focus) FOCUS=$2 ;; --interval) INTERVAL=$2 ;; + --stall) STALL=$2 ;; esac shift 2 done -case ",$PRS," in - ",,") bad_usage "--pr is required" ;; - *[!0-9,]*|*,,*) bad_usage "--pr takes pull request numbers separated by commas, got '$PRS'" ;; -esac +[ -n "$PRS$FOCUS" ] || bad_usage "--pr or --focus is required" +for list in "$PRS" "$FOCUS"; do + case ",$list," in + ",,") ;; + *[!0-9,]*|*,,*) bad_usage "--pr and --focus take pull request numbers separated by commas, got '$list'" ;; + esac +done +# Focus first; a number in both lists is read once. +ALL="" +for n in $(printf '%s,%s' "$FOCUS" "$PRS" | tr ',' ' '); do + case " $ALL " in *" $n "*) ;; *) ALL="$ALL $n" ;; esac +done +case "$STALL" in ''|*[!0-9]*) bad_usage "--stall takes whole minutes, got '$STALL'" ;; esac +STALL=$((10#$STALL)) case "$INTERVAL" in ''|*[!0-9]*) bad_usage "--interval takes whole seconds, got '$INTERVAL'" ;; esac [ "$INTERVAL" -ge "$MIN_INTERVAL" ] 2>/dev/null \ || bad_usage "--interval $INTERVAL is below the minimum of $MIN_INTERVAL seconds" @@ -304,13 +331,40 @@ EOF [ -n "$MERGE" ] && [ -z "$extra" ] || { ERR="unexpected answer from gh: '$out'"; return 1; } } +clock() { if [ -n "${YTSTACK_WATCH_CLOCK:-}" ]; then "$YTSTACK_WATCH_CLOCK"; else date -u +%s; fi; } +FRONTIER="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/ytstack-frontier" +# stall : the STALL line of an open pull request whose actionable state +# outlasted a window of --stall minutes on the same head (see the header). +stall() { + local n=$1 why="" t k own + [ "$CHECKS" != red ] || why="checks red" + [ "$MERGE" != conflict ] || why="${why:+$why, }conflict" + [ "$REVIEW" != "changes_requested@$HEAD" ] || why="${why:+$why, }review changes_requested" + if [ "$ST" != open ] || [ -z "$why" ]; then STALL_AT[$n]=""; return 0; fi + t=$(clock) + if [ -z "${STALL_AT[$n]:-}" ] || [ "${STALL_HEAD[$n]}" != "$HEAD" ]; then + STALL_AT[$n]=$t; STALL_HEAD[$n]=$HEAD; STALL_N[$n]=0; return 0 + fi + k=$((STALL_N[$n] + 1)) + [ "$k" -le 2 ] && [ $((t - STALL_AT[$n])) -ge $((k * STALL * 60)) ] || return 0 + STALL_N[$n]=$k + own=$(bash "$FRONTIER" -C "$PWD" owner --pr "$n" 2>/dev/null | head -1) + echo "$(now) #$n STALL $k: $why; no new head for $(((t - STALL_AT[$n]) / 60)) min (head $HEAD)${own:+; $own}" +} + # Indexed by pull request number (bash 3.2 has no associative arrays). -LAST=(); MERGE_SEEN=(); FINISHED=() -fails=0 +LAST=(); MERGE_SEEN=(); FINISHED=(); NEXT=(); STALL_AT=(); STALL_HEAD=(); STALL_N=() +fails=0; elapsed=0 while :; do - failed=no; left=0 - for n in $(printf '%s' "$PRS" | tr ',' ' '); do + failed=no; left=0; focus_open=no + for n in $ALL; do [ -z "${FINISHED[$n]:-}" ] || continue + case ",$FOCUS," in + *",$n,"*) ;; + *) # not in focus: every --interval seconds of the loop's time + if [ "$ONCE" = no ] && [ "${NEXT[$n]:-0}" -gt "$elapsed" ]; then left=$((left + 1)); continue; fi + NEXT[$n]=$((elapsed + INTERVAL)) ;; + esac if ! read_pr "$n"; then failed=yes; left=$((left + 1)) if [ "$ONCE" = yes ]; then echo "#$n error: $ERR read $(now)"; else echo "$(now) #$n error: $ERR"; fi @@ -329,7 +383,13 @@ while :; do echo "$(now) #$n $cur" fi LAST[$n]=$cur - if [ "$ST" = open ]; then left=$((left + 1)); else FINISHED[$n]=1; fi + [ "$ONCE" = yes ] || [ "$STALL" -eq 0 ] || stall "$n" + if [ "$ST" = open ]; then + left=$((left + 1)) + case ",$FOCUS," in *",$n,"*) focus_open=yes ;; esac + else + FINISHED[$n]=1 + fi done if [ "$ONCE" = yes ]; then [ "$failed" = no ]; exit $?; fi if [ "$failed" = yes ]; then @@ -342,5 +402,7 @@ while :; do fails=0 fi [ "$left" -gt 0 ] || exit 0 - "${YTSTACK_WATCH_SLEEP:-sleep}" "$INTERVAL" + nap=$INTERVAL; [ "$focus_open" = no ] || nap=$FOCUS_INTERVAL + "${YTSTACK_WATCH_SLEEP:-sleep}" "$nap" + elapsed=$((elapsed + nap)) done diff --git a/tests/ytstack-watch.test.sh b/tests/ytstack-watch.test.sh index de8c661..a64b02b 100644 --- a/tests/ytstack-watch.test.sh +++ b/tests/ytstack-watch.test.sh @@ -12,6 +12,13 @@ # pull request is not read again # errors a failed read prints one line and the loop continues; three # failed polls in a row end it with 1 +# focus --focus PRs are read every 20 seconds and listed first, the +# others every --interval +# stall a STALL line when an open pull request sat in an actionable state +# (red checks, a conflict, changes requested on the head) without +# a new head for --stall minutes (default 15), once per window, +# two windows; with the lane of LANES.md that holds it and that +# lane's last commit (ytstack-frontier owner) # usage no --pr, a value that is no number, --interval below 20: exit 64 # no state nothing is written into the repository # release reads "Release" of RUNTIME.md through bin/ytstack-runtime; asks @@ -267,7 +274,7 @@ watch --pr 12 --interval 19 --once eq "also with --once" 64 "$EC" watch --pr 12 --interval soon; eq "--interval that is no number" 64 "$EC" watch --once; eq "no --pr" 64 "$EC" -has "usage on stderr" "ytstack-watch [-C DIR] --pr N[,N...] [--interval SECONDS] [--once]" "$ERRS" +has "usage on stderr" "ytstack-watch [-C DIR] --pr N[,N...] [--focus N[,N...]] [--interval SECONDS] [--stall MINUTES] [--once]" "$ERRS" watch --pr 12,x --once; eq "--pr with a value that is no number" 64 "$EC" watch --pr "12;id" --once; eq "--pr with shell characters" 64 "$EC" watch --pr 12, --once; eq "--pr with an empty entry" 64 "$EC" @@ -288,6 +295,86 @@ eq "gh ran in that directory" "$REPO" "$(cat "$FIX/cwd")" echo "# no state in the repository" eq "the repository is clean after every run above" "" "$(git -C "$REPO" status --porcelain)" +# ---- 5b. focus pull requests and STALL lines (issue #91) --------------------------- +echo "# focus and stall" +# The clock: five minutes per poll (YTSTACK_WATCH_CLOCK, test only). +cat > "$FAKE/clock" <<'EOF' +#!/usr/bin/env bash +k=$(cat "$FIX/polls" 2>/dev/null || echo 1); echo $((1000000 + (k - 1) * 300)) +EOF +chmod +x "$FAKE/clock" +LREPO="$TMP/lanes"; mkdir -p "$LREPO/.ytstack" +( cd "$LREPO" && git init -q -b main && git config user.email t@t.t && git config user.name t && git config commit.gpgsign false \ + && echo seed > f.txt && git add -A && git commit -qm seed && git branch work/s01 ) >/dev/null 2>&1 +{ printf -- '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n' + echo '| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |' + echo '|---|---|---|---|---|---|---|---|---|---|' + echo '| M001-S01 | implement | running | w1 2026-01-01T00:00Z | work/s01 | - | 20 | - | 1 | fix the review |' +} > "$LREPO/.ytstack/LANES.md" +# swatch : watch in the lanes repository with the fake clock +swatch() { + OUT=$(cd "${SDIR:-$LREPO}" && FIX="$FIX" PATH="$FAKE:$PATH" YTSTACK_WATCH_SLEEP="$FAKE/next-step" YTSTACK_WATCH_CLOCK="$FAKE/clock" bash "$BIN" "$@" 2>"$TMP/stderr"); EC=$? + ERRS=$(cat "$TMP/stderr") +} +fresh +BLOCK=$(review CHANGES_REQUESTED "$A" 2026-11-15T13:40:00Z) +pr "$FIX/now" 20 OPEN "$A" "$RUN_OK" "$BLOCK" MERGEABLE # poll 1 (t 0): a blocking review on the head +pr "$FIX/step5" 20 OPEN "$A" "$RUN_OK" "$BLOCK" CONFLICTING # poll 5 (t 20 min): a conflict too +pr "$FIX/step9" 20 OPEN "$B" "$RUN_OK" "$BLOCK" CONFLICTING # poll 9: a new head; the review is on the old one +pr "$FIX/step10" 20 CLOSED "$B" "$RUN_OK" "$BLOCK" CONFLICTING +swatch --pr 20 +eq "the loop ends when the pull request closed" 0 "$EC" +S1=$(printf '%s\n' "$OUT" | grep ' STALL 1: ') +S2=$(printf '%s\n' "$OUT" | grep ' STALL 2: ') +like "STALL 1 after 15 minutes in an actionable state without a new head, with the lane's liveness" \ + "^$STAMP #20 STALL 1: review changes_requested; no new head for 15 min \(head a1b2c3d\); lane M001-S01 held by w1 \(running\), last commit [0-9]+ min ago on work/s01\$" "$S1" +like "STALL 2 after the next window, with what is actionable now" \ + "^$STAMP #20 STALL 2: conflict, review changes_requested; no new head for 30 min \(head a1b2c3d\); lane M001-S01 " "$S2" +eq "one line per window, two windows only" "1 1" "$(lines "$S1") $(lines "$S2")" +eq "nothing after the new head: no STALL from poll 9 on" 0 "$(printf '%s\n' "$OUT" | sed -n '/head=b2c3d4e/,$p' | grep -c STALL)" +fresh +pr "$FIX/now" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE +pr "$FIX/step4" 20 OPEN "$A" "$RUN_BUSY" "" MERGEABLE # poll 4: the checks run again: not actionable +pr "$FIX/step7" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE +pr "$FIX/step8" 20 MERGED "$A" "$RUN_BAD" "" MERGEABLE +swatch --pr 20 --stall 20 +eq "a state that stops being actionable starts the clock again" 0 "$(printf '%s\n' "$OUT" | grep -c STALL)" +fresh +pr "$FIX/now" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE +pr "$FIX/step6" 20 MERGED "$A" "$RUN_BAD" "" MERGEABLE +swatch --pr 20 --stall 0 +eq "--stall 0: no STALL line" 0 "$(printf '%s\n' "$OUT" | grep -c STALL)" +watch --pr 20 --stall 1 --once +hasnt "--once has no history: no STALL line" "STALL" "$OUT" +watch --pr 20 --stall x; eq "--stall takes whole minutes" 64 "$EC" +fresh +pr "$FIX/now" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE +pr "$FIX/step4" 20 MERGED "$A" "$RUN_BAD" "" MERGEABLE +SDIR=$REPO swatch --pr 20 --stall 1 +like "a pull request without a lane row: the STALL line without liveness" "^$STAMP #20 STALL 1: checks red; no new head for [0-9]+ min \(head a1b2c3d\)\$" "$OUT" + +# --focus: read every 20 seconds and first; the other pull requests every --interval +fresh +pr "$FIX/now" 30 OPEN "$A" "$RUN_OK" "" MERGEABLE +pr "$FIX/now" 31 OPEN "$A" "$RUN_OK" "" MERGEABLE +pr "$FIX/step7" 31 CLOSED "$A" "$RUN_OK" "" MERGEABLE +pr "$FIX/step8" 30 MERGED "$A" "$RUN_OK" "" MERGEABLE +watch --pr 31 --focus 30 +eq "--focus: the loop ends when all are finished" 0 "$EC" +eq "it sleeps 20 seconds while a focus pull request is open" "20 20 20 20 20 20 20" "$(tr '\n' ' ' < "$FIX/sleeps" | sed 's/ $//')" +eq "the focus pull request is read every poll" 8 "$(grep -c 'pr view 30' "$FIX/calls")" +eq "the other one every 60 seconds (polls 1, 4, 7)" 3 "$(grep -c 'pr view 31' "$FIX/calls")" +like "the focus pull request comes first" "^$STAMP #30 " "$(L 1)" +fresh +pr "$FIX/now" 30 OPEN "$A" "$RUN_OK" "" MERGEABLE +pr "$FIX/now" 31 OPEN "$A" "$RUN_OK" "" MERGEABLE +watch --pr 31,30 --focus 30 --once +like "--once: the focus pull request first" "^#30 " "$(L 1)" +eq "a pull request in --pr and --focus is read once" 2 "$(lines "$OUT")" +watch --focus 30 --once +eq "--focus alone is enough" 0 "$EC" +watch --focus 30,x --once; eq "--focus takes numbers" 64 "$EC" + # ---- 6. release ------------------------------------------------------------------- echo "# release" OLD=0123456789abcdef0123456789abcdef01234567 # what the target serves before the rollout From 77d9367657700cfc24dc8fc4886bdc7c8572e20d Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 19:10:17 +0100 Subject: [PATCH 03/10] feat: PR watch focus PRs and STALL marks with the holding lane (#91) register --pr N --focus reads a PR every tick and lists it first; an action_required PR without a new head or status for stall_minutes gets STALL 1 and STALL 2, with ytstack-frontier owner from the watch's checkout. Co-Authored-By: Claude Opus 5.5 --- docs/pr-watch.md | 30 +++++- tests/pr_watch/test_focus_stall.py | 157 +++++++++++++++++++++++++++++ tools/pr-watch/pr-watch.py | 9 +- tools/pr-watch/prwatch/claude.py | 75 ++++++++++++-- tools/pr-watch/prwatch/state.py | 3 +- tools/pr-watch/prwatch/worker.py | 12 +-- 6 files changed, 266 insertions(+), 20 deletions(-) create mode 100644 tests/pr_watch/test_focus_stall.py diff --git a/docs/pr-watch.md b/docs/pr-watch.md index 6b03e33..95aae86 100644 --- a/docs/pr-watch.md +++ b/docs/pr-watch.md @@ -72,6 +72,7 @@ Code, Codex and the worker, and stays the same across plugin updates. ```bash bin/ytstack-pr-watch create --repo OWNER/REPO --session SESSION_ID --cwd WORKTREE -- --title "..." --body-file body.md bin/ytstack-pr-watch register --repo OWNER/REPO --pr 123 --session SESSION_ID --cwd WORKTREE +bin/ytstack-pr-watch register --repo OWNER/REPO --pr 123 --focus # read every tick, listed first (--no-focus undoes it) bin/ytstack-pr-watch register --repo OWNER/REPO --all-open # your open PRs, for this session bin/ytstack-pr-watch handover --from claude: # take over another session's watches bin/ytstack-pr-watch pause --repo OWNER/REPO --pr 123 # and resume @@ -188,6 +189,26 @@ refspec keeps none, then differs from the watched head), the line says `head moved by a push ... ago, not yet polled` instead of the old head's findings, and the worker reads that PR on its next tick. +**Focus and STALL (issue #91).** A PR registered with `--focus` (only with +`--pr`; a later `register` without the flag keeps it, `--no-focus` clears it) +is read on every tick instead of every 5 minutes, and its line stands first in +the block under `Focus (read every tick):`, the other lines under `Others:`. +A PR that is `action_required` (a red check, a conflict, a blocking review or +an unresolved thread), not paused, and has had no new head or status for +`stall_minutes` (15 by default) gets a mark on its line: +`STALL 1: no new head or status for 16 min`, and `STALL 2` after the next +window of the same length; then nothing more until the pause suggestion at +24 hours. Each mark shows the line once, like any other change. When the +watch's checkout (`--cwd` of the registration) is a checkout of the PR's +repository and its `.ytstack/LANES.md` names the PR in a lane row, the mark +ends with that lane's holder and its last sign of life, read from local files +by `ytstack-frontier owner --pr N`: `lane M004-S03 held by impl-S03 (running), +last commit 52 min ago on ytstack/M004-S03`. A blocking review followed by +silence and a lane that is still working look the same without it. What a +coordinator does with the two marks is in `skills/coordinate/SKILL.md`, +Step 7. `bin/ytstack-watch --stall` prints the same two lines for a process +that is not the PR watch. + **Codex.** The worker talks to the running Codex app server over its local socket and starts a turn in the owning thread when that thread is idle, after a fresh GitHub read and a second idle check. Busy or unloaded threads keep the @@ -235,7 +256,8 @@ would use nearly the whole hour on its own. The worker therefore: - reads a PR every minute only while something moves: right after it was registered, and while it is `waiting` within 30 minutes of its last head or - status change. Every other open PR (`ready`, blocked, `unavailable`, or a + status change, and a focus PR always (about 480 calls an hour each, so + focus only the one or two PRs that block others). Every other open PR (`ready`, blocked, `unavailable`, or a `waiting` that never ends, such as a repository without a review policy) is read every 5 minutes; - never takes a snapshot of a closed PR. A closed, unmerged PR can be @@ -281,6 +303,7 @@ finish before a PR counts as ready. Start from - A reviewer with `completion: "review"` is done when it submitted a review on the current head that is not a quota or failure notice. - A skipped or neutral check run that is neither required (branch rules or a label) nor a review bot's check does not block: workflows that skip jobs by change class report their normal green state that way. A required check or a review bot's check that was skipped still blocks. The older key `optional_skipped_checks` is no longer needed and is ignored. - `label_required_checks`: with the label set, the check must exist and pass. +- `stall_minutes` (in `defaults` or per repository, default 15, `0` turns it off): the window of the STALL mark. Without a policy entry a repository still gets notices, but its PRs stay `waiting` ("Expected review bots not configured"). An explicit empty @@ -345,5 +368,6 @@ bin/ytstack-pr-watch uninstall-worker --yes # stop polling ``` State stays in `~/.ytstack/pr-watch/`; delete it yourself once no watch is -needed. `bin/ytstack-watch` is unrelated and unchanged: it reads PR state on -demand while an agent keeps it running. +needed. `bin/ytstack-watch` is a separate process: it reads PR state on demand +while an agent keeps it running, with its own `--focus` and `--stall` and the +same `ytstack-frontier owner` line. diff --git a/tests/pr_watch/test_focus_stall.py b/tests/pr_watch/test_focus_stall.py new file mode 100644 index 0000000..ef0f122 --- /dev/null +++ b/tests/pr_watch/test_focus_stall.py @@ -0,0 +1,157 @@ +"""Issue #91: a focus PR is read every tick and listed first in the status block; an +action_required PR without a new head or status for `stall_minutes` (default 15) gets a +STALL mark, once per window and two windows, with the lane of LANES.md that holds it +(`ytstack-frontier owner`).""" +import io +import json +import os +import subprocess +import sys +import tempfile +import time +import unittest +from contextlib import redirect_stdout, redirect_stderr +from pathlib import Path +from unittest.mock import patch +import test_findings +from test_scope import cli +from test_watch import snapshot, POLICY +from prwatch import github, hooks, worker +from prwatch.state import register + + +class Focus(unittest.TestCase): + setUp = test_findings.Findings.setUp + tearDown = test_findings.Findings.tearDown + + def observe(self, number, s): + with patch.object(github, 'snapshot', return_value=s): + worker.monitor(self.db, self.db.execute('SELECT * FROM watches WHERE number=?', (number,)).fetchone()) + + def prompt(self): + out = hooks.handle({'session_id': 'abc', 'hook_event_name': 'UserPromptSubmit', 'cwd': '/tmp'}, 'claude') + return out['hookSpecificOutput']['additionalContext'] if out else None + + def register_cli(self, *argv): + with patch.object(sys, 'argv', ['pr-watch', 'register', '--repo', 'o/r', '--session', 'claude:abc', *argv]), \ + patch.object(github, 'api', return_value={'state': 'open', 'html_url': 'https://github.com/o/r/pull/7'}), \ + redirect_stdout(io.StringIO()) as out, redirect_stderr(io.StringIO()): + code = cli.main() + return code, out.getvalue() + + def focus(self, number): + return self.db.execute('SELECT focus FROM watches WHERE number=?', (number,)).fetchone()['focus'] + + def test_register_sets_and_clears_focus(self): + code, out = self.register_cli('--pr', '7', '--focus') + self.assertEqual((code, self.focus(7)), (0, 1)) + self.assertIn('(focus)', out) + self.register_cli('--pr', '7') + self.assertEqual(self.focus(7), 1, 'register without the flag keeps it') + self.register_cli('--pr', '7', '--no-focus') + self.assertEqual(self.focus(7), 0) + with self.assertRaises(SystemExit): + self.register_cli('--all-open', '--focus') + + def test_a_focus_pr_is_read_every_tick(self): + with self.db: + register(self.db, 'o/r', 7, 'claude:abc', '/tmp') + self.observe(7, snapshot()) + now = time.time() + with self.db: + self.db.execute('UPDATE watches SET updated=?, changed_at=? WHERE number=7', (now - 60, now - 7200)) + row = lambda: self.db.execute('SELECT * FROM watches WHERE number=7').fetchone() + self.assertFalse(worker.due(row(), now), 'a settled PR waits for the quiet interval') + with self.db: + self.db.execute('UPDATE watches SET focus=1 WHERE number=7') + self.assertTrue(worker.due(row(), now)) + with self.db: + self.db.execute("UPDATE watches SET status='closed' WHERE number=7") + self.assertFalse(worker.due(row(), now), 'never a closed one') + + def test_focus_lines_come_first_and_separately(self): + with self.db: + for n in (7, 8, 9): + register(self.db, 'o/r', n, 'claude:abc', '/tmp') + self.db.execute('UPDATE watches SET focus=1 WHERE number=9') + for n in (7, 8, 9): + self.observe(n, snapshot()) + text = self.prompt() + self.assertLess(text.index('Focus (read every tick):'), text.index('o/r#9')) + self.assertLess(text.index('o/r#9'), text.index('Others:')) + self.assertLess(text.index('Others:'), text.index('o/r#7')) + s = snapshot(); s['pr']['mergeable'] = False + self.observe(8, s) + text = self.prompt() + self.assertNotIn('Focus', text, 'no heading without a focus line') + self.assertIn('o/r#8', text) + + +class Stall(unittest.TestCase): + setUp = test_findings.Findings.setUp + tearDown = test_findings.Findings.tearDown + observe = Focus.observe + prompt = Focus.prompt + + def checkout(self, origin='https://github.com/o/r.git'): + """A checkout of o/r whose LANES.md says lane M001-S01 (branch work/s01) holds PR 7.""" + d = Path(self.tmp.name) / 'checkout' + (d / '.ytstack').mkdir(parents=True) + git = lambda *a: subprocess.run(['git', '-C', str(d), *a], check=True, capture_output=True) + git('init', '-q', '-b', 'main') + git('remote', 'add', 'origin', origin) + claimed = time.strftime('%Y-%m-%dT%H:%MZ', time.gmtime(time.time() - 3 * 3600)) + (d / '.ytstack/LANES.md').write_text( + '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n' + '| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n' + '|---|---|---|---|---|---|---|---|---|---|\n' + f'| M001-S01 | implement | running | w1 {claimed} | - | - | 7 | - | 1 | fix the review |\n') + return str(d) + + def stalled(self, number, minutes, cwd='/tmp'): + with self.db: + register(self.db, 'o/r', number, 'claude:abc', cwd) + s = snapshot(); s['pr']['mergeable'] = False + self.observe(number, s) + self.prompt() + self.age(number, minutes) + + def age(self, number, minutes): + with self.db: + self.db.execute('UPDATE watches SET changed_at=? WHERE number=?', (time.time() - minutes * 60 - 5, number)) + + def test_two_windows_with_the_lane_that_holds_the_pr(self): + self.stalled(7, 14, self.checkout()) + self.assertIsNone(self.prompt(), 'not before the window ends') + self.age(7, 16) + text = self.prompt() + self.assertRegex(text, r'o/r#7: action_required .*; STALL 1: no new head or status for 16 min; ' + r'lane M001-S01 held by w1 \(running\), claimed 1[78]\d min ago, no branch in its row') + self.assertIsNone(self.prompt(), 'once per window') + self.age(7, 31) + self.assertIn('STALL 2: no new head or status for 31 min; lane M001-S01', self.prompt()) + self.age(7, 50) + self.assertIsNone(self.prompt(), 'two windows only') + + def test_without_a_lane_paused_or_switched_off(self): + self.stalled(8, 16) + text = self.prompt() + self.assertIn('STALL 1: no new head or status for 16 min', text) + self.assertNotIn('lane ', text, '/tmp has no LANES.md') + with self.db: + self.db.execute('UPDATE watches SET paused=1 WHERE number=8') + self.age(8, 31) + self.assertNotIn('STALL', self.prompt() or '') + Path(self.tmp.name, 'policy.json').write_text(json.dumps({'defaults': {**POLICY, 'stall_minutes': 0}})) + self.stalled(9, 40) + self.assertNotIn('STALL', self.prompt() or '') + + def test_a_checkout_of_another_repository_names_no_lane(self): + self.stalled(7, 16, self.checkout('https://github.com/o/other.git')) + text = self.prompt() + self.assertIn('STALL 1', text) + self.assertNotIn('lane M001-S01', text) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/pr-watch/pr-watch.py b/tools/pr-watch/pr-watch.py index 0329a5b..36c909b 100755 --- a/tools/pr-watch/pr-watch.py +++ b/tools/pr-watch/pr-watch.py @@ -83,6 +83,8 @@ def main(): add.add_argument('--include-drafts', action='store_true', help='with --all-open: also draft PRs') add.add_argument('--include-labelled', action='store_true', help='with --all-open: also PRs with a do-not-merge label') + add.add_argument('--focus', action=argparse.BooleanOptionalAction, default=None, + help='with --pr: read the PR every tick and list it first (--no-focus undoes it)') add.add_argument('--session', default=default_session) add.add_argument('--cwd', default=os.getcwd()) create = sub.add_parser('create', help='Create a PR and persist ownership before returning') @@ -113,6 +115,8 @@ def main(): args = parser.parse_args() if args.command == 'register' and not args.all_open and (args.author or args.include_drafts or args.include_labelled): parser.error('--author, --include-drafts and --include-labelled apply to --all-open only') + if args.command == 'register' and args.all_open and args.focus is not None: + parser.error('--focus applies to --pr only') # The current Claude session's id given bare would be stored as a Codex thread and never delivered. own = os.environ.get('CLAUDE_CODE_SESSION_ID') if own and getattr(args, 'session', None) == own: @@ -252,7 +256,10 @@ def main(): if pr['state'] != 'open': parser.error('Only open PRs can be registered') register(db, args.repo, args.pr, args.session, str(Path(args.cwd).resolve())) - print('Registered', pr['html_url'], 'to', args.session) + if args.focus is not None: + db.execute('UPDATE watches SET focus=? WHERE repo=? AND number=?', + (int(args.focus), args.repo, args.pr)) + print('Registered', pr['html_url'], 'to', args.session + (' (focus)' if args.focus else '')) elif args.command in ('pause', 'resume'): cursor = db.execute('UPDATE watches SET paused=? WHERE repo=? AND number=?', (int(args.command == 'pause'), args.repo, args.pr)) diff --git a/tools/pr-watch/prwatch/claude.py b/tools/pr-watch/prwatch/claude.py index 120fd5e..97da03d 100644 --- a/tools/pr-watch/prwatch/claude.py +++ b/tools/pr-watch/prwatch/claude.py @@ -10,13 +10,19 @@ agent re-fetches before acting. """ import json +import subprocess import time import uuid -from .state import cli +from pathlib import Path +from .state import cli, policy PREFIX = 'claude:' # A PR action_required without a head or status change for this long gets one pause suggestion. STALE = 24 * 3600 +# Before that: a STALL mark after this many minutes, and once more after the next window +# (policy `stall_minutes`, 0 = off; issue #91). +STALL_MINUTES = 15 +FRONTIER = Path(__file__).resolve().parents[3] / 'bin/ytstack-frontier' def qualify(session): @@ -48,6 +54,35 @@ def is_claude(session): return bool(session) and session.startswith(PREFIX) +def stall_minutes(repo): + try: + return max(0, int(policy(repo).get('stall_minutes', STALL_MINUTES))) + except (TypeError, ValueError): + return STALL_MINUTES + + +def owner(w): + """The lane of LANES.md in the watch's checkout that holds the PR, with its last commit or + claim (`ytstack-frontier owner`), or ''. Only from a checkout of the PR's repository: a PR + number means nothing in another one. Local files only, no GitHub call.""" + from .hooks import REPO + cwd = w['cwd'] or '' + if not cwd or not FRONTIER.is_file(): + return '' + try: + origin = subprocess.run(['git', '-C', cwd, 'remote', 'get-url', 'origin'], + capture_output=True, text=True, timeout=3).stdout.strip() + match = REPO.fullmatch(origin) + if not match or match[1].lower() != w['repo'].lower(): + return '' + p = subprocess.run(['bash', str(FRONTIER), '-C', cwd, 'owner', '--pr', str(w['number'])], + capture_output=True, text=True, timeout=10) + except (OSError, subprocess.TimeoutExpired): + return '' + lines = p.stdout.strip().splitlines() + return lines[0] if p.returncode == 0 and lines else '' + + def _age(seconds): seconds = int(max(0, seconds)) return f'{seconds}s' if seconds < 120 else f'{seconds // 60}min' @@ -71,15 +106,19 @@ def surface(db, session, now=None): return None hinted, hints = _meta_dict(db, hint_key(session)), {} # Each line with its fingerprint (ages excluded); only changed lines are injected (issues #61, #85). - current, due = {}, set() + # A focus or STALL mark joins the fingerprint only when set: older fingerprints stay equal. + current, due, focused, stalled, limits = {}, set(), set(), {}, {} for w in watches: key = f'{w["repo"]}#{w["number"]}' + if 'focus' in w.keys() and w['focus']: + focused.add(key) + mark = (('focus',),) if key in focused else () detail = json.loads(w['detail'] or '[]') paused = ' [paused]' if w['paused'] else '' pushed = w['pushed_at'] if 'pushed_at' in w.keys() else None if pushed and pushed > (w['updated'] or 0): # The old head's findings would mislead: the session pushed since the last read. - current[key] = ((w['paused'], 'moved'), f'- {key}{paused}: head moved by a push ' + current[key] = ((w['paused'], 'moved') + mark, f'- {key}{paused}: head moved by a push ' f'{_age(now - pushed)} ago, not yet polled') continue observed = _age(now - w['updated']) + ' ago' if w['updated'] else 'not yet polled' @@ -88,6 +127,16 @@ def surface(db, session, now=None): + (f' -- {summary}' if summary else '')) # changed_at NULL (rows from before it existed) counts as long ago (state.py). changed = w['changed_at'] if 'changed_at' in w.keys() else None + if w['repo'] not in limits: + limits[w['repo']] = stall_minutes(w['repo']) * 60 + limit = limits[w['repo']] + if (w['status'] == 'action_required' and not w['paused'] and limit and changed is not None + and limit <= now - changed < STALE): + # The lane (owner) is looked up only for a line that is shown. + stall = min(2, int((now - changed) // limit)) + stalled[key] = w + mark += (('stall', stall),) + line += f'; STALL {stall}: no new head or status for {int((now - changed) // 60)} min' if w['status'] == 'action_required' and not w['paused'] and (changed is None or now - changed >= STALE): hints[key] = changed if key not in hinted or hinted[key] != changed: @@ -96,19 +145,27 @@ def surface(db, session, now=None): age = f'{int((now - changed) // 3600)} h' if changed is not None else 'over 24 h' line += (f'; no new head or status for {age}: if nobody works on it, ' f'{cli()} pause --repo {w["repo"]} --pr {w["number"]}') - current[key] = ((w['paused'], w['status'], w['head'], w['detail']), line) + current[key] = ((w['paused'], w['status'], w['head'], w['detail']) + mark, line) fingerprints = {key: json.dumps(fp) for key, (fp, _) in current.items()} with db: db.execute('INSERT OR REPLACE INTO meta VALUES(?,?)', (surface_key(session), json.dumps(fingerprints))) db.execute('INSERT OR REPLACE INTO meta VALUES(?,?)', (hint_key(session), json.dumps(hints))) - changed_lines = [line for key, (_, line) in current.items() if key in due or seen.get(key) != fingerprints[key]] + shown = [key for key in current if key in due or seen.get(key) != fingerprints[key]] + text = {key: current[key][1] + (f'; {lane}' if key in stalled and (lane := owner(stalled[key])) else '') + for key in shown} + focus_lines = [text[key] for key in shown if key in focused] + changed_lines = [text[key] for key in shown if key not in focused] closed_lines = [f'- {w["repo"]}#{w["number"]}: closed' + (' (merged)' if 'merged' in json.loads(w['detail'] or '[]') else '') for w in gone] - if not notices and not changed_lines and not closed_lines: + if not notices and not shown and not closed_lines: return None - unchanged = len(current) - len(changed_lines) - lines = ['PR Watch (silent background monitor; evidence from the last worker tick, re-fetch before acting):', - *changed_lines, *closed_lines] + unchanged = len(current) - len(shown) + lines = ['PR Watch (silent background monitor; evidence from the last worker tick, re-fetch before acting):'] + if focus_lines: + lines += ['Focus (read every tick):', *focus_lines] + if changed_lines or closed_lines or unchanged: + lines.append('Others:') + lines += [*changed_lines, *closed_lines] if unchanged: lines.append(f'- {unchanged} unchanged') if notices: diff --git a/tools/pr-watch/prwatch/state.py b/tools/pr-watch/prwatch/state.py index 38217dc..015103a 100644 --- a/tools/pr-watch/prwatch/state.py +++ b/tools/pr-watch/prwatch/state.py @@ -63,7 +63,8 @@ def connect(): db.execute("UPDATE watches SET closed_at=updated WHERE status='closed'") # The PR's head branch (set by the worker) lets an own `git push` mark the # watch: pushed_at newer than updated means the stored head is stale. - for name, kind in [('branch', 'TEXT'), ('pushed_at', 'REAL')]: + # focus=1 (register --focus): read every tick and listed first (issue #91). + for name, kind in [('branch', 'TEXT'), ('pushed_at', 'REAL'), ('focus', 'INTEGER DEFAULT 0')]: if name not in watch_columns: db.execute(f'ALTER TABLE watches ADD COLUMN {name} {kind}') return db diff --git a/tools/pr-watch/prwatch/worker.py b/tools/pr-watch/prwatch/worker.py index f6f4f85..89cf029 100644 --- a/tools/pr-watch/prwatch/worker.py +++ b/tools/pr-watch/prwatch/worker.py @@ -281,15 +281,15 @@ def tick(send=True, reconcile=True): def due(watch, now): - """Whether a watch is read this tick. A new registration, and a PR whose - head or status changed within FAST_WINDOW while it is still `waiting`, - every tick; every other open PR every QUIET_INTERVAL (a `waiting` that - never ends, such as a repository without a review policy, settles there); - closed ones never (reopen_checks() brings a reopened one back).""" + """Whether a watch is read this tick. A new registration, a focus PR, and a + PR whose head or status changed within FAST_WINDOW while it is still + `waiting`, every tick; every other open PR every QUIET_INTERVAL (a `waiting` + that never ends, such as a repository without a review policy, settles + there); closed ones never (reopen_checks() brings a reopened one back).""" status, age = watch['status'], now - (watch['updated'] or 0) if status == 'closed': return False - if status == 'registered': + if status == 'registered' or ('focus' in watch.keys() and watch['focus']): return True pushed = watch['pushed_at'] if 'pushed_at' in watch.keys() else None if pushed and pushed > (watch['updated'] or 0): From 75ec3a4be7281d2261bfe282eda01c8bfc03f68a Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 19:10:18 +0100 Subject: [PATCH 04/10] feat: coordinate Step 7 asks once on STALL 1, hands over on STALL 2 (#91) Co-Authored-By: Claude Opus 5.5 --- skills/coordinate/SKILL.md | 4 +++- tests/skill-preambles.test.sh | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index 7ee12f6..a0a2fa6 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -3,7 +3,7 @@ name: coordinate description: "Coordinator mode for the session that owns a plan and delegates all of it, writing no product code itself. Use when many lanes are in flight, when a plan has dozens of work packages, when a session with open lanes continues after a compaction or a resume, or when the user says coordinate this, run the plan, you are the coordinator, keep the lanes moving, where does each lane stand. Not for one milestone with a handful of independent slices (spawn-milestone-team) and not for doing a task yourself (plan-task)." metadata: tier: task - version: 0.6.1 + version: 0.6.2 allowed-tools: - Bash - Read @@ -243,6 +243,8 @@ A lane named in the `blocks:` of an open or asked question is not ready, whateve **Watching pull requests.** Polling happens outside the model. The PR watch counts as on only when `pr_watch=on` is set in `~/.ytstack/config` (`docs/pr-watch.md`) and the worker runs (`PR_WATCH: on, heartbeat s ago`, under 600). The flag alone enables only the hooks; without a fresh heartbeat nothing polls. With the PR watch on, the worker reports red checks, unresolved bot threads, conflicts and merges to this session with the next prompt, also for pull requests the lanes' subagents opened. The `register` call defaults to this session; check that its output says `registered to claude:` in Claude Code. `--all-open` takes only open pull requests by your GitHub login (the lanes' workers open them under it) and skips drafts, a `do-not-merge` label and the ones another session owns, each by name; `--author [,]`, `--include-drafts` and `--include-labelled` widen it only where this coordination owns such a pull request. Only the coordinator runs it; a session that works in the same repository outside this coordination keeps its own PRs (`register --pr N`). Without the PR watch, start `ytstack-watch` as a background process; on a host with a monitor tool, through that tool, so that each new line reaches you as an event. It prints a line only when a head moved, the checks changed, a review arrived, mergeability changed or a pull request closed, and it ends when all are merged or closed; start it again with the new list when a pull request opens. Act on a line or a notice: red checks go back to the lane's worker with the name of the check; a review on a commit that is not the head is no review of the head. Never read status in a loop from the conversation, with or without a sleep. The single read of Step 4 before an action is not polling. +**A pull request that stalls.** A pull request other lanes wait on is a focus pull request: `ytstack-pr-watch register --repo --pr --focus` (without the PR watch, `ytstack-watch --focus `) reads it every tick and lists it first. `STALL 1` on its line (PR watch or `ytstack-watch`, `docs/ux/coordinator-format.md`, "Pull requests that stall") means a blocking review, conflict or red check and no new head for one window; the tail names the lane and its last commit. Ask that lane once for an ETA, at its address. `STALL 2` means no head came in the next window: do not relay the same instruction again. Run `ytstack-frontier release `, then `ytstack-frontier claim --by --branch `, and dispatch the fresh worker in a new worktree from `origin/` with the review, conflict or check in its brief; the old worktree keeps its checkout. A STALL without a lane is a pull request outside the lanes: it goes into the next status. + **After a merge.** A pull request that merged, also when a person merged it: set its lane to `merged`, then the release watch and the review lessons of the table. A merged lesson lane also closes its lesson: `ytstack-signals set F### --state fixed` once this checkout has the merged check (the script refuses while the file is missing). The receipt goes into the next status; `not arrived` or `unhealthy` is a status at once. You deploy nothing and roll nothing back: a countermeasure on the target is a step for the human (`ytstack:handover-step`). **Step 8 -- Queue and ask questions.** First look the question up: the plan, `DECISIONS.md`, the answered files in `questions/`. What they answer is not asked. Otherwise `ytstack-questions new --question "" --decides "" --blocks ""` and fill Context, Options and Recommendation until the human can answer from the file alone. The state is `open` and the lanes that do not depend on it go on. Ask as late as the work allows: when nothing ready is left that is independent of it, or at a boundary from a standing instruction. Ask one (`ytstack-questions next`), mark it (`ytstack-questions ask `), and use AskUserQuestion: diff --git a/tests/skill-preambles.test.sh b/tests/skill-preambles.test.sh index e1d3a15..4c377d3 100644 --- a/tests/skill-preambles.test.sh +++ b/tests/skill-preambles.test.sh @@ -493,6 +493,11 @@ awk '/^### Step 14: Lesson/ { p = 1; next } /^### / { p = 0 } p' "$ROOT/skills/f && ok "finish-lane: Step 14 is the lesson" || bad "finish-lane: Step 14 is the lesson" awk '/^\*\*Step 7 --/ { p = 1 } /^\*\*Step 8 --/ { p = 0 } p' "$ROOT/skills/coordinate/SKILL.md" | grep_q -F 'a red `main`' \ && ok "coordinate: Step 7 runs the lesson on a red main" || bad "coordinate: Step 7 runs the lesson on a red main" +# issue #91: STALL 1 asks the lane once, STALL 2 hands the branch to a fresh worker +awk '/^\*\*Step 7 --/ { p = 1 } /^\*\*Step 8 --/ { p = 0 } p' "$ROOT/skills/coordinate/SKILL.md" > "$TMP/step7.md" +for want in '--focus' 'STALL 1' 'STALL 2' 'ytstack-frontier release ' 'ytstack-frontier claim '; do + grep_q -F -- "$want" "$TMP/step7.md" && ok "coordinate: Step 7 names $want" || bad "coordinate: Step 7 names $want" +done # ---- technical spec in the preambles (M022) ---------------------------------- # One area `core` over f.txt and cr.txt (the file the code-review case committed From 72a58d465151b68e697f410a4596a9b7bb584bac Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 19:10:20 +0100 Subject: [PATCH 05/10] docs: focus PRs and STALL lines in coordinator format, spec, DECISIONS, CHANGELOG (#91) Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 21 +++++++++++++++++++++ .ytstack/spec/checks-and-evals.md | 8 ++++---- .ytstack/spec/hooks-and-state.md | 3 ++- .ytstack/spec/skills.md | 4 ++-- CHANGELOG.md | 14 ++++++++++++++ docs/ux/coordinator-format.md | 15 ++++++++++++++- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index d3024f1..3e4779a 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1305,3 +1305,24 @@ Plus: ops-layer split during the same session (yopstack created as own public re - `--worktrees` prints no command for a branch with any open pull request, or whose local head is in neither the pull request head nor `origin/` (unpushed commits). It leaves out the worktree it runs in and reads `LANES.md` from the main checkout (PR #90 review). **Supersedes:** None. Extends "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)". + +## 2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91) + +**Context:** Issue #91: in a coordinator run a PR sat for an hour with a blocking review and then a conflict while its lane ran a long local job and pushed nothing. PR watch reported the conflict among 15 other PRs on every tick, `ytstack-watch` prints only on change, so a PR on which nothing happens was as quiet as a healthy one. The coordinator relayed "merge main" and noticed the stall only after the operator escalated twice. + +**Options considered:** +- Where the stall rule lives: A) only in the PR watch engine, B) only in `ytstack-watch`, C) in both, with the lane lookup in one place. +- Where liveness comes from: the PR watch reading `LANES.md` itself, or a `ytstack-frontier` subcommand both call. +- Focus: an interval per watch, or "every tick" as a flag. + +**Chose:** C. Each watcher keeps its own clock, because the clock is state only it has: the PR watch's `changed_at` (head or status) in its database, `ytstack-watch`'s first sight in its process. The rule is one (an actionable state, no new head for T minutes, default 15, a mark after T and after 2T, never a third) and the lane lookup is one: `ytstack-frontier owner --pr N`, which reuses the clock of `check` (the last commit on the lane's branch, or the claim when newer; `claimed_at` and `last_commit` are shared by both). The PR watch calls it from the UserPromptSubmit hook only for a STALL line it shows, only from the watch's `cwd` and only when that checkout's `origin` is the PR's repository. Focus is a flag: the PR watch reads a focus watch on every 60-second tick and lists it first under `Focus (read every tick):`; `ytstack-watch --focus` reads it every 20 seconds (its minimum) and the others every `--interval`. + +**Reason:** A without B leaves the coordinator without the PR watch (worker off, or another host) with no stall signal, and the PR watch's block reaches a Claude session only with a prompt, while `ytstack-watch` under a monitor tool wakes it. B without A leaves the per-prompt block, where the issue's coordinator looked, as quiet as before. Moving one clock into the other watcher would need the PR watch to run as a long process or `ytstack-watch` to keep state on disk. The lane lookup is the part that must not drift: it reads the coordinator's format, and `ytstack-frontier` already owns that format and the liveness clock. Two windows match what the coordinator does with them (ask once, then hand over); more marks would bring back the noise of issue #85. Stall marks stop at 24 hours, where the pause suggestion takes over. Every tick for a focus PR costs about 480 REST calls an hour, so focus stays opt-in and per PR. + +**How to apply:** +- STALL 1: ask the lane once for an ETA. STALL 2: `ytstack-frontier release `, claim a fresh worker on the same branch in a new worktree, never relay the same instruction a third time (`coordinate` Step 7). +- PR watch: `stall_minutes` in `policy.json` (`defaults` or per repository, 0 = off); `ytstack-watch --stall MINUTES` (0 = off). A focus or stall mark joins a line's fingerprint only when set, so existing fingerprints stay equal across the upgrade. +- The PR watch's state is `action_required` (it includes unresolved threads); `ytstack-watch` counts checks red, a conflict and changes requested on the head, the states its five fields show. +- A new caller that needs "who holds PR N and is it alive" calls `ytstack-frontier owner`, not its own `LANES.md` reader. + +**Supersedes:** None. Extends "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" and "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)". diff --git a/.ytstack/spec/checks-and-evals.md b/.ytstack/spec/checks-and-evals.md index 979a262..f5e8b01 100644 --- a/.ytstack/spec/checks-and-evals.md +++ b/.ytstack/spec/checks-and-evals.md @@ -91,19 +91,19 @@ Everything that tells a contributor whether a change is acceptable: the static c **The coordinator scripts** (formats and rules: `docs/ux/coordinator-format.md`; each has a suite of the same name under `tests/`) -- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). +- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `owner --pr N` prints the lane whose `PR` cell is `N` or `#N`, its holder and status and the age of the last commit on its branch (local, else `origin/`) or of the claim when that is newer, the clock of `check` (exit 1 without a lanes file or row; issue #91); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). - `bin/ytstack-plans` (`docs/ux/external-plans.md`): `scan` counts the work rows (task-list items, rows of tables with a status or checkbox column, nothing in a code fence) of `plans/`, `roadmap/` and their variants and prints one line per directory with `verdict=large` from 10 open rows and the answer recorded in `PREFERENCES.md`; exit 0 only for a large directory without an answer. `rows` prints `path:line`, state, id, section and title per row; a relative PATH is read from where the command was started, else from the repository root, and the output names files relative to the root. It writes nothing; the mapping is the agent's (`reconcile`, `adopt-brownfield`). - `bin/ytstack-questions`: `new`, `list`, `next`, `ask` (once), `answer` (refused without text under "Answer"), `check`. - `bin/ytstack-finish-lane`: one step per call (`leftovers`, `commit`, `push`, `open-pr`, `wait-head`, `body-check`, `gates`, `merge`, `route`); every gate is read from GitHub through `gh` at the moment of the call, and `merge` passes the reviewed commit to the host so that a moved head cannot be merged. `route --lane [--pr ]` reads the lane's worker (the author) and plan from `LANES.md` and runs `bin/ytstack-risk route`; with `--pr` it passes the pull request on, and a lane without a plan file is routed from the host's reviews. `leftovers` and `commit` leave the evidence directory out. Its suite uses a stand-in for `gh` and a local bare remote. - `bin/ytstack-handover`: `new` copies `skills/handover-step/template.sh`; `check` is the static verification of a staged script (syntax, unchanged helper block, no raw command, a confirmation of its own before every mutation, no pipe into a shell). The helpers hold the same rule when the script runs: one yes carries one change. -- `bin/ytstack-watch`: polls pull requests through `gh` and prints a line only when head, checks, review or mergeability changed; `--once` prints the snapshot with its read time. `release --commit ` runs `deployed` of "Release" until it names the commit (or `--timeout`, default 900 s), then `healthy` for the settle time, and ends with five receipt lines (`Target:`, `Commit:`, `Arrived:`, `Health:`, `Result:`) with read times. Exit 0 released or no health command, 2 not arrived, 3 unhealthy, 4 no "Release" section, 1 `RUNTIME.md` fails its check. It runs only those two commands and changes nothing. +- `bin/ytstack-watch`: polls pull requests through `gh` and prints a line only when head, checks, review or mergeability changed; `--once` prints the snapshot with its read time. `--focus N[,N...]` lists those first and reads them every 20 seconds while one is open, the others every `--interval`; `--stall MINUTES` (default 15, 0 off, not with `--once`) prints `#N STALL 1:` when an open pull request had red checks, a conflict or changes requested on the head for that long without a new head, `STALL 2` after the next window, with the line of `ytstack-frontier owner` at the end (issue #91). `release --commit ` runs `deployed` of "Release" until it names the commit (or `--timeout`, default 900 s), then `healthy` for the settle time, and ends with five receipt lines (`Target:`, `Commit:`, `Arrived:`, `Health:`, `Result:`) with read times. Exit 0 released or no health command, 2 not arrived, 3 unhealthy, 4 no "Release" section, 1 `RUNTIME.md` fails its check. It runs only those two commands and changes nothing. **Shell suites: `tests/*.test.sh`** - Plain bash, no framework. A suite prints one line per assertion and ends with its pass and fail count; fixtures live in `mktemp` directories. The comment at the top of each file states the contract it pins. - `tests/run-all.sh` runs every suite from a neutral temporary directory and prints `PASS` or `FAIL` per suite with that suite's last line. It stops at the first failing suite, prints up to ten of its `FAIL` lines and exits 1. The last line is `ALL SUITES PASSED` or `SUITE FAILURE`. `--linux` runs the same inside an `alpine/git` container with the repository mounted read-only; without a working Docker daemon it prints a skip line and exits 0. - `tests/ytstack-check.test.sh` tests the checker on a copy of the plugin tree. `tests/ytstack-spec.test.sh` tests `bin/ytstack-spec` on fixture repositories, one case per rule. `tests/ytstack-brief.test.sh` does the same for `bin/ytstack-brief` and compares the rendered contract with the real `skills/minimal-code/SKILL.md`. `tests/evidence-rule.test.sh` pins the evidence reuse rule: the verifier, the dispatcher and the skills area reuse a PASS only for the same commit, and its git fixture shows why (an unchanged planned file, a changed imported helper, a failing check). -- `tests/pr-watch.test.sh` runs the PR watch engine's `unittest` suite (`tests/pr_watch/`, standard library, `gh` and the Codex daemon mocked) and then shell cases for `hooks/pr-watch` (off, on, malformed input), `bin/ytstack-pr-watch` (enable/disable, install-worker and migrate plans, migrate copy, the worker launcher's engine choice; `register --all-open` with its author, draft and label filters is covered in `tests/pr_watch/test_register_all.py`, the changed-lines block, the pause suggestion and the `status` scope in `test_scope.py`, the `claude:` qualification of a bare session id in `test_session_spelling.py`, the handover to a successor session in `test_handover.py`, skipped checks, a moved head (with `remote_head` against a real temporary repository), the once-per-change status block and the merge suggestion in `test_under_load.py`) under a temporary HOME. The resolver rule of `bin/ytstack-check` exempts `hooks/pr-watch` by name (`_HOOKS_WITHOUT_RESOLVER`). +- `tests/pr-watch.test.sh` runs the PR watch engine's `unittest` suite (`tests/pr_watch/`, standard library, `gh` and the Codex daemon mocked) and then shell cases for `hooks/pr-watch` (off, on, malformed input), `bin/ytstack-pr-watch` (enable/disable, install-worker and migrate plans, migrate copy, the worker launcher's engine choice; `register --all-open` with its author, draft and label filters is covered in `tests/pr_watch/test_register_all.py`, the changed-lines block, the pause suggestion and the `status` scope in `test_scope.py`, the `claude:` qualification of a bare session id in `test_session_spelling.py`, the handover to a successor session in `test_handover.py`, focus watches and STALL marks with the lane from `LANES.md` in `test_focus_stall.py`, skipped checks, a moved head (with `remote_head` against a real temporary repository), the once-per-change status block and the merge suggestion in `test_under_load.py`) under a temporary HOME. The resolver rule of `bin/ytstack-check` exempts `hooks/pr-watch` by name (`_HOOKS_WITHOUT_RESOLVER`). **Python host tests: `tests/*_test.py`** @@ -184,7 +184,7 @@ Not covered by these checks: `claude plugin eval` (costs money). `bash tests/run - DECISIONS.md -- "2026-11-14: Kimi uses native plugin bootstrap and pending lifecycle context (M020)". Source of the offline Kimi CI checks and the separately run native suite. - DECISIONS.md -- "2026-11-13: Whether a person looks at a change is decided per change: a floor from the diff, the class an independent reviewer states, a ceiling per area, lenses per kind of change (M025)". Source of `bin/ytstack-risk` and the lint rules for `auto_merge` and `REVIEW.md`. Extended by "2026-11-15: The risk route reads the review round from the review on the host first; the plan is the fallback (M031-S02, issue #54)". - DECISIONS.md -- "2026-11-13: `RUNTIME.md` has three sections with a fixed line format, read only through `bin/ytstack-runtime` (M025-S01)" -- DECISIONS.md -- "2026-11-13: After a merge the release is watched, not driven; upkeep is a script and a recipe, not a skill (M026)". Source of `release` and `bin/ytstack-upkeep`. Extended by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)": the `stale:` lines, `ytstack-upkeep --worktrees`, `peer set` and `peer list`. +- DECISIONS.md -- "2026-11-13: After a merge the release is watched, not driven; upkeep is a script and a recipe, not a skill (M026)". Source of `release` and `bin/ytstack-upkeep`. Extended by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)": the `stale:` lines, `ytstack-upkeep --worktrees`, `peer set` and `peer list`; and by "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)": `owner`, `ytstack-watch --focus` and `--stall`. - DECISIONS.md -- "2026-11-13: Production findings and incidents are skill work on read-only access; a mitigation is a handover script a person runs (M027)". Source of `bin/ytstack-signals`. "2026-11-15: Feedback about ytstack itself goes through one channel with a setting; a script checks the body, the agent posts (M033-S01, issue #55)" is the source of `bin/ytstack-upstream`. - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)". Source of `bin/ytstack-spec` and the two spec checks. - DECISIONS.md -- "2026-11-13: Verification, review and orchestration work are bounded like code (M023, issue #35)". Source of `bin/ytstack-brief`. diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index 970231f..1d9011a 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -64,7 +64,7 @@ W8 and W9 are prompts for `ytstack:reconcile`, which moves history out with cons Every hook except `pr-watch` sources the library and resolves from the payload `cwd`. Every hook except `session-start` and `pr-watch` exits 0 silently when no `.ytstack` directory resolves. -`pr-watch` (SessionStart, UserPromptSubmit, PreToolUse and PostToolUse on `Bash|mcp__.*create_pull_request.*`; for Codex also Stop, via `bin/ytstack-codex hook pr-watch`) is the opt-in PR watch: it exits 0 with no output and without starting Python unless `~/.ytstack/config` has `pr_watch=on`, then hands the payload to `tools/pr-watch/pr-watch.py hook`. It works for any repository, with or without `.ytstack`, and fails open (an engine error is one stderr line, exit 0). Engine, state (`~/.ytstack/pr-watch/`), worker and migration are described in `docs/pr-watch.md`; `bin/ytstack-check` exempts this hook from the resolver rule by name. For Claude Code the UserPromptSubmit output is injected only when a status line changed since the last injection in that session (one fingerprint per PR line in `meta` key `surface:`, reset on SessionStart) or a notice is pending, and it lists only the changed lines plus `- N unchanged`, and one `closed (merged)` / `closed` line for a watch of the last block that closed since; an `action_required` watch that is not paused and whose `changed_at` is 24 h old or NULL gets one `pause` suggestion per stretch (`meta` key `pause-hint:`, PR to `changed_at`, not reset on SessionStart) (`tests/pr_watch/test_scope.py`); a `git push` the PostToolUse hook sees in a bound worktree sets `pushed_at` on that branch's watch when `refs/remotes/origin/` (without one, `refs/heads/`) then differs from the watched head, which shows `head moved` and makes the worker read it next tick (`tests/pr_watch/test_under_load.py`). A merge the worker observes queues one notice per PR when the watch saw a bot finding on it (outbox key `merged::`, a fixed template that names `ytstack:review-lessons`); it is delivered without the fresh GitHub read other notices get and is never cancelled by a later read (`tests/pr_watch/test_merge_notice.py`). `handover --from [--to ]` moves a session's watches, its undelivered notices (not a Codex notice with a `dispatch_id`), bindings and candidates to its successor and writes `meta` key `handover:`; `register` follows that chain, so a PR a subagent of the old session opens later goes to the successor, and discovery counts a binding of the old session as its successor (no "Multiple sessions" ambiguity). A bare `--from`/`--to` id is qualified to `claude:` when only that is stored, and a bare `--to` naming nothing follows a Claude `--from` (`tests/pr_watch/test_handover.py`). `register --all-open` takes only PRs whose author is the `gh` login or a login of `--author` (case-insensitive, a `[bot]` suffix ignored; without a readable login only `--author`, else an error), and skips drafts and labels that contain the words "do not merge" or `dnm` after `-_/:.` read as spaces unless `--include-drafts` / `--include-labelled` (which, like `--author`, need `--all-open`), naming each skipped PR with its reason and pausing a skipped PR this session already watches (`tests/pr_watch/test_register_all.py`). `status` is scoped to the current session and the `origin` repository of the working directory (`--session`, `--repo` compared without case; `--all` for everything; what does not resolve does not narrow) and prints the `scope` it used; `health` stays whole. +`pr-watch` (SessionStart, UserPromptSubmit, PreToolUse and PostToolUse on `Bash|mcp__.*create_pull_request.*`; for Codex also Stop, via `bin/ytstack-codex hook pr-watch`) is the opt-in PR watch: it exits 0 with no output and without starting Python unless `~/.ytstack/config` has `pr_watch=on`, then hands the payload to `tools/pr-watch/pr-watch.py hook`. It works for any repository, with or without `.ytstack`, and fails open (an engine error is one stderr line, exit 0). Engine, state (`~/.ytstack/pr-watch/`), worker and migration are described in `docs/pr-watch.md`; `bin/ytstack-check` exempts this hook from the resolver rule by name. For Claude Code the UserPromptSubmit output is injected only when a status line changed since the last injection in that session (one fingerprint per PR line in `meta` key `surface:`, reset on SessionStart) or a notice is pending, and it lists only the changed lines plus `- N unchanged`, and one `closed (merged)` / `closed` line for a watch of the last block that closed since; an `action_required` watch that is not paused and whose `changed_at` is 24 h old or NULL gets one `pause` suggestion per stretch (`meta` key `pause-hint:`, PR to `changed_at`, not reset on SessionStart) (`tests/pr_watch/test_scope.py`); before 24 h, an `action_required` watch that is not paused and whose `changed_at` is `stall_minutes` old (policy, default 15, 0 off) gets `STALL 1`, and `STALL 2` after the next window, each part of the fingerprint so it shows once, with the line of `bin/ytstack-frontier owner --pr N` run in the watch's `cwd` when that checkout's `origin` is the PR's repository, only for a line that is shown; a watch with `focus=1` (`register --pr N --focus`, `--no-focus`) is read on every tick and listed first under `Focus (read every tick):`, the rest under `Others:`; the focus and stall marks enter a fingerprint only when set (`tests/pr_watch/test_focus_stall.py`); a `git push` the PostToolUse hook sees in a bound worktree sets `pushed_at` on that branch's watch when `refs/remotes/origin/` (without one, `refs/heads/`) then differs from the watched head, which shows `head moved` and makes the worker read it next tick (`tests/pr_watch/test_under_load.py`). A merge the worker observes queues one notice per PR when the watch saw a bot finding on it (outbox key `merged::`, a fixed template that names `ytstack:review-lessons`); it is delivered without the fresh GitHub read other notices get and is never cancelled by a later read (`tests/pr_watch/test_merge_notice.py`). `handover --from [--to ]` moves a session's watches, its undelivered notices (not a Codex notice with a `dispatch_id`), bindings and candidates to its successor and writes `meta` key `handover:`; `register` follows that chain, so a PR a subagent of the old session opens later goes to the successor, and discovery counts a binding of the old session as its successor (no "Multiple sessions" ambiguity). A bare `--from`/`--to` id is qualified to `claude:` when only that is stored, and a bare `--to` naming nothing follows a Claude `--from` (`tests/pr_watch/test_handover.py`). `register --all-open` takes only PRs whose author is the `gh` login or a login of `--author` (case-insensitive, a `[bot]` suffix ignored; without a readable login only `--author`, else an error), and skips drafts and labels that contain the words "do not merge" or `dnm` after `-_/:.` read as spaces unless `--include-drafts` / `--include-labelled` (which, like `--author`, need `--all-open`), naming each skipped PR with its reason and pausing a skipped PR this session already watches (`tests/pr_watch/test_register_all.py`). `status` is scoped to the current session and the `origin` repository of the working directory (`--session`, `--repo` compared without case; `--all` for everything; what does not resolve does not narrow) and prints the `scope` it used; `health` stays whole. | Hook | Event | Reads from the payload | Effect | Exit | |---|---|---|---|---| @@ -180,6 +180,7 @@ python3 -m unittest discover -s tests -p 'kimi_lifecycle_test.py' -v - DECISIONS.md -- "2026-11-15: SessionStart stays read-only; factory-tool notices are said on startup only, the plugin version is recorded by a prompt hook (M031-S03)" - DECISIONS.md -- "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)" +- DECISIONS.md -- "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)" (focus watches and STALL marks of the PR watch) - DECISIONS.md -- "2026-11-14: Kimi uses native plugin bootstrap and pending lifecycle context (M020)" (plain output is explicit, the helper owns pending context and consumes it once) - DECISIONS.md -- "2026-11-13: Whether a person looks at a change is decided per change: a floor from the diff, the class an independent reviewer states, a ceiling per area, lenses per kind of change (M025)" (`merge_by` and `evidence_dir` in `yt_prefs`) - DECISIONS.md -- "2026-11-07: Hooks never write relative to CLAUDE_PROJECT_DIR; volatile state lives out-of-tree, per session and per worktree" diff --git a/.ytstack/spec/skills.md b/.ytstack/spec/skills.md index 7209eb6..d0f8f88 100644 --- a/.ytstack/spec/skills.md +++ b/.ytstack/spec/skills.md @@ -105,7 +105,7 @@ Read from `PREFERENCES.md` in the resolved `.ytstack` directory by `yt_prefs` in Formats: `docs/ux/coordinator-format.md`. The four skills below are for the session that owns a plan and delegates all of it; none of them writes product code. -- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), ask one question at a time from a question file, write a standing instruction down when it is given (a new file in `standing/`; `STANDING.md` only where no `standing/` exists), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). +- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), ask one question at a time from a question file, write a standing instruction down when it is given (a new file in `standing/`; `STANDING.md` only where no `standing/` exists), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). - `spawn-milestone-team` claims each lane with `bin/ytstack-frontier` before it dispatches, keeps the lane's row current, and looks at the frontier again whenever a lane is verified or merged. - `finish-lane` takes a reported lane to a merged pull request with `bin/ytstack-finish-lane`: review pinned to the host's head, the required lenses, `route`, the gates read from the host, the merge decided by `merge_by` and the route, then `bin/ytstack-watch release` on the merge commit when `RUNTIME.md` has a "Release" section (in the background; the receipt goes into the report, nothing is rolled back). A merge without a person is reported in one line with class, ceiling and lenses. After a merge it made itself, and when `REVIEW.md` declares own reviewers, it invokes `review-lessons` for the pull request. Before a lane goes back for a review that requested changes, a failed lens or a failed check, it invokes `lesson` (its Step 14). These two are the skills it may invoke. The pipeline supports GitHub through `gh` only; on another host the skill stops after the route. - **The class of a change.** `code-review` prints the floor of `bin/ytstack-risk` and has a reviewer that is not the author end with `Risk:`, `Severity:`, `Reach:` and `Invariants touched:`, read against "Invariants and security boundaries" and "Decisions that apply now" of the touched areas, also when only code moved. The round line records class, invariants and reviewer; a session reviewing its own change writes `by: self`, which routes to a person. On a pull request `finish-lane` and `code-review` post the round and lens lines in the body of a review on the reviewed head, and `finish-lane` routes with `--pr`: the record needs no commit that would move the head away from a head-bound review. Each lens the floor names gets a separate fresh reviewer with the lens brief (`bin/ytstack-brief render --kind review --lens `) and one lens line. @@ -196,5 +196,5 @@ Formats: `docs/ux/coordinator-format.md`. The four skills below are for the sess - DECISIONS.md -- "2026-10-13: Remove generated Codex copies; load the existing skills directly" (one skill tree for both hosts) - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)" (the spec steps in the loop) - DECISIONS.md -- "2026-11-13: Verification, review and orchestration work are bounded like code (M023, issue #35)" (the work contract; extends the ceremony entry of 2026-11-07 from code to evidence and review) -- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)", by "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)" and by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" (the peers of `coordinate`) +- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)", by "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)" and by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" (the peers of `coordinate`) and by "2026-11-15: STALL detection lives in both watchers, owner liveness in `ytstack-frontier owner`; focus PRs are read every tick (issue #91)" (focus PRs and the two STALL steps of `coordinate`) - DECISIONS.md -- "2026-11-13: `STATE.md` is a pointer with a size bound; history leaves it through `reconcile`, a closed milestone is folded into the spec (M022-S03)" diff --git a/CHANGELOG.md b/CHANGELOG.md index c36e56b..48e4da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- **Focus PRs and STALL lines** (issue #91): a pull request that sat in a + blocking review, a conflict or a red check with no new head for 15 minutes + now gets a `STALL 1` mark, and `STALL 2` after the next 15, instead of + looking like every other waiting PR. The mark names the lane that holds it + and that lane's last commit, from `LANES.md` + (`ytstack-frontier owner --pr N`, new), so "still working" and "gone" read + differently. Both watchers have it: the PR watch's status block (policy key + `stall_minutes`) and `ytstack-watch --stall MINUTES`. A PR other lanes wait + on can be a focus PR: `ytstack-pr-watch register --pr N --focus` reads it + every tick and lists it first; `ytstack-watch --focus N` reads it every 20 + seconds. `coordinate` 0.6.2, Step 7: on `STALL 1` ask the lane once for an + ETA, on `STALL 2` release the lane and give the branch to a fresh worker + instead of relaying the same instruction again. + - **Progress per phase** (issue #81): `ytstack-status --phases [--json]` prints done, in review and total per milestone and in total. When a total changed since the last report, the line says by how much and why (slices diff --git a/docs/ux/coordinator-format.md b/docs/ux/coordinator-format.md index ff65d29..ef8c6e9 100644 --- a/docs/ux/coordinator-format.md +++ b/docs/ux/coordinator-format.md @@ -91,6 +91,19 @@ stale: M004-S06: ready, nobody claimed it for 70 minutes (first seen 2026-11-15T A `running` row is stale when its worktree no longer exists (the worker ended) or, for an `implement` lane, when its branch had no commit for N minutes (default 60), counted from the claim when that is newer or the row names no branch. A running row with a pull request in it is a fix round (`finish-lane`), not a report: its clock starts when a check first sees that pull request and round in the row, and a new round starts it again. A `review` or `prepare` lane commits nothing; it is stale after 3 x N minutes since its claim without a report. A `ready` lane of the frontier is stale when nobody claimed it for N minutes since a check first saw it ready. First sights are kept outside the tree, one writer at a time (`/repos//frontier-seen`, the base of `yt_state_base`). `bin/ytstack-upkeep` lists these lines under `lanes`. A stale line is a prompt to read the lane's branch and set its row, or to dispatch the ready lane; it never releases a lane by itself. +### Pull requests that stall + +A lane with a pull request can stall in a way the clock above does not see in time: a blocking review, a conflict or a red check, and then nobody pushes. Both watchers say so (issue #91). The rule is the same in both: a pull request in an actionable state with no new head for T minutes (default 15) gets a mark, once after T and once more after the next T, never a third time. + +``` +2026-11-15T14:30:07Z #1896 STALL 1: conflict, review changes_requested; no new head for 15 min (head a1b2c3d); lane M004-S03 held by impl-S03 (running), last commit 52 min ago on ytstack/M004-S03 +- acme/app#1896: action_required (head a1b2c3d4, 40s ago) -- Merge conflict with base branch; STALL 2: no new head or status for 31 min; lane M004-S03 held by impl-S03 (running), last commit 68 min ago on ytstack/M004-S03 +``` + +The first is a line of `ytstack-watch --stall ` (states it counts: checks red, a conflict, changes requested on the head), the second the line of the PR watch's status block (state `action_required`, policy key `stall_minutes`; `docs/pr-watch.md`). The tail after the time is `ytstack-frontier owner --pr `: the lane whose `PR` cell names the pull request (`12` or `#12`), its holder and status, and the age of the last commit on its branch, or of the claim when that is newer, the clock `check` uses. Without such a row the line ends after the time. What the coordinator does with `STALL 1` and `STALL 2` is in `skills/coordinate/SKILL.md`, Step 7. + +A pull request that blocks other lanes is a focus pull request: `ytstack-pr-watch register --pr --focus` reads it on every worker tick and lists it first under `Focus (read every tick):`, `ytstack-watch --focus ` reads it every 20 seconds and prints it first. + ### Lesson lanes Every incident ends with a lesson (`docs/ux/signal-format.md`, "Lessons"). A lesson whose target is a check that nobody built yet, `open` or `planned`, is work that may start like a slice. The frontier lists it after the slices of the milestone, also when no milestone is open: @@ -251,7 +264,7 @@ The old session stays open as a relay until every listed worker has reported. Pe ## Checked mechanically -- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). +- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). `ytstack-frontier owner --pr `: the lane that holds a pull request and its last commit or claim, exit 1 without a row ("Pull requests that stall"). - `bin/ytstack-upkeep --worktrees`: the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest), the age of the last commit, uncommitted changes, unpushed commits and the lane of the main checkout's `LANES.md` that holds them, and the `git worktree remove` / `git branch -D` commands for those whose pull request is merged or closed, with no open one, nothing unpushed, clean, unlocked and unheld. It prints the commands and runs none. - `bin/ytstack-status --phases [--json]`: done, in review and total per milestone and in total, with each change since the last text report, its cause and the phases that joined or left (`docs/statusline.md`, "Progress per phase"). - `bin/ytstack-questions check`: ids are unique and match the file name, `state` holds a listed value, `asked` and `answered` are set exactly when the state says so, an answered file has text under `## Answer`. From 5d5b11d41ad17a5181d4040320c054e7e63f8664 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 19:46:09 +0100 Subject: [PATCH 06/10] fix: ytstack-watch reads blocking reviews per reviewer and keeps focus cadence on a read error (PR #92 review) Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 1 + .ytstack/spec/checks-and-evals.md | 2 +- bin/ytstack-watch | 23 ++++++++++++++++------- docs/ux/coordinator-format.md | 2 +- tests/ytstack-watch.test.sh | 22 +++++++++++++++++++++- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index ed0e713..815f069 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1396,5 +1396,6 @@ Plus: ops-layer split during the same session (yopstack created as own public re - PR watch: `stall_minutes` in `policy.json` (`defaults` or per repository, 0 = off); `ytstack-watch --stall MINUTES` (0 = off). A focus or stall mark joins a line's fingerprint only when set, so existing fingerprints stay equal across the upgrade. - The PR watch's state is `action_required` (it includes unresolved threads); `ytstack-watch` counts checks red, a conflict and changes requested on the head, the states its five fields show. - A new caller that needs "who holds PR N and is it alive" calls `ytstack-frontier owner`, not its own `LANES.md` reader. +- `ytstack-watch` reads a blocking review per reviewer: one whose newest review on the head requests changes blocks, also when another reviewer approved later (the rule of `ytstack-finish-lane`). A failed read of an open focus pull request keeps the 20-second cadence (PR #92 review). **Supersedes:** None. Extends "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" and "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)". diff --git a/.ytstack/spec/checks-and-evals.md b/.ytstack/spec/checks-and-evals.md index ecc9dfb..b472ea1 100644 --- a/.ytstack/spec/checks-and-evals.md +++ b/.ytstack/spec/checks-and-evals.md @@ -97,7 +97,7 @@ Everything that tells a contributor whether a change is acceptable: the static c - `bin/ytstack-questions`: `new`, `list`, `next`, `ask` (once), `answer` (refused without text under "Answer"), `check`. `bin/ytstack-standing` (`docs/ux/coordinator-format.md`, "standing/"): `add` writes one entry, validated by `ytstack-check --standing` before anything is committed, by default in its own worktree outside the checkout on `standing/` with a commit, a push and one pull request per UTC day (opened through `ytstack-pr-watch create` when `pr_watch=on` and the session has an id, else `gh pr create`; updated when one is open); `--here` and user scope write into the resolved directory only; exit 3 when the commit stands but the push or the PR failed; a new day's branch starts from the newest pending standing branch, an earlier one with unpushed commits is pushed first. `end` writes the closing entry of `kind: end`, also of a pending entry. `list` prints the newest entry's age and the human prompts since (from the coordinate session's counter), the active entries with the pending ones marked (local `standing/*` branches and their upstreams only), then the ended ones, the conditions to check and the failed checks; it is the only place `until-check` and `check` run, and only for a working-tree entry identical to the default branch's (bash in its own process group, killed on timeout, stdin closed, `YTSTACK_STANDING_TIMEOUT` seconds each, default 5, at most ten per call, every one not run says why), `--no-checks` runs none. Its suite uses a stand-in for `gh`, a local bare remote behind an `insteadOf` URL and the real `ytstack-pr-watch create`. - `bin/ytstack-finish-lane`: one step per call (`leftovers`, `commit`, `push`, `open-pr`, `wait-head`, `body-check`, `gates`, `merge`, `route`); every gate is read from GitHub through `gh` at the moment of the call, and `merge` passes the reviewed commit to the host so that a moved head cannot be merged. `route --lane [--pr ]` reads the lane's worker (the author) and plan from `LANES.md` and runs `bin/ytstack-risk route`; with `--pr` it passes the pull request on, and a lane without a plan file is routed from the host's reviews. `leftovers` and `commit` leave the evidence directory out. Its suite uses a stand-in for `gh` and a local bare remote. - `bin/ytstack-handover`: `new` copies `skills/handover-step/template.sh`; `check` is the static verification of a staged script (syntax, unchanged helper block, no raw command, a confirmation of its own before every mutation, no pipe into a shell). The helpers hold the same rule when the script runs: one yes carries one change. -- `bin/ytstack-watch`: polls pull requests through `gh` and prints a line only when head, checks, review or mergeability changed; `--once` prints the snapshot with its read time. `--focus N[,N...]` lists those first and reads them every 20 seconds while one is open, the others every `--interval`; `--stall MINUTES` (default 15, 0 off, not with `--once`) prints `#N STALL 1:` when an open pull request had red checks, a conflict or changes requested on the head for that long without a new head, `STALL 2` after the next window, with the line of `ytstack-frontier owner` at the end (issue #91). `release --commit ` runs `deployed` of "Release" until it names the commit (or `--timeout`, default 900 s), then `healthy` for the settle time, and ends with five receipt lines (`Target:`, `Commit:`, `Arrived:`, `Health:`, `Result:`) with read times. Exit 0 released or no health command, 2 not arrived, 3 unhealthy, 4 no "Release" section, 1 `RUNTIME.md` fails its check. It runs only those two commands and changes nothing. +- `bin/ytstack-watch`: polls pull requests through `gh` and prints a line only when head, checks, review or mergeability changed; `--once` prints the snapshot with its read time. `--focus N[,N...]` lists those first and reads them every 20 seconds while one is open, the others every `--interval`; `--stall MINUTES` (default 15, 0 off, not with `--once`) prints `#N STALL 1:` when an open pull request had red checks, a conflict or a reviewer whose newest review on the head requests changes for that long without a new head, `STALL 2` after the next window, with the line of `ytstack-frontier owner` at the end (issue #91). `release --commit ` runs `deployed` of "Release" until it names the commit (or `--timeout`, default 900 s), then `healthy` for the settle time, and ends with five receipt lines (`Target:`, `Commit:`, `Arrived:`, `Health:`, `Result:`) with read times. Exit 0 released or no health command, 2 not arrived, 3 unhealthy, 4 no "Release" section, 1 `RUNTIME.md` fails its check. It runs only those two commands and changes nothing. **Shell suites: `tests/*.test.sh`** diff --git a/bin/ytstack-watch b/bin/ytstack-watch index d04bfa6..57d742f 100755 --- a/bin/ytstack-watch +++ b/bin/ytstack-watch @@ -32,7 +32,8 @@ # the others are still read every --interval seconds. # --stall MINUTES (default 15, 0 = off; not with --once) one line when an # open pull request sat in an actionable state (checks red, a merge -# conflict, or changes requested on the head commit) for that long +# conflict, or a reviewer whose newest review on the head requests +# changes, also after another reviewer approved) for that long # without a new head, and one more after the next window of the same # length; a new head or a state that is no longer actionable starts # the clock again. When LANES.md names the lane that holds it, the @@ -310,25 +311,31 @@ def one: else ($r.state | ascii_downcase) + "@" + (($r.commit.oid // "unknown")[0:7]) end), (if .mergeable == "MERGEABLE" then "mergeable" elif .mergeable == "CONFLICTING" then "conflict" - else "unknown" end) + else "unknown" end), + # blocked: a reviewer whose newest review on the head requests changes + # (another reviewer approving later does not lift it; as ytstack-finish-lane) + (.headRefOid as $h + | [ (.reviews // [])[] | select(.submittedAt != null and .commit.oid == $h) ] + | if any(group_by(.author.login)[]; max_by(.submittedAt).state == "CHANGES_REQUESTED") + then "blocked" else "-" end) ] | join(" ")' ERRF=$(mktemp "${TMPDIR:-/tmp}/ytwatch.XXXXXX") || exit 1 trap 'rm -f "$ERRF"' EXIT -# read_pr : sets ST HEAD CHECKS REVIEW MERGE; on failure returns 1 with the -# reason in ERR. An answer that is not the five expected words is a failure. +# read_pr : sets ST HEAD CHECKS REVIEW MERGE BLOCK; on failure returns 1 with +# the reason in ERR. An answer that is not the six expected words is a failure. read_pr() { local out extra if ! out=$(gh pr view "$1" --json state,headRefOid,statusCheckRollup,reviews,mergeable --jq "$JQ" 2>"$ERRF"); then ERR=$(head -1 "$ERRF"); ERR=${ERR:-gh exited with an error and no message} return 1 fi - read -r ST HEAD CHECKS REVIEW MERGE extra <` (states it counts: checks red, a conflict, changes requested on the head), the second the line of the PR watch's status block (state `action_required`, policy key `stall_minutes`; `docs/pr-watch.md`). The tail after the time is `ytstack-frontier owner --pr `: the lane whose `PR` cell names the pull request (`12` or `#12`), its holder and status, and the age of the last commit on its branch, or of the claim when that is newer, the clock `check` uses. Without such a row the line ends after the time. What the coordinator does with `STALL 1` and `STALL 2` is in `skills/coordinate/SKILL.md`, Step 7. +The first is a line of `ytstack-watch --stall ` (states it counts: checks red, a conflict, a reviewer whose newest review on the head requests changes), the second the line of the PR watch's status block (state `action_required`, policy key `stall_minutes`; `docs/pr-watch.md`). The tail after the time is `ytstack-frontier owner --pr `: the lane whose `PR` cell names the pull request (`12` or `#12`), its holder and status, and the age of the last commit on its branch, or of the claim when that is newer, the clock `check` uses. Without such a row the line ends after the time. What the coordinator does with `STALL 1` and `STALL 2` is in `skills/coordinate/SKILL.md`, Step 7. A pull request that blocks other lanes is a focus pull request: `ytstack-pr-watch register --pr --focus` reads it on every worker tick and lists it first under `Focus (read every tick):`, `ytstack-watch --focus ` reads it every 20 seconds and prints it first. diff --git a/tests/ytstack-watch.test.sh b/tests/ytstack-watch.test.sh index a64b02b..af68ad7 100644 --- a/tests/ytstack-watch.test.sh +++ b/tests/ytstack-watch.test.sh @@ -15,7 +15,8 @@ # focus --focus PRs are read every 20 seconds and listed first, the # others every --interval # stall a STALL line when an open pull request sat in an actionable state -# (red checks, a conflict, changes requested on the head) without +# (red checks, a conflict, a reviewer's newest review on the head +# requests changes) without # a new head for --stall minutes (default 15), once per window, # two windows; with the lane of LANES.md that holds it and that # lane's last commit (ytstack-frontier owner) @@ -332,6 +333,18 @@ like "STALL 2 after the next window, with what is actionable now" \ "^$STAMP #20 STALL 2: conflict, review changes_requested; no new head for 30 min \(head a1b2c3d\); lane M001-S01 " "$S2" eq "one line per window, two windows only" "1 1" "$(lines "$S1") $(lines "$S2")" eq "nothing after the new head: no STALL from poll 9 on" 0 "$(printf '%s\n' "$OUT" | sed -n '/head=b2c3d4e/,$p' | grep -c STALL)" +# PR #92 review: a later approval by another reviewer does not lift a changes request +fresh +OTHER='{"author":{"login":"rev2"},"state":"CHANGES_REQUESTED","submittedAt":"2026-11-15T13:00:00Z","commit":{"oid":"'"$A"'"}}' +pr "$FIX/now" 20 OPEN "$A" "$RUN_OK" "$OTHER,$(review APPROVED "$A" 2026-11-15T14:00:00Z)" MERGEABLE +pr "$FIX/step5" 20 MERGED "$A" "$RUN_OK" "$OTHER,$(review APPROVED "$A" 2026-11-15T14:00:00Z)" MERGEABLE +swatch --pr 20 +like "a reviewer's changes request stays blocking after another reviewer approved" "^$STAMP #20 STALL 1: review changes_requested; " "$OUT" +fresh +pr "$FIX/now" 20 OPEN "$A" "$RUN_OK" "$OTHER,$(review APPROVED "$A" 2026-11-15T14:00:00Z),$(echo "$OTHER" | sed 's/CHANGES_REQUESTED/APPROVED/; s/13:00/15:00/')" MERGEABLE +pr "$FIX/step5" 20 MERGED "$A" "$RUN_OK" "" MERGEABLE +swatch --pr 20 +eq "the same reviewer's newer approval lifts it" 0 "$(printf '%s\n' "$OUT" | grep -c STALL)" fresh pr "$FIX/now" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE pr "$FIX/step4" 20 OPEN "$A" "$RUN_BUSY" "" MERGEABLE # poll 4: the checks run again: not actionable @@ -365,6 +378,13 @@ eq "it sleeps 20 seconds while a focus pull request is open" "20 20 20 20 20 20 eq "the focus pull request is read every poll" 8 "$(grep -c 'pr view 30' "$FIX/calls")" eq "the other one every 60 seconds (polls 1, 4, 7)" 3 "$(grep -c 'pr view 31' "$FIX/calls")" like "the focus pull request comes first" "^$STAMP #30 " "$(L 1)" +# PR #92 review: a failed read of an open focus pull request keeps the 20 seconds +fresh +pr "$FIX/now" 30 OPEN "$A" "$RUN_OK" "" MERGEABLE +mkdir -p "$FIX/step2" "$FIX/step3"; echo "HTTP 502: Bad Gateway" > "$FIX/step2/30.err"; : > "$FIX/step3/30.err.gone" +pr "$FIX/step3" 30 MERGED "$A" "$RUN_OK" "" MERGEABLE +watch --focus 30 --interval 300 +eq "after a failed read of a focus pull request the loop still sleeps 20 seconds" "20 20" "$(tr '\n' ' ' < "$FIX/sleeps" | sed 's/ $//')" fresh pr "$FIX/now" 30 OPEN "$A" "$RUN_OK" "" MERGEABLE pr "$FIX/now" 31 OPEN "$A" "$RUN_OK" "" MERGEABLE From 630e9e2210363782b21fae43a2a1e1cd130ad43d Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 21:16:25 +0100 Subject: [PATCH 07/10] fix: frontier owner takes several PRs and prefers a held row; re-claim worktree tested (PR #92 review) Co-Authored-By: Claude Opus 5.5 --- bin/ytstack-frontier | 45 +++++++++++++++++++++++++++------- tests/ytstack-frontier.test.sh | 26 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/bin/ytstack-frontier b/bin/ytstack-frontier index f895719..a3438dc 100755 --- a/bin/ytstack-frontier +++ b/bin/ytstack-frontier @@ -7,7 +7,7 @@ # ytstack-frontier [-C DIR] set [--status S] [--next TEXT] [--pr N] [--head SHA] [--round N] [--branch B] [--worktree W] # ytstack-frontier [-C DIR] release # ytstack-frontier [-C DIR] check [--minutes N] -# ytstack-frontier [-C DIR] owner --pr N +# ytstack-frontier [-C DIR] owner --pr N[,N...] [--pr N...] # ytstack-frontier [-C DIR] peer set --repo R --address A [--contact UTC] # ytstack-frontier [-C DIR] peer list # @@ -51,7 +51,12 @@ # with the clock of check: the holder, the status and the age of the # last commit on its branch, or of the claim when that is newer: # lane M004-S03 held by impl-S03 (running), last commit 52 min ago on ytstack/M004-S03 +# A held row wins over a dropped or merged one with the same PR. +# With several PRs (comma separated or --pr repeated) each line +# starts with the number and a tab; PRs without a row are left out. # The PR watch and ytstack-watch put it into their STALL lines. +# claim on a released row keeps branch and worktree unless given: +# --worktree sets a fresh worker's worktree, --worktree - clears it. # peer the sessions in other repositories this coordinator works with, # one line each under "## Peers" in LANES.md: # - | |
| @@ -69,7 +74,7 @@ # release 0; 1 the lane has no row # check 0 "lanes ok" or "no lanes file"; 1 one line per problem; 2 the # file is well-formed and some lanes are stale -# owner 0; 1 no lanes file or no row with that pull request +# owner 0; 1 no lanes file or no row with any of the pull requests # peer 0 # 64 usage, or a cell value with "|" or a newline @@ -572,15 +577,37 @@ EOF # ---- owner ----------------------------------------------------------------------- cmd_owner() { - local n row lane st by br since c now - [ $# -eq 2 ] && [ "$1" = --pr ] || { usage >&2; return 64; } - case "$2" in ''|*[!0-9]*) usage >&2; return 64 ;; esac - n=$((10#$2)) + local list="" n rows row found=no + while [ $# -gt 0 ]; do + [ "$1" = --pr ] && [ $# -ge 2 ] || { usage >&2; return 64; } + case ",$2," in *[!0-9,]*|*,,*) usage >&2; return 64 ;; esac + list="$list${list:+,}$2"; shift 2 + done + [ -n "$list" ] || { usage >&2; return 64; } [ -n "$YT_DIR" ] && [ -f "$LANES" ] || return 1 - row=$(lane_rows | awk -F'\t' -v n="$n" '$7 == n || $7 == "#" n { print; exit }') - [ -n "$row" ] || return 1 + rows=$(lane_rows) + for n in $(printf '%s' "$list" | tr ',' ' '); do + n=$((10#$n)) + # A held row first, else the first row that names the PR. + row=$(printf '%s\n' "$rows" | awk -F'\t' -v n="$n" -v held="$HELD" ' + $7 == n || $7 == "#" n { + if (index("|" held "|", "|" $3 "|")) { print; f = 1; exit } + if (first == "") first = $0 + } + END { if (!f && first != "") print first }') + [ -n "$row" ] || continue + found=yes + # Several PRs: each line starts with its number and a tab. + case "$list" in *,*) printf '%s\t' "$n" ;; esac + owner_line "$row" + done + [ "$found" = yes ] +} +# owner_line : the lane, its holder and status, and its last sign of life +owner_line() { + local lane st by br since c now IFS=' ' read -r lane _ st by br _ < "$OL" +run "$O" owner --pr 30 +like "the held row wins over a dropped row with the same PR" "^lane M001-S02 held by w2 \(running\), " "$OUT" +run "$O" owner --pr 30 --pr 31,99 +eq "several PRs: exit 0" 0 "$EC" +eq "one line per PR with a row" 2 "$(printf '%s\n' "$OUT" | grep -c .)" +like "each led by the number and a tab (30)" "^30${TAB}lane M001-S02 held by w2 \(running\), claimed 1[01] min ago, no branch in its row\$" "$OUT" +like "each led by the number and a tab (31, written #31)" "^31${TAB}lane M001-S03 held by w3 \(running\), claimed 2[01] min ago, no branch in its row\$" "$OUT" +run "$O" owner --pr 98,99 +eq "several PRs, none with a row: exit 1, nothing printed" "1 " "$EC $OUT" +run "$O" owner --pr 30,x; eq "a list with no number: exit 64" 64 "$EC" +run "$O" release M001-S02 +run "$O" claim M001-S02 --by w9 --branch work/s02 --worktree wt/fresh +has "a re-claim sets the fresh worker's worktree" "| work/s02 | wt/fresh | 30 |" "$(grep '^| M001-S02 ' "$OL")" +run "$O" release M001-S02 +run "$O" claim M001-S02 --by w10 --worktree - +has "--worktree - clears it, the branch stays" "| work/s02 | - | 30 |" "$(grep '^| M001-S02 ' "$OL")" sed 's/| running | w1/| working | w1/' "$L" > "$L.x" && mv "$L.x" "$L" run "$R" check eq "a format problem: exit 1, liveness not read" "1" "$EC" From 95f9fac7c5ca0ddb7c70e479ef8b6501fcc1c253 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 21:16:25 +0100 Subject: [PATCH 08/10] fix: PR watch shows STALL 1 before STALL 2 and looks lanes up once per checkout before saving (PR #92 review) Co-Authored-By: Claude Opus 5.5 --- .ytstack/spec/hooks-and-state.md | 2 +- docs/pr-watch.md | 14 +++-- tests/pr_watch/test_focus_stall.py | 96 +++++++++++++++++++++++++++--- tools/pr-watch/prwatch/claude.py | 87 ++++++++++++++++++++------- 4 files changed, 163 insertions(+), 36 deletions(-) diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index 99595b3..01e5f77 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -64,7 +64,7 @@ W8 and W9 are prompts for `ytstack:reconcile`, which moves history out with cons Every hook except `pr-watch` sources the library and resolves from the payload `cwd`. Every hook except `session-start` and `pr-watch` exits 0 silently when no `.ytstack` directory resolves. -`pr-watch` (SessionStart, UserPromptSubmit, PreToolUse and PostToolUse on `Bash|mcp__.*create_pull_request.*`; for Codex also Stop, via `bin/ytstack-codex hook pr-watch`) is the opt-in PR watch: it exits 0 with no output and without starting Python unless `~/.ytstack/config` has `pr_watch=on`, then hands the payload to `tools/pr-watch/pr-watch.py hook`. It works for any repository, with or without `.ytstack`, and fails open (an engine error is one stderr line, exit 0). Engine, state (`~/.ytstack/pr-watch/`), worker and migration are described in `docs/pr-watch.md`; `bin/ytstack-check` exempts this hook from the resolver rule by name. For Claude Code the UserPromptSubmit output is injected only when a status line changed since the last injection in that session (one fingerprint per PR line in `meta` key `surface:`, reset on SessionStart) or a notice is pending, and it lists only the changed lines plus `- N unchanged`, and one `closed (merged)` / `closed` line for a watch of the last block that closed since; an `action_required` watch that is not paused and whose `changed_at` is 24 h old or NULL gets one `pause` suggestion per stretch (`meta` key `pause-hint:`, PR to `changed_at`, not reset on SessionStart) (`tests/pr_watch/test_scope.py`); before 24 h, an `action_required` watch that is not paused and whose `changed_at` is `stall_minutes` old (policy, default 15, 0 off) gets `STALL 1`, and `STALL 2` after the next window, each part of the fingerprint so it shows once, with the line of `bin/ytstack-frontier owner --pr N` run in the watch's `cwd` when that checkout's `origin` is the PR's repository, only for a line that is shown; a watch with `focus=1` (`register --pr N --focus`, `--no-focus`) is read on every tick and listed first under `Focus (read every tick):`, the rest under `Others:`; the focus and stall marks enter a fingerprint only when set (`tests/pr_watch/test_focus_stall.py`); a `git push` the PostToolUse hook sees in a bound worktree sets `pushed_at` on that branch's watch when `refs/remotes/origin/` (without one, `refs/heads/`) then differs from the watched head, which shows `head moved` and makes the worker read it next tick (`tests/pr_watch/test_under_load.py`). A merge the worker observes queues one notice per PR when the watch saw a bot finding on it (outbox key `merged::`, a fixed template that names `ytstack:review-lessons`); it is delivered without the fresh GitHub read other notices get and is never cancelled by a later read (`tests/pr_watch/test_merge_notice.py`). `handover --from [--to ]` moves a session's watches, its undelivered notices (not a Codex notice with a `dispatch_id`), bindings and candidates to its successor and writes `meta` key `handover:`; `register` follows that chain, so a PR a subagent of the old session opens later goes to the successor, and discovery counts a binding of the old session as its successor (no "Multiple sessions" ambiguity). A bare `--from`/`--to` id is qualified to `claude:` when only that is stored, and a bare `--to` naming nothing follows a Claude `--from` (`tests/pr_watch/test_handover.py`). `register --all-open` takes only PRs whose author is the `gh` login or a login of `--author` (case-insensitive, a `[bot]` suffix ignored; without a readable login only `--author`, else an error), and skips drafts and labels that contain the words "do not merge" or `dnm` after `-_/:.` read as spaces unless `--include-drafts` / `--include-labelled` (which, like `--author`, need `--all-open`), naming each skipped PR with its reason and pausing a skipped PR this session already watches (`tests/pr_watch/test_register_all.py`). `status` is scoped to the current session and the `origin` repository of the working directory (`--session`, `--repo` compared without case; `--all` for everything; what does not resolve does not narrow) and prints the `scope` it used; `health` stays whole. +`pr-watch` (SessionStart, UserPromptSubmit, PreToolUse and PostToolUse on `Bash|mcp__.*create_pull_request.*`; for Codex also Stop, via `bin/ytstack-codex hook pr-watch`) is the opt-in PR watch: it exits 0 with no output and without starting Python unless `~/.ytstack/config` has `pr_watch=on`, then hands the payload to `tools/pr-watch/pr-watch.py hook`. It works for any repository, with or without `.ytstack`, and fails open (an engine error is one stderr line, exit 0). Engine, state (`~/.ytstack/pr-watch/`), worker and migration are described in `docs/pr-watch.md`; `bin/ytstack-check` exempts this hook from the resolver rule by name. For Claude Code the UserPromptSubmit output is injected only when a status line changed since the last injection in that session (one fingerprint per PR line in `meta` key `surface:`, reset on SessionStart) or a notice is pending, and it lists only the changed lines plus `- N unchanged`, and one `closed (merged)` / `closed` line for a watch of the last block that closed since; an `action_required` watch that is not paused and whose `changed_at` is 24 h old or NULL gets one `pause` suggestion per stretch (`meta` key `pause-hint:`, PR to `changed_at`, not reset on SessionStart) (`tests/pr_watch/test_scope.py`); before 24 h, an `action_required` watch that is not paused and whose `changed_at` is `stall_minutes` old (policy, default 15, 0 off) gets `STALL 1` first, and `STALL 2` a full window after `STALL 1` was shown (`meta` key `stall:`, PR to `changed_at`, step and time shown), each part of the fingerprint so it shows once, with the line of `bin/ytstack-frontier owner --pr N,...`, one call per `cwd` whose `origin` is the PR's repository, only for lines that are shown, all within `OWNER_BUDGET` (3 s), resolved before the fingerprints are saved and never failing the block; a watch with `focus=1` (`register --pr N --focus`, `--no-focus`) is read on every tick and listed first under `Focus (read every tick):`, the rest under `Others:`; the focus and stall marks enter a fingerprint only when set (`tests/pr_watch/test_focus_stall.py`); a `git push` the PostToolUse hook sees in a bound worktree sets `pushed_at` on that branch's watch when `refs/remotes/origin/` (without one, `refs/heads/`) then differs from the watched head, which shows `head moved` and makes the worker read it next tick (`tests/pr_watch/test_under_load.py`). A merge the worker observes queues one notice per PR when the watch saw a bot finding on it (outbox key `merged::`, a fixed template that names `ytstack:review-lessons`); it is delivered without the fresh GitHub read other notices get and is never cancelled by a later read (`tests/pr_watch/test_merge_notice.py`). `handover --from [--to ]` moves a session's watches, its undelivered notices (not a Codex notice with a `dispatch_id`), bindings and candidates to its successor and writes `meta` key `handover:`; `register` follows that chain, so a PR a subagent of the old session opens later goes to the successor, and discovery counts a binding of the old session as its successor (no "Multiple sessions" ambiguity). A bare `--from`/`--to` id is qualified to `claude:` when only that is stored, and a bare `--to` naming nothing follows a Claude `--from` (`tests/pr_watch/test_handover.py`). `register --all-open` takes only PRs whose author is the `gh` login or a login of `--author` (case-insensitive, a `[bot]` suffix ignored; without a readable login only `--author`, else an error), and skips drafts and labels that contain the words "do not merge" or `dnm` after `-_/:.` read as spaces unless `--include-drafts` / `--include-labelled` (which, like `--author`, need `--all-open`), naming each skipped PR with its reason and pausing a skipped PR this session already watches (`tests/pr_watch/test_register_all.py`). `status` is scoped to the current session and the `origin` repository of the working directory (`--session`, `--repo` compared without case; `--all` for everything; what does not resolve does not narrow) and prints the `scope` it used; `health` stays whole. | Hook | Event | Reads from the payload | Effect | Exit | |---|---|---|---|---| diff --git a/docs/pr-watch.md b/docs/pr-watch.md index 95aae86..4d8ee45 100644 --- a/docs/pr-watch.md +++ b/docs/pr-watch.md @@ -196,15 +196,21 @@ the block under `Focus (read every tick):`, the other lines under `Others:`. A PR that is `action_required` (a red check, a conflict, a blocking review or an unresolved thread), not paused, and has had no new head or status for `stall_minutes` (15 by default) gets a mark on its line: -`STALL 1: no new head or status for 16 min`, and `STALL 2` after the next -window of the same length; then nothing more until the pause suggestion at -24 hours. Each mark shows the line once, like any other change. When the +`STALL 1: no new head or status for 16 min`, and `STALL 2` one full window +after `STALL 1` was shown; then nothing more until the pause suggestion at +24 hours. The first mark is always `STALL 1`, also when the first prompt comes +after a longer silence, and a new head or status starts at `STALL 1` again +(the step shown is kept per session, `meta` key `stall:`). Each mark +shows the line once, like any other change. When the watch's checkout (`--cwd` of the registration) is a checkout of the PR's repository and its `.ytstack/LANES.md` names the PR in a lane row, the mark ends with that lane's holder and its last sign of life, read from local files by `ytstack-frontier owner --pr N`: `lane M004-S03 held by impl-S03 (running), last commit 52 min ago on ytstack/M004-S03`. A blocking review followed by -silence and a lane that is still working look the same without it. What a +silence and a lane that is still working look the same without it. The hook +makes one such call per checkout for all PRs it shows, all within 3 seconds; +a checkout that fails or runs out of time names no lane, and the line is shown +anyway. What a coordinator does with the two marks is in `skills/coordinate/SKILL.md`, Step 7. `bin/ytstack-watch --stall` prints the same two lines for a process that is not the PR watch. diff --git a/tests/pr_watch/test_focus_stall.py b/tests/pr_watch/test_focus_stall.py index ef0f122..950e973 100644 --- a/tests/pr_watch/test_focus_stall.py +++ b/tests/pr_watch/test_focus_stall.py @@ -16,7 +16,7 @@ import test_findings from test_scope import cli from test_watch import snapshot, POLICY -from prwatch import github, hooks, worker +from prwatch import claude, github, hooks, worker from prwatch.state import register @@ -93,8 +93,8 @@ class Stall(unittest.TestCase): observe = Focus.observe prompt = Focus.prompt - def checkout(self, origin='https://github.com/o/r.git'): - """A checkout of o/r whose LANES.md says lane M001-S01 (branch work/s01) holds PR 7.""" + def checkout(self, origin='https://github.com/o/r.git', numbers=(7,)): + """A checkout of o/r whose LANES.md says lane M001-S (no branch) holds PR NN.""" d = Path(self.tmp.name) / 'checkout' (d / '.ytstack').mkdir(parents=True) git = lambda *a: subprocess.run(['git', '-C', str(d), *a], check=True, capture_output=True) @@ -105,9 +105,18 @@ def checkout(self, origin='https://github.com/o/r.git'): '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n' '| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n' '|---|---|---|---|---|---|---|---|---|---|\n' - f'| M001-S01 | implement | running | w1 {claimed} | - | - | 7 | - | 1 | fix the review |\n') + + ''.join(f'| M001-S{n:02d} | implement | running | w{n} {claimed} | - | - | {n} | - | 1 | fix |\n' + for n in numbers)) return str(d) + def shown_earlier(self, minutes): + """Move the time each STALL step was shown back by `minutes`.""" + key = 'stall:claude:abc' + row = self.db.execute('SELECT value FROM meta WHERE key=?', (key,)).fetchone() + state = {k: [v[0], v[1], v[2] - minutes * 60] for k, v in json.loads(row['value']).items()} + with self.db: + self.db.execute('UPDATE meta SET value=? WHERE key=?', (json.dumps(state), key)) + def stalled(self, number, minutes, cwd='/tmp'): with self.db: register(self.db, 'o/r', number, 'claude:abc', cwd) @@ -117,8 +126,16 @@ def stalled(self, number, minutes, cwd='/tmp'): self.age(number, minutes) def age(self, number, minutes): + """Let `minutes` pass since the last head or status change: the same stretch, so a STALL + step already shown for it stays on record.""" + changed = time.time() - minutes * 60 - 5 with self.db: - self.db.execute('UPDATE watches SET changed_at=? WHERE number=?', (time.time() - minutes * 60 - 5, number)) + self.db.execute('UPDATE watches SET changed_at=? WHERE number=?', (changed, number)) + row = self.db.execute("SELECT value FROM meta WHERE key='stall:claude:abc'").fetchone() + state = json.loads(row['value']) if row else {} + if f'o/r#{number}' in state: + state[f'o/r#{number}'][0] = changed + self.db.execute("UPDATE meta SET value=? WHERE key='stall:claude:abc'", (json.dumps(state),)) def test_two_windows_with_the_lane_that_holds_the_pr(self): self.stalled(7, 14, self.checkout()) @@ -126,13 +143,76 @@ def test_two_windows_with_the_lane_that_holds_the_pr(self): self.age(7, 16) text = self.prompt() self.assertRegex(text, r'o/r#7: action_required .*; STALL 1: no new head or status for 16 min; ' - r'lane M001-S01 held by w1 \(running\), claimed 1[78]\d min ago, no branch in its row') + r'lane M001-S07 held by w7 \(running\), claimed 1[78]\d min ago, no branch in its row') self.assertIsNone(self.prompt(), 'once per window') self.age(7, 31) - self.assertIn('STALL 2: no new head or status for 31 min; lane M001-S01', self.prompt()) + self.assertIsNone(self.prompt(), 'STALL 2 waits a full window after STALL 1 was shown') + self.shown_earlier(15) + self.assertIn('STALL 2: no new head or status for 31 min; lane M001-S07', self.prompt()) self.age(7, 50) + self.shown_earlier(30) self.assertIsNone(self.prompt(), 'two windows only') + def test_a_long_silence_starts_with_stall_1(self): + # PR #92 review: a first look after 31 minutes must not skip the question to the lane. + self.stalled(7, 31) + text = self.prompt() + self.assertIn('STALL 1: no new head or status for 31 min', text) + self.assertNotIn('STALL 2', text) + self.assertIsNone(self.prompt()) + + def test_a_new_stretch_starts_at_stall_1_again(self): + self.stalled(7, 16) + self.prompt() + self.shown_earlier(15) + self.age(7, 31) + self.assertIn('STALL 2', self.prompt()) + # same status, another head: a new stretch + snap = snapshot(); snap['pr']['mergeable'] = False; snap['head'] = 'head3' + self.observe(7, snap) + self.assertNotIn('STALL', self.prompt(), 'the new head is shown without a mark') + self.age(7, 16) + self.assertIn('STALL 1', self.prompt()) + + def test_fifteen_stalls_take_one_frontier_call(self): + numbers = range(7, 22) + d = self.checkout(numbers=numbers) + for n in numbers: + self.stalled(n, 0, d) + for n in numbers: + self.age(n, 16) + real = subprocess.run + calls = [] + def run(args, *a, **k): + calls.append(args) + return real(args, *a, **k) + started = time.time() + with patch('prwatch.claude.subprocess.run', side_effect=run): + text = self.prompt() + self.assertEqual(text.count('STALL 1'), 15) + for n in numbers: + self.assertIn(f'o/r#{n}: action_required', text) + self.assertRegex(text, rf'STALL 1: [^\n]*; lane M001-S{n:02d} held by w{n} ') + self.assertEqual(sum('owner' in args for args in calls), 1, 'one ytstack-frontier call per checkout') + self.assertLess(time.time() - started, 5) + + def test_a_failing_lookup_keeps_the_line(self): + self.stalled(7, 16, self.checkout()) + with patch('prwatch.claude.owners', side_effect=UnicodeDecodeError('utf-8', b'x', 0, 1, 'bad')): + text = self.prompt() + self.assertIn('STALL 1: no new head or status for 16 min', text) + self.assertNotIn('lane M001', text) + self.assertIsNone(self.prompt(), 'shown once, not lost') + + def test_the_lookup_has_one_time_budget(self): + self.stalled(7, 16, self.checkout()) + def slow(args, *a, **k): + raise subprocess.TimeoutExpired(args, k.get('timeout')) + with patch('prwatch.claude.subprocess.run', side_effect=slow) as run: + text = self.prompt() + self.assertIn('STALL 1', text) + self.assertTrue(all(c.kwargs['timeout'] <= claude.OWNER_BUDGET for c in run.call_args_list)) + def test_without_a_lane_paused_or_switched_off(self): self.stalled(8, 16) text = self.prompt() @@ -150,7 +230,7 @@ def test_a_checkout_of_another_repository_names_no_lane(self): self.stalled(7, 16, self.checkout('https://github.com/o/other.git')) text = self.prompt() self.assertIn('STALL 1', text) - self.assertNotIn('lane M001-S01', text) + self.assertNotIn('lane M001', text) if __name__ == '__main__': diff --git a/tools/pr-watch/prwatch/claude.py b/tools/pr-watch/prwatch/claude.py index 97da03d..7108cd9 100644 --- a/tools/pr-watch/prwatch/claude.py +++ b/tools/pr-watch/prwatch/claude.py @@ -22,6 +22,8 @@ # Before that: a STALL mark after this many minutes, and once more after the next window # (policy `stall_minutes`, 0 = off; issue #91). STALL_MINUTES = 15 +# Seconds all lane lookups of one prompt may take together (the hook has 15 s). +OWNER_BUDGET = 3 FRONTIER = Path(__file__).resolve().parents[3] / 'bin/ytstack-frontier' @@ -61,26 +63,50 @@ def stall_minutes(repo): return STALL_MINUTES -def owner(w): - """The lane of LANES.md in the watch's checkout that holds the PR, with its last commit or - claim (`ytstack-frontier owner`), or ''. Only from a checkout of the PR's repository: a PR - number means nothing in another one. Local files only, no GitHub call.""" +def stall_key(session): + """The STALL step last shown to `session`: PR key -> [changed_at, step, shown at]. A step + advances by one per window after the previous one was shown, as in ytstack-watch.""" + return f'stall:{session}' + + +def owners(watches, budget=None): + """PR key -> the lane of LANES.md that holds it, with its last commit or claim + (`ytstack-frontier owner`): one call per checkout, all within `budget` seconds. Only from a + checkout of the PR's repository (a PR number means nothing in another one). Local files + only, no GitHub call; a checkout that fails or runs out of time names no lane.""" from .hooks import REPO - cwd = w['cwd'] or '' - if not cwd or not FRONTIER.is_file(): - return '' - try: - origin = subprocess.run(['git', '-C', cwd, 'remote', 'get-url', 'origin'], - capture_output=True, text=True, timeout=3).stdout.strip() - match = REPO.fullmatch(origin) - if not match or match[1].lower() != w['repo'].lower(): - return '' - p = subprocess.run(['bash', str(FRONTIER), '-C', cwd, 'owner', '--pr', str(w['number'])], - capture_output=True, text=True, timeout=10) - except (OSError, subprocess.TimeoutExpired): - return '' - lines = p.stdout.strip().splitlines() - return lines[0] if p.returncode == 0 and lines else '' + deadline = time.monotonic() + (OWNER_BUDGET if budget is None else budget) + found, by_cwd = {}, {} + if not FRONTIER.is_file(): + return found + for w in watches: + if w['cwd']: + by_cwd.setdefault(w['cwd'], []).append(w) + for cwd, ws in by_cwd.items(): + try: + left = deadline - time.monotonic() + if left <= 0: + break + origin = subprocess.run(['git', '-C', cwd, 'remote', 'get-url', 'origin'], + capture_output=True, text=True, timeout=left).stdout.strip() + match = REPO.fullmatch(origin) + ws = [w for w in ws if match and w['repo'].lower() == match[1].lower()] + left = deadline - time.monotonic() + if not ws or left <= 0: + continue + p = subprocess.run(['bash', str(FRONTIER), '-C', cwd, 'owner', '--pr', + ','.join(str(w['number']) for w in ws)], + capture_output=True, text=True, timeout=left) + except Exception: + continue + lines = p.stdout.splitlines() if p.returncode == 0 else [] + for line in lines: + number, tab, rest = line.partition('\t') + if tab and number.isdigit(): + found.update({f'{w["repo"]}#{w["number"]}': rest for w in ws if w['number'] == int(number)}) + elif len(ws) == 1 and line: + found[f'{ws[0]["repo"]}#{ws[0]["number"]}'] = line + return found def _age(seconds): @@ -105,6 +131,7 @@ def surface(db, session, now=None): if not watches and not notices and not gone: return None hinted, hints = _meta_dict(db, hint_key(session)), {} + steps, stalls = _meta_dict(db, stall_key(session)), {} # Each line with its fingerprint (ages excluded); only changed lines are injected (issues #61, #85). # A focus or STALL mark joins the fingerprint only when set: older fingerprints stay equal. current, due, focused, stalled, limits = {}, set(), set(), {}, {} @@ -132,8 +159,17 @@ def surface(db, session, now=None): limit = limits[w['repo']] if (w['status'] == 'action_required' and not w['paused'] and limit and changed is not None and limit <= now - changed < STALE): + # STALL 1 first, also after a long silence; STALL 2 a full window after STALL 1 was + # shown (PR #92 review). A new head or status starts at STALL 1 again. + prev = steps.get(key) + if not isinstance(prev, list) or len(prev) != 3 or prev[0] != changed: + stall, at = 1, now + elif prev[1] == 1 and now - prev[2] >= limit: + stall, at = 2, now + else: + stall, at = prev[1], prev[2] + stalls[key] = [changed, stall, at] # The lane (owner) is looked up only for a line that is shown. - stall = min(2, int((now - changed) // limit)) stalled[key] = w mark += (('stall', stall),) line += f'; STALL {stall}: no new head or status for {int((now - changed) // 60)} min' @@ -147,12 +183,17 @@ def surface(db, session, now=None): f'{cli()} pause --repo {w["repo"]} --pr {w["number"]}') current[key] = ((w['paused'], w['status'], w['head'], w['detail']) + mark, line) fingerprints = {key: json.dumps(fp) for key, (fp, _) in current.items()} + shown = [key for key in current if key in due or seen.get(key) != fingerprints[key]] + # Lanes before the fingerprints are saved: a failed lookup must not lose the block. + try: + lanes = owners([stalled[key] for key in shown if key in stalled]) + except Exception: + lanes = {} + text = {key: current[key][1] + (f'; {lanes[key]}' if key in lanes else '') for key in shown} with db: db.execute('INSERT OR REPLACE INTO meta VALUES(?,?)', (surface_key(session), json.dumps(fingerprints))) db.execute('INSERT OR REPLACE INTO meta VALUES(?,?)', (hint_key(session), json.dumps(hints))) - shown = [key for key in current if key in due or seen.get(key) != fingerprints[key]] - text = {key: current[key][1] + (f'; {lane}' if key in stalled and (lane := owner(stalled[key])) else '') - for key in shown} + db.execute('INSERT OR REPLACE INTO meta VALUES(?,?)', (stall_key(session), json.dumps(stalls))) focus_lines = [text[key] for key in shown if key in focused] changed_lines = [text[key] for key in shown if key not in focused] closed_lines = [f'- {w["repo"]}#{w["number"]}: closed' From a21da60fea8913548019fffc1168a2fcd5293254 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 21:16:25 +0100 Subject: [PATCH 09/10] fix: a comment does not lift a changes request in ytstack-watch and finish-lane gates (PR #92 review) Also tests that a new head after STALL 1 restarts the clock. Co-Authored-By: Claude Opus 5.5 --- bin/ytstack-finish-lane | 3 ++- bin/ytstack-watch | 5 +++-- tests/ytstack-finish-lane.test.sh | 2 ++ tests/ytstack-watch.test.sh | 13 +++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/ytstack-finish-lane b/bin/ytstack-finish-lane index 0fe8aff..a414d39 100755 --- a/bin/ytstack-finish-lane +++ b/bin/ytstack-finish-lane @@ -373,7 +373,8 @@ VIEW_JQ=' .name, (if .status == "COMPLETED" then .conclusion else .status end) ] end | "check\t" + (map(tostring) | join("\t"))), (.headRefOid as $h | [ (.reviews // [])[] | select(.commit.oid == $h and .state != "PENDING") ] | - (group_by(.author.login)[] | max_by(.submittedAt) | "review\t\(.state)\t\(.author.login)"), + # A comment does not lift a changes request of the same reviewer (PR #92 review). + ([ .[] | select(.state != "COMMENTED") ] | group_by(.author.login)[] | max_by(.submittedAt) | "review\t\(.state)\t\(.author.login)"), (max_by(.submittedAt) // empty | "newest\t\(.author.login)", ((.body // "") | split("\n")[] | "body\t" + .))) ' # shortcut: the first 100 review threads; more than that fails the gate instead diff --git a/bin/ytstack-watch b/bin/ytstack-watch index 57d742f..e33ed46 100755 --- a/bin/ytstack-watch +++ b/bin/ytstack-watch @@ -313,9 +313,10 @@ def one: elif .mergeable == "CONFLICTING" then "conflict" else "unknown" end), # blocked: a reviewer whose newest review on the head requests changes - # (another reviewer approving later does not lift it; as ytstack-finish-lane) + # (another reviewer approving later does not lift it, nor a later comment + # of the same reviewer; as ytstack-finish-lane) (.headRefOid as $h - | [ (.reviews // [])[] | select(.submittedAt != null and .commit.oid == $h) ] + | [ (.reviews // [])[] | select(.submittedAt != null and .commit.oid == $h and .state != "COMMENTED") ] | if any(group_by(.author.login)[]; max_by(.submittedAt).state == "CHANGES_REQUESTED") then "blocked" else "-" end) ] | join(" ")' diff --git a/tests/ytstack-finish-lane.test.sh b/tests/ytstack-finish-lane.test.sh index a7a9717..205d5ef 100644 --- a/tests/ytstack-finish-lane.test.sh +++ b/tests/ytstack-finish-lane.test.sh @@ -362,6 +362,8 @@ eq "changes requested on an earlier commit do not count" 0 "$EC" has "the head has no review then" "ok review: none on ${SHA:0:7}" "$OUT" host; tweak view '.reviews[0].state = "CHANGES_REQUESTED" | .reviews += [.reviews[0] | .state = "APPROVED" | .submittedAt = "2026-11-13T11:00:00Z"]'; gates eq "a reviewer's newer review replaces the older one" 0 "$EC" +host; tweak view '.reviews[0].state = "CHANGES_REQUESTED" | .reviews += [.reviews[0] | .state = "COMMENTED" | .submittedAt = "2026-11-13T11:00:00Z"]'; gates +only "a reviewer's later comment does not lift their changes request (PR #92 review)" review host; tweak view '.reviews += [{author: {login: "sam"}, state: "CHANGES_REQUESTED", submittedAt: "2026-11-13T09:00:00Z", commit: {oid: .headRefOid}, body: ""}]'; gates only "another reviewer's changes requested stand beside a newer comment" review host; tweak graphql '.data.repository.pullRequest.reviewThreads |= (.totalCount = 2 | .nodes += [{isResolved: false}])'; gates diff --git a/tests/ytstack-watch.test.sh b/tests/ytstack-watch.test.sh index af68ad7..a6b8a65 100644 --- a/tests/ytstack-watch.test.sh +++ b/tests/ytstack-watch.test.sh @@ -346,6 +346,19 @@ pr "$FIX/step5" 20 MERGED "$A" "$RUN_OK" "" MERGEABLE swatch --pr 20 eq "the same reviewer's newer approval lifts it" 0 "$(printf '%s\n' "$OUT" | grep -c STALL)" fresh +pr "$FIX/now" 20 OPEN "$A" "$RUN_OK" "$OTHER,$(echo "$OTHER" | sed 's/CHANGES_REQUESTED/COMMENTED/; s/13:00/15:00/')" MERGEABLE +pr "$FIX/step5" 20 MERGED "$A" "$RUN_OK" "" MERGEABLE +swatch --pr 20 +like "the same reviewer's later comment does not lift it (PR #92 review)" "^$STAMP #20 STALL 1: review changes_requested; " "$OUT" +# PR #92 review: a new head after STALL 1 restarts the clock; the next mark is STALL 1 again +fresh +pr "$FIX/now" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE # poll 1 (t 0) +pr "$FIX/step5" 20 OPEN "$B" "$RUN_BAD" "" MERGEABLE # poll 5 (t 20 min): a new head, still red +pr "$FIX/step10" 20 MERGED "$B" "$RUN_BAD" "" MERGEABLE # poll 10 (t 45 min), before a second window +swatch --pr 20 +eq "STALL 1 before the push and STALL 1 again 15 minutes after it, no STALL 2" "1:head a1b2c3d 1:head b2c3d4e" \ + "$(printf '%s\n' "$OUT" | sed -n 's/.* STALL \([12]\): .*(\(head [0-9a-f]*\)).*/\1:\2/p' | paste -sd' ' -)" +fresh pr "$FIX/now" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE pr "$FIX/step4" 20 OPEN "$A" "$RUN_BUSY" "" MERGEABLE # poll 4: the checks run again: not actionable pr "$FIX/step7" 20 OPEN "$A" "$RUN_BAD" "" MERGEABLE From 16511cbfcd7def7a24e4ddf7f94d7778c9397e00 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 21:16:26 +0100 Subject: [PATCH 10/10] docs: coordinate Step 7 gives the fresh worker its own detached worktree; spec bullet de-duplicated (PR #92 review) Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 1 + .ytstack/spec/checks-and-evals.md | 4 ++-- .ytstack/spec/skills.md | 2 +- docs/ux/coordinator-format.md | 4 ++-- skills/coordinate/SKILL.md | 2 +- tests/skill-preambles.test.sh | 3 ++- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index 34b89e4..7fd0d36 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1505,5 +1505,6 @@ Plus: ops-layer split during the same session (yopstack created as own public re - The PR watch's state is `action_required` (it includes unresolved threads); `ytstack-watch` counts checks red, a conflict and changes requested on the head, the states its five fields show. - A new caller that needs "who holds PR N and is it alive" calls `ytstack-frontier owner`, not its own `LANES.md` reader. - `ytstack-watch` reads a blocking review per reviewer: one whose newest review on the head requests changes blocks, also when another reviewer approved later (the rule of `ytstack-finish-lane`). A failed read of an open focus pull request keeps the 20-second cadence (PR #92 review). +- The PR watch shows `STALL 1` first and `STALL 2` only a full window after `STALL 1` was shown, as `ytstack-watch` does; the step shown is kept per session (`stall:`). The lane lookup is one `ytstack-frontier owner --pr N,N,...` call per checkout within one 3-second budget, made before the fingerprints are saved; any failure leaves the line without a lane. A comment does not lift a changes request of the same reviewer, in `ytstack-watch` and in `ytstack-finish-lane gates`. `owner` prefers a held row. A fresh worker gets its own worktree: `git worktree add --detach origin/`, `claim --worktree ` (PR #92 independent review). **Supersedes:** None. Extends "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" and "2026-11-15: PR watch bulk registration takes only your own ready PRs; bins are called through `YT_BIN` (issue #85)". diff --git a/.ytstack/spec/checks-and-evals.md b/.ytstack/spec/checks-and-evals.md index 4d08378..8519494 100644 --- a/.ytstack/spec/checks-and-evals.md +++ b/.ytstack/spec/checks-and-evals.md @@ -93,12 +93,12 @@ Everything that tells a contributor whether a change is acceptable: the static c **The coordinator scripts** (formats and rules: `docs/ux/coordinator-format.md`; each has a suite of the same name under `tests/`) -- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `owner --pr N` prints the lane whose `PR` cell is `N` or `#N`, its holder and status and the age of the last commit on its branch (local, else `origin/`) or of the claim when that is newer, the clock of `check` (exit 1 without a lanes file or row; issue #91); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). +- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `owner --pr N[,N...]` prints the lane whose `PR` cell is `N` or `#N` (a held row before a dropped or merged one; with several PRs one line each, led by the number and a tab), its holder and status and the age of the last commit on its branch (local, else `origin/`) or of the claim when that is newer, the clock of `check` (exit 1 without a lanes file or row; issue #91); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). - `bin/ytstack-plans` (`docs/ux/external-plans.md`): `scan` counts the work rows (task-list items, rows of tables with a status or checkbox column, nothing in a code fence) of `plans/`, `roadmap/` and their variants and prints one line per directory with `verdict=large` from 10 open rows and the answer recorded in `PREFERENCES.md`; exit 0 only for a large directory without an answer. `rows` prints `path:line`, state, id, section and title per row; a relative PATH is read from where the command was started, else from the repository root, and the output names files relative to the root. It writes nothing; the mapping is the agent's (`reconcile`, `adopt-brownfield`). `bin/ytstack-reconcile` (the two migration classes of `reconcile`, issue #76): `skeletons` lists, per open task of a slice that has no task plan at all and no `## Files` of its own, in a milestone not done, dropped, shipped-informally or backlog, the task, the plan to write beside the slice plan and the number of paths found; `--write` (optionally `--slice M###-S##`) writes each in `plan-task`'s format with Files from the task line's backticked paths or the slice plan's `Own:`/`Files:` lines, Spec impact lines per area with `TODO` fields that `ytstack-spec impact` rejects until filled, a `TODO` verification, `skeleton: reconcile `, and never over an existing file. `pointer` says `ok`, `no milestone in progress` or `behind` (exit 10) when `current_milestone` is closed, `none` or older than the newest roadmap `in-progress`; `--fix` sets `current_milestone`, `active_slice` (its first open slice), `active_task: none` and `last_updated` in the pointer block only (the frontmatter, or the `key: value` lines a file without one starts with), adds the keys that are missing there, refuses a file with neither (exit 1, nothing written) and reports what the file says after the write. - `bin/ytstack-questions`: `new`, `list`, `next`, `ask` (once), `answer` (refused without text under "Answer"), `check`. `bin/ytstack-standing` (`docs/ux/coordinator-format.md`, "standing/"): `add` writes one entry, validated by `ytstack-check --standing` before anything is committed, by default in its own worktree outside the checkout on `standing/` with a commit, a push and one pull request per UTC day (opened through `ytstack-pr-watch create` when `pr_watch=on` and the session has an id, else `gh pr create`; updated when one is open); `--here` and user scope write into the resolved directory only; exit 3 when the commit stands but the push or the PR failed; a new day's branch starts from the newest pending standing branch, an earlier one with unpushed commits is pushed first. `end` writes the closing entry of `kind: end`, also of a pending entry. `list` prints the newest entry's age and the human prompts since (from the coordinate session's counter), the active entries with the pending ones marked (local `standing/*` branches and their upstreams only), then the ended ones, the conditions to check and the failed checks; it is the only place `until-check` and `check` run, and only for a working-tree entry identical to the default branch's (bash in its own process group, killed on timeout, stdin closed, `YTSTACK_STANDING_TIMEOUT` seconds each, default 5, at most ten per call, every one not run says why), `--no-checks` runs none. Its suite uses a stand-in for `gh`, a local bare remote behind an `insteadOf` URL and the real `ytstack-pr-watch create`. - `bin/ytstack-finish-lane`: one step per call (`leftovers`, `commit`, `push`, `open-pr`, `wait-head`, `body-check`, `gates`, `merge`, `route`); every gate is read from GitHub through `gh` at the moment of the call, and `merge` passes the reviewed commit to the host so that a moved head cannot be merged. `route --lane [--pr ] [--report ]` reads the lane's worker (the author) and plan from `LANES.md` and runs `bin/ytstack-risk route`; with `--pr` it passes the pull request on, and a lane without a plan file is routed from the host's reviews. With a technical spec it then checks the spec delta and prints `spec:` lines: every plan of the lane that belongs to the range (changed in it, or a commit `:` in it; a slice lane's task plans too) with a "Spec impact" through `ytstack-spec impact --base --head`; then every area the diff touches (`--no-renames`) needs its area file or a source in the diff, a plan of the range with `none -- ` for the files of its commits, or `Spec: none -- ` in the worker's report; a path the report names is the area file or a source of its area, and in the diff. Each gap is a `reason: spec` line and turns `unattended` into `person` (exit 10). When `REVIEW.md` keeps a "Checks" section and the diff edits CI without touching `REVIEW.md`, one `checks:` line says so (a note, CI changes go to a person anyway). `leftovers` and `commit` leave the evidence directory out. Its suite uses a stand-in for `gh` and a local bare remote. - `bin/ytstack-handover`: `new` copies `skills/handover-step/template.sh`; `check` is the static verification of a staged script (syntax, unchanged helper block, no raw command, a confirmation of its own before every mutation, no pipe into a shell). The helpers hold the same rule when the script runs: one yes carries one change. -- `bin/ytstack-watch`: polls pull requests through `gh` and prints a line only when head, checks, review or mergeability changed; `--once` prints the snapshot with its read time. `--focus N[,N...]` lists those first and reads them every 20 seconds while one is open, the others every `--interval`; `--stall MINUTES` (default 15, 0 off, not with `--once`) prints `#N STALL 1:` when an open pull request had red checks, a conflict or a reviewer whose newest review on the head requests changes for that long without a new head, `STALL 2` after the next window, with the line of `ytstack-frontier owner` at the end (issue #91). `release --commit ` runs `deployed` of "Release" until it names the commit (or `--timeout`, default 900 s), then `healthy` for the settle time, and ends with five receipt lines (`Target:`, `Commit:`, `Arrived:`, `Health:`, `Result:`) with read times. Exit 0 released or no health command, 2 not arrived, 3 unhealthy, 4 no "Release" section, 1 `RUNTIME.md` fails its check. It runs only those two commands and changes nothing. +- `bin/ytstack-watch`: polls pull requests through `gh` and prints a line only when head, checks, review or mergeability changed; `--once` prints the snapshot with its read time. `--focus N[,N...]` lists those first and reads them every 20 seconds while one is open, the others every `--interval`; `--stall MINUTES` (default 15, 0 off, not with `--once`) prints `#N STALL 1:` when an open pull request had red checks, a conflict or a reviewer whose newest review on the head requests changes for that long without a new head, `STALL 2` after the next window, with the line of `ytstack-frontier owner` at the end (issue #91); a reviewer blocks when the newest of their reviews on the head that is not a comment requests changes (also in `ytstack-finish-lane gates`). `release --commit ` runs `deployed` of "Release" until it names the commit (or `--timeout`, default 900 s), then `healthy` for the settle time, and ends with five receipt lines (`Target:`, `Commit:`, `Arrived:`, `Health:`, `Result:`) with read times. Exit 0 released or no health command, 2 not arrived, 3 unhealthy, 4 no "Release" section, 1 `RUNTIME.md` fails its check. It runs only those two commands and changes nothing. **Shell suites: `tests/*.test.sh`** diff --git a/.ytstack/spec/skills.md b/.ytstack/spec/skills.md index 0396c57..040fc55 100644 --- a/.ytstack/spec/skills.md +++ b/.ytstack/spec/skills.md @@ -105,7 +105,7 @@ Read from `PREFERENCES.md` in the resolved `.ytstack` directory by `yt_prefs` in Formats: `docs/ux/coordinator-format.md`. The four skills below are for the session that owns a plan and delegates all of it; none of them writes product code. -- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), ask one question at a time from a question file, write a standing instruction down when it is given (a new file in `standing/`; `STANDING.md` only where no `standing/` exists), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, - `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), ask one question at a time from a question file, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). +- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`, and `YT_BIN=`, through which it runs every bin): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests by its own GitHub login, without drafts and do-not-merge labels, to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), ask one question at a time from a question file, write a standing instruction down when it is given, before the next dispatch, with `ytstack-standing add` (a new file in `standing/` on the day's standing branch and pull request, `--here` in user scope; `STANDING.md` only where no `standing/` exists; agent memory is no substitute), close an ended one with `ytstack-standing end`, act on the ended, to-check and failed-check lines its preamble prints from `ytstack-standing list` (with the newest entry's age and the human prompts since), its preamble writes the coordinate session marker (the resolved `.ytstack` and the repository key) the coordinate-mode hooks act on, finds the automatic handoff through `yt_latest_handoff`, and prints the operating checklist of `docs/ux/coordinator-format.md` (the same block `session-start` injects), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). A pull request other lanes wait on is registered as a focus PR (`register --pr N --focus`, or `ytstack-watch --focus N`); on `STALL 1` it asks the holding lane once for an ETA, on `STALL 2` it releases the lane and claims a fresh worker on the same branch in a new worktree instead of relaying the same instruction again (issue #91). - `spawn-milestone-team` claims each lane with `bin/ytstack-frontier` before it dispatches, keeps the lane's row current, and looks at the frontier again whenever a lane is verified or merged. - `finish-lane` takes a reported lane to a merged pull request with `bin/ytstack-finish-lane`: review pinned to the host's head, the required lenses, `route` with the worker's report (its spec delta is checked against the diff, so a lane that skipped `summarize-task` and changed an area without its description or a reason goes to a person, under `merge_by: coordinator` back to the worker; a `checks:` line notes a CI edit that the checks inventory of `REVIEW.md` did not follow and goes to the person who merges), the gates read from the host, the merge decided by `merge_by` and the route, then `bin/ytstack-watch release` on the merge commit when `RUNTIME.md` has a "Release" section (in the background; the receipt goes into the report, nothing is rolled back). A merge without a person is reported in one line with class, ceiling and lenses. After a merge it made itself, and when `REVIEW.md` declares own reviewers, it invokes `review-lessons` for the pull request. Before a lane goes back for a review that requested changes, a failed lens or a failed check, it invokes `lesson` (its Step 14). These two are the skills it may invoke. The pipeline supports GitHub through `gh` only; on another host the skill stops after the route. - **The class of a change.** `code-review` prints the floor of `bin/ytstack-risk` and has a reviewer that is not the author end with `Risk:`, `Severity:`, `Reach:` and `Invariants touched:`, read against "Invariants and security boundaries" and "Decisions that apply now" of the touched areas, also when only code moved. The round line records class, invariants and reviewer; a session reviewing its own change writes `by: self`, which routes to a person. On a pull request `finish-lane` and `code-review` post the round and lens lines in the body of a review on the reviewed head, and `finish-lane` routes with `--pr`: the record needs no commit that would move the head away from a head-bound review. Each lens the floor names gets a separate fresh reviewer with the lens brief (`bin/ytstack-brief render --kind review --lens `) and one lens line. diff --git a/docs/ux/coordinator-format.md b/docs/ux/coordinator-format.md index 09e33bf..773df57 100644 --- a/docs/ux/coordinator-format.md +++ b/docs/ux/coordinator-format.md @@ -113,7 +113,7 @@ A lane with a pull request can stall in a way the clock above does not see in ti - acme/app#1896: action_required (head a1b2c3d4, 40s ago) -- Merge conflict with base branch; STALL 2: no new head or status for 31 min; lane M004-S03 held by impl-S03 (running), last commit 68 min ago on ytstack/M004-S03 ``` -The first is a line of `ytstack-watch --stall ` (states it counts: checks red, a conflict, a reviewer whose newest review on the head requests changes), the second the line of the PR watch's status block (state `action_required`, policy key `stall_minutes`; `docs/pr-watch.md`). The tail after the time is `ytstack-frontier owner --pr `: the lane whose `PR` cell names the pull request (`12` or `#12`), its holder and status, and the age of the last commit on its branch, or of the claim when that is newer, the clock `check` uses. Without such a row the line ends after the time. What the coordinator does with `STALL 1` and `STALL 2` is in `skills/coordinate/SKILL.md`, Step 7. +The first is a line of `ytstack-watch --stall ` (states it counts: checks red, a conflict, a reviewer whose newest review on the head requests changes), the second the line of the PR watch's status block (state `action_required`, policy key `stall_minutes`; `docs/pr-watch.md`). `STALL 2` comes one full window after `STALL 1`, never first; a new head starts at `STALL 1` again. The tail after the time is `ytstack-frontier owner --pr `: the lane whose `PR` cell names the pull request (`12` or `#12`; a held row before a dropped or merged one), its holder and status, and the age of the last commit on its branch, or of the claim when that is newer, the clock `check` uses. Without such a row the line ends after the time. What the coordinator does with `STALL 1` and `STALL 2` is in `skills/coordinate/SKILL.md`, Step 7. A pull request that blocks other lanes is a focus pull request: `ytstack-pr-watch register --pr --focus` reads it on every worker tick and lists it first under `Focus (read every tick):`, `ytstack-watch --focus ` reads it every 20 seconds and prints it first. @@ -321,7 +321,7 @@ The old session stays open as a relay until every listed worker has reported. Pe ## Checked mechanically -- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). `ytstack-frontier owner --pr `: the lane that holds a pull request and its last commit or claim, exit 1 without a row ("Pull requests that stall"). +- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). `ytstack-frontier owner --pr [,...]`: the lane that holds a pull request and its last commit or claim, one line per PR (with several, each led by the number and a tab), exit 1 without a row ("Pull requests that stall"). A fresh worker's `claim` of a released lane keeps branch and worktree unless given: `--worktree ` sets its own, `--worktree -` clears it. - `bin/ytstack-upkeep --worktrees`: the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest), the age of the last commit, uncommitted changes, unpushed commits and the lane of the main checkout's `LANES.md` that holds them, and the `git worktree remove` / `git branch -D` commands for those whose pull request is merged or closed, with no open one, nothing unpushed, clean, unlocked and unheld. It prints the commands and runs none. - `bin/ytstack-status --phases [--json]`: done, in review and total per milestone and in total, with each change since the last text report, its cause and the phases that joined or left (`docs/statusline.md`, "Progress per phase"). - `bin/ytstack-questions check`: ids are unique and match the file name, `state` holds a listed value, `asked` and `answered` are set exactly when the state says so, an answered file has text under `## Answer`. diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index 2f60bb9..6075efa 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -261,7 +261,7 @@ A lane named in the `blocks:` of an open or asked question is not ready, whateve **Watching pull requests.** Polling happens outside the model. The PR watch counts as on only when `pr_watch=on` is set in `~/.ytstack/config` (`docs/pr-watch.md`) and the worker runs (`PR_WATCH: on, heartbeat s ago`, under 600). The flag alone enables only the hooks; without a fresh heartbeat nothing polls. With the PR watch on, the worker reports red checks, unresolved bot threads, conflicts and merges to this session with the next prompt, also for pull requests the lanes' subagents opened. The `register` call defaults to this session; check that its output says `registered to claude:` in Claude Code. `--all-open` takes only open pull requests by your GitHub login (the lanes' workers open them under it) and skips drafts, a `do-not-merge` label and the ones another session owns, each by name; `--author [,]`, `--include-drafts` and `--include-labelled` widen it only where this coordination owns such a pull request. Only the coordinator runs it; a session that works in the same repository outside this coordination keeps its own PRs (`register --pr N`). Without the PR watch, start `ytstack-watch` as a background process; on a host with a monitor tool, through that tool, so that each new line reaches you as an event. It prints a line only when a head moved, the checks changed, a review arrived, mergeability changed or a pull request closed, and it ends when all are merged or closed; start it again with the new list when a pull request opens. Act on a line or a notice: red checks go back to the lane's worker with the name of the check; a review on a commit that is not the head is no review of the head. Never read status in a loop from the conversation, with or without a sleep. The single read of Step 4 before an action is not polling. -**A pull request that stalls.** A pull request other lanes wait on is a focus pull request: `ytstack-pr-watch register --repo --pr --focus` (without the PR watch, `ytstack-watch --focus `) reads it every tick and lists it first. `STALL 1` on its line (PR watch or `ytstack-watch`, `docs/ux/coordinator-format.md`, "Pull requests that stall") means a blocking review, conflict or red check and no new head for one window; the tail names the lane and its last commit. Ask that lane once for an ETA, at its address. `STALL 2` means no head came in the next window: do not relay the same instruction again. Run `ytstack-frontier release `, then `ytstack-frontier claim --by --branch `, and dispatch the fresh worker in a new worktree from `origin/` with the review, conflict or check in its brief; the old worktree keeps its checkout. A STALL without a lane is a pull request outside the lanes: it goes into the next status. +**A pull request that stalls.** A pull request other lanes wait on is a focus pull request: `ytstack-pr-watch register --repo --pr --focus` (without the PR watch, `ytstack-watch --focus `) reads it every tick and lists it first. `STALL 1` on its line (PR watch or `ytstack-watch`, `docs/ux/coordinator-format.md`, "Pull requests that stall") means a blocking review, conflict or red check and no new head for one window; the tail names the lane and its last commit. Ask that lane once for an ETA, at its address. `STALL 2` means no head came in the next window: do not relay the same instruction again. Run `ytstack-frontier release `. The old worktree still has the branch checked out and may hold the old worker's uncommitted work, so leave it alone: `git fetch origin `, then `git worktree add --detach origin/`. Claim with `ytstack-frontier claim --by --branch --worktree ` and dispatch the fresh worker there with the review, conflict or check in its brief; it pushes with `git push origin HEAD:`. A STALL without a lane is a pull request outside the lanes: it goes into the next status. **After a merge.** A pull request that merged, also when a person merged it: set its lane to `merged`, then the release watch and the review lessons of the table. A merged lesson lane also closes its lesson: `ytstack-signals set F### --state fixed` once this checkout has the merged check (the script refuses while the file is missing). The receipt goes into the next status; `not arrived` or `unhealthy` is a status at once. You deploy nothing and roll nothing back: a countermeasure on the target is a step for the human (`ytstack:handover-step`). diff --git a/tests/skill-preambles.test.sh b/tests/skill-preambles.test.sh index 1ebd7e4..9ff8a38 100644 --- a/tests/skill-preambles.test.sh +++ b/tests/skill-preambles.test.sh @@ -539,7 +539,8 @@ awk '/^\*\*Step 7 --/ { p = 1 } /^\*\*Step 8 --/ { p = 0 } p' "$ROOT/skills/coor && ok "coordinate: Step 7 runs the lesson on a red main" || bad "coordinate: Step 7 runs the lesson on a red main" # issue #91: STALL 1 asks the lane once, STALL 2 hands the branch to a fresh worker awk '/^\*\*Step 7 --/ { p = 1 } /^\*\*Step 8 --/ { p = 0 } p' "$ROOT/skills/coordinate/SKILL.md" > "$TMP/step7.md" -for want in '--focus' 'STALL 1' 'STALL 2' 'ytstack-frontier release ' 'ytstack-frontier claim '; do +for want in '--focus' 'STALL 1' 'STALL 2' 'ytstack-frontier release ' 'ytstack-frontier claim ' \ + 'git worktree add --detach origin/' '--worktree ' 'git push origin HEAD:'; do grep_q -F -- "$want" "$TMP/step7.md" && ok "coordinate: Step 7 names $want" || bad "coordinate: Step 7 names $want" done