Repository navigation
fix(server): preserve stall traces and move sync xcrun and SQLite reads off the event loop - #62
Merged
Merged
Conversation
…ds off the event loop
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosNo All 64 scenario measurements
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
…worker, and harden stall capture
syz51
marked this pull request as ready for review
November 24, 2026 22:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The T3 server's
server.trace.ndjson*(11 × 10 MB) rotates completely in ~4.7 minutes on an active host (~930 spans/s; 91% of bytes are <10 ms spans), so wheneverEventLoopMonitordetects a stall (such as the residual ~2.1 s stalls on 2026-11-24 after upstream PR pingdotgg#35728 moved primary SQLite writes off the loop), no trace remains minutes later andevent-loop-stalls.ndjsoncontains no span attribution. Several synchronous operations also remained on the server event loop:packages/shared/src/shell.ts:execFileSync("/usr/bin/xcrun", ["--find", "git"], { timeout: 5_000 })runs every 30 s on macOS when the resolution cache expires.apps/server/src/provider/Drivers/antigravityUsageReader.ts: opened and queried Antigravity.dbfiles (451 files / 1.7 GB on Air) synchronously on the main thread withPRAGMA busy_timeout = 100.apps/server/src/project/AgentSessionScanner.tsandpackages/provider-opencode/src/server/usageLimits.ts: opened Codexstate_5.sqliteand OpenCodeopencode.dbsynchronously withDatabaseSyncon the main thread.apps/server/src/observability/EventLoopMonitor.ts: wroteevent-loop-stalls.ndjsonusing synchronousRotatingFileSink.Changes
apps/server/src/observability/StallTraceCapture.ts,Observability.ts,EventLoopMonitor.ts):>= 50 ms) in bounded memory and attachactiveSpansandslowSpanstoserver.eventLoop.stallandevent-loop-stalls.ndjson.server.trace.ndjson{.1,}asynchronously, and atomically preserves up to 4 MB covering the stall window inlogs/event-loop-stall-traces/(retaining up to 10 snapshots with a 30 s cooldown).EventLoopMonitorfrom synchronousRotatingFileSinktomakeAsyncRotatingFileSink.xcrunlookup off the event loop (packages/shared/src/shell.ts):execFileSyncwith asyncexecFileinlocateXcodeGitWithXcrun, handle synchronous throws safely, and deduplicate concurrent in-flight lookups per cache key.apps/server/src/provider/Drivers/antigravityUsageReader.ts,apps/server/src/project/AgentSessionScanner.ts,packages/provider-opencode/src/server/usageLimits.ts,packages/shared/src/nodeSqliteClient.ts):antigravityUsageReaderSQLite reads on a single lazy scoped worker thread per scan (per-worker pending maps and termination on error).busyTimeoutMstoNodeSqliteClientso worker startup respects the caller's 100 ms fail-fast lock budget, and switchAgentSessionScanner.readCodexProjectRootsandusageLimits.readStoredApiKeystoNodeSqliteClient.layer({ readonly: true, writerWorker: true, busyTimeoutMs: 100 })with safe URL parsing.Verification
.db(50 msBEGIN EXCLUSIVElock,PRAGMA busy_timeout = 100): synchronousDatabaseSyncstalled the event loop for 123 ms and failed withSQLITE_BUSY; worker-backedreadAntigravityUsagesucceeded (errors: 0) with 2 ms max timer lag (60× lower). Real Pro Antigravity scan (141.dbfiles / 534 MB): 1,025 ms wall, 2 ms max timer lag, 7 ms max event-loop delay.vp run check:changed:format,lint,knip 1/2,knip 2/2,graphql, andtypecheck(37 packages) all pass; all affected tests pass (StallTraceCapture,EventLoopMonitor,antigravityUsageReader,AgentSessionScanner,nodeSqliteClient,status,shellmacOS git suite).posix_spawnoffload tracked in board sub-taskt3code-327(Size: M).