Skip to content

refactor: simplify sweep runtime and recover publication backlog - #1012

Merged
steipete merged 3 commits into
mainfrom
codex/clawsweeper-runtime-simplification
Aug 2, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/clawsweeper-runtime-simplification

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace the 3,277-line ClawSweeper entrypoint with a 19-line launcher; move runtime policy, GitHub access, repository paths, review leases, sweep status, action commands, apply record operations, proof freshness, close guards, and mutation-lease guards into focused modules.
  • Shrink the 4,091-line apply workflow to 2,945 lines while preserving standalone offline --local-range review and every conservative review/apply mutation guard.
  • Reload authoritative dead-letter inventory at most twice after an atomic guarded cleanup race, preserve the original per-run target/recovery caps, and fail closed if the Worker's atomic cleanup contract is ever violated.
  • Refill the existing bounded publication-batch slots every five seconds instead of thirty seconds without changing the 450/hour review cap, publication capacity of 50, batch size of 8, maximum of 8 concurrent batches, or state-writer fencing.
  • Continue creating OpenClaw fix PRs with gpt-5.6-sol / xhigh; issue-generated jobs keep CLAWSWEEPER_ALLOW_MERGE=0 and never automatically merge OpenClaw PRs.

Directly inspectable real-behavior proof

Actual rebuilt production CLI

$ node dist/clawsweeper.js check
ok

The actual rebuilt production CLI was also executed against a new, committed two-revision Git checkout. A fake Codex executable deliberately exits 1 after recording its actual checkout and GitHub-isolation directory; that expected exit proves the real review --local-range path reached Codex without GitHub credentials:

$ node /tmp/clawsweeper-local-range-proof.mjs
{
  "launcher": "dist/clawsweeper.js",
  "command": "review --local-range --base proof-base --target-repo openclaw/clawsweeper",
  "committed_local_range": true,
  "codex_started": true,
  "codex_checkout_matches": true,
  "isolated_gh_config": ".gh-empty",
  "expected_fake_codex_exit": 1
}

Actual operator subprocess against signed HTTP endpoints

This launches node scripts/exact-review-dead-letter-operator.mjs --action reconcile --execute --max-targets 1 as a separate production subprocess against real local HTTP endpoints. An authoritative cleanup race leaves a second closed target available, but the original one-target cap prevents any mutation of it:

$ node /tmp/clawsweeper-dlq-review-repro.mjs
{
  "exit_code": 0,
  "summary": {
    "action": "reconcile",
    "dry_run": false,
    "inventory_complete": true,
    "queue_pressure": "idle",
    "inspected_targets": 1,
    "recovered_targets": 0,
    "resolved_rows": 0,
    "invalid_rows": 0,
    "closed_rows": 0,
    "duplicate_rows": 0,
    "active_review_rows": 0,
    "skipped_targets": 0,
    "inventory_changed": true,
    "skipped_rows": 1
  },
  "resolution_calls": [["closed-one"]],
  "inventory_requests": 1,
  "stderr": ""
}

Actual Worker/SQLite guarded-resolution transaction

The real ExactReviewQueue Worker, durable-object SQLite state, and /dead-letters/resolve route were exercised with one safe row plus one unsafe row. The transaction rejected the entire batch; both dead letters remained open:

$ node --test --test-name-pattern='guarded dead-letter resolution' test/dashboard-worker.test.ts
✔ guarded dead-letter resolution preserves a concurrently active transferred alias
✔ guarded dead-letter resolution rejects an entire mixed-safe batch atomically
ℹ tests 2
ℹ pass 2
ℹ fail 0

The actual Worker response in the two-row case was:

{"ok":true,"resolved":0,"skipped":2,"unparked":0}

The production subprocess also rejects an impossible non-atomic upstream response without refreshing or recovering any item:

