Skip to content

refactor: split apply phases and safely accelerate dead-letter recovery - #1014

Merged
steipete merged 1 commit into
mainfrom
codex/clawsweeper-apply-phase-simplification
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/clawsweeper-apply-phase-simplification

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Shrink src/clawsweeper.ts to the already-landed 19-line launcher and further reduce the apply orchestrator from 2,945 to 1,990 lines by extracting small, separately testable candidate, policy, promotion, labels, source-freshness, review-activity, review-guard, and close-execution phases.
  • Keep local committed-range review fully offline, preserve conservative maintainer/protected-label/canonical-comment/activity/lease/proof/close fences, and keep OpenClaw fix creation on gpt-5.6-sol / xhigh with both automatic merge switches disabled.
  • Run the existing guarded dead-letter reconciliation every five minutes instead of every ten, inspect at most 100 canonical targets, and recover at most ten fresh reviews per serialized run. This raises bounded scheduled recovery capacity from 30 to 120 reviews/hour without changing the 100-target, ten-recovery, queue-pressure, authoritative-inventory, or mutation-guard hard limits.
  • Keep 100-target canonical discovery batched into three GraphQL queries, cap terminal GitHub rechecks at ten targets per run even when all 100 targets are closed, synchronize direct operator defaults with the scheduled workflow, and retain successful incremental label mutations when authentication fails or a mutation lease disappears.
  • Correct the exact failure behind [Bug]: [Bug] 长回合+多工具调用场景下最终回复偶发丢失,触发核心层兜底文案 openclaw#117838: separately distributed third-party products such as QClaw must close as not_actionable_in_repo when source/release/provider/renderer ownership proves they are external, instead of being mislabeled manual_review, requesting private third-party logs, and adding a self-blocking maintainer-review label.

Real behavior proof

Production bounded reconciliation after the landed starvation fix

Four successful production runs produced these signed-operator summaries:

{"recovered_targets":10,"resolved_rows":141,"closed_rows":129,"duplicate_rows":2,"inventory_complete":true,"queue_pressure":"idle"}
{"recovered_targets":5,"resolved_rows":7,"closed_rows":0,"duplicate_rows":2,"inventory_complete":true,"queue_pressure":"idle"}
{"recovered_targets":10,"resolved_rows":17,"closed_rows":0,"duplicate_rows":7,"inventory_complete":true,"queue_pressure":"idle"}
{"recovered_targets":10,"resolved_rows":10,"closed_rows":0,"duplicate_rows":0,"inventory_complete":true,"queue_pressure":"idle"}

Total: 35 safely requeued reviews, 175 resolved dead-letter rows, 129 closed terminal rows, and 11 duplicate rows. Live inventory moved from 1,391 open dead letters to approximately 1,223 while review and publication lanes continued operating.

Actual signed operator batching proof

Running /tmp/clawsweeper-dead-letter-cadence-proof.mjs against a real HTTP server and the actual operator subprocess confirms the previous and proposed scheduled caps both make 13 GitHub requests: three batched identity GraphQL calls plus ten guarded recovery rechecks. The former regression made 110 requests at the 100-target cap.

{"previous_cap":{"max_targets":25,"rest":10,"graphql":3,"github_requests":13,"recovered":10},"scheduled_cap":{"max_targets":100,"rest":10,"graphql":3,"github_requests":13,"recovered":10}}

The actual /tmp/clawsweeper-closed-target-execute-budget-proof.mjs subprocess also proves that 100 already-closed issues require just 13 GitHub requests and 100 closed PRs require just 23 requests, limiting the five-minute worst case to 276 requests/hour, versus the 2,436 requests/hour regression. Intermediate 32- and 40-target PR batches are likewise GraphQL-batched and covered by explicit regression tests. /tmp/clawsweeper-operator-default-proof.mjs verifies direct CLI invocation now recovers the same ten items as the scheduled workflow.

Actual partial-failure apply proof

Running /tmp/clawsweeper-partial-label-auth-proof.mjs executes the real apply path against a subprocess-backed gh mock: P2 succeeds, a later impact-label write fails HTTP 401, apply returns a conservative kept_open, and the authoritative report still contains the successful P2 label.

{"github_labels":["P2"],"canonical_labels":"[\"P2\"]","label_record_matches":true}

The actual /tmp/clawsweeper-report-label-lease-e2e-proof.mjs subprocess separately proves P2 remains durable when its successful write invalidates the owned review lease before the next mutation; apply correctly remains fail-closed.

Actual offline local review

Running /tmp/clawsweeper-local-range-proof.mjs invokes dist/clawsweeper.js review --local-range against an actual committed local Git range. Codex starts in the expected checkout with an isolated .gh-empty config and no GitHub/network requirement.

{"launcher":"dist/clawsweeper.js","committed_local_range":true,"codex_started":true,"codex_checkout_matches":true,"isolated_gh_config":".gh-empty","expected_fake_codex_exit":1}

