Repository navigation
Description
1. Summary
Two small observability/operations rough edges observed during a live performance audit of long-running bb server/daemon processes:
spawnLoggedProcessrotatesserver-stdio.log/host-daemon-stdio.logonly once at spawn time (MAX_STDIO_LOG_BYTES_AT_SPAWN = 10 MiB) via a raw file descriptor, with no runtime size cap while long-lived processes run and no cleanup/cap on oversized.1.logfiles (leaving 887 MB of stale.1.logfiles on disk for weeks).invokeWrappedrecords total async wall-clock duration (performance.now() - startedAt, including passive 25s long-polls and proxied streams) intohandlerStats.totalMs/maxMsand wraps the entire async lifetime inrunEventLoopWork, so"Event loop stalled"inFlightWorkAtObservationlists passive awaited I/O handlers (likebb-account25s long-poll oraccount-poolproxy hub) alongside genuine synchronous CPU blockers.
2. Versions and environment
- bb version:
0.50.1(Desktop app on macOS), code verified onmainat commitb0ddaad731565d7e4de68d824120d802fc78f7d5 - OS: macOS 27.2.0 (
arm64, Apple Silicon)
3. Steps to reproduce
- Stdio log growth: Run
bbserver / host daemon across long uptimes with verbose plugin or process stderr/stdout output; inspect~/.bb/logs/*-stdio*.log. Because the child writes directly to an openfdand rotation only happens inspawnLoggedProcess, a single process run can grow*-stdio.logunboundedly and leave hundreds of MB in*-stdio.1.loguntil the next spawn overwrites it. - Async wait attribution: Trigger any synchronous event-loop stall while a plugin holds a long-lived async handler or service (e.g.,
bb-account25swaitForStatusChangelong-poll oraccount-poolservice hub), and inspect"Event loop stalled"in~/.bb/logs/server.*.logor pluginhandlerStats.
4. Expected vs actual
Actual:
- Disk:
~/.bb/logs/server-stdio.1.log+host-daemon-stdio.1.logaccumulated 887 MB (from Oct 24, still sitting on disk on Nov 28). - Server log (
server.14.log, 631 stall entries): every stall printsinFlightWorkAtObservationdominated by passive long-lived services/waits, masking which synchronous handler actually stalled the loop:
{"level":30,"component":"server","intervalMs":5000,"maxDelayMs":1104,"thresholdMs":500,"inFlightWorkAtObservation":"plugin:account-pool service hub | plugin:admiral service scheduler | ..."}- Plugin
handlerStatsreportsbb-accountat10.76s avg / 25.2s maxdespite0msCPU usage, purely from its 25s long-poll wait.
Expected:
- Cap/rotate
*-stdio.logduring long process lifetimes (or truncate/expire oversized*-stdio.1.logfiles) so stale stdio logs cannot hold ~1 GB indefinitely. - Distinguish synchronous event-loop execution time (or active sync frames) from total async wall-clock lifetime in
handlerStatsandinFlightWorkAtObservation, making real stall attribution immediate.
5. Evidence
MAX_STDIO_LOG_BYTES_AT_SPAWN = 10 * 1024 * 1024and spawn-only rotation inpackages/bb-app/src/logged-process.ts:
bb/packages/bb-app/src/logged-process.ts
Line 14 in b0ddaad
const MAX_STDIO_LOG_BYTES_AT_SPAWN = 10 * 1024 * 1024;
bb/packages/bb-app/src/logged-process.ts
Lines 60 to 80 in b0ddaad
export function spawnLoggedProcess(args: SpawnLoggedProcessArgs): ChildProcess { mkdirSync(args.logDir, { recursive: true }); const logPath = join(args.logDir, `${args.logName}-stdio.log`); if ( (statSync(logPath, { throwIfNoEntry: false })?.size ?? 0) > MAX_STDIO_LOG_BYTES_AT_SPAWN ) { renameSync(logPath, join(args.logDir, `${args.logName}-stdio.1.log`)); } const launch = resolveLoggedProcessLaunch(args); const fd = openSync(logPath, "a", 0o600); try { return spawn(launch.command, launch.args, { cwd: process.cwd(), env: launch.env, stdio: args.ipc === true ? ["ignore", fd, fd, "ipc"] : ["ignore", fd, fd], }); } finally { closeSync(fd); } } invokeWrappedrecords full async wall-clock time intohandlerStatsand wraps the full async promise inrunEventLoopWork:
bb/apps/server/src/services/plugins/plugin-runtime.ts
Lines 557 to 564 in b0ddaad
function statsFor(id: string): PluginHandlerStats { let stats = handlerStats.get(id); if (!stats) { stats = { count: 0, totalMs: 0, maxMs: 0, errorCount: 0 }; handlerStats.set(id, stats); } return stats; }
bb/apps/server/src/services/plugins/plugin-runtime.ts
Lines 988 to 1028 in b0ddaad
async function invokeWrapped<T>( instance: LoadedPlugin, label: string, run: (signal: AbortSignal) => T | Promise<T>, callerSignal?: AbortSignal, ): Promise<PluginInvocationOutcome<T>> { const id = instance.pluginId; const released = instance.released.signal; if (released.aborted) { return { ok: false, error: `${label} not started: plugin "${id}" was reloaded or disabled`, cause: undefined, }; } const lifetime = instance.stopping.signal.aborted ? released : instance.stopping.signal; const call = callerSignal === undefined ? { signal: lifetime, unlink: () => {} } : linkCallSignal(callerSignal, lifetime); const signal = call.signal; const stats = statsFor(id); const startedAt = performance.now(); const execution = pluginCodeContext.run(id, () => runEventLoopWork(`plugin:${id} ${label}`, () => run(signal)), ); const settled = execution.then( () => undefined, () => undefined, ); instance.invocations.add(settled); void settled.then(() => { call.unlink(); instance.invocations.delete(settled); const elapsedMs = performance.now() - startedAt; stats.count += 1; stats.totalMs += elapsedMs; if (elapsedMs > stats.maxMs) stats.maxMs = elapsedMs; }); inFlightWorkAtObservationreports allactiveFrameson every event-loop stall:
bb/apps/server/src/services/system/event-loop-work.ts
Lines 170 to 207 in b0ddaad
function formatActiveWork(): string | null { if (activeFrames.size === 0) { return null; } const roots = [...activeFrames.values()] .filter( (frame) => frame.parent === null || !activeFrames.has(frame.parent.id), ) .sort((left, right) => left.id - right.id); return roots.map((root) => formatLineage(root)).join(" | "); } function roundNullableDurationMs(durationMs: number | null): number | null { return durationMs === null ? null : roundDurationMs(durationMs); } function getEventLoopWorkSnapshot(): EventLoopWorkSnapshot { const longest = longestInWindow; return { inFlightWorkAtObservation: formatActiveWork(), lastCompletedWork: lastCompleted === null ? null : describeLabel(lastCompleted.label), lastCompletedWorkWallMs: lastCompleted === null ? null : roundDurationMs(lastCompleted.durationMs), longestSynchronousWork: longest === null ? null : formatWorkChain(longest), longestSynchronousWorkCaller: longest?.callerDescription ?? null, longestSynchronousWorkCpuMs: roundNullableDurationMs( longest?.cpuMs ?? null, ), longestSynchronousWorkWallMs: roundNullableDurationMs( longest?.durationMs ?? null, ), longestSynchronousWorkVoluntaryContextSwitches: longest?.contextSwitches?.voluntary ?? null, longestSynchronousWorkInvoluntaryContextSwitches: longest?.contextSwitches?.involuntary ?? null, }; }
bb/apps/server/src/services/system/event-loop-work.ts
Lines 299 to 320 in b0ddaad
export async function runEventLoopWork<T>( label: string, work: () => Promise<T> | T, ): Promise<T> { const frame = createFrame(label, currentAsyncParentFrame(), false); const startedAt = performance.now(); activeFrames.set(frame.id, frame); const segmentCaller = currentSyncFrame ?? frame.parent; return currentAsyncFrame.run(frame, async () => { try { return await runSynchronousWorkFrame( `${label} (until first await)`, segmentCaller, true, work, ); } finally { activeFrames.delete(frame.id); completeFrame(frame, performance.now() - startedAt); } }); }
bb/apps/server/src/services/system/event-loop-stall-monitor.ts
Lines 21 to 43 in b0ddaad
prepareSample: () => { const work = takeEventLoopWorkWindowSnapshot(); return ({ stall, suspension }) => { if (suspension !== null) options.logger.info(suspension, "System suspension observed"); if (stall !== null) { const hasCandidate = work.longestSynchronousWorkWallMs !== null && work.longestSynchronousWorkWallMs + stall.resolutionMs >= stall.maxDelayMs; options.logger.info( { ...stall, ...work, stallAttribution: hasCandidate ? "candidate" : "unattributed", stallCauseCandidate: hasCandidate ? work.longestSynchronousWork : null, }, "Event loop stalled", ); } };
6. What you ruled out
- Still present on
mainatb0ddaad731565d7e4de68d824120d802fc78f7d5. - Checked commit
35eacba28(Stop service logs growing without limit #5933): it added spawn-timeMAX_STDIO_LOG_BYTES_AT_SPAWNrotation, but not runtime rotation or.1.logcap/cleanup. - Separate from eager plugin frontend loading (already tracked in Thread open on a slow phone: plugins the page does not need evaluate during the timeline's first render #8252 and being addressed in Load plugin surfaces and core contributions from chunks with one lazy helper #8152 / Start lazy plugin parts and their runtime slots as early as the screen needs them #8203).
7. Suggested priority and effort
Low priority, small-to-medium effort: improves disk hygiene for long-running servers and makes event-loop stall diagnostics far more actionable when debugging plugins or core stalls.
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 28, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilothost,plugins,perf.partial-repro.Keep only the last 10 MB of the previous stdio capture (get-bb#8435)
Keep only the last 10 MB of the previous stdio capture (get-bb#8435)