Skip to content

fix(utils): cancel pending batch timer on split flush - #5504

Merged
jxom merged 1 commit into
mainfrom
fix-batch-scheduler-stale-timer
Nov 13, 2026
Merged

jxom merged 1 commit into
mainfrom
fix-batch-scheduler-stale-timer

Conversation

@jxom

@jxom jxom commented Nov 13, 2026

Copy link
Copy Markdown
Member

Supersedes #5500 by @zjuncal (credited as co-author).

When shouldSplitBatch flushed a batch early, its wait timer stayed armed and later flushed the next batch under the same id before that batch's wait elapsed. This affects http and multicall batching with a non-zero wait. No requests were dropped or duplicated, but batches were smaller and more requests went out.

Example with wait: 100, splitting at more than 2 items. Items 1 and 2 arrive at t=0, item 3 at t=50 (splits), item 4 at t=70, item 5 at t=120:

  • Before: [1,2] flushed at 51, [3,4] at 100 (should be 150, or at the next split), [5] at 152 (32ms after it arrived).
  • After: [1,2] at 51, [3,4] at 120 (split by item 5), [5] at 221.

The timer handle is now stored per scheduler id and cleared in flush(), which every flush path goes through. It is keyed by id rather than kept per instance because callers create a new scheduler on each request and share batches by id.

The regression test fails on main and passes with the fix. It relies on the order in which timers are due, not on tight timing.

A split flush left the previous batch's wait timer armed, so it later
flushed the next batch under the same id before its wait elapsed.

Co-authored-by: zjuncal <[email protected]>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1ced8-5803-75d7-b106-9fcea9f5b316
Co-authored-by: jxom <[email protected]>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Error Error Nov 13, 2026 2:51am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eec11db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T02:48:14.175700Z eec11db PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jxom
jxom merged commit c05ab61 into main Nov 13, 2026
35 of 38 checks passed
@jxom
jxom deleted the fix-batch-scheduler-stale-timer branch November 13, 2026 02:51
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026

This branch had an error being deployed

1 failed deployment
Preview — eec11dbc Deployed Nov 13, 2026 by vercel[bot]
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