Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions scripts/dev-lead-fix-reviews.sh
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,10 @@ resolve_addressed_bot_threads() {
fi

# Our own account: the addressed-marker reply must have been posted by us before
# it can authorize resolution. GraphQL author.login omits the "[bot]" suffix, so
# match both the raw BOT_USER and its [bot]-stripped form (same pattern as
# resolve_actor_outdated_threads).
# it can authorize resolution. The acv_* thread helpers below derive the
# [bot]-stripped form internally (GraphQL author.login omits the "[bot]" suffix),
# so they match both the raw BOT_USER and its stripped form.
local bot_user="${BOT_USER:-donpetry-bot}"
local bot_user_stripped="${bot_user%\[bot\]}"

# The enumeration pass ONLY collects candidate thread ids (unresolved,
# bot-originated). It deliberately does NOT capture the last reply's body or
Expand Down Expand Up @@ -705,7 +704,7 @@ resolve_addressed_bot_threads() {
}'

local resolved_count=0
local id node_json cur_resolved reply_author reply_body
local id node_json cur_resolved comments_json marker_idx marker_body
while IFS= read -r id; do
[ -z "$id" ] && continue
# Re-read the thread's CURRENT state immediately before resolving so a reply
Expand All @@ -721,25 +720,36 @@ resolve_addressed_bot_threads() {
echo "::notice::skipping thread ${id} — already resolved or state unknown at re-check (${cur_resolved})"
continue
fi
# The latest reply is the last node of the full-thread fetch.
reply_author=$(printf '%s' "$node_json" | jq -r '.data.node.comments.nodes[-1]?.author?.login // ""' 2>/dev/null || echo "")
reply_body=$(printf '%s' "$node_json" | jq -r '.data.node.comments.nodes[-1]?.body // ""' 2>/dev/null || echo "")
# The addressed-marker only authorizes resolution when OUR account posted it.
# A marker-bearing reply from any other human or bot is not our confirmation.
if [ "$reply_author" != "$bot_user" ] && [ "$reply_author" != "$bot_user_stripped" ]; then
echo "::notice::skipping thread ${id} — latest reply author '${reply_author}' is not our account; a marker from another account does not authorize resolution"
# ── #1735: full-thread scan, not comments(last:1) ─────────────────────────
# Our addressed-marker reply need NOT be the thread's LATEST comment. Find the
# latest comment OUR account posted carrying the marker; a bot acknowledgement
# (or our own later note) landing after it must not lock the thread unresolvable
# forever (the regression #1691 exposed). A marker from any other account still
# does not authorize resolution (acv_latest_marker_index checks the author).
comments_json=$(printf '%s' "$node_json" | jq -c '.data.node.comments.nodes // []' 2>/dev/null || echo "[]")
if ! marker_idx=$(acv_latest_marker_index "$comments_json" "$bot_user"); then
echo "::notice::skipping thread ${id} — no addressed-marker reply from our account in the thread; leaving unresolved (#1735)"
continue
fi
marker_body=$(printf '%s' "$comments_json" | jq -r --argjson i "$marker_idx" '.[$i]?.body // ""' 2>/dev/null || echo "")

# Nothing UNADDRESSED may have landed since our marker (#1735 AC2/AC3/AC4): a bot
# acknowledgement is fine, but a bot NEW finding or ANY human comment (regardless
# of content, preserving #1415) blocks, and an undeterminable post-marker comment
# fails closed. This composes with the #1692 claim gate below (AC5) — both must pass.
local post_reason post_rc
post_reason=$(acv_post_marker_clear "$comments_json" "$marker_idx" "$bot_user") && post_rc=0 || post_rc=$?
if [ "${post_rc:-0}" -ne 0 ]; then
echo "::notice::skipping thread ${id} — an unaddressed comment landed after our marker (${post_reason}); leaving unresolved (#1735)"
continue
fi
# And the reply must actually carry the addressed-marker — a skip note or any
# other reply leaves the thread open.
review_reply_is_addressed_marker "$reply_body" || continue

# ── #1692: the marker is now a VERIFIABLE CLAIM, not an assertion ──────────
# A marker with no claim payload (pre-migration replies) is unverifiable — do
# NOT resolve (the safe direction; may leave some existing threads open until
# re-run). A malformed/contract-violating claim is likewise unverifiable.
local claim_json parse_reason
if ! claim_json=$(acv_parse_claim "$reply_body"); then
if ! claim_json=$(acv_parse_claim "$marker_body"); then
parse_reason="$claim_json"
echo "::notice::skipping thread ${id} — addressed-marker claim not verifiable (${parse_reason:-unparseable}); leaving unresolved (#1692)"
continue
Expand Down Expand Up @@ -785,11 +795,11 @@ resolve_addressed_bot_threads() {
fi
fi

# AC4: honour a standing maintainer disposition. Scan ALL comments; if a
# marker-less human maintainer asserted a required disposition, resolve only if
# the verified commit postdates it. Unparseable disposition -> fail closed.
local comments_json disposition disp_rc
comments_json=$(printf '%s' "$node_json" | jq -c '.data.node.comments.nodes // []' 2>/dev/null || echo "[]")
# AC4: honour a standing maintainer disposition. Scan ALL comments (reusing the
# comments_json captured above); if a marker-less human maintainer asserted a
# required disposition, resolve only if the verified commit postdates it.
# Unparseable disposition -> fail closed.
local disposition disp_rc
disposition=$(acv_latest_maintainer_disposition "$comments_json" "$bot_user") && disp_rc=0 || disp_rc=$?
if [ "${disp_rc:-0}" -eq 2 ]; then
echo "::notice::skipping thread ${id} — a maintainer disposition could not be parsed; leaving unresolved (fail closed) (#1692 AC4)"
Expand Down
146 changes: 146 additions & 0 deletions scripts/lib/addressed-claim-verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ readonly _ACV_CLAIM_SUFFIX=' -->'
# merge" shape) rather than any human chatter, so a neutral "thanks" never blocks.
readonly _ACV_DISPOSITION_RE_UPPER='(REQUIRED|MUST BE (FIXED|ADDRESSED|RESOLVED|CHANGED)|CHANGES REQUIRED|BLOCKING|REQUEST(ING|ED)? CHANGES)'

# Post-marker BOT-comment classification (#1735 AC2/AC4). A review bot that replies
# AFTER our addressed-marker either ACKNOWLEDGES (accepts our refutation / records a
# custom rule — the codeant-ai "✅ Customized review instruction saved!" shape) or
# raises a NEW finding. An acknowledgement must not keep the thread open; a new
# finding must. Both regexes are matched case-insensitively (against the upper-cased
# body). They are deliberately NARROW and the finding signal is checked FIRST, so a
# comment that is neither a clear ack nor a clear finding — or that mixes ack phrasing
# with a new point — resolves toward "undeterminable" / "finding" (fail closed): a
# stuck thread is a nuisance, a wrongly-resolved one clears a merge gate.
readonly _ACV_BOT_ACK_RE_UPPER='(CUSTOMIZED REVIEW INSTRUCTION SAVED|REVIEW INSTRUCTION SAVED|INSTRUCTION (SAVED|RECORDED)|ACKNOWLEDG|WILL NOT (FLAG|REPORT|RAISE)|NO (FURTHER|MORE) (ACTION|CONCERNS?)|MARKING (THIS )?(AS )?RESOLVED|DISMISS(ED|ING)?)'
Comment thread
don-petry marked this conversation as resolved.
Resolved
readonly _ACV_BOT_FINDING_RE_UPPER='(POTENTIAL ISSUE|REFACTOR SUGGESTION|SUGGESTION:|NEW (ISSUE|FINDING|PROBLEM|CONCERN)|SECURITY|VULNERABILIT|BUG|MUST (FIX|BE FIXED)|SHOULD (FIX|BE FIXED)|NITPICK|CRITICAL|BLOCKER|CHANGES REQUIRED)'
# A NEGATED acknowledgement ("cannot acknowledge this", "won't acknowledge", "unable to
# acknowledge") is not an ack — the bare ACKNOWLEDG alternative above would otherwise
# clear a thread the bot explicitly refused to accept. Detected before the ack match so
# such comments fall through to "undeterminable" (fail closed → thread stays open). The
# negator may be separated from ACKNOWLEDG by up to three words (e.g. "unable to fully
# acknowledge") so it survives light hedging.
readonly _ACV_BOT_ACK_NEGATION_RE_UPPER='(CANNOT|CAN.?T|COULD ?NOT|COULDN.?T|WILL NOT|WON.?T|DO(ES)? NOT|DON.?T|DOESN.?T|DID ?NOT|DIDN.?T|UNABLE|NOT ABLE|NEVER|NOT)[[:space:]]+([A-Z]+[[:space:]]+){0,3}ACKNOWLEDG'

# acv_parse_claim <reply_body>
# Extract and validate the single claim payload from a reply body. On success,
# echoes the canonical compact JSON and returns 0. On any failure, echoes a reason
Expand Down Expand Up @@ -124,6 +143,133 @@ acv_parse_claim() {
return 0
}

# acv_latest_marker_index <comments_json> <bot_user>
# Full-thread scan for OUR addressed-marker reply (#1735 AC1). <comments_json> is a
# JSON array of {author:{login,__typename}, body, createdAt} in thread order. Echoes
# the 0-based index of the LATEST comment authored by our account (bot_user or its
# [bot]-stripped form) that carries the dev-lead addressed-marker, and returns 0.
# Returns 1 (echoing nothing) when no such reply exists — the unchanged no-marker
# case. The marker need NOT be the thread's last comment: a bot acknowledgement (or
# our own later note) landing after it no longer hides the marker (the pre-#1735
# comments(last:1) hole). Pure — no gh/git/network.
acv_latest_marker_index() {
local comments_json="${1:-}" bot_user="${2:-}"
local bot_user_stripped="${bot_user%\[bot\]}"

# Single jq pass (no per-comment subprocess loop): select our-account comments whose
# body carries the addressed-marker and echo the LAST such index. The marker regex is
# the SAME _DEV_LEAD_ADDRESSED_MARKER constant review_reply_is_addressed_marker uses,
# so the pattern still has a single source of truth. Only OUR account's marker
# authorizes resolution (a foreign marker does not).
local idx
idx=$(jq -r \
--arg bot_user "$bot_user" \
--arg bot_user_stripped "$bot_user_stripped" \
--arg pattern "$_DEV_LEAD_ADDRESSED_MARKER" \
'if type == "array" then
to_entries
| map(select(
(.value.author.login == $bot_user or .value.author.login == $bot_user_stripped) and
((.value.body // "") | test($pattern))
))
| last | .key // ""
else
""
end' <<<"$comments_json" 2>/dev/null) || return 1

if [[ -n "$idx" ]]; then
echo "$idx"
return 0
fi
return 1
}
Comment thread
don-petry marked this conversation as resolved.
Resolved

# acv_bot_comment_is_acknowledgement <body>
# Classify a post-marker BOT comment (#1735 AC2/AC4). Returns:
# 0 = acknowledgement / no new finding (does not block resolution)
# 1 = a new finding (blocks — thread stays open)
# 2 = undeterminable (fail closed — thread stays open, AC4)
# The finding signal is checked FIRST so a comment that both acknowledges and raises
# a new point fails toward blocking. Pure — no gh/git/network.
acv_bot_comment_is_acknowledgement() {
local body="${1:-}"
[[ -z "$body" ]] && return 2
local up="${body^^}"
if [[ "$up" =~ $_ACV_BOT_FINDING_RE_UPPER ]]; then
return 1
fi
# A negated acknowledgement is not an ack — fail closed rather than clearing.
if [[ "$up" =~ $_ACV_BOT_ACK_NEGATION_RE_UPPER ]]; then
return 2
fi
if [[ "$up" =~ $_ACV_BOT_ACK_RE_UPPER ]]; then
return 0
fi
return 2
}

# acv_post_marker_clear <comments_json> <marker_index> <bot_user>
# Assert nothing UNADDRESSED has landed since our marker reply (#1735 AC2/AC3/AC4).
# Scans every comment AFTER <marker_index> and classifies it, reusing the SAME
# discriminators the rest of the gate uses (no second classifier, #1735 AC3):
# - our own account (login == bot_user / stripped) -> ours, ignored;
# - an agent-marker-bearing comment (review_thread_is_agent_authored) -> ours;
# - a bot comment (author __typename Bot, or login endswith [bot]) -> classified
# by acv_bot_comment_is_acknowledgement: ack clears, finding blocks (rc1),
# undeterminable fails closed (rc2);
# - any other marker-less User comment ALWAYS blocks (rc1), regardless of content
# — this preserves the #1415 maintainer guard exactly;
# - any other undeterminable author type -> fail closed (rc2).
# Echoes a short reason token ("clear" | "bot-finding" | "bot-ambiguous" | "human" |
# "unknown-author" | "unparseable"). Returns 0 only when clear. Pure.
acv_post_marker_clear() {
local comments_json="${1:-}" marker_index="${2:-0}" bot_user="${3:-}"
local bot_user_stripped="${bot_user%\[bot\]}"

# Single jq pass extracts the three fields of every post-marker comment as one TSV
# row (login, typename, base64(body)). Body is base64-encoded so embedded tabs and
# newlines survive the row split; the loop then decodes it and runs the SAME shared
# discriminators (review_thread_is_agent_authored, acv_bot_comment_is_acknowledgement)
# — no jq is spawned inside the loop and no second classifier is introduced (#1735 AC3).
local rows
rows=$(jq -r --argjson mi "$marker_index" '
if type == "array" then
to_entries[]
| select(.key > $mi)
| [ (.value.author.login // ""), (.value.author.__typename // ""), ((.value.body // "") | @base64) ]
| @tsv
else empty end
' <<<"$comments_json" 2>/dev/null) || { echo "unparseable"; return 2; }
[[ -z "$rows" ]] && { echo "clear"; return 0; }

local login typename body_b64 body ack_rc
while IFS=$'\t' read -r login typename body_b64; do
body=$(base64 --decode <<<"$body_b64" 2>/dev/null || printf '')
# Our own account is never an unaddressed comment.
[[ "$login" == "$bot_user" || "$login" == "$bot_user_stripped" ]] && continue
# An agent-marker-bearing comment is ours by the shared discriminator.
review_thread_is_agent_authored "$body" && continue
Comment thread
don-petry marked this conversation as resolved.
Resolved
if [[ "$typename" == "Bot" || "$login" == *"[bot]" ]]; then
acv_bot_comment_is_acknowledgement "$body" && ack_rc=0 || ack_rc=$?
if [[ "$ack_rc" -eq 0 ]]; then
continue
elif [[ "$ack_rc" -eq 1 ]]; then
echo "bot-finding"; return 1
else
echo "bot-ambiguous"; return 2
fi
fi
if [[ "$typename" == "User" ]]; then
echo "human"; return 1
fi
# Undeterminable author type -> fail closed.
echo "unknown-author"; return 2
done <<<"$rows"

echo "clear"
return 0
}
Comment thread
don-petry marked this conversation as resolved.
Resolved

# acv_verify_intersection <files_json> <own_diff_files_nl> <cumulative_diff_files_nl>
# The file-level hard gate (AC2/AC3). <files_json> is the claim's `files` array;
# the two diff lists are newline-separated repo-relative paths (own = the named
Expand Down
Loading
Loading