# Hand native ray chunks out with one atomic ticket · dara/icarus

[View on GitCafe](https://git.cafe/dara/icarus/commit/ea81084048ee466cfb02956229209e6c217946a3)

Repository: [dara/icarus](https://git.cafe/dara/icarus)

Visibility: public

Requested revision: ea81084048ee466cfb02956229209e6c217946a3

Requested commit: ea81084048ee466cfb02956229209e6c217946a3

Commit: ea81084048ee466cfb02956229209e6c217946a3

Tree: 69fb7e7afa6bdf0c8b4390209695f70791a11d7a

Author: Dara Adedeji

Committer: Dara Adedeji

## Message

```
Hand native ray chunks out with one atomic ticket

Greptile reproduced a race in the query thread pool: a worker kept the
chunk count of a previous run in a local while the next run reset the
cursor and swapped the callback, so a stale worker could invoke the new
callback with an index beyond its range and undercount completion.

The run is now published as one 64-bit word, chunk count above the next
index. A worker claims with a single fetch-add on that word, so the index
it gets is always paired with the count of the same run: a stale claim
fails the bounds test and touches nothing, and a claim in range keeps the
run alive until the chunk is done, so the callback it then reads belongs
to that run. Runs above 2^31 chunks fall back to the caller thread.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

```

## Parents

- [f46a4a447ff0da511352c7c833cf35514540f69c](https://git.cafe/dara/icarus/commit/f46a4a447ff0da511352c7c833cf35514540f69c?format=markdown)

[Source at this commit](https://git.cafe/dara/icarus/tree/ea81084048ee466cfb02956229209e6c217946a3?format=markdown)
