Skip to content

Commit 7be64b5

Browse files
fix(review): supersede stale exact-review runs (#749)
* fix(review): supersede stale exact-review runs * test(review): cover active supersession semantics * test(review): align zero-debounce timing assertion * fix(review): harden active run supersession * test(review): normalize supersession audit rows * test(workflow): align exact-run cancellation contract * fix(review): bind supersession cleanup authority * fix(review): handle missing issue revision * test(review): bind cancellation to exact tuple * fix(review): cooperatively stop superseded workers * test(review): pin heartbeat interval * fix(review): serialize source authority * fix(review): preserve command and process authority * fix(review): queue active command follow-ups * test(review): model durable storage listing --------- Co-authored-by: snowzlmbot <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
1 parent cb5f53f commit 7be64b5

16 files changed

Lines changed: 2670 additions & 193 deletions

‎.github/workflows/sweep.yml‎

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ run-name: >-
1717
github.event.action == 'clawsweeper_target_sweep') &&
1818
format('Review target repo {0}', github.event.client_payload.target_repo || 'openclaw/openclaw') ||
1919
(github.event_name == 'repository_dispatch' && github.event.client_payload.queue_lease_id != '') &&
20-
format('Review event item {0}', github.event.client_payload.queue_claim.item_key || github.event.client_payload.item_key || '?') ||
20+
format('Review exact item {0} rev {1} head {2}', github.event.client_payload.queue_claim.item_key || github.event.client_payload.item_key || '?', github.event.client_payload.queue_claim.lease_revision || github.event.client_payload.lease_revision || '?', github.event.client_payload.source_head_sha || 'na') ||
2121
(github.event_name == 'repository_dispatch' && github.event.client_payload.dispatch_key != '') &&
2222
format('Review event item {0}#{1} [{2}]', github.event.client_payload.target_repo || 'openclaw/openclaw', github.event.client_payload.item_number || '?', github.event.client_payload.dispatch_key) ||
2323
github.event_name == 'repository_dispatch' &&
@@ -278,6 +278,9 @@ jobs:
278278
sourceEvent,
279279
sourceAction: payload.source_action || "legacy_dispatch",
280280
supersedesInProgress: payload.supersedes_in_progress === true,
281+
...(/^[0-9a-f]{40}$/.test(String(payload.source_head_sha || "").trim().toLowerCase())
282+
? { sourceHeadSha: String(payload.source_head_sha).trim().toLowerCase() }
283+
: {}),
281284
...(Number.isFinite(Number(payload.codex_timeout_ms))
282285
? { codexTimeoutMs: Number(payload.codex_timeout_ms) }
283286
: {}),
@@ -413,6 +416,9 @@ jobs:
413416
sourceEvent: String(dispatch.source_event || ""),
414417
sourceAction: String(dispatch.source_action || "legacy_dispatch"),
415418
supersedesInProgress: dispatch.supersedes_in_progress === true,
419+
...(/^[0-9a-f]{40}$/.test(String(dispatch.source_head_sha || "").trim().toLowerCase())
420+
? { sourceHeadSha: String(dispatch.source_head_sha).trim().toLowerCase() }
421+
: {}),
416422
...(Number.isFinite(Number(reviewOptions.codex_timeout_ms))
417423
? { codexTimeoutMs: Number(reviewOptions.codex_timeout_ms) }
418424
: {}),
@@ -785,6 +791,12 @@ jobs:
785791
ITEM_NUMBER: ${{ steps.target.outputs.item_number }}
786792
CODEX_TIMEOUT_MS: ${{ steps.target.outputs.codex_timeout_ms }}
787793
MEDIA_PROOF_TIMEOUT_MS: ${{ steps.target.outputs.media_proof_timeout_ms }}
794+
EXACT_REVIEW_ITEM_KEY: ${{ steps.claim-exact-review-queue.outputs.item_key }}
795+
EXACT_REVIEW_LEASE_ID: ${{ steps.claim-exact-review-queue.outputs.lease_id }}
796+
EXACT_REVIEW_LEASE_REVISION: ${{ steps.claim-exact-review-queue.outputs.lease_revision }}
797+
EXACT_REVIEW_CLAIM_GENERATION: ${{ steps.claim-exact-review-queue.outputs.claim_generation }}
798+
EXACT_REVIEW_SOURCE_HEAD_SHA: ${{ fromJSON(steps.claim-exact-review-queue.outputs.decision).sourceHeadSha || '' }}
799+
EXACT_REVIEW_QUEUE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
788800
run: |
789801
set -euo pipefail
790802
test -n "$GH_TOKEN"
@@ -849,13 +861,41 @@ jobs:
849861
EXACT_REVIEW_ITEM_KEY: ${{ steps.claim-exact-review-queue.outputs.item_key }}
850862
EXACT_REVIEW_LEASE_ID: ${{ steps.claim-exact-review-queue.outputs.lease_id }}
851863
EXACT_REVIEW_LEASE_REVISION: ${{ steps.claim-exact-review-queue.outputs.lease_revision }}
864+
EXACT_REVIEW_CLAIM_GENERATION: ${{ steps.claim-exact-review-queue.outputs.claim_generation }}
865+
EXACT_REVIEW_SOURCE_HEAD_SHA: ${{ fromJSON(steps.claim-exact-review-queue.outputs.decision).sourceHeadSha || '' }}
852866
QUEUE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
853867
REVIEW_LEASE_OWNER: ${{ steps.reserve-exact-review-lease.outputs.owner }}
854868
REVIEW_LEASE_COMMENT_ID: ${{ steps.reserve-exact-review-lease.outputs.comment_id }}
855869
run: |
856870
set -euo pipefail
857871
test -n "$GH_TOKEN"
858872
heartbeat_pid=""
873+
review_pid=""
874+
review_pgid=""
875+
superseded_marker="$RUNNER_TEMP/exact-review-superseded-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
876+
rm -f "$superseded_marker"
877+
terminate_review_group() {
878+
[ -n "$review_pgid" ] || return 0
879+
kill -TERM -- "-$review_pgid" 2>/dev/null || true
880+
}
881+
wait_for_review_group() {
882+
[ -n "$review_pgid" ] || return 0
883+
for _ in {1..30}; do
884+
if ! kill -0 -- "-$review_pgid" 2>/dev/null; then
885+
return 0
886+
fi
887+
sleep 1
888+
done
889+
kill -KILL -- "-$review_pgid" 2>/dev/null || true
890+
for _ in {1..50}; do
891+
if ! kill -0 -- "-$review_pgid" 2>/dev/null; then
892+
return 0
893+
fi
894+
sleep 0.1
895+
done
896+
echo "::error::Exact-review process group $review_pgid did not terminate."
897+
return 1
898+
}
859899
heartbeat_loop() {
860900
while true; do
861901
heartbeat_status="$(curl --silent --connect-timeout 5 --max-time 20 \
@@ -867,23 +907,34 @@ jobs:
867907
"${QUEUE_URL%/}/internal/exact-review/heartbeat" 2>/dev/null)" || heartbeat_status=""
868908
if [ "$heartbeat_status" = "409" ]; then
869909
echo "::notice::Exact-review heartbeat lost its lease tuple."
910+
: > "$superseded_marker"
911+
terminate_review_group
870912
return
871913
fi
872-
sleep 300
914+
sleep 60
873915
done
874916
}
875917
start_heartbeat() {
876918
# Heartbeat authenticates by the full lease tuple (same capability model as
877919
# claim/complete), so this Codex-adjacent step never sees the webhook secret.
878920
heartbeat_payload="$(node -e '
879921
const leaseRevision = Number(process.env.EXACT_REVIEW_LEASE_REVISION);
922+
const claimGeneration = Number(process.env.EXACT_REVIEW_CLAIM_GENERATION);
923+
const runAttempt = Number(process.env.GITHUB_RUN_ATTEMPT);
924+
const sourceHeadSha = String(process.env.EXACT_REVIEW_SOURCE_HEAD_SHA || "").trim().toLowerCase();
880925
if (!process.env.EXACT_REVIEW_ITEM_KEY || !process.env.EXACT_REVIEW_LEASE_ID) process.exit(1);
881926
if (!Number.isInteger(leaseRevision) || leaseRevision < 1) process.exit(1);
927+
if (!Number.isInteger(claimGeneration) || claimGeneration < 1) process.exit(1);
928+
if (!Number.isInteger(runAttempt) || runAttempt < 1) process.exit(1);
929+
if (sourceHeadSha && !/^[0-9a-f]{40}$/.test(sourceHeadSha)) process.exit(1);
882930
process.stdout.write(JSON.stringify({
883931
item_key: process.env.EXACT_REVIEW_ITEM_KEY,
884932
lease_id: process.env.EXACT_REVIEW_LEASE_ID,
885933
lease_revision: leaseRevision,
934+
claim_generation: claimGeneration,
886935
run_id: process.env.GITHUB_RUN_ID,
936+
run_attempt: runAttempt,
937+
...(sourceHeadSha ? { source_head_sha: sourceHeadSha } : {}),
887938
}));
888939
')" || return 0
889940
heartbeat_loop &
@@ -894,7 +945,6 @@ jobs:
894945
kill "$heartbeat_pid" 2>/dev/null || true
895946
wait "$heartbeat_pid" 2>/dev/null || true
896947
}
897-
start_heartbeat
898948
trap cleanup_heartbeat EXIT
899949
codex_timeout_ms="${{ steps.target.outputs.codex_timeout_ms }}"
900950
if ! [[ "$codex_timeout_ms" =~ ^[0-9]+$ ]] || [ "$codex_timeout_ms" -lt 1 ]; then
@@ -912,7 +962,7 @@ jobs:
912962
review_timeout_seconds=$((codex_timeout_seconds + media_preprocessing_reserve_seconds + 180))
913963
echo "::notice::Exact event review timeout is ${review_timeout_seconds}s for per-item Codex timeout ${codex_timeout_seconds}s, reserved media preprocessing ${media_preprocessing_reserve_seconds}s, and detected media allowance ${media_proof_timeout_seconds}s."
914964
set +e
915-
timeout --kill-after=30s "${review_timeout_seconds}s" pnpm run review -- \
965+
setsid timeout --kill-after=30s "${review_timeout_seconds}s" pnpm run review -- \
916966
--target-repo "${{ steps.target.outputs.target_repo }}" \
917967
--target-dir "${{ steps.target.outputs.target_checkout_dir }}" \
918968
--artifact-dir artifacts/event \
@@ -929,8 +979,17 @@ jobs:
929979
--review-lease-comment-id "$REVIEW_LEASE_COMMENT_ID" \
930980
--shard-index 0 \
931981
--shard-count 1 \
932-
"${additional_prompt_arg[@]}"
982+
"${additional_prompt_arg[@]}" &
983+
review_pid=$!
984+
review_pgid=$review_pid
985+
start_heartbeat
986+
wait "$review_pid"
933987
review_exit_code=$?
988+
cleanup_heartbeat
989+
if [ -f "$superseded_marker" ]; then
990+
wait_for_review_group
991+
review_exit_code=143
992+
fi
934993
set -e
935994
echo "exit_code=$review_exit_code" >> "$GITHUB_OUTPUT"
936995
if [ "$review_exit_code" -ne 0 ]; then

0 commit comments

Comments
 (0)