Skip to content

refactor: route sha256 hex digests through content-hash - #1790

Merged
obviyus merged 1 commit into
mainfrom
cleanup-sha256-owner
Oct 9, 2026
Merged

obviyus merged 1 commit into
mainfrom
cleanup-sha256-owner

Conversation

@obviyus

@obviyus obviyus commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Route every single-update SHA-256 hex digest in src/ through sha256() from src/content-hash.ts. This rewrites 56 hand-rolled createHash("sha256").update(x).digest("hex") chains in 38 files and drops the createHash / default crypto imports that become unused.

  • Mixed imports keep their other crypto members (createHmac, randomUUID, timingSafeEqual), and comment-webhook.ts keeps its default crypto import for HMAC/signing.
  • record-tuple.ts and telegram-proof-evidence.ts import ../content-hash.ts, because their tests load them as bare .ts. Telegram's private hash wrapper is inlined.
  • commentBodySha256 passed an explicit "utf8". That is Node's default string encoding, so sha256(String(body ?? "")) returns the same digest.
  • Intentionally unchanged: target-validation.ts (7 multi-update/streaming hashes) and scheduled-review-noop.ts (a capsule proof loads it as a bare .ts file).
  • Added test/content-hash.test.ts.

Why

This gives sha256 hex hashing a single owner. Before this PR, src/ had 65 raw createHash("sha256") sites next to an existing content-hash.ts owner. After it, 9 remain: the owner itself, the 7 multi-update sites in target-validation and the capsule-loaded noop. Overall the diff is net-negative (159+/172−, including the new test and changelog fragment).

