Skip to content

[Repo Assist] Fix CircularBuffer.Enqueue(array) - head pointer advances by count, not 1#233

Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/fix-issue-125-circular-buffer-array-enqueue-806b1b4611ff3be2
Draft

[Repo Assist] Fix CircularBuffer.Enqueue(array) - head pointer advances by count, not 1#233
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/fix-issue-125-circular-buffer-array-enqueue-806b1b4611ff3be2

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 8, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #125

Root Cause

In CircularBuffer.Enqueue(value: _[], offset, count), the head pointer was unconditionally advanced by 1, regardless of how many elements were being enqueued:

head <- (head + 1) % bufferSize   // BUG: always +1
for x, y in nextBuffer head count do
    Array.blit value offset buffer x y

This meant that after enqueueing an array of N elements, head pointed to the start of the written region, not the end. Subsequent enqueue operations then computed the wrong start position, causing data to be written to incorrect buffer locations and the tail pointer to be miscalculated.

Fix

Separate the start-position calculation from the head update:

let startPos = (head + 1) % bufferSize   // where writing begins
for x, y in nextBuffer startPos count do
    Array.blit value offset buffer x y
    offset <- offset + y
head <- (head + count) % bufferSize      // head ends at last written position

For count = 1 (single-element enqueue, which delegates here) the behaviour is identical to before.

Changes

  • src/FSharpx.Collections/CircularBuffer.fs — fix the head advancement logic
  • tests/FSharpx.Collections.Tests/CircularBufferTests.fs — promote the three ptest (pending/skipped) tests to test since they now pass

Test Status

FSharpx.Collections.Tests: 709 passed, 3 ignored, 0 failed (includes the three newly-enabled CircularBuffer array tests)

⚠️ FSharpx.Collections.Experimental.Tests: killed with exit code 137 (OOM) — this is a pre-existing infrastructure issue unrelated to this change (see issues #115 and #116).

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

When enqueueing an array of count elements, the head pointer was only
advanced by 1 instead of count, causing subsequent array enqueues to
overwrite incorrect positions in the buffer.

The fix separates the start position calculation from the head update:
- startPos = (head + 1) % bufferSize  (where writing begins)
- head = (head + count) % bufferSize  (where head ends after writing)

Also enables the three ptest tests that were previously pending due to
this bug, confirming they now pass.

Closes #125

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme
Copy link
Contributor

dsyme commented Mar 8, 2026

@gdziadkiewicz Over to you :)

@dsyme
Copy link
Contributor

dsyme commented Mar 8, 2026

@gdziadkiewicz Repo Assist creates all PRs in draft mode. There is a CI trigger in place so CI will run automatically. If it's green you can usually take them out of draft mode and assess.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Circular buffer does not enque arrays properly

1 participant