$ node --test test/exact-review-dead-letter-operator.test.ts
✔ reconciliation rejects a non-atomic guarded cleanup response
✔ inventory refreshes preserve cleanup counters when later target discovery fails
ℹ tests 39
ℹ pass 39
ℹ fail 0

An independent reviewer reproduced a second real race: one closed row is resolved, a later closed-row cleanup races, refreshed GitHub discovery fails, then one invalid row is safely resolved. The actual production operator now retains all completed work in its public totals:

$ node /tmp/clawsweeper-reconcile-counter-repro.mjs
{
  "code": 0,
  "summary": {
    "action": "reconcile",
    "dry_run": false,
    "inventory_complete": true,
    "queue_pressure": "idle",
    "inspected_targets": 2,
    "recovered_targets": 0,
    "resolved_rows": 2,
    "invalid_rows": 1,
    "closed_rows": 1,
    "duplicate_rows": 0,
    "active_review_rows": 0,
    "skipped_targets": 1
  },
  "resolutions": [["closed-one"], ["closed-two"], ["invalid-row"]],
  "inventoryRequests": 2,
  "stderr": ""
}

Production failure and bounded rollout evidence

  • The existing production operator repeatedly fails with dead-letter cleanup changed during reconciliation; refusing stale recovery: https://github.com/openclaw/clawsweeper/actions/runs/30756033690.
  • Before deployment the live queue had 85 pending publications, a 31-hour-old publication, and 1,379 open dead letters. Manually running one already-authorized bounded publication worker reduced a later observed backlog from 36 to 22 while keeping only two concurrent publishers.
  • The deployed configuration changes EXACT_REVIEW_PUBLICATION_BATCH_DISPATCH_COOLDOWN_MS from 30000 to 5000; the configured eight-batch cap, 50 publication slots, eight-item batches, and state-writer fences are unchanged.
  • OpenClaw had 24 open ClawSweeper-authored PRs and zero with auto-merge enabled during verification. Repository variables are CLAWSWEEPER_FIX_PR_MODEL=gpt-5.6-sol and CLAWSWEEPER_FIX_PR_REASONING_EFFORT=xhigh; both CLAWSWEEPER_ALLOW_AUTOMERGE and CLAWSWEEPER_ALLOW_MERGE are now 0, while automatic issue implementation and fix-PR creation remain enabled.

Independent review and finding disposition

  • The first independent review found that refreshing inventory reset the per-run canonical-target limit. Fixed by keeping one shared reconciliation summary and target budget; the actual operator transcript above confirms exactly one inspection and no second-target mutation.
  • A subsequent independent review questioned partial guarded-cleanup accounting. Tracing the actual Worker showed guarded cleanup is one SQLite transaction and can never partially succeed; the real two-row transaction above confirms resolved=0, skipped=2. The operator now explicitly rejects any future violation of that contract instead of inventing misleading counters or recovering from unsafe partial state.
  • A fresh committed-branch review then found an actual cross-refresh accounting regression: safe fallback cleanup reset counters for earlier successful cleanup. The fallback now accumulates counters; the reviewer's exact independent production-operator reproduction above reports resolved_rows=2, closed_rows=1, and invalid_rows=1.
  • Focused validation executes the real rebuilt launcher, committed local Git review path, signed operator subprocess, actual Worker/SQLite transaction, and all 39 dead-letter operator integration cases. Repository CI reruns on the final pushed head.

@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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. 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, 12:49 PM ET / 16:49 UTC.

ClawSweeper review

What this changes

This PR replaces the large CLI entrypoint with a launcher plus focused runtime modules, safely retries dead-letter reconciliation after an atomic cleanup race, and lowers the bounded publication-batch refill delay from 30 seconds to 5 seconds.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR appears technically sound and includes strong after-fix operator proof, but it is a 22-file extraction of central sweep/apply orchestration plus a production queue-timing change. Keep it open for the current-head checks to finish and maintainer merge review rather than treating it as cleanup or an automated repair. Likely related people: Peter Steinberger is the strongest routing candidate (high confidence), with Vincent Koc as an adjacent apply/publication contributor (medium confidence).

