Repository navigation
fix(rowbinary): harden writer edge cases from #911 review - #916
Merged
Merged
Conversation
Addresses the remaining Copilot review findings on #911 (the writer follow-ups left for a separate PR): - datetime_writer: writeDate/writeDate32/writeDateTime now floor instead of Math.round, so a non-midnight Date or sub-second DateTime truncates to its calendar day / whole second (matching the reader and CH) rather than rounding up into the next day/second. Date32 floors toward -inf so pre-1970 instants land on the correct earlier day. - ip_writer: parseIPv6 validates each hex group (1-4 hex digits) instead of `parseInt(part, 16) & 0xffff`, which silently turned invalid groups into 0 (NaN & 0xffff) and wrapped negatives like "-1" to 0xffff. - geo_writer: writeGeometry validates the discriminant before writing its byte, so an out-of-range value throws without leaving a partial payload in the sink (mirrors writeVariant). Adds CH-independent tests for each. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Follow-up hardening for the @clickhouse/rowbinary writer introduced in #911/#915, addressing edge cases where encoding could silently produce incorrect bytes or leave partial payloads on failure.
Changes:
- Date/time writers now truncate (
Math.floor) to day/second boundaries to avoid rounding into the next day/second. parseIPv6now strictly validates IPv6 hex groups (rejecting malformed/negative/empty/overlong groups).writeGeometrynow validates discriminants before writing the discriminant byte to avoid partial payloads.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| skills/clickhouse-js-node-rowbinary-parser/src/datetime_writer.ts | Switches date/time encoding from rounding to flooring; updates docs (review note: suggest range/NaN validation + changelog entry). |
| skills/clickhouse-js-node-rowbinary-parser/src/ip_writer.ts | Tightens IPv6 group parsing to reject malformed groups instead of coercing/wrapping. |
| skills/clickhouse-js-node-rowbinary-parser/src/geo_writer.ts | Moves discriminant write into valid switch cases to avoid advancing the sink on invalid discriminants. |
| skills/clickhouse-js-node-rowbinary-parser/tests/DateTime.write.test.ts | Adds ClickHouse-independent tests asserting flooring behavior for date/time writers. |
| skills/clickhouse-js-node-rowbinary-parser/tests/IP.write.test.ts | Adds tests for strict IPv6 validation error cases. |
| skills/clickhouse-js-node-rowbinary-parser/tests/Geo.write.test.ts | Adds a regression test ensuring invalid geometry discriminants don’t write any bytes. |
Per #916 review: the date/time leaf writers intentionally don't runtime-validate input — matching the convention set on #911's varint writer ("we expect the data at this level to be correct or throw at the server side"). Document the valid-range precondition in each JSDoc (mirroring writeUVarint) instead of adding NaN/range guards to these hot-path writers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
peter-leonov-ch
added a commit
that referenced
this pull request
Jun 28, 2026
Make explicit the convention applied on #911/#916: readX/writeX hot-path functions don't runtime-validate input values — invalid input is a programming error documented in JSDoc, and the ClickHouse server rejects bad bytes server-side. The only checks that belong in are ones that keep the wire protocol in sync (e.g. writeIPv6's 16-byte length) or zero-cost parse-time helpers that never reach the server. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
peter-leonov-ch
force-pushed
the
fix/rowbinary-writer-review-followups
branch
from
June 28, 2026 22:39
bd30bcb to
0a919a0
Compare
peter-leonov-ch
added a commit
that referenced
this pull request
Jun 28, 2026
## Summary The root [`AGENTS.md`](https://github.com/ClickHouse/clickhouse-js/blob/main/AGENTS.md) had grown to cover packages, examples, skills, docs and the upstream test harness all in one file. This splits each section into a nested `AGENTS.md` next to the code it describes, so an agent (or human) reads the guidance closest to the files being edited: | File | Content | | ---- | ------- | | `packages/AGENTS.md` | Log-message conventions, package structure, intentional node/web duplication | | `examples/AGENTS.md` | Example corpus layout and conventions | | `skills/AGENTS.md` | Skill declaration requirement (`agents.skills` array) | | `skills/clickhouse-js-node-rowbinary-parser/AGENTS.md` | RowBinary reader/writer test conventions **+ a new no-defensive-validation rule** for the codecs | | `docs/AGENTS.md` | Embedded docs guidance | | `tests/clickhouse-test-runner/AGENTS.md` | Upstream SQL harness + allowlist-growth strategy | The **root `AGENTS.md`** keeps only cross-cutting guidance — the audience note, TypeScript LSP, and the code-review section (security / API stability / changelog rules) — plus an **index** linking to each nested file. ## Notes - **Relative links rewritten** for each file's new location; all link targets verified to resolve on disk. - The "API quality and stability" section stays at root because [`.github/instructions/review.instructions.md`](https://github.com/ClickHouse/clickhouse-js/blob/main/.github/instructions/review.instructions.md) links to it by name. - The new **no-defensive-validation rule** for the RowBinary codecs (don't runtime-validate input in hot-path `readX`/`writeX`; document the precondition in JSDoc and let the server reject bad bytes — with narrow exceptions for wire-framing checks and zero-cost parse helpers) lands in the rowbinary skill's `AGENTS.md`. It codifies the convention applied in #911/#916. Docs-only; no code or test changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up PR for the RowBinary writer added in #911. Peter's own review comments on #911 were all resolved during that PR; the remaining items were the Copilot bot's review findings, which Peter left for a separate PR ("Looks good so far, gonna continue in another PR"). This addresses the three that were still live in
main:datetime_writer.ts— round → floor.writeDate,writeDate32andwriteDateTimeusedMath.round, which shifts a non-midnightDateinto the next/previous day (12:00→ next day) and a sub-secondDateTimeup to the next second (00:00:00.600→+1s). They nowMath.floor, truncating to the calendar day / whole second — matchingreadDate*/readDateTimeand the existingwriteDateTime64(Math.floor(getTime()/1000)).writeDate32floors toward-inf, so pre-1970 instants land on the correct earlier day rather than rounding toward the epoch.ip_writer.ts— strict IPv6 group parsing.parseIPv6didparseInt(part, 16) & 0xffff, which silently encoded malformed groups as0(NaN & 0xffff === 0) and wrapped negatives like"-1"to0xffff. It now validates each group is 1–4 hex digits and throwsRangeErrorotherwise.geo_writer.ts— validate before writing.writeGeometrywrote the 1-byte discriminant before theswitch, so an out-of-range discriminant threw after advancing the sink, leaving a partial payload. The discriminant byte is now written only inside an acceptedcase; an unknown value throws fromdefaultbefore any bytes are written (mirrorswriteVariant).Two other Copilot findings on #911 are already resolved and need no change here: the
WRITER_TODO.mdNeedMoreSpace/BufferFullmismatch (the file was removed) and the missing CHANGELOG entry (added for #911/#915). ThewriteRowsdesign comment was handled in #915.Tests
Each fix gets a ClickHouse-independent test (
encode-vs-encodefor the flooring, throw-assertions for the validation), so they run without a live server and can't be masked by a reader. Full package suite: 724 passing, typecheck and prettier clean.🤖 Generated with Claude Code