refactor(utils): consolidate hash, sleep, and base64 helpers onto canonical utils - #3045
Conversation
…onical utils Three low-level concerns were reimplemented across the codebase; this routes every call site to a single canonical implementation in #veryfront/utils without behavior changes: - SHA-256 hex hashing: 13 local digest blocks -> computeHash / new computeHashBytes; src/release-assets/hash.ts deleted - sleep/delay: canonical abort-aware sleep(ms, signal?) in src/utils/sleep.ts; 12 local copies removed - base64/base64url: encodeBase64 moved from security/http/auth.ts into utils/base64url.ts (kept dependency-free for client bundles) and base64url helpers exported from the barrel; 9 ad-hoc encoders removed
There was a problem hiding this comment.
Pull request overview
Consolidates repeated low-level helpers (SHA-256 hashing, sleep/delay, and base64/base64url encoding) into canonical implementations under #veryfront/utils, updating call sites across workflow, server, build, proxy, oauth, eval, and rendering to reduce duplication while keeping behavior consistent.
Changes:
- Replaced scattered
crypto.subtle.digestSHA-256 helpers withcomputeHash/computeHashBytes. - Replaced inline
setTimeout-based delays with canonicalsleep(ms, signal?). - Centralized base64/base64url encoding with
encodeBase64,base64urlEncode, andbase64urlEncodeBytes, updating call sites accordingly.
Verification (as reported in PR description):
deno task verify:quick: exit 0deno task test:unit: 2634 passed / 0 failed- Pre-push hook: passed
Reviewed changes
Copilot reviewed 40 out of 41 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/workflow/worker/workflow-worker.ts | Uses canonical sleep and removes local sleep helper. |
| src/workflow/executor/workflow-executor.ts | Replaces inline polling delay with canonical sleep. |
| src/workflow/executor/dag/utils.ts | Removes local abort-aware sleep helper (moved to utils). |
| src/workflow/executor/dag/loop-node-strategy.ts | Switches DAG sleep import to #veryfront/utils. |
| src/workflow/executor/dag/composite-node-execution.ts | Switches DAG sleep import to #veryfront/utils. |
| src/workflow/claude-code/workspace-sync.ts | Replaces local SHA-256 checksum with computeHash. |
| src/workflow/blob/gcs-storage.ts | Replaces ad-hoc base64url helpers with canonical base64url utils. |
| src/utils/sleep.ts | Adds canonical abort-aware sleep(ms, signal?). |
| src/utils/index.ts | Re-exports new canonical hashing, base64/base64url, and sleep utilities. |
| src/utils/hash-utils.ts | Adds computeHashBytes and refactors hex encoding into shared helper. |
| src/utils/base64url.ts | Adds canonical base64/base64url encoding helpers. |
| src/transforms/mdx/compiler/import-rewriter.ts | Uses canonical base64urlEncode for browser FS path encoding. |
| src/studio/bridge/bridge-bundle.generated.ts | Regenerates studio bridge bundle after underlying utility consolidation. |
| src/server/services/rsc/orchestrators/stream-handler.ts | Removes local sleep helper in favor of canonical sleep. |
| src/server/services/rsc/endpoints/rsc-bundles.generated.ts | Regenerates RSC client bundles to use canonical base64 encoding logic. |
| src/server/project-env/fetcher.ts | Uses canonical encodeBase64 for basic auth header generation. |
| src/server/handlers/studio/bridge-modules.handler.ts | Uses computeHash to generate ETag consistently. |
| src/security/http/auth.ts | Removes local base64 implementation and uses canonical encodeBase64. |
| src/sandbox/lazy-sandbox.ts | Replaces polling delays with canonical sleep. |
| src/routing/api/module-loader/esbuild-plugin.ts | Replaces retry delay helper with canonical sleep. |
| src/rendering/orchestrator/module-loader/cache.ts | Replaces custom hashing with computeHash. |
| src/release-assets/index.ts | Stops exporting deleted release-asset-specific SHA helpers. |
| src/release-assets/hash.ts | Deletes duplicated SHA-256 helper module. |
| src/release-assets/build-executor.ts | Replaces release asset hashing with computeHashBytes. |
| src/proxy/server-resolver.ts | Uses canonical encodeBase64 for basic auth header generation. |
| src/proxy/routing-invalidation-redis.ts | Uses canonical base64urlEncodeBytes for signature encoding. |
| src/oauth/providers/base.ts | Uses canonical base64urlEncodeBytes for PKCE code challenge. |
| src/metrics/index.ts | Uses canonical encodeBase64 for internal metrics basic auth. |
| src/knowledge/index.ts | Uses canonical base64urlEncodeBytes for cursor encoding. |
| src/html/styles-builder/plugin-loader.ts | Uses canonical encodeBase64 for data URL module imports. |
| src/eval/report.ts | Replaces local SHA-256 hex helper with computeHash. |
| src/eval/provenance.ts | Replaces local string/bytes SHA-256 helpers with computeHash / computeHashBytes. |
| src/eval/agent-service/live-evals/api-client.ts | Uses canonical sleep via a wait helper. |
| src/eval/agent-service/durable-run-canaries/runner.ts | Removes local sleep helper in favor of canonical sleep. |
| src/discovery/transpiler.ts | Replaces local SHA-256 helper with computeHash for cache keys and dep verification. |
| src/build/vendor-cache.ts | Replaces local SHA-256 helper with computeHash for vendor cache keys. |
| src/build/production-build/local-release-assets.ts | Uses computeHashBytes for local release asset manifest signatures. |
| src/build/bundler/code-splitter/manifest-builder.ts | Uses computeHashBytes for chunk hashing. |
| src/agent/service/registration.ts | Uses computeHash for stable service keys. |
| src/agent/service/detached-run-tracker.ts | Removes local sleep helper in favor of canonical sleep. |
| src/agent/input/human-input.ts | Uses canonical sleep and removes local delay helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4d6484d3d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 40 out of 41 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/utils/base64url.ts:42
base64urlEncodeBytescallsbtoa(binary)directly, which throws a ReferenceError in runtimes wherebtoais not defined (for example, Node). SinceencodeBase64already supports a Buffer fallback, mirror that behavior here (and useglobalThis.btoafor consistency).
|
Follow-ups on the post-merge review comments:
|
Summary
First PR in the code-reduction refactor campaign: three low-level concerns were each implemented many times across
src/; this routes every call site to one canonical implementation in#veryfront/utilswith no behavior changes.Net: −140 lines (41 files, +137/−277), 2634 unit tests pass, full lint/typecheck/fmt gates green.
Consolidations
crypto.subtle.digestblocks across oauth, discovery, server, agent, workflow, release-assets, eval, rendering, build, channelscomputeHash/ newcomputeHashBytes;src/release-assets/hash.tsdeletedsleep/delaydefs + inlinenew Promise(setTimeout)in workflow, agent, sandbox, eval, routing, serversleep(ms, signal?)(src/utils/sleep.ts, impl lifted from workflow/dag)encodeBase64local tosecurity/http/auth.ts; 9 ad-hocbtoa/Buffer encoders in workflow, knowledge, proxy, transforms, metrics, server, htmlencodeBase64moved intoutils/base64url.ts; all base64url helpers now exported from the#veryfront/utilsbarrel (they previously weren't — which is why modules reimplemented them)Notes for review
utils/base64url.tsstays dependency-free because it ships in client bundles (rendering/rsc imports it; the client esbuild alias for#veryfront/errorsdoesn't carrycreateError). The unreachable no-btoa/no-Buffer fallback now throws a plainErrorinstead of a registry error.bridge-modules.handler.tsETag keeps its exact old value: first 16 digest bytes ≡ first 32 hex chars ofcomputeHash.security-handler.tsCSP nonce (padded base64 of raw bytes),ssr-cache-manager.ts(size-thresholded hash fallback),channels/control-plane.ts(base64url digest, already partly canonical),workflow-executor.ts:829(cancellable timeout, not a pure sleep).Verification
deno task verify:quick(manifests, fmt, full lint suite, typecheck): exit 0deno task test:unit: 2634 passed / 0 failed