Skip to content

Refactor tracker flushing#14

Merged
deepso7 merged 4 commits into
mainfrom
effect-queue-flushing
May 5, 2026
Merged

Refactor tracker flushing#14
deepso7 merged 4 commits into
mainfrom
effect-queue-flushing

Conversation

@deepso7
Copy link
Copy Markdown
Owner

@deepso7 deepso7 commented May 5, 2026

Summary

  • Replaces the tracker's manual array buffer with Effect Queue-based buffering.
  • Adds Effect Schedule-driven interval flushing with semaphore-protected queue draining.
  • Reuses the Effect interval implementation from the plain TypeScript entry point and adds coverage for partial interval flushes.

Verification

  • pnpm test
  • pnpm run build
  • pnpm run check

Summary by cubic

Refactors tracker buffering and flushing to use effect queues, schedules, and semaphores, removing manual arrays and timers. Protects interval flush delivery during shutdown, serializes interval setup, and reports interval flush errors for better reliability.

  • Refactors

    • Replaced manual array buffer with Queue.dropping and semaphores for uninterruptible draining and serialized interval setup.
    • Removed timer logic from src/index.ts; interval handling now lives in the Effect tracker.
    • Flush triggers on batch size; shutdown stops the interval and drains without interrupting in-flight deliveries.
  • New Features

    • Interval-based flushing via Schedule.duration (default 5s, configurable with flushInterval).
    • Reports interval flush errors via onError.

Written for commit 5112836. Summary will update on new commits.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/effect.ts">

<violation number="1" location="src/effect.ts:196">
P1: The drain operation inside `withPermit` is interruptible. If `shutdown` interrupts the interval fiber while it's mid-drain (after `takeBatch` removes items from the queue but before `sendWithRetries` completes), those events are lost permanently. Mark the critical section as uninterruptible so that an in-flight batch completes delivery before the fiber responds to the interrupt.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/effect.ts
@deepso7
Copy link
Copy Markdown
Owner Author

deepso7 commented May 5, 2026

@cubic-dev-ai can we review the whole codebase?

@cubic-dev-ai
Copy link
Copy Markdown

cubic-dev-ai Bot commented May 5, 2026

@cubic-dev-ai can we review the whole codebase?

@deepso7 I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/effect.ts">

<violation number="1" location="src/effect.ts:224">
P2: Race condition: concurrent `track` calls can both pass the `intervalFiber !== undefined` guard and fork duplicate interval fibers, leaking the first. Consider wrapping `ensureFlushInterval` with the semaphore or using a `Ref` with an atomic compare-and-set to guard fiber creation.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/effect.ts Outdated
@deepso7 deepso7 merged commit 4412a49 into main May 5, 2026
2 checks passed
@deepso7 deepso7 deleted the effect-queue-flushing branch May 5, 2026 21:46
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