fix(misc): cryptographic taskId, hoisted fs import, graceful shutdown, awaited transport#20
Conversation
Code Review: PR #20 — fix(misc): cryptographic taskId, hoisted fs import, graceful shutdown, awaited transportReviewed commit: 1. Cryptographic taskId (
|
| Change | Verdict | Issues |
|---|---|---|
| Cryptographic taskId | Correct | None |
| Hoisted fs import | Correct | None |
| Awaited transport | Correct | Minor race (non-blocking) |
| Graceful shutdown | Correct | Recommend disconnect timeout |
Overall: APPROVE — All changes are clear improvements. No security issues, bugs, or correctness problems. Safe to merge.
Single-reviewer analysis focused on: crypto randomness, import ordering, shutdown logic, transport awaiting.
RapierCraft
left a comment
There was a problem hiding this comment.
APPROVED: commit 871befc after code review (1 reviewer). 0 blocking issues. 1 non-blocking recommendation (disconnect timeout for graceful shutdown). Safe to merge.
…, awaited transport
Small reliability / hygiene fixes — independently small but mutually
unrelated, hence bundled here. Happy to split if reviewer prefers.
`generateTaskId` used `Math.random().toString(36).substring(2, 8)` —
six base36 chars, roughly 31 bits of entropy, disambiguated only by
the `Date.now()` prefix. Two concurrent callers in the same
millisecond have a real birthday collision risk (and `Math.random` is
flagged by every standard "no insecure RNG" lint rule even for
non-security uses).
Switched to `crypto.randomUUID()` (Node ≥ 14.17). Same shape
(`task_<unix-ms>_<rand>`), now collision-free for any reasonable
volume. Existing test regex updated to the UUID v4 shape.
`comet_upload` did `const fs = await import('fs')` per call. Cached
after the first call but added an unnecessary microtask on every
upload and prevented bundlers from tree-shaking. Hoisted
`existsSync` to a top-level import.
`server.connect(transport)` was fire-and-forget. If the transport
failed to attach (e.g. stdin already closed in a misconfigured
parent process) the promise silently rejected and the process
exited with no logs. Now `await server.connect(transport).catch(...)`
logs the error before exiting non-zero.
Added handlers that call `cometClient.disconnect()` before exiting, so
the underlying WebSocket to Comet closes cleanly instead of sitting
half-open until Comet times it out. Exits 130 on SIGINT (POSIX
convention for Ctrl+C), 0 on SIGTERM.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
871befb to
5ff609e
Compare
Summary
Small reliability / hygiene fixes — independently small but unrelated, hence bundled. Happy to split.
`crypto.randomUUID` for task IDs
`generateTaskId` used `Math.random().toString(36).substring(2, 8)` — six base36 chars, ~31 bits, disambiguated only by the `Date.now()` prefix. Two concurrent callers in the same millisecond have a real birthday-collision risk, and `Math.random` triggers every standard "no insecure RNG" lint rule.
Switched to `crypto.randomUUID()` (Node ≥ 14.17). Same shape (`task__`), collision-free for any reasonable volume. Existing test regex updated to the UUID v4 shape.
Hoisted `fs` import
`comet_upload` did `const fs = await import('fs')` on every call. Cached after the first, but adds an unnecessary microtask each request and prevents bundlers from tree-shaking. Hoisted to a top-level `import { existsSync } from "fs"`.
Awaited `server.connect()`
`server.connect(transport)` was fire-and-forget. If the transport failed to attach (e.g. stdin already closed in a misconfigured parent) the promise silently rejected and the process exited with no logs. Now `await server.connect(transport).catch(...)` logs the error before exiting non-zero.
Graceful SIGINT / SIGTERM handler
Added handlers that call `cometClient.disconnect()` before exiting, so the WebSocket to Comet closes cleanly instead of sitting half-open until Comet times it out. Exits 130 on SIGINT (POSIX convention for Ctrl+C), 0 on SIGTERM.
Test plan
🤖 Generated with Claude Code