Priority: P2
Reviewed head: 93d04c1316de78ca50a610520244bf31fd9d4828

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong direct runtime proof and focused regression scenarios support the fix, while the broad central-runtime extraction still deserves final current-head automation validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides after-fix terminal evidence for the rebuilt production CLI, a committed local-range review path, a separate operator subprocess against signed endpoints, and the guarded Worker/SQLite transaction; it also includes final counter-preservation output.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides after-fix terminal evidence for the rebuilt production CLI, a committed local-range review path, a separate operator subprocess against signed endpoints, and the guarded Worker/SQLite transaction; it also includes final counter-preservation output.
Evidence reviewed 6 items Entrypoint compatibility: The final branch preserves the established compiled entrypoint: the small launcher delegates to the extracted runtime's exported main function and retains the user-facing command-error boundary.
Apply guard wiring: The extracted apply workflow imports and instantiates record, lease, close, and proof-freshness guard modules; the final runtime constructs the apply workflow with its dependencies rather than bypassing the guarded path.
Bounded reconciliation recovery: The reconciler retries only inventory-change errors, fails closed if guarded cleanup ever reports a partial mutation, preserves accumulated progress, and caps inventory refreshes at two.
Findings None None.
Security None None.

How this fits together

ClawSweeper's runtime accepts review and apply commands, coordinates GitHub operations and durable records, then publishes results through Worker-backed queues. The changed dead-letter operator cleans up terminal publication records and can queue safe fresh reviews without exceeding configured recovery or publication limits.

flowchart LR
  Commands[CLI and workflow commands] --> Runtime[Sweep and apply runtime]
  Runtime --> Guards[Lease, proof, and close guards]
  Guards --> Records[Durable review records]
  Records --> Queue[Publication queue]
  Queue --> Reconcile[Dead-letter reconciler]
  Reconcile --> Worker[Worker guarded resolution]
  Worker --> Status[Published state and dashboard]
Loading

Before merge

  • Resolve merge risk (P1) - This 22-file refactor moves review/apply guard wiring and increases publication refill frequency; an omitted dependency or production-only queue interaction could surface only in scheduled automation, so the current-head checks and maintainer review should complete before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Runtime extraction 22 files affected; 5,507 added and 4,538 removed Central CLI and apply orchestration moved across focused modules, making final integration validation more important than ordinary unit-level review.
Dispatch timing 1 cooldown changed from 30 seconds to 5 seconds The faster refill targets publication backlog recovery while retaining the stated bounded capacity settings.

Merge-risk options

Maintainer options:

  1. Complete final automation validation (recommended)
    Let the current-head workflow checks complete, then merge only if the extracted sweep/apply paths remain green alongside the supplied live operator proof.
  2. Pause if scheduled-path confidence drops
    If final checks or maintainer inspection expose a missed runtime dependency, pause this broad refactor and land the bounded dead-letter fix separately.

Technical review

Best possible solution:

Land the focused modular runtime and bounded retry behavior only after the final branch's checks confirm the extracted command paths remain intact; retain the existing capacity caps and fail-closed cleanup contract.

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

Not applicable: this is a refactor plus an operational recovery correction, not an issue report requiring a user reproduction. The PR body supplies direct after-fix CLI, Worker transaction, and operator-subprocess evidence for the changed behavior.

Is this the best way to solve the issue?

Yes: extracting focused modules while retaining the public launcher is a maintainable direction, and the dead-letter retry remains bounded and fail-closed rather than recovering from a non-atomic cleanup response.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8cdf2a157a04.

Labels