Actual gpt-5.6-sol/xhigh replay of the QClaw issue

Replaying the complete original issue and first ClawSweeper review from openclaw/openclaw#117838 against the updated policy and actual OpenClaw checkout, while excluding the later maintainer closure, now produces the correct real-model decision:

{"decision":"close","closeReason":"not_actionable_in_repo","confidence":"high","workCandidate":"none","requiresMaintainerDecision":false}

The model verified that QClaw 0.2.35.624 and qclaw/pool-hy3-preview are absent from the OpenClaw 2026.7.2 checkout, WeChat is provided by the external @tencent-weixin/openclaw-weixin package, and none of the reported QClaw renderer/fallback strings exist in OpenClaw source. Merely citing healthy upstream delivery/fallback files does not qualify as evidence of an upstream defect.

Safety and validation

  • Full apply, promotion, lease, stale-canonical, protected-label, proof-freshness, source/activity, source-contract, operator, label-auth, and local-review suites are run on the final head.
  • New tests prove 100-target batches of open issues, closed issues, and closed PRs stay within the GitHub token budget; direct CLI defaults match the scheduled limits; and neither authentication failures nor mutation-lease races can roll back an already-written canonical label snapshot.
  • The external-product regression reproduces the QClaw ownership signals from [Bug]: [Bug] 长回合+多工具调用场景下最终回复偶发丢失,触发核心层兜底文案 openclaw#117838 and proves a valid high-confidence not_actionable_in_repo decision becomes proposed_close without maintainer-review routing.
  • Preserve CLAWSWEEPER_ALLOW_AUTOMERGE=0, CLAWSWEEPER_ALLOW_MERGE=0, CLAWSWEEPER_ALLOW_FIX_PR=1, CLAWSWEEPER_FIX_PR_MODEL=gpt-5.6-sol, and CLAWSWEEPER_FIX_PR_REASONING_EFFORT=xhigh.
  • Independent pre-commit Codex review findings about open/closed-target API request amplification, operator defaults, extracted source contracts, partial label persistence across authentication failures and lease races, and upstream-path references that lacked an actual defect were fixed and have executable reproduction proof. The final independent pre-commit review found no actionable defects and passed all 82 affected tests.
  • A separate pre-existing 33-hour terminal-finalization item is not force-resolved: the read-only bounded maintenance operator found no eligible safe mutation for it.

@steipete
steipete requested a review from a team as a code owner August 2, 2026 18:23
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 2:41 PM ET / 18:41 UTC.

ClawSweeper review

What this changes

This PR splits the guarded apply workflow into focused modules, changes dead-letter reconciliation to run every five minutes with 100 inspected targets and 10 recoveries by default, and adds regression coverage for bounded recovery and label persistence.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR remains necessary: it is a current-head refactor plus a bounded operational-capacity change, not work already present on main. Static review found no discrete correctness defect in the extracted apply phases or the recovery cap changes; the five-minute schedule remains a meaningful automation risk that needs normal maintainer review before merge. Likely related people: steipete is the strongest routing candidate from the recent apply and dead-letter history (high confidence).

Priority: P2
Reviewed head: 8b6af4cbab8bd3a2f41a9c85a223d9ea0baead22

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The current head has strong runtime-oriented proof and focused safety coverage; its broad automation refactor still merits ordinary maintainer review of the cadence change.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies post-change production reconciliation summaries and concrete subprocess-backed live-output evidence for request limits, direct defaults, partial label-auth failures, lease races, local review isolation, and the QClaw policy replay.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies post-change production reconciliation summaries and concrete subprocess-backed live-output evidence for request limits, direct defaults, partial label-auth failures, lease races, local review isolation, and the QClaw policy replay.
Evidence reviewed 6 items Current-head refactor wiring: The current PR head imports and invokes the extracted candidate, review, source-freshness, label, promotion, policy, and close-execution phases from the apply orchestrator; the orchestration still keeps the guarded sequence around canonical review-comment synchronization and close handling.
Bounded terminal reconciliation: Closed canonical targets are still constrained by the normal inspected-target limit and a separate maximum of ten terminal rechecks before a terminal row can be resolved.
Scheduled workflow remains serialized: The workflow changes cadence and dispatch defaults but preserves the existing concurrency group, cancel-in-progress: false, read-only GitHub permissions, and deployment-guard check before invoking reconciliation.
Findings None None.
Security None None.

How this fits together

ClawSweeper’s apply lane reads durable review reports, rechecks freshness and policy fences, then synchronizes GitHub labels and eligible close actions. Its dead-letter operator inventories failed review events, verifies their canonical GitHub targets, resolves terminal rows, and queues a bounded number of safe fresh reviews.