Proof

  • Raw createHash("sha256") sites in src/: 65 → 9 (git grep -c).
  • Byte-identical hashing: every rewritten site passed a string (default utf8) or a Buffer/Uint8Array to a single update, and sha256() does exactly that. test/content-hash.test.ts checks sha256() against raw createHash for strings (empty, ASCII, NUL, non-BMP unicode, JSON), explicit-utf8 strings, Buffer and Uint8Array, plus the NIST ""/"abc" vectors.
  • I re-rendered the saved real reports (prompt-rest, prompt-lean, prompt-dump, async-proof/{base,branch}, retire-proof/166090; 9 reports) with render-comments.mjs, comparing an origin/main dist with this branch's dist. The output is byte-identical in all 6 sets (cmp), with 0 render failures.
  • pnpm run build:all: pass.
  • Focused tests: the 61 test files that import a touched module, plus the new test, pass (2388 pass, 0 fail).
  • pnpm run check: check:static, build, lint and coverage:changed pass. The full suite had 6948/6988 pass with 3 failures. Two were 120s/180s load timeouts in command-proof-consumer.test.ts and one was a supervisor-completion timing failure in review-git-acquisition.test.ts, all on a loaded host (load avg ~20). Re-running both files alone: 42/42 pass.
  • After rebasing on 6270db414 (resolved import conflicts with refactor: import asRecord and login from value-coerce #1787 in issue-implementation-intake.ts and review-activity-cursor.ts): build, lint and format:check pass, and the 10 test files covering the conflicted/neighbouring modules plus the new test pass (335/335).

Codex dispositions

codex review --base origin/main found no P0–P2 issues: "The refactor preserves hash inputs, encoding, and digest truncation."

Merge Danger

Low. Every digest is byte-identical, so persisted hashes (ledger keys, delivery IDs, receipts, cursors, packet digests) are unchanged. The only risk is import resolution for modules loaded as bare .ts. The two known cases use the .ts specifier, and the capsule-loaded scheduled-review-noop.ts is left alone. A follow-up PR removes the redundant sha256 dependency injection.

@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 routes 56 single-update SHA-256 hexadecimal digest calculations across 38 source files through the existing shared hashing helper.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is useful and appears correct, but the supplied execution evidence does not cover the changed hashing path.
Proof confidence 🦪 silver shellfish (2/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: This extends the established shared hashing owner without changing product behavior. Removing duplicate implementations reduces maintenance cost with a net reduction in production code.

Merge readiness

✅ Ready for maintainer review

This PR is a useful, behavior-preserving consolidation, and no concrete patch defect was found. Current main still contains the duplicated implementations; no merged fixing PR supersedes this work.

Priority: P3
Reviewed head: cf0a2165ab95b6d284c6051b3ff3fd525839d06a

Before merge

None.

Findings

None.

Tests

  • Low-value test test/content-hash.test.ts: sha256 matches the raw createHash digest for strings and bytes, comparison loop: Remove the comparison loop that repeats the helper's implementation and duplicates the Buffer assertion; the independent published digest vectors can remain.
  • Missing end-to-end proof: A current-head production entry point must exercise a rewritten fingerprint or artifact-integrity path and show its unchanged digest or acceptance result.
Agent review details

How this fits together

ClawSweeper uses content fingerprints to identify review inputs, verify artifacts, and correlate durable records. The shared hashing helper converts text or bytes into the hexadecimal fingerprints consumed by these workflows.

flowchart TD
  A[Review text and artifact bytes] --> B[Existing serialization]
  B --> C[Shared SHA-256 helper]
  C --> D[Hexadecimal fingerprint]
  D --> E[Artifact integrity checks]
  D --> F[Record and delivery identities]
Loading

Technical review

Best possible solution:

Keep one shared owner for single-update SHA-256 digests while preserving exact inputs, durable identities, and direct TypeScript loading.

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

Not applicable: this PR consolidates existing implementations without claiming a user-facing bug.

Is this the best way to solve the issue?

Yes: extending the existing helper is a narrow solution, and the diff preserves serialization, encoding, truncation, and direct-source imports.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced hunks preserve input expressions, JSON field ordering, string coercion, and digest truncation. Hashing ownership and imports change without changing the resulting bytes. (cf0a2165ab95)
  • Identical hashing contract: The unchanged helper performs exactly one createHash("sha256").update(value).digest("hex") operation on string or Uint8Array input; Buffer inputs remain supported. (src/content-hash.ts:3, 405764da3257)
  • Shared-owner history: The helper appears in commit c75901a. Its introducing patch adds the current implementation, and its raw commit records parent d32eaf1. (src/content-hash.ts:3, c75901a57a96)
  • Prior consolidation direction: refactor(core): consolidate coercion, hashing, and env readers #1391 established content-hash as the shared owner while preserving accepted inputs and direct-source consumers. This PR extends that direction to remaining inline calculations. (c75901a57a96)
  • Import compatibility: Both compiler configurations rewrite relative TypeScript import extensions. The repair compiler already includes content-hash.ts, and the directly source-loaded record-tuple and Telegram evidence modules use the .ts specifier. (tsconfig.repair.json:6, cf0a2165ab95)
  • Persisted identity compatibility: Publication delivery IDs, ledger identities, packet digests, cursor hashes, and blob digests retain their exact serialized inputs and hashing operation. No stored format, schema, or migration changes, and no Bay data-contract change is needed. (src/repair/publish-main.ts:273, cf0a2165ab95)

Likely related people:

  • Peter Steinberger: Raw commit c75901a adds src/content-hash.ts:3 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c75901a57a96; files: src/content-hash.ts)

Review metrics

Metric Value Why it matters
Production and test changes production +134/-172; tests +24/-0 Production shrinks by 38 lines through reuse of an existing helper without adding another abstraction.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This behavior-preserving internal cleanup reduces maintenance duplication without addressing a reported runtime failure.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-09T06:13:34.055Z sha 019a473 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 2:27 AM ET / 06:27 UTC (Revision 2).

@obviyus
obviyus force-pushed the cleanup-sha256-owner branch from 019a473 to cf0a216 Compare October 9, 2026 06:22
@obviyus
obviyus merged commit cf34fa9 into main Oct 9, 2026
14 of 17 checks passed
@obviyus
obviyus deleted the cleanup-sha256-owner branch October 9, 2026 06:38
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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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