clawsweeper icon indicating copy to clipboard operation
clawsweeper copied to clipboard

Review labels are not restored after stale-strip and re-review: PR #388 gates fresh-head label sync behind comment-recency freshness

Open yetval opened this issue 5 months ago • 4 comments

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)

  1. 21:33: apply pass detects a stale reviewed head (ce97339 vs live 5ceedac) and strips proof: 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 (comment updated_at becomes 21:33:21). This part of #388 worked as designed.
  2. 21:42:28: contributor pushes new head bc60b889 and requests a re-review.
  3. 21:42:48: review snapshots the item (updated_at=2026-07-03T21:42:48Z in the verdict marker).
  4. 21:43:45: ClawSweeper edits its own command-ack comment ("review queued" to "review finished"), bumping the PR updatedAt to 21:43:45.
  5. 21:47:23: review completes for head bc60b889. The durable comment shows the verdict marker sha=bc60b889... matching the live head, and the report plans the label adds explicitly: add merge-risk: compatibility, add proof: sufficient, add the diamond lobster rating label.
  6. 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: S and P2.

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:

  • stalePrReviewHead is null: the report head bc60b889 equals 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), so updatedSinceReview is true.
    • reviewCommentOnlyUpdate is false: the durable comment's updatedAt was 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 comment updatedAt (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:

  1. 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.
  2. Self-inflicted activity. The command-ack comment edit is ClawSweeper's own mutation, but only the durable review comment's updatedAt is added to allowedSelfMutationUpdatedAts; the ack edit still bumps item.updatedAt and trips updatedSinceReview. 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.

yetval avatar Jul 03 '26 21:07 yetval

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 stalePrReviewHead is null and labelSyncFreshEnough() 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 blame and git log -S tie 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 tie labelSyncFreshEnough() 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-review comments, 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-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to 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 explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Jul 03 '26 22:07 clawsweeper[bot]

I Will Work On this issue. Please do not Open A PR for this.

yetval avatar Jul 03 '26 22:07 yetval

🦞✅ 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

clawsweeper[bot] avatar Jul 03 '26 22:07 clawsweeper[bot]

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.

yetval avatar Jul 03 '26 23:07 yetval