Skip to content

fix: repair the benchmarks build and a flaky identity-hash key - #23

Merged
michaelstonis merged 2 commits into
mainfrom
pr1/benchmarks-build-and-flaky-key
Aug 31, 2026
Merged

fix: repair the benchmarks build and a flaky identity-hash key#23
michaelstonis merged 2 commits into
mainfrom
pr1/benchmarks-build-and-flaky-key

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Two pre-existing problems that made verification unreliable. Both independent of the query work in the rest of this stack, split out first because the benchmarks fix is what makes the solution build at all.

TychoDB.Benchmarks has not compiled since 123c79f

That commit added an IJsonSerializer parameter to SortBuilder.Build so property expressions render against the serializer's member names. One call site in Diagnostics.cs was never updated, so dotnet build TychoDB.sln failed outright — nobody could run the benchmarks that back our performance claims.

A test keyed 1000 objects by their runtime identity hash

TychoDb_QueryUsingContains_ShouldBeSuccessful used x => x.GetHashCode().ToString() on a type that doesn't override GetHashCode. That's the identity hash, not a value hash: instances collide, INSERT OR REPLACE overwrites, and Count().ShouldBe(1000) fails.

Measured over 2000 trials of building 1000 TestClassA instances: 16 collided (0.80%), with as few as 998 distinct keys. Observed twice as a real suite failure across roughly 20 full runs while working on the rest of this stack.

Now keyed by IntProperty, already distinct over Range(100, 1000) — deterministic by construction rather than 0.8%-per-run.

The other four GetHashCode() uses in that file are left alone: they write a single object and read it back by the same instance's hash, so there's only ever one key and no collision is possible.

Verification

dotnet build TychoDB.sln -c Release clean; 227 tests pass.

🤖 Generated with Claude Code

Two pre-existing problems that made verification unreliable, both
independent of the query work that follows.

TychoDB.Benchmarks has not compiled since 123c79f, which added an
IJsonSerializer parameter to SortBuilder.Build so property expressions
could render against the serializer's member names. One call site in
Diagnostics.cs was never updated, so `dotnet build TychoDB.sln` failed
outright and nobody could run the benchmarks backing our perf claims.

TychoDb_QueryUsingContains_ShouldBeSuccessful keyed 1000 objects by
GetHashCode() on a type that does not override it — the runtime identity
hash, not a value hash. Instances collide, INSERT OR REPLACE overwrites,
and the count assertion fails at random. Measured over 2000 trials of
building 1000 TestClassA instances: 16 trials collided (0.80%), with as
few as 998 distinct keys. Observed twice as a real suite failure across
roughly 20 full runs. Keyed by IntProperty instead, which is already
distinct over Range(100, 1000).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two independent issues that made verification unreliable: a broken benchmarks build due to an outdated SortBuilder.Build call site, and a flaky unit test caused by using runtime identity hashes as keys (leading to occasional key collisions and overwritten rows).

Changes:

  • Update TychoDB.Benchmarks diagnostics sort-query generation to pass an IJsonSerializer into SortBuilder.Build.
  • Make TychoDb_QueryUsingContains_ShouldBeSuccessful deterministic by keying writes on IntProperty instead of Object.GetHashCode().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
TychoDB.UnitTests/TychoDbTests.cs Replaces identity-hash-based keys with a deterministic value key to eliminate flaky collisions; adds explanatory comment.
TychoDB.Benchmarks/Diagnostics.cs Fixes build by updating SortBuilder.Build invocation to include the required serializer parameter.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread TychoDB.UnitTests/TychoDbTests.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 31, 2026 14:19
@michaelstonis
michaelstonis merged commit 4d903d0 into main Aug 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants