Skip to content

Fix for incremental reader chunk-drop#259

Merged
MaxHeimbrock merged 2 commits intomainfrom
max/datastream-incremental-chunk-drop
Apr 27, 2026
Merged

Fix for incremental reader chunk-drop#259
MaxHeimbrock merged 2 commits intomainfrom
max/datastream-incremental-chunk-drop

Conversation

@MaxHeimbrock
Copy link
Copy Markdown
Contributor

@MaxHeimbrock MaxHeimbrock commented Apr 22, 2026

Summary

  • Add a single EditMode regression test that pins down the chunk-drop bug in ReadIncrementalInstructionBase<T>.
  • The base class stores each OnChunk call into a single _latestChunk field, so when several ChunkReceived FFI events are dispatched on the same sync-context flush (common: multiple chunks arriving between Unity frames), earlier chunks are silently overwritten before the consumer coroutine can resume from its yield.
  • No Runtime changes in this PR — the queue-backed fix lands on a follow-up branch once this failing test is in place.

Test plan

@MaxHeimbrock MaxHeimbrock changed the title Add failing test for incremental reader chunk-drop Fix for incremental reader chunk-drop Apr 22, 2026
@MaxHeimbrock MaxHeimbrock changed the base branch from max/datastream-reader-dedupe to main April 23, 2026 11:39
MaxHeimbrock and others added 2 commits April 23, 2026 13:41
Exercise ReadIncrementalInstructionBase<T>.OnChunk with several chunks
arriving before the consumer drains, simulating multiple ChunkReceived
events delivered on the same sync-context flush. The base keeps only a
single _latestChunk, so earlier chunks are silently overwritten; the
test pins this down ahead of the queue-backed fix on a follow-up branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ReadIncrementalInstructionBase<T> previously stored each incoming chunk
in a single _latestChunk field. When several ChunkReceived FFI events
were dispatched on the same sync-context flush (routine between Unity
frames), OnChunk overwrote the field before the consumer coroutine
could resume from its yield, silently dropping earlier chunks.

Queue chunks that arrive while a prior read is still pending. Reset()
advances _latestChunk to the next queued chunk and keeps
IsCurrentReadDone true so the next yield completes immediately, draining
the buffer before waiting for more FFI events.

Flips DataStreamIncrementalReadTests from failing to passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MaxHeimbrock MaxHeimbrock force-pushed the max/datastream-incremental-chunk-drop branch from 2e92fe4 to f01d5b6 Compare April 23, 2026 11:41
Copy link
Copy Markdown
Contributor

@ladvoc ladvoc left a comment

Choose a reason for hiding this comment

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

LGTM ✅

[Test]
public void OnChunk_MultipleChunksBeforeConsumerDrains_AllChunksAreObserved()
{
using var handle = new FfiHandle(IntPtr.Zero);
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.

question: I'm probably missing something obvious, but how does creating a zero FfiHandle work here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is a null pointer and we just need it to satisfy the constructor. In the TestIncrementalReader we can push chunks to mock callbacks without needing any native stuff, so the null handle is never used. Does that answer your question?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And on cleanup we check if the handle is valid, so it would also not be released.

@MaxHeimbrock MaxHeimbrock merged commit a7ddf4d into main Apr 27, 2026
29 of 31 checks passed
@MaxHeimbrock MaxHeimbrock deleted the max/datastream-incremental-chunk-drop branch April 27, 2026 10:47
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