Skip to content

Fix EventColumnView._byKey unsafe publication; add sort tie-break tests#641

Open
jschick04 wants to merge 1 commit into
mainfrom
fix/eventcolumnview-bykey-publication
Open

Fix EventColumnView._byKey unsafe publication; add sort tie-break tests#641
jschick04 wants to merge 1 commit into
mainfrom
fix/eventcolumnview-bykey-publication

Conversation

@jschick04

Copy link
Copy Markdown
Collaborator

What — Fixes an unsafe-publication data race in EventColumnView._byKey and adds two direct sort-kernel regression tests.

WhyResolveByKey published the lazily-built _byKey dictionary via _byKey ??= BuildByKey() with no memory barrier — unlike every sibling M6 cache (TemplateFieldSchema, CombinedColumnView._index, the column store/pool) which use Volatile/Interlocked/Lock. Under concurrent ResolveByKey, a reader could observe the non-null reference before the dictionary's internal writes are visible on a weak-memory CPU (ARM64) — yielding a wrong/absent result or a throw.

Fix — Publish via Volatile.Read + Interlocked.CompareExchange(ref _byKey, byKey, null) (mirrors TemplateFieldSchema.GetOrBuildIndex). BuildByKey is idempotent over the immutable order, so a benign build-race is harmless.

Tests — grouped group/within-order negation (pins the two -Math.Sign sites independently of the AoS parity oracle); full-tie corpus with a reversed survivor input, so the ascending physical-index tie-break must actively reorder regardless of descending (mutation-verified: the test fails when WithIndexTieBreak is broken).

Validation — Full EventLogExpert.Runtime.Tests: 1641/1641 pass. Surfaced by a post-release audit of the M6 columnar store; the race is latent today (ResolveByKey has no production caller yet — only parity tests).

Copilot AI review requested due to automatic review settings July 11, 2026 16:30

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

Addresses a potential unsafe-publication race in EventColumnView.ResolveByKey by changing how the lazily built _byKey map is published under concurrency, and adds focused regression tests that pin deterministic sort tie-break behavior in the column-direct sort kernel.

Changes:

  • Publish EventColumnView._byKey with Volatile.Read + Interlocked.CompareExchange to ensure safe visibility on weak-memory CPUs under concurrent ResolveByKey.
  • Add a full-tie corpus test to ensure the final physical-index tie-break actively reorders even when the primary sort is descending.
  • Add a grouped-chain test matrix that independently verifies group-order negation vs within-group-order negation.

Reviewed changes

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

File Description
tests/Unit/EventLogExpert.Runtime.Tests/LogTable/ColumnDirectSortKernelTests.cs Adds two direct regression tests covering index tie-break and grouped-chain negation behavior.
src/EventLogExpert.Runtime/LogTable/EventColumnView.cs Fixes unsafe publication of the lazily built _byKey dictionary via Volatile + Interlocked.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

@jschick04 jschick04 marked this pull request as ready for review July 11, 2026 16:37
@jschick04 jschick04 requested a review from a team as a code owner July 11, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants