Skip to content

refactor(core): consolidate coercion, hashing, and env readers - #1391

Merged
steipete merged 1 commit into
mainfrom
refactor/deslop-shared-coercion
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
refactor/deslop-shared-coercion

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Value guards, hashes, environment reads, and regex escaping were repeated across the review and repair lanes. This change consolidates 55 local helper implementations while preserving their accepted inputs, fallback values, whitespace handling, and error messages.

Why This Change Was Made

value-coerce.ts owns the matching record, scalar-validation, and error-text contracts. content-hash.ts replaces all nine local SHA-256 wrappers, required-env.ts replaces the three matching trimming readers, and the string-only regex escaping copies use the existing text module. The repair compiler allowlist includes the shared modules.

The inventory covered all 149 declarations of the 25 requested names under src/**. Different integer, timestamp, string, array, and loosely typed contracts remain separate. No parseArgs copy matches repair/lib.ts: the main parser rewrites flag names and the other repair parsers have distinct option schemas. Source-loaded admission, ETag, telemetry, and coverage-manifest modules stay self-contained so direct TypeScript consumers keep working without compiler or workflow changes.

User Impact

Behavior-neutral; no runtime contract, config, or workflow change. No dependency or environment-variable additions.

Evidence

The pr-behavior-proof contract for this behavior-neutral refactor is the full pnpm run check run plus the targeted suites, as specified by the work order.

  • Claim: extracted helpers preserve values, validation decisions, error text, hashes, and CLI environment handling.
  • Exercised surface: compiled review and repair modules, their existing fixture suites, direct-source consumers, and both TypeScript compilation boundaries.
  • Scenario/fixture: existing artifact, cursor, cache, admission, repair, and publication fixtures; 1,192 before/after comparisons against the original helper bodies, including invalid values, arrays, whitespace, integer boundaries, binary input, and synthetic environment reads.
  • Command and environment: Node 26.8.1, pnpm 11.10.0, macOS arm64; pnpm run build:all, pnpm run format, the test commands below, and pnpm run check.
  • Observable result: full gate passed with 4,733 passing tests, 11 skips, zero failures/cancellations, and coverage of 83.71% lines, 76.39% branches, and 88.68% functions. The focused rerun passed all 170 tests; all 1,192 before/after helper comparisons matched.
  • Artifact or trace: local /tmp/deslop-helpers-check.log, /tmp/deslop-helpers-focused.log, /tmp/deslop-helpers-equivalence.log, and /tmp/autoreview-deslop-helpers.md; exhaustive declaration inventory at /tmp/deslop-helpers-inventory.md.
  • Limits: fixture-based proof of behavior preservation; no live service mutation or deployment. The broad targeted run had one pinned-Knip fixture timeout; that exact case passed on rerun. An earlier import-resolution failure identified the direct-source boundary and was removed before the final gate.
node scripts/run-node-tests.mjs all -- --test-name-pattern='assist|structural|hydration|coverage|etag|hosted target|state writer|state append|canonical|bundle|action session|cluster|live proof|live verification|OpenClaw|openclaw|Codex|ledger|timeline|external message|repository profile'
node scripts/run-node-tests.mjs repair -- --test-name-pattern='stages pinned Knip|fanout|cursor'
pnpm run check
Full check, focused coverage gate:
ℹ tests 13
ℹ pass 13
ℹ fail 0
ℹ cancelled 0

Full check, complete suite:
ℹ tests 4744
ℹ pass 4733
ℹ fail 0
ℹ cancelled 0
ℹ skipped 11
ℹ duration_ms 1536912.213875
ℹ all files | 83.71 | 76.39 | 88.68 |

Focused repair rerun:
ℹ tests 170
ℹ pass 170
ℹ fail 0
ℹ cancelled 0

PASS: 1192 before/after helper comparisons; values, error text, whitespace, arrays, integers, hashes, regex escaping, and synthetic environment reads match.

Independent Codex review: scoped-clean at P1, with no accepted/actionable findings. Review base pinned to the branch merge base (72041f31e1d34cff19f50da4b23c4a22a78c828a) after origin/main advanced during validation; this keeps unrelated upstream work out of the local candidate review.

OpenClaw Bay not affected: no dashboard changes.

Scope Added Removed Net LOC
Production (src/**) 131 312 -181
Tests 0 0 0
Docs 0 0 0
Repair build allowlist 4 0 +4
Total 135 312 -177

Update after ClawSweeper review (head 738beb5, rebased onto main; unchanged content)

Real behavior proof (production command-chain harness, current head): the documented automerge e2e harness (docs/repair/automerge-e2e.md, --scenario all) ran on this exact head in CI: https://github.com/openclaw/clawsweeper/actions/runs/33827474822 (job production automerge flow, success, all scenarios across both fixtures). It runs the compiled repair entrypoints that consume the consolidated modules (validate-job, run-worker, review-results, execute-fix-artifact, report-only publication, apply-result, post-flight, and the comment router), so the shared value-coerce, content-hash, and required-env modules are exercised on real Git, real compiled CLIs, and real artifact handoff. GitHub and Codex are the harness's simulators. Review-lane entrypoints (clawsweeper-runtime, structural cache, decision packets) are covered by the full pnpm run check suite on this head plus the 1,192-case equivalence comparison recorded above.

Rebase note: the only conflict with main was the import block in src/github-etag-read-broker.ts after the ETag body cap landed; resolved by keeping GITHUB_ETAG_CACHE_MAX_BODY_BYTES and importing sha256 from content-hash. Full pnpm run check re-run locally on the rebased head passed (one unrelated target-validation fixture timed out once under machine load and passed on rerun; that test is untouched by this PR).

@steipete
steipete marked this pull request as ready for review September 4, 2026 01:35
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. 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 Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 3, 2026, 10:28 PM ET / September 4, 2026, 02:28 UTC.

ClawSweeper review

What this changes

The branch replaces duplicated validation, SHA-256, environment-reading, and regex-escaping helpers with shared modules across ClawSweeper’s review and repair code.

Merge readiness

✅ Ready for maintainer review

Keep this PR open for normal maintainer landing: the prior proof blocker is resolved by exact-head production command-chain evidence, and this remains a meaningful unmerged internal refactor with no actionable correctness or security finding.

Priority: P3
Reviewed head: 738beb51ebb8b8b3d64749bf54d16ca968fdd049

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A broad but focused consolidation with current-head production-path proof and no discrete defect found.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The added shared validation, hashing, and environment modules are consumed by repair entrypoints; the supplied exact-head production automerge-flow run exercised compiled CLIs, real Git, and artifact handoff across both fixtures, with successful after-change scenarios.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The added shared validation, hashing, and environment modules are consumed by repair entrypoints; the supplied exact-head production automerge-flow run exercised compiled CLIs, real Git, and artifact handoff across both fixtures, with successful after-change scenarios.
Evidence reviewed 4 items Shared helper implementation: The introduced shared coercion module preserves the object, string, positive-integer, unexpected-key, and error-summary contracts used by the affected callers.
Repair build boundary: The repair compiler explicitly includes each newly shared runtime dependency, avoiding an omitted-module build boundary for repair entrypoints.
Current-head production proof: The supplied PR context identifies successful run https://github.com/openclaw/clawsweeper/actions/runs/33827474822 on this exact head; the repository workflow runs all scenarios across both fixtures through the compiled production automerge command chain.
Findings None None.
Security None None.

How this fits together

ClawSweeper review and repair entrypoints parse untrusted data and environment settings, create decisions and artifacts, then publish or apply automation outcomes. This refactor centralizes low-level validation and hashing behavior used along those paths.

flowchart LR
  A[GitHub data and environment] --> B[Review and repair entrypoints]
  B --> C[Shared validation and hashing helpers]
  C --> D[Decision and artifact processing]
  D --> E[Publication and apply outcomes]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Refactor scope 41 files; +134 / -312 lines The change removes substantially more duplicated implementation than it adds across review and repair paths.
Production versus tests production +134 / -312; tests +0 / -0 No test files change; confidence rests on retained suites, equivalence comparisons, and the production command-chain run.
Production harness 2 fixtures, all scenarios The cited exact-head workflow exercises compiled repair entrypoints with real Git and artifact handoff.

Technical review

Best possible solution:

Land the consolidated helpers with the existing exact-head command-chain proof and preserve the distinct validation contracts that were intentionally left local.

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

Not applicable: this is a behavior-preserving refactor, and the supplied exact-head harness reports the after-change production command chain succeeding.

Is this the best way to solve the issue?

Yes. Reusing narrowly equivalent shared helpers while retaining intentionally distinct contracts is the maintainable way to reduce duplicated implementation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The added shared validation, hashing, and environment modules are consumed by repair entrypoints; the supplied exact-head production automerge-flow run exercised compiled CLIs, real Git, and artifact handoff across both fixtures, with successful after-change scenarios.
  • 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 (linked_artifact): The added shared validation, hashing, and environment modules are consumed by repair entrypoints; the supplied exact-head production automerge-flow run exercised compiled CLIs, real Git, and artifact handoff across both fixtures, with successful after-change scenarios.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P3: This is behavior-neutral internal cleanup with no demonstrated user-facing regression.
  • 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 (linked_artifact): The added shared validation, hashing, and environment modules are consumed by repair entrypoints; the supplied exact-head production automerge-flow run exercised compiled CLIs, real Git, and artifact handoff across both fixtures, with successful after-change scenarios.
  • proof: sufficient: Contributor real behavior proof is sufficient. The added shared validation, hashing, and environment modules are consumed by repair entrypoints; the supplied exact-head production automerge-flow run exercised compiled CLIs, real Git, and artifact handoff across both fixtures, with successful after-change scenarios.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-04T01:38:50.490Z sha c2c0be6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-04T01:58:36.717Z sha 738beb5 :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the refactor/deslop-shared-coercion branch from c2c0be6 to 738beb5 Compare September 4, 2026 01:53
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current-head real behavior proof from the automerge e2e harness (run 33827474822) is now cited in the PR body, covering the repair entrypoints that consume the consolidated modules. Head unchanged.

@clawsweeper

clawsweeper Bot commented Sep 4, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@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 status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Sep 4, 2026
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Landing: CI green on exact head 738beb5 (rebased onto main), fresh ClawSweeper review reports no findings and no before-merge items; real behavior proof from the automerge e2e harness (run 33827474822) is cited in the body. Behavior-neutral consolidation of 55 helper copies, production -181 LOC.

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