flowchart LR
  Reports[Durable review reports] --> Apply[Apply workflow]
  Apply --> Guards[Freshness and policy guards]
  Guards --> GitHub[Label and close actions]
  DeadLetters[Dead-letter inventory] --> Canonical[Canonical target discovery]
  Canonical --> Recovery[Bounded reconciliation]
  Recovery --> Queue[Fresh review queue]
Loading

Before merge

  • Resolve merge risk (P1) - The five-minute schedule raises the frequency of Worker and GitHub reconciliation activity; the branch mitigates this with serialized execution, a 100-target discovery ceiling, ten recovery attempts, and ten terminal rechecks, so those hard limits should remain intact when merged.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Apply refactor surface 9 focused apply modules added; 1,451 lines changed in the orchestrator The change moves safety-critical apply behavior into separately testable phases while preserving a central guarded sequence.
Recovery schedule bounds 10 to 5 minutes; defaults 25/5 to 100/10 The workflow doubles run frequency and raises per-run discovery and recovery defaults, making the hard limits material before merge.

Merge-risk options

Maintainer options:

  1. Accept the bounded cadence increase (recommended)
    Merge with the five-minute schedule only while retaining the existing serialized workflow and the explicit discovery, terminal-recheck, recovery, and queue-pressure limits.

Technical review

Best possible solution:

Land the modular apply workflow while preserving the serialized reconciliation workflow, deployment guard, queue-pressure gate, 100-target discovery limit, ten terminal rechecks, and ten-recovery ceiling.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR refactors existing automation and changes bounded operating defaults rather than repairing a separately reproducible user bug. The PR body does provide after-change production and subprocess evidence for the altered reconciliation path.

Is this the best way to solve the issue?

Yes. Extracting the apply phases while retaining the existing policy, freshness, lease, label, promotion, and close fences is a maintainable approach, and the higher reconciliation cadence is constrained by explicit request and recovery limits.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5f8543d985cc.

Labels

Label justifications:

  • P2: This is a bounded operational improvement to review recovery and apply maintainability, without evidence of an active user-facing outage.
  • merge-risk: 🚨 automation: The PR changes a scheduled GitHub-and-Worker reconciliation workflow, so a regression could affect automated review recovery volume or safety fences.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies post-change production reconciliation summaries and concrete subprocess-backed live-output evidence for request limits, direct defaults, partial label-auth failures, lease races, local review isolation, and the QClaw policy replay.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies post-change production reconciliation summaries and concrete subprocess-backed live-output evidence for request limits, direct defaults, partial label-auth failures, lease races, local review isolation, and the QClaw policy replay.

Evidence

What I checked:

  • Current-head refactor wiring: The current PR head imports and invokes the extracted candidate, review, source-freshness, label, promotion, policy, and close-execution phases from the apply orchestrator; the orchestration still keeps the guarded sequence around canonical review-comment synchronization and close handling. (src/clawsweeper-apply-decision-workflow.ts:1, 8b6af4cbab8b)
  • Bounded terminal reconciliation: Closed canonical targets are still constrained by the normal inspected-target limit and a separate maximum of ten terminal rechecks before a terminal row can be resolved. (scripts/exact-review-dead-letter-operator.mjs:443, 8b6af4cbab8b)
  • Scheduled workflow remains serialized: The workflow changes cadence and dispatch defaults but preserves the existing concurrency group, cancel-in-progress: false, read-only GitHub permissions, and deployment-guard check before invoking reconciliation. (.github/workflows/exact-review-dead-letter-reconcile.yml:4, 8b6af4cbab8b)
  • Focused regression coverage: The branch adds checks for the five-minute workflow defaults, 100-target GraphQL batching, terminal target request limits, direct operator defaults, partial label-auth failure persistence, and lease-race persistence. (test/exact-review-dead-letter-operator.test.ts:52, 8b6af4cbab8b)
  • Recent feature history: The current main behavior dates to the immediately preceding dead-letter starvation fix, following the original automatic reconciliation implementation; the same author also performed the recent apply-workflow decomposition. (scripts/exact-review-dead-letter-operator.mjs:1, 5f8543d985cc)
  • Diff integrity: The proposed tree has no whitespace errors according to Git’s diff checker. (8b6af4cbab8b)

Likely related people:

  • steipete: Recent history shows Peter Steinberger authored the original dead-letter reconciliation, the current-main starvation fix, and the prior apply-workflow decomposition that this PR continues. (role: recent area contributor; confidence: high; commits: 60ad8788f545, 4a39cfcf6a96, 5f8543d985cc; files: scripts/exact-review-dead-letter-operator.mjs, src/clawsweeper-apply-decision-workflow.ts, .github/workflows/exact-review-dead-letter-reconcile.yml)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-02T18:27:49.199Z sha 065a992 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/clawsweeper-apply-phase-simplification branch from 065a992 to 8b6af4c Compare August 2, 2026 18:37
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant