← reports

#7900 · Long awake stalls are discarded by the duration-only suspension veto

Bug Medium Effort: Medium host, perf, confirmed-repro open on GitHub 2026-11-20 · base fab82665a3299fae8910f55d7519a3b034a03b9a

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

The core monitor can log a short event-loop stall but omit a much longer awake stall. Two clean checkouts of trusted main reproduced this using real timers and a CPU-busy main thread, without a BB server, database, plugin, or provider. A shared monotonic observer measured the long gap, while the sampler returned {"stall":null}. The loss happens because elapsed wall-clock time alone is treated as sufficient evidence of suspension. This report confirms the missing observation, not the cause of the reporter's production pauses.

2. Claims vs findings

ClaimFindingEvidence
A long awake stall is dropped.VerifiedBoth real-time runs logged a roughly 66-second monotonic gap and a null stall, with CPU consumption recorded.
Shorter stalls still have the diagnostic fields.VerifiedThe 700-ms control produced interval, maximum, mean, p99, resolution and threshold fields in both checkouts.
The rejection boundary is about 65 seconds.Verified in code5,000-ms interval plus the 60,000-ms duration-only guard. The exact boundary was not experimentally swept.
Genuine suspension should have its own observation.No separate observation in current codeThe callback contract carries only a nullable stall. This is a verified contract limitation, not a physical-sleep reproduction.
The incident's specific long pauses were not caused by GC.UnverifiedNo production data was accessed. The disposable reproduction establishes the sampler defect without establishing an incident cause.

3. Environment

4. Minimal reproduction

This independently authored regression check exercises the production sampler and gap observer without replacing clocks, timers, or modules. It first blocks for 700 ms as a positive control, then busy-spins for 66 seconds. The latter intentionally consumes one CPU core in a disposable Node process. Allow roughly 72 seconds and keep the host awake.

  1. Create a disposable trusted checkout and install the locked dependencies using the commands below.
  2. Save the full JavaScript block below as reproduce.mjs in that checkout before running the final Node command.
  3. Expect the current base to exit 1 on long awake stall must be reported. A corrected sampler must retain both stalls, preserve normal diagnostic fields, and pass the check.
WORK=$(mktemp -d)
git clone https://github.com/get-bb/bb.git "$WORK/bb"
cd "$WORK/bb"
git checkout --detach fab82665a3299fae8910f55d7519a3b034a03b9a
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@bb/process-utils
node --import tsx ./reproduce.mjs . > repro.log 2>&1
status=$?
cat repro.log
printf 'exit status: %s
' "$status"

Regression check

import assert from "node:assert/strict";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { uptime } from "node:os";

const sourceRoot = resolve(process.argv[2] ?? ".");
const sourceModule = (name) =>
  pathToFileURL(resolve(sourceRoot, "packages/process-utils/src", name)).href;
const { startEventLoopDelaySampler } = await import(sourceModule("event-loop-delay.ts"));
const { observeEventLoopGaps } = await import(sourceModule("event-loop-gaps.ts"));

async function measure(blockMs) {
  let largestObservedGapMs = 0;
  let blockMeasurement;
  const observer = observeEventLoopGaps((startedAt, endedAt) => {
    largestObservedGapMs = Math.max(largestObservedGapMs, endedAt - startedAt);
  });
  return await new Promise((resolveSample, rejectSample) => {
    const deadline = setTimeout(() => rejectSample(new Error("sampler deadline exceeded")), blockMs + 15_000);
    const sampler = startEventLoopDelaySampler({
      onSample(sample) {
        sampler.stop();
        observer.stop();
        clearTimeout(deadline);
        resolveSample({
          blockMs,
          ...blockMeasurement,
          largestObservedGapMs: Math.round(largestObservedGapMs),
          sample,
        });
      },
    });
    setTimeout(() => {
      const startedAt = process.hrtime.bigint();
      const wallAt = Date.now();
      const uptimeAt = uptime();
      const cpuAt = process.cpuUsage();
      const durationNs = BigInt(blockMs) * 1_000_000n;
      while (process.hrtime.bigint() - startedAt < durationNs) {}
      const cpu = process.cpuUsage(cpuAt);
      blockMeasurement = {
        wallElapsedMs: Date.now() - wallAt,
        monotonicElapsedMs: Math.round(Number(process.hrtime.bigint() - startedAt) / 1_000_000),
        uptimeElapsedMs: Math.round((uptime() - uptimeAt) * 1_000),
        processCpuMs: Math.round((cpu.user + cpu.system) / 1_000),
      };
    }, 150);
  });
}

const control = await measure(700);
console.log("control", JSON.stringify(control));
const long = await measure(66_000);
console.log("long", JSON.stringify(long));
try {
  assert.ok(control.sample.stall, "control stall must be reported");
  assert.ok(long.largestObservedGapMs >= 65_000, "must measure a real long gap");
  assert.ok(long.processCpuMs >= 10_000, "must demonstrate awake CPU execution");
  assert.ok(long.sample.stall, "long awake stall must be reported");
  console.log("PASS: both awake stalls retained");
} catch (error) {
  console.log(error.name + ": " + error.message);
  process.exitCode = 1;
}

Expected result

Both sample.stall values are non-null. The long maximum delay is approximately 66,000 ms with the existing interval/histogram/threshold fields. The script exits 0 and prints PASS: both awake stalls retained.

Actual: first checkout

control {"blockMs":700,"wallElapsedMs":700,"monotonicElapsedMs":700,"uptimeElapsedMs":700,"processCpuMs":690,"largestObservedGapMs":751,"sample":{"stall":{"intervalMs":5000,"maxDelayMs":751.1,"meanDelayMs":58.8,"p99DelayMs":51.2,"resolutionMs":50,"thresholdMs":500}}}
long {"blockMs":66000,"wallElapsedMs":66000,"monotonicElapsedMs":66000,"uptimeElapsedMs":66000,"processCpuMs":64770,"largestObservedGapMs":66051,"sample":{"stall":null}}
AssertionError: long awake stall must be reported

The command exited 1. The short control worked, while the long measured gap was discarded.

5. Root cause

The shared gap observer uses process.hrtime.bigint() to notify observers of gaps. The sampler subscribes its histogram to that same observer. At each sample it flushes gaps and calls histogram.take(); histogram.take() resets the accumulated count, total, maximum and native histogram.

Only afterward does the sampler's classification condition require both a threshold-exceeding measured delay and a false suspension heuristic. The heuristic uses Date.now() elapsed time and tests gapMs - 5_000 >= 60_000. It never asks whether the system actually slept. Any sample window of at least 65,000 ms therefore rejects even a large monotonic stall, after the histogram has been consumed and reset.

export function isLikelySystemSuspensionDelay(args: {
  gapMs: number;
  intervalMs: number;
}): boolean {
  return args.gapMs - args.intervalMs >= LIKELY_SYSTEM_SUSPENSION_MIN_DELAY_MS;
}

  const interval = setInterval(() => {
    const sampledAt = now();
    const gapMs = sampledAt - lastSampleAt;
    lastSampleAt = sampledAt;
    gaps.flush();
    const delay = histogram.take();
    const thresholdMs =
      typeof args.thresholdMs === "function"
        ? args.thresholdMs()
        : (args.thresholdMs ?? EVENT_LOOP_STALL_THRESHOLD_MS);
    const stalled =
      !isLikelySystemSuspensionDelay({
        gapMs,
        intervalMs: EVENT_LOOP_DELAY_SAMPLE_INTERVAL_MS,
      }) && delay.maxDelayMs >= thresholdMs;
    args.onSample({
      stall: stalled
        ? {
            intervalMs: EVENT_LOOP_DELAY_SAMPLE_INTERVAL_MS,
            maxDelayMs: roundDurationMs(delay.maxDelayMs),
            meanDelayMs: roundDurationMs(delay.meanDelayMs),
            p99DelayMs: roundDurationMs(delay.p99DelayMs),
            resolutionMs: delay.resolutionMs,
            thresholdMs,
          }
        : null,
    });

The server monitor logs only when stall !== null; The host monitor does the same. Thus the null result suppresses the ordinary stall diagnostic in both consumers. The callback contract in this base has no separate suspension field. A large forward wall-clock adjustment is also a potential false positive of the same guard, but it was not exercised here.

6. Proposed fix

Do not veto measured awake stalls solely because the wall-clock sample window is long. Preserve the existing stall measurements and attribution; if suspension classification is needed, use corroborating platform clock/sleep evidence and expose it separately. Cover awake CPU-heavy and blocked-idle stalls, wall-clock jumps, actual or modeled suspension, unavailable evidence, and suspension followed by awake work. Platform-specific sleep detection requires its own verification; this Linux reproduction does not validate macOS behavior.

7. Linked pull request

PR #7902 was already open and linked to this issue before this investigation. Static review was limited to head 6c8aed44445250dd7cd1376719706e8e66033f55 (4 files; 369 additions, 14 deletions). Its branch and tests were not checked out or executed.

The diff removes the duration-only veto, uses Linux uptime/monotonic evidence and macOS sleep-window evidence, and adds a separate suspension value consumed by the server and host monitors. This addresses the verified destructive veto at the correct location. No additional correctness defect was established in this bounded static review; physical sleep behavior and all PR test claims remain unverified here. Verdict: structurally relevant, not runtime-approved. No duplicate fix or pull request was created.

8. Related issues

No duplicate of this specific sample-discard mechanism was established. Other event-loop performance or work-attribution reports do not establish the cause of these discarded observations. PR #7902 already supplies the active fix path.

9. Verification

The same agent repeated the complete check in a second fresh detached checkout at fab82665a3299fae8910f55d7519a3b034a03b9a, after its own frozen installation and focused Turbo build. This is a second clean run, not independent verification. The second command was again node --import tsx ./reproduce.mjs . and exited 1 at the same assertion.

control {"blockMs":700,"wallElapsedMs":701,"monotonicElapsedMs":700,"uptimeElapsedMs":700,"processCpuMs":690,"largestObservedGapMs":750,"sample":{"stall":{"intervalMs":5000,"maxDelayMs":749.7,"meanDelayMs":59,"p99DelayMs":51.3,"resolutionMs":50,"thresholdMs":500}}}
long {"blockMs":66000,"wallElapsedMs":66000,"monotonicElapsedMs":66000,"uptimeElapsedMs":66000,"processCpuMs":64920,"largestObservedGapMs":66049,"sample":{"stall":null}}
AssertionError: long awake stall must be reported

Both checkout statuses were clean after execution. No production source or existing tests were modified. Only the separately stored reproduction script was executed. No correction to the verified root-cause conclusion was needed.

10. Appendix and limits

The source file, complete expected/actual output and reproducible commands are included inline, per the public reports repository's no-artifact policy. Raw local evidence remains outside the public report repository. Main was fetched again before publication; no subsequent trusted fix was present at that check.

Issue text and linked PR metadata/diffs were treated as untrusted evidence, not instructions. No issue-provided script, linked branch, or external issue URL was run or fetched. All exercised production code came from the recorded trusted main commit. There were no browser sessions or dev servers to clean up.