[Bug]: ClawSweeper can close a PR as superseded by another PR that is later closed unmerged
Bug type
Behavior bug (incorrect output/state without crash)
Beta release blocker
No
Summary
ClawSweeper closed openclaw/openclaw#85873 as duplicate_or_superseded by openclaw/openclaw#46949, but #46949 was also later closed unmerged by ClawSweeper. The original linked issue openclaw/openclaw#72013 remains open, and current main still appears to lack the narrow fix from #85873.
Steps to reproduce
- Open
openclaw/openclaw#85873. - Read the durable ClawSweeper review comment: https://github.com/openclaw/openclaw/pull/85873#issuecomment-4526877798
- Observe that ClawSweeper recommends closing
#85873as superseded byopenclaw/openclaw#46949. - Read the close-applied comment on
#85873: https://github.com/openclaw/openclaw/pull/85873#issuecomment-4526892942 - Open
openclaw/openclaw#46949. - Observe that
#46949was later also closed unmerged by ClawSweeper: https://github.com/openclaw/openclaw/pull/46949#issuecomment-4527511661 - Open the linked source issue
openclaw/openclaw#72013. - Observe that
#72013is still open. - Inspect current
mainaroundAcpSessionManager.reconcilePendingSessionIdentitiesand observe that the narrowsession.acp.mode === "oneshot"skip from#85873is still not present before pending identity reconciliation.
Expected behavior
ClawSweeper should not close a PR as duplicate_or_superseded by another PR unless the replacement target is a safe canonical path, for example:
- already merged, or
- open and still viable / merge-ready, or
- clearly backed by a still-open canonical issue that preserves the remaining work.
If the replacement PR is stale, blocked, unmerged, no-proof, F-rated, already has a proposed close, or is later closed unmerged by ClawSweeper, then the original PR should stay open or be routed to the canonical issue instead.
Actual behavior
#85873 was closed as superseded by #46949 while #46949 was not actually a safe replacement path. ClawSweeper's own review on #46949 said it was not safe to merge, lacked real proof, had pressure-eviction correctness risks, and should be closed as stale. #46949 was then closed unmerged by ClawSweeper a few hours later.
Net result:
#85873closed unmerged#46949closed unmerged#72013still open- current
mainstill appears to lack the narrow one-shot startup reconcile skip
OpenClaw version
ClawSweeper production behavior observed on GitHub on 2026-05-24. Exact deployed ClawSweeper SHA is NOT_ENOUGH_INFO.
Operating system
N/A - GitHub automation behavior.
Install method
ClawSweeper GitHub automation / GitHub Actions.
Model
The review comments state model gpt-5.5, reasoning high.
Provider / routing chain
ClawSweeper GitHub app / GitHub Actions / Codex review.
Additional provider/model setup details
NOT_ENOUGH_INFO
Logs, screenshots, and evidence
Relevant links:
#85873: https://github.com/openclaw/openclaw/pull/85873#85873durable ClawSweeper review: https://github.com/openclaw/openclaw/pull/85873#issuecomment-4526877798#85873close-applied comment: https://github.com/openclaw/openclaw/pull/85873#issuecomment-4526892942#46949: https://github.com/openclaw/openclaw/pull/46949#46949durable ClawSweeper review: https://github.com/openclaw/openclaw/pull/46949#issuecomment-4333077112#46949close-applied comment: https://github.com/openclaw/openclaw/pull/46949#issuecomment-4527511661- linked issue
#72013: https://github.com/openclaw/openclaw/issues/72013 - current
mainsource around the relevant reconcile path: https://github.com/openclaw/openclaw/blob/main/src/acp/control-plane/manager.core.ts
Key quote from #85873 review:
Canonical path: Close this PR as superseded by https://github.com/openclaw/openclaw/pull/46949.
Key quote from #46949 review:
No. The direction is appropriate, but this PR needs a hard getStatus timeout, capacity and idleness rechecks at eviction time, a rebase, and real after-fix proof before it is the safest implementation.
Impact and severity
Affected: contributor PR close/apply decisions for OpenClaw PRs.
Severity: medium to high. A useful, narrow PR can be closed as superseded by another PR that is not merged and is itself unsafe/stale/no-proof.
Frequency: observed once in the #85873 -> #46949 -> #72013 chain.
Consequence: potentially valid fixes can be removed from the active review queue while the underlying issue remains unresolved.
Additional information
This may have been exposed by the recent related-context improvement in openclaw/clawsweeper#176, because richer related context can make ClawSweeper more likely to identify an adjacent PR such as #46949.
However, the likely bug is not the context enrichment itself. The unsafe behavior appears to be in the close decision/apply guard: before applying duplicate_or_superseded, ClawSweeper should verify that the referenced canonical PR is actually a safe replacement target, or that the remaining work is preserved by a still-open canonical issue.
Potential guardrail:
Do not close item A as superseded by item B when B is closed unmerged, already has a close proposal, is blocked/no-proof/stale, or is not itself merge-ready/merged. Prefer keeping A open or linking the canonical issue.
Coordination signal
I can help work on a focused fix PR if maintainers agree this is a real ClawSweeper close-policy bug.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 25, 2026, 5:23 AM ET / 09:23 UTC.
Summary Keep open: current source and live GitHub evidence show the superseded-close path can treat an open but not merge-ready replacement PR as canonical, and no current-main guard validates that replacement before applying the close.
Reproducibility: yes. source-level reproduction is high confidence: current code promotes linked open PRs without checking replacement viability, and the live OpenClaw chain shows the reported close sequence. I did not run an apply-path repro because this review is read-only.
Next step This is a bounded ClawSweeper close-policy bug with clear source files, live evidence, and focused regression-test paths.
Review details
Best possible solution:
Add a conservative canonical-target validator for duplicate/superseded PR closes, then keep or route the source PR to the open canonical issue whenever the referenced replacement PR is closed unmerged, F/no-proof, already proposed for close, conflicted, or otherwise not a safe landing path.
Do we have a high-confidence way to reproduce the issue?
Yes, source-level reproduction is high confidence: current code promotes linked open PRs without checking replacement viability, and the live OpenClaw chain shows the reported close sequence. I did not run an apply-path repro because this review is read-only.
Is this the best way to solve the issue?
Yes, a narrow guard in the duplicate/superseded promotion/apply path is the maintainable fix. It should preserve merged or genuinely viable canonical targets while blocking unsafe replacement PRs and falling back to the open canonical issue when appropriate.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- The repair should define 'open and viable replacement PR' using existing ClawSweeper signals without overblocking legitimate merged or clearly merge-ready canonical replacements.
Codex review notes: model gpt-5.5, reasoning high; reviewed against eef3e9ab6847.
Label changes
Label changes:
- add
P1: Incorrect close/apply decisions can remove valid contributor PRs from the active review queue while the source issue remains unresolved. - add
impact:other: The impact is maintainer-visible automation state: PRs can be closed as superseded by unsafe or unmerged replacement work. - 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: Incorrect close/apply decisions can remove valid contributor PRs from the active review queue while the source issue remains unresolved.impact:other: The impact is maintainer-visible automation state: PRs can be closed as superseded by unsafe or unmerged replacement work.
Evidence reviewed
Acceptance criteria:
- pnpm run test:unit
- pnpm run check
What I checked:
- Repository policy requires conservative apply closes: AGENTS.md says the review lane is proposal-only and the apply lane closes only unchanged, high-confidence proposals, which makes the reported unsafe close-policy behavior in scope for this repository. (
AGENTS.md:25, eef3e9ab6847) - Linked PR supersession accepts any open replacement PR: The stale-PR promotion path fetches a linked PR and only rejects it when it is neither open nor merged; it does not inspect proof status, rating, mergeability, close proposals, or whether the linked PR is itself a safe landing path. (
src/clawsweeper.ts:10117, eef3e9ab6847) - Apply validation has no duplicate-canonical safety check: validateCloseDecision checks structural close metadata, protected labels, close reason allowlists, and implementation evidence for implementation closes, but duplicate_or_superseded has no canonical PR state or viability validation. (
src/clawsweeper.ts:11445, eef3e9ab6847) - Apply closes after generic validation: The apply loop validates the report, checks age and low-signal-specific blockers, then closes the item; there is no duplicate_or_superseded-specific guard before closeItem runs. (
src/clawsweeper.ts:13823, eef3e9ab6847) - Existing test permits open low-proof linked PR promotion: The current test suite explicitly expects an old PR with proof tier D to close when its work_cluster_refs say it is superseded by an open linked PR. (
test/clawsweeper.test.ts:7894, eef3e9ab6847) - Prompt asks for state disclosure, not replacement safety enforcement: The review prompt tells Codex to explain whether a duplicate/superseded canonical item is open, closed, merged, or shipped, but it does not encode the stricter replacement-viability rule requested here. (
prompts/review-item.md:370, eef3e9ab6847)
Likely related people:
- Peter Steinberger: git blame and git show tie linkedPullRequestSupersession, stale/F-rated close promotion, and the matching tests to the stale PR close lanes commit. (role: introduced linked-PR close promotion behavior; confidence: high; commits: 97885cf4e291, 6808b583b, c45201aa4; files:
src/clawsweeper.ts,test/clawsweeper.test.ts) - Tak Hoffman: git blame ties validateCloseDecision, the duplicate/superseded allowed-close prompt text, and the baseline duplicate close tests to this author, which is adjacent to the missing guard. (role: introduced base close validation and duplicate/superseded prompt surface; confidence: medium; commits: 390e5211aa5a; files:
src/clawsweeper.ts,prompts/review-item.md,test/clawsweeper.test.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.