Label justifications:

  • P2: The PR improves a bounded operational workflow but does not establish an active emergency or user-facing service outage.
  • merge-risk: 🚨 availability: Dead-letter recovery and publication dispatch timing can affect whether queued review publications are recovered and processed.
  • merge-risk: 🚨 automation: The patch reorganizes the central CLI, review, apply, lease, and workflow orchestration paths.
  • 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 (terminal): The PR body provides after-fix terminal evidence for the rebuilt production CLI, a committed local-range review path, a separate operator subprocess against signed endpoints, and the guarded Worker/SQLite transaction; it also includes final counter-preservation output.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix terminal evidence for the rebuilt production CLI, a committed local-range review path, a separate operator subprocess against signed endpoints, and the guarded Worker/SQLite transaction; it also includes final counter-preservation output.

Evidence

What I checked:

  • Entrypoint compatibility: The final branch preserves the established compiled entrypoint: the small launcher delegates to the extracted runtime's exported main function and retains the user-facing command-error boundary. (src/clawsweeper.ts:4, 93d04c1316de)
  • Apply guard wiring: The extracted apply workflow imports and instantiates record, lease, close, and proof-freshness guard modules; the final runtime constructs the apply workflow with its dependencies rather than bypassing the guarded path. (src/clawsweeper-apply-decision-workflow.ts:3, 93d04c1316de)
  • Bounded reconciliation recovery: The reconciler retries only inventory-change errors, fails closed if guarded cleanup ever reports a partial mutation, preserves accumulated progress, and caps inventory refreshes at two. (scripts/exact-review-dead-letter-operator.mjs:71, 93d04c1316de)
  • Focused regression coverage: The final branch adds scenarios for bounded refreshes, preservation of the original target budget, rejection of non-atomic cleanup, and counter preservation after a refreshed discovery failure. (test/exact-review-dead-letter-operator.test.ts:431, 93d04c1316de)
  • Patch hygiene: The final three-commit branch applies cleanly with no whitespace errors. (93d04c1316de)
  • Feature-history routing: Recent history shows Peter Steinberger repeatedly carrying the entrypoint modularization and dead-letter recovery surfaces, while Vincent Koc contributed recent apply/publication-state work. (src/clawsweeper.ts:1, dccfa528f038)

Likely related people:

  • Peter Steinberger: Recent history attributes the central entrypoint decomposition, multiple modularization passes, and dead-letter recovery work to Peter; this PR extends those same runtime boundaries. (role: recent area contributor; confidence: high; commits: dccfa528f038, 60ad8788f545, 93d04c1316de; files: src/clawsweeper.ts, src/clawsweeper-apply-decision-workflow.ts, scripts/exact-review-dead-letter-operator.mjs)
  • Vincent Koc: Recent apply/publication-state history connects Vincent to the bounded exact-review publication surface affected by the reconciliation and scheduling changes. (role: adjacent area contributor; confidence: medium; commits: 0925ecae3787; files: src/clawsweeper-apply-decision-workflow.ts, dashboard/wrangler.toml)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Allow the in-progress current-head pnpm check and Actions analysis to complete before merge.
  • Have a maintainer inspect the final scheduled sweep/apply integration once, because the refactor moves central orchestration rather than a single isolated helper.

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 (3 earlier review cycles)
  • reviewed 2026-08-02T16:25:19.180Z sha 41d4c78 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T16:29:47.745Z sha 41d4c78 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T16:40:52.814Z sha b278c4d :: needs maintainer review before merge. :: none

@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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 2, 2026
@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:

@steipete
steipete merged commit 4a39cfc into main Aug 2, 2026
10 of 11 checks passed
@steipete
steipete deleted the codex/clawsweeper-runtime-simplification branch August 2, 2026 16:53
azaj01 pushed a commit to azaj01/clawsweeper that referenced this pull request Sep 21, 2026
…nclaw#1012)

* refactor: simplify sweep runtime and recover publication backlog

* fix: fence non-atomic dead-letter cleanup

* fix: preserve reconciliation counters across retries

---------

Co-authored-by: Peter Steinberger <[email protected]>
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. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. 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