Skip to content

Fix nondeterministic concurrency in PointCommand - #7

Merged
progys merged 1 commit into
masterfrom
fix-concurrency-point-command
Aug 15, 2026
Merged

progys merged 1 commit into
masterfrom
fix-concurrency-point-command

Conversation

@progys

@progys progys commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Problem

`PointCommand` performed its work in a parallel stream via a mutable `AreaConsumer` that accumulated `totalArea` and printed each matching shape from inside `accept()`, which runs on worker threads. Consequences:

  • Shape lines were printed in nondeterministic order across runs.
  • The `totalArea` float sum order varied run to run.

Fix

  • The parallel stream now only computes matches: `parallelStream().filter(shape.inShape(point)).toList()` — no shared mutable state, and `toList()` preserves encounter order.
  • Printing and the area summation happen afterwards in a single sequential loop, so output ordering and the float result are deterministic.

Verification

  • New `PointCommandTest` (2 cases): encounter-order + combined area output, and empty-result path. Full suite now 11/11 green.
  • End-to-end: two runs of a parallel point query produce byte-identical output (same hash).

Compute inShape checks in parallel but collect matches in encounter order;
print and accumulate total area sequentially afterwards.
@cursor

cursor Bot commented Aug 15, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@progys
progys merged commit c97cee9 into master Aug 15, 2026
4 checks passed
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.

1 participant