Skip to content

refactor: import label policy, selection and proof policy directly instead of building them in the runtime - #1814

Merged
obviyus merged 1 commit into
mainfrom
lattice-labels-guards
Oct 9, 2026
Merged

obviyus merged 1 commit into
mainfrom
lattice-labels-guards

Conversation

@obviyus

@obviyus obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What

Row 3, PR 2a of the dependency-lattice collapse: labels. The diff was larger than 2k lines, so the apply guards go in a separate PR 2b, which I open after this one lands.

  • pullRequestReviewReadinessFromReport moves out of the report-comment-helpers factory with the same body. It is a module export now, as are securitySensitiveRepairAllowed and the private publicBeforeMergeItems/typedBlockerDetail. The pure text helpers that it reads (sentence, stripListMarker, reportRiskEntries, publicRealBehaviorProofLine, …) move to module scope in review-presentation. That factory still returns them, so the rendering interfaces do not change here (cluster 3).
  • proof-policy: reportRealBehaviorProofPolicy is a plain export. createRealBehaviorProofPolicy and its dependency interface are gone.
  • label-policy and label-selection are plain exports. createLabelPolicy, createLabelSelectionPolicy and the labelPolicy object are deleted.
  • label-mutations keeps one factory, createLabelMutationOperations({ ghJson, ghObservedMutationCommand }), because its pending batch and label-catalog cache are real state. The pure error classifiers (labelAlreadyExistsError, missingLabelError, labelCapacityError) are module exports. createLabelSyncOperations(mutations) builds on that instance, so the sync calls and the review-comment removeIssueLabel share one batch. The runtime builds the instance once, in place of the orchestration foundation.
  • Deleted: clawsweeper-label-sync.ts, clawsweeper-label-dependencies.ts, all 21 label *ForTest twins, and the label, proof and readiness members of the report-orchestration, report-rendering, review-comment, apply and github-execution dependency interfaces. Also deleted: the runtime spreads (...labelPolicy, labelSynchronization) and 12 forward arrows ((...args) => and friends). hasNormalizedLabel/normalizedLabelSet move to item-policy.
  • Tests call the real exports. The 3 tests in test/pr-label-policy.test.ts that injected fake readers now use real reports:
    • the failed-review apply label sync runs real readiness and proof policy through a recording gh;
    • the external-PR proof test uses real proof sections;
    • the receipt matrix (absent/passed/failed/malformed × review failed × contributor action) attaches real live-verification receipts to the shared pullRequestProofReport fixture. That fixture is the former reportFor from test/pr-proof-automation.test.ts, now in test/helpers.ts.
    • test/label-mutation-batch.test.ts passes only the gh context.

Why

The label cluster rebuilt pure functions through four factories, a 21-line dependency interface and a 61-line aggregator. The runtime then copied them back out with forward arrows. Callers now import what they use. Real dependency injection stays only where something varies: the gh shell for label writes.

Proof

  • pnpm run check on 8870d9d17: exit 0. 7005 tests, 6968 pass, 0 fail.
  • Counts (origin/main 7494c448a → branch):
main branch
dependency-interface lines (*-dependencies.ts + *Dependencies interfaces) 2156 1955
dependency-interface members 803 753
export function createX factories 91 87
*ForTest exports 89 68
clawsweeper-runtime.ts lines 1393 1312
diff (git diff -w --shortstat) +952 / −1718
  • Saved-report re-render with render-comments.mjs, main dist against branch dist: byte-identical for prompt-rest, prompt-lean, prompt-dump, async-proof/base, async-proof/branch and retire-proof/166090 (9 reports, 0 render failures).
  • Shipped CLI, main against branch: node dist/clawsweeper.js apply-decisions --target-repo openclaw/openclaw --apply-kind all --sync-comments-only --item-numbers <n> with the repo's recording gh stub (promotionGhMock, the fix(review): status label contradicts Before merge; regex classifiers add refuted blockers #1766 driver), on saved reports 167298, 167054 and 166090. The results are the same on both builds:
    • the written comment bodies are byte-identical apart from the review timestamp;
    • the label edits (labels.log) are identical and in the same order: 1, 2 and 4 gh issue edit calls, for example the 166090 rating change 🐚 platinum hermit → 🦐 gold shrimp and the status 👀 ready for maintainer look → ⏳ waiting on author;
    • the full gh call logs (66, 81 and 105 calls) are identical as multisets. Two things differ: the order of the concurrent status/check-runs reads, and the temporary artifact path.

Codex dispositions

codex review --base origin/main: "No actionable regressions were found against the supplied merge base. The build and all 393 selected tests passed." No P0–P2 findings.

Merge Danger

