Skip to content

refactor: decompose ClawSweeper orchestration into focused workflows - #998

Merged
steipete merged 1 commit into
mainfrom
codex/clawsweeper-monolith-decomposition
Aug 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/clawsweeper-monolith-decomposition

Conversation

@steipete

@steipete steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Reduce src/clawsweeper.ts from 25,173 lines to 19,923 lines (5,250 lines / 20.9% smaller) by moving complete workflows behind explicit, typed dependency boundaries:

  • src/clawsweeper-github-context.ts: bounded REST/GraphQL pagination and exact activity cursors.
  • src/clawsweeper-media-proof.ts: bounded image/video proof extraction and inspection.
  • src/clawsweeper-review-ledger.ts and src/clawsweeper-apply-ledger.ts: immutable review/apply receipts, mutation observation, and business idempotency.
  • src/clawsweeper-label-sync.ts: all advisory, priority, rating, status, bulk-filer, proof, and stale-protection labels through the existing observed-mutation boundary.
  • src/clawsweeper-assist.ts: isolated maintainer-assist generation, exact artifact binding, and write-token publication.
  • src/clawsweeper-failed-review-retry.ts: exact-source retry state, dispatch checkpoints, exhaustion, and immutable retry receipts.
  • src/clawsweeper-links.ts and src/clawsweeper-close-reasons.ts: repository link and close-reason presentation.

The existing public src/clawsweeper.ts exports and command surface remain unchanged. Unused orchestration imports and bindings were removed.

Real behavior proof

Ran the actual standalone package command pnpm run local-review and integrated --local-range against committed local fixtures. Both succeeded with 0 GitHub calls, 0 leaked GitHub credentials, web search disabled, read-only Codex sandbox, and isolated GitHub config.

Real repair workflow proof against canonical issue openclaw/openclaw#98276 and generated PR openclaw/openclaw#117144 verifies direct exact-item Worker hydration (recordCount: 1) and all merge controls remain fail closed: generated autofix merge false, replacement PR auto-merge false, fallback replacement auto-merge false. Authorized ClawSweeper-service merges remain separately permitted; generated issue PR creation continues to use gpt-5.6-sol / xhigh.

Focused command-level tests execute real bounded retry dispatch, immutable receipt publication, source-revision changes, assist artifact binding, label mutation sync, and offline review:

node --test test/context.test.ts test/assist-artifact.test.ts test/clawsweeper-action-ledger.test.ts test/failed-review-retry.test.ts test/local-review.test.ts test/repair/cluster-workflow-security.test.ts

tests 87
pass 87
fail 0

node --test test/apply-label-sync.test.ts test/pr-label-policy.test.ts test/bulk-filer-policy.test.ts test/pr-review-labels.test.ts test/pr-proof-automation.test.ts

tests 98
pass 98
fail 0

pnpm run build:all
pnpm run lint:src
pnpm run check:active-surface
pnpm run check:limits
git diff --check

The independent fresh precommit review performed further command-level verification: No actionable findings. All 142 targeted tests passed, including offline review, credential isolation, retry checkpoints, ledger idempotency, and label synchronization.

Review disposition

No accepted or actionable findings remain. The refactor is rebased on the independently reviewed production changed-gate fix from #997.

@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

/review

@clawsweeper

clawsweeper Bot commented Aug 1, 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 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 6:00 AM ET / 10:00 UTC.

ClawSweeper review

What this changes

The PR moves GitHub context, media-proof handling, review/apply ledgers, label synchronization, maintainer assist, retry logic, and link presentation from the monolithic orchestrator into nine focused TypeScript modules while retaining the public command surface.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This active PR appears to be a coherent, behavior-preserving orchestration refactor rather than obsolete work. The extracted modules are explicitly composed through typed dependency boundaries, the supplied current-head command proof covers the critical review/apply safety paths, and no discrete patch defect was found; keep it open for normal maintainer landing review because of its automation scope.

Priority: P2
Reviewed head: 5dd93b90404df06e9c87eb940a363a333d49944a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong command-level proof and explicit dependency wiring support a mergeable refactor, with normal residual automation risk from its size.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body includes current-head terminal proof for offline review and a real repair workflow, including observed fail-closed merge controls; redact environment details if reposting 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 includes current-head terminal proof for offline review and a real repair workflow, including observed fail-closed merge controls; redact environment details if reposting output.
Evidence reviewed 6 items Clean patch mechanics: The proposed commit is based directly on current main, and the full branch diff has no whitespace errors.
Explicit workflow composition: The main orchestrator constructs the extracted repository-link, GitHub-context, assist, label-sync, review-ledger, retry, and apply-ledger workflows through dependency objects and retains their returned command helpers.
Extracted behavior remains defined: A static whole-source pass found definitions for all 343 function names removed from the monolithic file, including the new extracted modules.
Findings None None.
Security None None.

How this fits together

ClawSweeper turns GitHub item context into Codex review reports and, in separate guarded workflows, labels, repair work, or apply decisions. The changed orchestrator composes these modules and passes their outputs to reports and GitHub mutation boundaries.

flowchart LR
  GitHub[GitHub items and activity] --> Context[Context collection]
  Context --> Review[Review workflows]
  Review --> Ledgers[Review and apply receipts]
  Ledgers --> Labels[Label synchronization]
  Labels --> Apply[Guarded apply and repair paths]
  Apply --> Outcomes[Reports and GitHub mutations]
Loading

Before merge

  • Resolve merge risk (P1) - This 18,468-line churn across review, apply, retry, and label automation could alter a rarely used command path despite the focused coverage and clean extraction.
  • Complete next step (P2) - No discrete repair is identified; maintainers should review the current proof and accept the remaining automation-composition risk before merging.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Refactor scope 9 modules added; 12 files affected; 9,628 additions and 8,840 deletions The branch relocates high-impact orchestration logic while retaining src/clawsweeper.ts as the command composition layer.
Focused validation 185 targeted tests reported passing The supplied proof covers offline review, retry, ledger, assist, proof, and label-sync surfaces central to the extraction.

Merge-risk options

Maintainer options:

  1. Accept current proof (recommended)
    Merge after maintainer review of the supplied current-head offline review, repair-flow, retry, ledger, and label-sync validation, accepting the remaining integration risk of a large internal refactor.
  2. Refresh focused validation
    Re-run the documented focused commands against the exact head if maintainers need a new terminal transcript before landing.

Technical review

Best possible solution:

Preserve the existing public commands and fail-closed mutation behavior, then land this refactor with its current command-level proof and a fresh review of the exact head.

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

Not applicable: this is an internal refactor rather than a reported user bug; the relevant verification is preservation of existing review and apply workflows through focused command-level proof.

Is this the best way to solve the issue?

Yes: retaining the public command surface while isolating complete workflows behind explicit dependency boundaries is a maintainable solution, provided the documented guarded behavior remains intact.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This broad internal automation refactor has meaningful but bounded operator impact if a workflow path regresses.
  • add merge-risk: 🚨 automation: The diff extracts workflows that control review retries, receipts, label updates, and guarded apply actions.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes current-head terminal proof for offline review and a real repair workflow, including observed fail-closed merge controls; redact environment details if reposting output.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes current-head terminal proof for offline review and a real repair workflow, including observed fail-closed merge controls; redact environment details if reposting output.

Label justifications:

  • P2: This broad internal automation refactor has meaningful but bounded operator impact if a workflow path regresses.
  • merge-risk: 🚨 automation: The diff extracts workflows that control review retries, receipts, label updates, and guarded apply actions.
  • 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 includes current-head terminal proof for offline review and a real repair workflow, including observed fail-closed merge controls; redact environment details if reposting output.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes current-head terminal proof for offline review and a real repair workflow, including observed fail-closed merge controls; redact environment details if reposting output.

Evidence

What I checked:

  • Clean patch mechanics: The proposed commit is based directly on current main, and the full branch diff has no whitespace errors. (src/clawsweeper.ts:1, 5dd93b90404d)
  • Explicit workflow composition: The main orchestrator constructs the extracted repository-link, GitHub-context, assist, label-sync, review-ledger, retry, and apply-ledger workflows through dependency objects and retains their returned command helpers. (src/clawsweeper.ts:577, 5dd93b90404d)
  • Extracted behavior remains defined: A static whole-source pass found definitions for all 343 function names removed from the monolithic file, including the new extracted modules. (src/clawsweeper.ts:1, 5dd93b90404d)
  • Focused extraction coverage: The updated action-ledger test now inspects the extracted retry, review-ledger, and apply-ledger modules for stable event ordering and idempotency invariants. (test/clawsweeper-action-ledger.test.ts:393, 5dd93b90404d)
  • Feature-history provenance: Recent main history shows earlier modularization and merge-safety work on this same orchestration surface, including commits by Peter Steinberger, Vincent Koc, and Martin Cleary. (src/clawsweeper.ts:1, 8ee77751965b)
  • Current real-behavior proof: The PR body records successful offline local-review and repair-flow runs, 185 focused test passes, and build/lint/check commands on this refactor; it also reports generated and replacement auto-merge controls remained fail closed. (5dd93b90404d)

Likely related people:

  • steipete: Authored the proposed extraction and multiple recent current-main modularization and repair-safety commits for this orchestration surface. (role: feature owner; confidence: high; commits: 5dd93b90404d, 8fd1140e7aa9, 16f01b295086; files: src/clawsweeper.ts, src/clawsweeper-review-ledger.ts, src/clawsweeper-apply-ledger.ts)
  • Vincent Koc: Recent current-main commits changed apply-publication bounds and stable-label behavior adjacent to the extracted ledger and label paths. (role: recent area contributor; confidence: medium; commits: 0925ecae3787, 2e6bacee3813; files: src/clawsweeper.ts, src/clawsweeper-label-sync.ts)
  • Martin Cleary: A recent current-main fix changed duplicate suppression in the review path that this refactor continues to orchestrate. (role: recent area contributor; confidence: medium; commits: 0ced0b5e515b; files: src/clawsweeper.ts, src/clawsweeper-github-context.ts)

Rank-up moves

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

  • Keep the documented focused validation and current-head review evidence in the PR body through maintainer landing.

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.

@clawsweeper

clawsweeper Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: refactor: decompose ClawSweeper orchestration into focused workflows This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

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