Repository navigation
fix(apply): restore PR review labels when the reviewed head matches the live head - #396
Conversation
…he live head After a stale-strip pass edited the durable review comment, a fresh re-review of the new head was blocked from label sync because the freshness gate compares item.updatedAt to the durable comment updatedAt with a 5 minute window, and ClawSweeper's own ack edits bump item.updatedAt past it. Allow label sync for complete PR reviews whose reviewed head SHA equals the live head SHA, keeping the non-automation-activity check so human label changes after the review snapshot are never stomped. Fixes openclaw#394
|
Codex review: passed. Reviewed July 3, 2026, 9:26 PM ET / 01:26 UTC. Summary Reproducibility: yes. The linked issue gives a live timeline, and current-main source shows same-head complete PR label sync can be skipped when automation bumps item.updatedAt while the durable review comment timestamp is older than the five-minute gate. Review metrics: 2 noteworthy metrics.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge one canonical fix that uses PR head-SHA equality for complete same-head PR reports while preserving stale-head cleanup, close-proposal handling, and human-activity protection. Do we have a high-confidence way to reproduce the issue? Yes. The linked issue gives a live timeline, and current-main source shows same-head complete PR label sync can be skipped when automation bumps item.updatedAt while the durable review comment timestamp is older than the five-minute gate. Is this the best way to solve the issue? Yes. The patch uses report/live head-SHA equality as the narrow PR-specific freshness signal and still leaves human activity and close proposals guarded. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ead7d6461a6c. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-run |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@momothemage - pls follow this PR as the issue it is fixing is saying it's caused as a regression from one of your PRs. Pls follow it, and if after it is fully ready, pls look to merge to main. Thanks |
The fresh-head allowance now also requires the report not be a close proposal, so a PR the bot proposes to close never regains review labels through that path and falls back to the comment-recency window. Also broadens the fresh-head regression to cover merge-risk label sync, the patched durable comment justifications, and the apply report record. Refs openclaw#394
|
@brokemac79 @momothemage Thanks. Quick orientation for review: Provenance: the regression comes from #388 (commit b1e238d). Its stale-head label strip is correct and untouched here. The regression is that the same commit also gated open-PR label sync behind a comment-recency freshness window, which fails by construction on the exact stale-strip plus re-review cycle it creates: the strip leaves the durable comment timestamp in the past and the bot's own command-ack edit bumps the item past the review snapshot, so a fresh, head-matching review never gets its labels applied. Live occurrence with full timeline: openclaw/openclaw#97157, details in #394 and the PR body. State: ready from my side at head 4c41d09. The fix is a fresh-head allowance inside the existing labelSyncFreshEnough gate (head-SHA equality, the same signal the stale branch already uses) plus a close-proposal exclusion folded in from the autogenerated #399, which this PR now subsumes. Coverage: 11/11 in test/apply-label-sync.test.ts, including a regression replaying the #97157 timestamps and a close-proposal scenario, both verified failing without their respective changes; full unit, repair, and coverage suites pass. The PR body carries real dist-CLI before/after runtime proof with three legs: pristine main (reads only, no labels), patched (labels applied), and close-proposal (allowance correctly withheld). Note on the current labels: the "needs proof" rating predates both the proof block and the latest head; a fresh ClawSweeper pass on 4c41d09 should clear it. |
|
@yetval i am away from my pc now and don't have the authority to do it but if you create a comment just with below then wait for 10-15 mins then clawsweeper should update its last comments hopefully Type below into a new comment @clawsweeper re-review (Ignore any comment it makes from me doing this as it won't trigter( you need to do it) |
|
🦞👀 Command router queued. I will update this comment with the next step. |
Sounds Good! |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
hxy91819
left a comment
There was a problem hiding this comment.
LGTM. Thank you for finding and fixing the issue. @momothemage will handle the follow-up.
momothemage
left a comment
There was a problem hiding this comment.
Thanks for digging this up and for the careful repro.
As the author of #388, I can confirm this is a real follow-up regression from that change. #388 intentionally fixed the stale-head side by stripping review-derived PR labels when the live head no longer matched the reviewed head, but I also moved the fresh open-PR label sync behind labelSyncFreshEnough(). That made the first apply pass after a stale-strip plus fresh re-review vulnerable to the durable-comment timestamp proxy, especially when ClawSweeper's own command-ack/status edit bumped the PR updatedAt while the durable review comment still had the older stale-notice timestamp.
No blocking findings.
LOC: +555/-5 (2 files)
Code review: this is the right layer and the right freshness signal. freshPullRequestReviewHead() reuses the same report-vs-live PR head invariant that #388 introduced for stale detection, and the new allowance only bypasses the five-minute comment-recency proxy. It still requires a complete PR report, excludes close proposals, and still runs contextHasNonAutomationActivityAfter(), so maintainer/user activity after the review snapshot remains protected.
I specifically checked the normal PR label sync, complete-report priority/merge-risk sync, stale-head cleanup, close-proposal path, and the non-automation activity guard. The added tests cover the incident shape I missed in #388: bot activity bumps updated_at but fresh head labels are restored; human activity after the snapshot still blocks label writes; close proposals do not regain readiness labels through the fresh-head allowance.
Best-fix verdict: best. Alternatives I considered were treating command-ack edits as additional self-mutations or simply widening the timestamp window, but both keep relying on the wrong proxy. Head-SHA equality is the stable contract for PR review-derived labels.
Validation run locally on Node 24.14.0:
pnpm run buildnode --test test/apply-label-sync.test.ts(11 pass)
Remaining uncertainty: I did not perform live GitHub label mutations during review, which is appropriate for this apply-lane change; the PR's staged CLI proof plus CI cover the behavior boundary well enough for me.
|
@clawsweeper automerge |
|
🦞✅ Source: What merged:
Automerge notes:
The automerge loop is complete. Automerge progress:
|
…he live head (openclaw#396) Summary: - The PR updates apply-decision label freshness logic so complete same-head PR reviews can restore review labels after bot-updated timestamps, with regression tests for bot activity, human activity, and close proposals. - Reproducibility: yes. The linked issue gives a live timeline, and current-main source shows same-head comple ... omation bumps item.updatedAt while the durable review comment timestamp is older than the five-minute gate. Automerge notes: - PR branch already contained follow-up commit before automerge: fix(apply): keep fresh-head label restore out of close proposals Validation: - ClawSweeper review passed for head 4c41d09. - Required merge gates passed before the squash merge. Prepared head SHA: 4c41d09 Review: openclaw#396 (comment) Co-authored-by: yetval <[email protected]> Approved-by: momothemage
What problem this solves
Fixes #394.
PR #388 (commit b1e238d) correctly strips ClawSweeper review labels when a PR head moves past the reviewed head, but it also demoted the open-PR label sync block from unconditional to gated behind
labelSyncFreshEnough(). That gate measures freshness by comment recency: when the item was updated after the review snapshot, it requires the itemupdatedAtto be within 5 minutes of the durable review comment'supdatedAt.After the exact stale-strip and re-review cycle that #388 creates, that proxy fails by construction: the stale-strip leaves the durable comment timestamp in the past, and ClawSweeper's own command-ack comment edit bumps the item
updatedAtpast the review snapshot. The apply pass that follows a fresh, head-matching review therefore skips every label write. The review comment updates (comment sync is a separate path) while the rating, status, proof, and merge-risk labels stay missing.Live occurrence, openclaw/openclaw#97157 on 2026-07-03 (UTC): stale-strip at 21:33 (durable comment
updatedAtbecomes 21:33:21), re-review requested at 21:42:28 for new head bc60b889, review snapshotitem_updated_at21:42:48, ack edit bumps itemupdatedAtto 21:43:45, review completes at 21:47 for head bc60b889 with planned label adds in the report. On the 21:48 apply pass, |21:43:45 - 21:33:21| = 10m24s exceeds the 5 minute window,labelSyncFreshEnough()returns false, and the whole label sync block is skipped. The PR is left reviewed and rated with zero readiness labels.The fix
For PR review labels the correct freshness signal is head-SHA equality between the report and the live PR, which #388 already computes for the stale branch. This change adds a
freshPullRequestReviewHead()helper (report head SHA present, live head SHA present, equal) and skips the 5 minute comment-recency window insidelabelSyncFreshEnough()when the item is a pull request with areview_status: completereport for a provably fresh head.The maintainer-override protection is preserved: the
contextHasNonAutomationActivityAftercheck still runs, so genuine human activity after the review snapshot continues to block label re-sync. Bot self-activity such as the command-ack edit is already classified as automation by that check, so no change to self-mutation handling was needed. Theitem.kind === "pull_request"short-circuit ahead of the helper avoids collecting item context for issue-kind items, whose gate is unchanged.The priority label sync gate (
isCurrentCompleteReport) routes throughlabelSyncFreshEnough()and picks up the same allowance with no separate edit. The stale-strip path from #388 is untouched.The allowance is also excluded for close proposals: a report whose decision proposes closing the PR falls back to the pre-existing changed-since-review handling exactly as on main, so this path never relabels a PR that is being proposed for closure.
Tests
test/apply-label-sync.test.ts:Validation
node --test test/apply-label-sync.test.ts: 11 pass, 0 fail.pnpm check:changedsubgates: check:active-surface, check:limits, build:all (tsgo), lint, and format:check all pass; test:unit 559 pass 0 fail; test:repair 573 pass 0 fail; coverage suites 1132 pass 0 fail with no threshold violations. The only anomalies are 5 dashboard-worker test cancellations that reproduce identically on pristine origin/main under this machine's Node 22.19.0 (repo declares engines node >= 24); they are an environment artifact, not caused by this change.Real behavior proof
Behavior addressed: After a stale-strip followed by a fresh re-review of the current head, the apply pass skipped every review-label write, leaving a reviewed and rated PR with no rating, status, or proof labels (live occurrence: openclaw/openclaw#97157 on 2026-07-03).
Real environment tested: the real dist CLI apply-decisions entry point, invoked exactly as the sweep.yml comment-sync apply pass runs it, built from pristine main@1343d8ec0cef4a5088be01084937fe4396cf9571 (before) and from PR head 4c41d09 (after, plus a close-proposal leg), against an identical records fixture replaying the openclaw/openclaw#97157 timestamps (report item_updated_at 21:42:48Z, live item updatedAt 21:43:45Z from the bot ack edit, durable review comment updatedAt 21:33:21Z, reviewed head equal to live head); the only faked boundary was a PATH-provided gh executable serving item, comment, timeline, and pull JSON and logging every invocation.
Exact steps or command run after this patch: node dist/clawsweeper.js apply-decisions --target-repo openclaw/openclaw --skip-dashboard --items-dir records/items --closed-dir records/closed --plans-dir records/plans --report-path apply-report.json --limit 0 --min-age-days 0 --apply-kind all --stale-min-age-days 60 --close-delay-ms 0 --progress-every 25 --processed-limit 1000 --comment-sync-min-age-days 7 --item-numbers 97157 --sync-comments-only
Evidence after fix:
Observed result after fix: on identical inputs the pristine build issued only read calls and left the item unlabeled, while the patched build added the proof, rating, and status labels and recorded labels_synced_at for the keep-open report and correctly withheld the allowance for the close-proposal report, restoring label sync for a completed review whose reviewed head matches the live head.
What was not tested: no live GitHub API traffic (the gh boundary was a local logging stub with canned JSON); the human-activity guard path was exercised in the committed regression tests rather than this CLI run; Node 24 engine-matched validation is left to CI on this PR.