Low. This is a mechanical move: function bodies stay the same, and TypeScript checks every caller.

  • Behavior: the re-renders and the apply-decisions CLI give the same output on both builds.
  • Label writes: there is still one mutation instance per process, shared by apply and review comments, as before.
  • Removed dist/clawsweeper.js re-exports: the 21 label *ForTest twins (featureShowcaseLabelsForTest, prStatusLabelsForTest, prStatusLabelSchemeForTest, priority/impact/maturity/mergeRisk/prRating LabelScheme/LabelsForTest, issueAdvisoryLabelsForTest, telegramVisibleProofLabelsForTest, realBehaviorProof{Media,Sufficient}LabelsForTest, isGitHubLabel{AlreadyExists,Capacity}ErrorForTest, isMissingGitHubLabelErrorForTest, syncBulkFilerLabelForTest). Repo tests import the owner modules now.
  • The label-sync-identity-determinism proof driver passes extra keys to createLabelMutationOperations. The factory ignores them, so the driver works on both sides of the cutover.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR simplifies how ClawSweeper connects its label and proof rules, while retaining one shared instance for GitHub label writes.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation is coherent and reduces maintenance cost, while the recorded GitHub boundary limits runtime confidence.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes
Reason: The change reduces substantial runtime wiring and removes redundant policy factories without proposing different product behavior. It continues the same area's merged direct-import work and retains the established mutation owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides distinct maintenance value that current main does not include, and the inspected changes introduce no actionable correctness regression.

Priority: P3
Reviewed head: 8870d9d179ba386445cd12a8d8e2a1ebad7d98d9

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied CLI comparison records gh commands through a stub; it does not show base/head apply-decisions results and final labels through a real GitHub transport.
Agent review details

How this fits together

ClawSweeper turns saved review reports into public comments, readiness decisions, and GitHub labels. This subsystem selects labels and batches their writes through the existing GitHub execution layer.

flowchart TD
  A[Saved review reports] --> B[Proof and readiness rules]
  A --> C[Label selection rules]
  B --> C
  B --> D[Public review comments]
  C --> E[Shared label mutation instance]
  D --> E
  E --> F[GitHub execution layer]
  F --> G[Updated comments and labels]
Loading

Technical review

Best possible solution:

Use direct imports for pure policy functions and retain one shared owner for label mutation state.

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

Not applicable: this PR proposes a behavior-preserving refactor rather than a reported runtime bug.

Is this the best way to solve the issue?

Yes: direct imports remove redundant policy construction while preserving the stateful mutation owner and existing decision rules.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d559d9e498e4.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Applicable repository policy: Read the full root AGENTS.md. No nested AGENTS.md or maintainer-notes directory was found. Applied the conservative review, runtime-proof, changelog, and observer-only dashboard guidance. (AGENTS.md, 8870d9d179ba)
  • Verified author permission: GitHub reports permission write and role_name maintain for obviyus, supporting the supplied MEMBER classification despite the PR endpoint's CONTRIBUTOR association. The maintainer-authored close guard applies.
  • Current main still uses factories: At the fetched main revision, label policy and proof policy still have their dependency interfaces and factory constructors. The merged predecessor refactor: import report readers directly instead of building them in the runtime #1800 explicitly left this cluster for subsequent work. (src/clawsweeper-label-policy.ts:42, d559d9e498e4)
  • One shared mutation owner: The runtime creates one label mutation instance, passes it to synchronization operations, supplies its removeIssueLabel operation to review comments, and supplies the same instance to apply. Pending batches and the label catalog remain instance-local. (src/clawsweeper-runtime.ts:811, 8870d9d179ba)
  • Proof and security semantics preserved: The direct proof-policy export retains the authority marker, override, trusted-author treatment, and failed or malformed verification blockers. Readiness retains typed findings, security concerns, next-step interpretation, and stored-data compatibility assessment. (src/clawsweeper-proof-policy.ts:19, 8870d9d179ba)
  • Current-head proof scope: The complete PR body reports identical saved-report rendering and shipped apply-decisions CLI output between base and head, including label-edit ordering. It expressly uses a recording gh stub, so it does not establish actual GitHub transport or final label state. No additional runtime artifact was supplied in the discussion or proof scratch directory. The repository's code-bearing runtime-proof requirement is stronger than the ordinary external-contributor gate. (8870d9d179ba)

Review metrics

Metric Value Why it matters
Production and test lines Production +1030 / −1853; tests +480 / −424 Production shrinks by 823 lines while test fixtures replace injected policy readers with actual report parsing.

Labels

Label changes:

  • add P3: This is internal maintenance intended to preserve existing behavior, with no reported urgent user failure.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is internal maintenance intended to preserve existing behavior, with no reported urgent user failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 6:10 AM ET / 10:10 UTC.

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

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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