Skip to content

[Bug]: ProviderCommitBatch can drop to one unit per transaction when commits are slow, because a barrier still waiting on its own thread's jobs counts toward the 100 ms cutoff #41380

Closed

Description

@Sawtaytoes

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Run t3 serve with a lot going on at once. Here, that was about 27 live Claude sessions (root threads plus delegated children) on a busy Linux host.
  2. Get the server into a state where SQLite BEGIN, COMMIT, and reader queries are slow (SAVEPOINT stayed at about 0.01 ms). Across a 31-minute trace window, median BEGIN was 49.1 ms (n = 9,723), median COMMIT 54.1 ms, and median reader query 61.3 ms. Per-minute BEGIN medians reached 61 to 79 ms. The main thread was rarely idle at the time. Likely contributors were the per-session ps polling from On macOS every open Claude session runs ps -A once a second, which floods endpoint security with process launches #37582 (since fixed by fix(server): open Claude sessions on macOS share one process-table poll #37585) and heavy host load.
  3. Open or send a message in a thread that is streaming. That dispatches a command through EventSink, which calls coordinator.barrier(..., threadIds).

Expected behavior

When commits get slow, ProviderCommitBatch keeps batching, so the provider event backlog drains and thread.visit / message.dispatch waits stay bounded.

Actual behavior

Flushes commit one unit at a time (a unit can hold coalesced snapshots), the backlog grows, and commands wait behind it for minutes.

In commitPrefix (ProviderCommitBatch.ts:322-327):

if (
  taken > 0 &&
  waitingWriters > 0 &&
  (yield* Clock.monotonicTimeNanos) - startedAt >= MAX_HOLD_NANOS
)
  return;

MAX_HOLD_NANOS is 100 ms. Once one unit takes more than 100 ms, any waitingWriters > 0 ends the transaction after taken = 1, and the remaining units go to later transactions.

barrier() increments waitingWriters before it waits for its own thread's pending jobs (ProviderCommitBatch.ts:396-410):

waitingWriters++;
...
for (const job of Array.from(pending)) {
  if (threadIds === undefined || threadIds.includes(job.threadId)) yield* job.settled;
}

So a command on a busy thread counts as a waiting writer while it is still waiting for the batch to commit its own thread's queued jobs, and it can trip the cutoff for that same batch. If its last pending job is in the committed prefix, the shorter transaction settles it sooner. But if its jobs are further back, the cutoff splits the work ahead of them into more transactions, and each one pays its own BEGIN + COMMIT. I suspect this feeds itself on a busy server (slower commits → more waiters → smaller batches → slower drain), but I haven't measured how much it changes command latency.

From server.trace.ndjson on 0.1.11 (all times one evening, ~30 minutes):

  • 1,800 ProviderCommitBatch.flush spans: orchestration_v2.work_item_count median 1 (p90 5, max 49), with orchestration_v2.deferred_work_item_count median 22 (p90 50, max 63).
  • Per 2-minute bucket, summed work_item_count dropped from ~11 per flush early in the window to ~1.1 per flush once things got slow. The summed flush span time stayed at about 116 to 124 s per 2-minute bucket, so the batcher was busy the whole time and still falling behind.
  • Max orchestration_v2.batch_wait_ms per bucket rose from 22 s to 120 to 376 s.
  • 16 orchestration.dispatchCommand calls (14 thread.visit, 2 message.dispatch) took more than 15 s, up to 71 s. Their actual SQL transaction took only 0.46 to 1.49 s. The other 14.6 to 69.5 s was spent before the transaction started, which matches waiting in barrier() (it's fnUntraced, so I can't see it directly).

What I can't prove from the traces: the flush spans don't record waitingWriters or why a flush stopped. I'm inferring that the cutoff caused the one-unit flushes because deferred_work_item_count was high while work_item_count was 1. I also can't say how often the cutoff fired or how much of the command wait it caused. That needs a cutoff reason on the span or a controlled comparison. #39135 covers a different ProviderCommitBatch slowdown (Codex threads sharing one provider session). I don't think this one is the same thing, but they'd stack.

Impact

Major degradation or frequent failure

Version or commit

0.1.11 (also checked main @ f9f34aa; same code)

Environment

Linux x64, headless t3 serve in Docker, Claude Agent SDK provider, about 27 live Claude sessions

Workaround

Fewer concurrent sessions. T3CODE_PROVIDER_COMMIT_BATCHING=false bypasses batching and the barrier, which would be a useful comparison, but I haven't tested it on this workload.

What I think the fix is

One option: count a writer in waitingWriters only once its own pending jobs have settled, which is when it is actually waiting for the SQL writer. Then the cutoff fires only when cutting short lets that writer in. A floor on how many units a transaction takes before the cutoff applies (or a cutoff based on time per unit) would also stop the one-unit-per-transaction collapse when every statement is slow. It would also help to add a cutoff reason attribute on the flush span, plus a span on barrier(), so this shows up in traces.

Activity

  1. changed the title [-][Bug]: ProviderCommitBatch drops to one event per transaction when commits are slow, because a barrier waiting on its own thread's jobs trips the 100 ms cutoff[/-] [+][Bug]: ProviderCommitBatch can drop to one unit per transaction when commits are slow, because a barrier still waiting on its own thread's jobs counts toward the 100 ms cutoff[/+] on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions