Review labels are not restored after stale-strip and re-review: PR #388 gates fresh-head label sync behind comment-recency freshness
Summary
PR #388 (commit b1e238d) correctly strips ClawSweeper review labels when a PR head moves past the reviewed head, but the same commit also demoted open-PR label sync from unconditional to gated behind labelSyncFreshEnough(). After the exact stale-strip and re-review cycle that #388 creates, that gate evaluates false on the apply pass that follows the fresh review, so the freshly earned rating, status, proof, and merge-risk labels are never written back. The review comment updates (comment sync is a separate path) while the labels stay missing, leaving a reviewed, rated PR with no readiness labels.
The gate fails partly because of ClawSweeper's own automation: the command-ack comment edit bumps the item updatedAt past the review snapshot, and the 5 minute recency window is measured against the durable review comment timestamp, which the stale-strip itself left in the past.
Observed behavior (openclaw/openclaw#97157, 2026-07-03, all times UTC)
- 21:33: apply pass detects a stale reviewed head (
ce97339vs live5ceedac) and stripsproof: sufficient, the platinum rating label, the compatibility merge-risk label, and the ready-for-maintainer status label. Durable review comment is rewritten to the stale notice (commentupdated_atbecomes 21:33:21). This part of #388 worked as designed. - 21:42:28: contributor pushes new head
bc60b889and requests a re-review. - 21:42:48: review snapshots the item (
updated_at=2026-07-03T21:42:48Zin the verdict marker). - 21:43:45: ClawSweeper edits its own command-ack comment ("review queued" to "review finished"), bumping the PR
updatedAtto 21:43:45. - 21:47:23: review completes for head
bc60b889. The durable comment shows the verdict markersha=bc60b889...matching the live head, and the report plans the label adds explicitly: addmerge-risk: compatibility, addproof: sufficient, add the diamond lobster rating label. - 21:48:20: apply edits the durable review comment with the fresh verdict, but zero label events fire. The PR is left with only
size: SandP2.
Timeline evidence: the issue timeline for openclaw/openclaw#97157 shows the four unlabeled events at 21:33:15-21:33:20 and no labeled events after that, while the durable review comment (id 4814732254) was updated at 21:48:20 with the fresh diamond lobster verdict and the planned label adds in its body.
Root cause
All line references at 1343d8ec0cef4a5088be01084937fe4396cf9571.
The open-PR label sync block now runs only when the report is stale or the gate passes:
https://github.com/openclaw/clawsweeper/blob/1343d8ec0cef4a5088be01084937fe4396cf9571/src/clawsweeper.ts#L17577-L17591
For the pass at 21:48:
stalePrReviewHeadis null: the report headbc60b889equals the live head, so the stale branch is not taken. Correct.labelSyncFreshEnough()(L17559-L17571) returns false:storedUpdatedAt= 21:42:48 (review snapshot),item.updatedAt= 21:43:45 (the bot's own ack edit), soupdatedSinceReviewis true.reviewCommentOnlyUpdateis false: the durable comment'supdatedAtwas still 21:33:21 (the stale notice edit), not 21:43:45.- The recency check at L17565 compares
item.updatedAt(21:43:45) with the durable commentupdatedAt(21:33:21): 10m24s > 5m, so the gate returns false before the non-automation activity check is even reached.
- Result: the entire rating/status/proof/merge-risk sync block (L17591 onward) is skipped. Before #388 this block ran unconditionally for open PRs.
Two design problems compound here:
- Wrong freshness signal. For PR review labels, the correct freshness signal is head-SHA equality between the report and the live PR, which the same commit already computes in
stalePullRequestReviewHead(). Comment recency is a proxy that measures the wrong thing: after a stale-strip, the durable comment timestamp is by construction old, so the first post-re-review apply pass is almost guaranteed to fail the 5 minute window. - Self-inflicted activity. The command-ack comment edit is ClawSweeper's own mutation, but only the durable review comment's
updatedAtis added toallowedSelfMutationUpdatedAts; the ack edit still bumpsitem.updatedAtand tripsupdatedSinceReview. The bot's own acknowledgement defeats its own gate on every command-triggered re-review.
Why it does not reliably self-heal
After the failed pass, the apply comment edit leaves item.updatedAt equal to the durable comment updatedAt (both 21:48:20), so reviewCommentOnlyUpdate becomes true and the next apply pass over the report would add the labels. But that window closes on any PR activity at all (a human comment, a CI label, a push), and a fresh re-review request just re-runs the same ack-edit race. Label restoration after a stale-strip therefore depends on the PR being untouched between two apply passes, which is exactly the period when a contributor is most likely to be active on it.
Suggested fix
When review_status is complete and stalePullRequestReviewHead() proves the report matches the live head (reportHeadSha === liveHeadSha), run the PR label sync unconditionally, or at minimum:
- treat ClawSweeper's own command-ack comment edits as allowed self-mutation the same way the durable review comment edit already is, and
- after taking the stale branch and completing a fresh review for the new head, ensure the next apply pass re-applies labels rather than re-deriving freshness from the durable comment timestamp the stale notice overwrote.
Repro
openclaw/openclaw#97157 is a live end-to-end repro: stale-strip at 21:33, fresh diamond lobster review of the current head at 21:47 with planned label adds in the comment body, and no label writes on the 21:48 apply pass.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 3, 2026, 6:03 PM ET / 22:03 UTC.
Summary
Keep open: the referenced OpenClaw PR later self-healed on a subsequent apply pass, but current main still contains the freshness gate that can skip review-derived PR label restoration on the first stale-strip-plus-re-review apply pass.
Reproducibility: yes. from source inspection: a same-head complete PR report skips all review-derived PR label sync when updatedSinceReview is true, reviewCommentOnlyUpdate is false, and the durable comment timestamp is more than five minutes from item.updatedAt. I did not run an apply repro because this review is read-only and the issue already provides a live end-to-end trace.
Next step This is a narrow apply-path regression with clear source evidence, likely files, and focused test coverage.
Review details
Best possible solution:
Patch the apply label-sync freshness logic so a complete same-head PR report restores review-derived labels after stale-strip without reopening stale-head label leakage.
Do we have a high-confidence way to reproduce the issue?
Yes from source inspection: a same-head complete PR report skips all review-derived PR label sync when updatedSinceReview is true, reviewCommentOnlyUpdate is false, and the durable comment timestamp is more than five minutes from item.updatedAt. I did not run an apply repro because this review is read-only and the issue already provides a live end-to-end trace.
Is this the best way to solve the issue?
Yes in direction: the narrow fix should keep stale-head stripping but let complete same-head PR reports sync their derived labels, with regression coverage for stale-strip followed by command-triggered re-review.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- The live referenced PR has labels now because a later apply pass restored them, so the remaining issue is the fragile first-pass race rather than the current state of that one PR.
Codex review notes: model internal, reasoning high; reviewed against 1343d8ec0cef.
Label changes
Label changes:
- add
P1: The bug affects live ClawSweeper PR readiness labeling after a supported stale-strip and re-review workflow. - add
impact:other: The impact is automation state drift in GitHub labels, which is maintainer-visible but outside the more specific owned impact categories. - add
issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label. - add
clawsweeper:source-repro: Current issue advisory state selects this label. - add
clawsweeper:queueable-fix: Current issue advisory state selects this label. - add
clawsweeper:fix-shape-clear: Current issue advisory state selects this label.
Label justifications:
P1: The bug affects live ClawSweeper PR readiness labeling after a supported stale-strip and re-review workflow.impact:other: The impact is automation state drift in GitHub labels, which is maintainer-visible but outside the more specific owned impact categories.
Evidence reviewed
Acceptance criteria:
- pnpm run check
- node --test test/apply-label-sync.test.ts
What I checked:
- Current source freshness gate:
labelSyncFreshEnough()can return false when item and durable-comment timestamps are more than five minutes apart, before non-automation activity is considered. (src/clawsweeper.ts:17559, 1343d8ec0cef) - Current source PR label sync gate: Fresh open-PR proof, media, rating, showcase, status, and Telegram-visible labels only sync when
stalePrReviewHeadis null andlabelSyncFreshEnough()passes. (src/clawsweeper.ts:17591, 1343d8ec0cef) - Complete-report label gate: Priority, impact, maturity, and merge-risk label sync for complete reports also requires
labelSyncFreshEnough(), so a false gate skips merge-risk label restoration too. (src/clawsweeper.ts:17906, 1343d8ec0cef) - Existing tests miss this sequence: The inspected apply-label-sync tests cover normal PR label additions and stale-head label removal, but not stale-strip followed by fresh same-head re-review with an intervening bot acknowledgement update. (
test/apply-label-sync.test.ts:107, 1343d8ec0cef) - Regression provenance:
git blameandgit log -Stie the freshness gate and stale-head label-removal branch to merged https://github.com/openclaw/clawsweeper/pull/388. (src/clawsweeper.ts:17559, b1e238da6eed) - Live reference later self-healed: The referenced PR timeline shows review-derived labels removed at 2026-07-03T21:33:15Z through 21:33:20Z, then added only later at 2026-07-03T21:54:46Z through 21:54:51Z.
Likely related people:
- momothemage: Git blame,
git log -S, and GitHub PR metadata tielabelSyncFreshEnough()and stale-head stripping to merged https://github.com/openclaw/clawsweeper/pull/388. (role: introduced stale-head freshness gate; confidence: high; commits: b1e238da6eed; files:src/clawsweeper.ts,test/apply-label-sync.test.ts) - RomneyDa: Git blame and PR metadata tie the underlying complete-report and merge-risk label-sync block to earlier PR policy and maturity-label work. (role: adjacent label-sync contributor; confidence: medium; commits: a811372b8fd0, 82a1bfda0da5; files:
src/clawsweeper.ts)
How this review workflow works
- ClawSweeper keeps one durable marker-backed review comment per issue or PR.
- Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
- A fresh review can be triggered by eligible
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch. - PR/issue authors and users with repository write access can comment
@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto request a fresh review only. - Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
- Maintainer-only repair and merge flows require explicit commands such as
@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review. - Maintainers can comment
@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.
I Will Work On this issue. Please do not Open A PR for this.
🦞✅ Implementation PR opened: https://github.com/openclaw/clawsweeper/pull/399 Status: The implementation PR passed the worker's edit, validation, review, publish, and post-flight gates. Worker: https://github.com/openclaw/clawsweeper/actions/runs/28687353342
Triage update: #396 (head 4c41d0923f) now also carries the close-proposal guard that #399 introduced, folded inside the single labelSyncFreshEnough gate, with a RED-verified regression for that branch and a refreshed real dist-CLI before/after proof that includes a close-proposal leg. At this point #396 covers everything #399 does plus the incident-faithful openclaw/openclaw#97157 regression and runtime evidence, so merging #396 resolves this fully and #399 can be closed as subsumed.