Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b108841
fix(main): crash instead of spinning on a fatal OOM, and name the wor…
brennanb2025 Nov 16, 2026
5fbf408
test(worker-threads): ledger names the sender and frees its slot on exit
brennanb2025 Nov 16, 2026
529441f
fix(worker-threads): refuse fault-signal listeners synchronously, sur…
brennanb2025 Nov 16, 2026
568a552
fix(worker-threads): cast-free guard and ledger, keyed collections co…
brennanb2025 Nov 16, 2026
192cb25
fix(worker-threads): visit each payload object once under one entry b…
brennanb2025 Nov 16, 2026
0442b55
fix(worker-threads): split main heap into old and large-object space …
brennanb2025 Nov 16, 2026
47f1e13
fix(native-chat): refuse a journal reader reply over 256 MB instead o…
brennanb2025 Nov 16, 2026
27e60c8
fix(native-chat): cap reader replies at 64 MB from measured decode co…
brennanb2025 Nov 16, 2026
b000c36
test(crash-reporting): a real process with proper-lockfile holds no S…
brennanb2025 Nov 16, 2026
7e5beb7
fix(native-chat): measure any reader reply the bounded walk cut short…
brennanb2025 Nov 16, 2026
41be42c
chore(worker-threads): satisfy lint/format, split hang worker-send pa…
brennanb2025 Nov 16, 2026
cc3c160
chore(worker-threads): typed calls instead of Reflect in the send led…
brennanb2025 Nov 16, 2026
bca8bf2
fix(native-chat): page items-by-kind visits by 8 MiB of JSON so a pag…
brennanb2025 Nov 17, 2026
6f0c0c4
perf(native-chat): read items-by-kind payloads lazily so rows past th…
brennanb2025 Nov 17, 2026
99efae1
fix(native-chat): never refuse a reader reply that carries one stored…
brennanb2025 Nov 17, 2026
2bd72db
fix(worker-threads): list the spawn module's new imports in the web t…
brennanb2025 Nov 17, 2026
4b83fd3
Merge remote-tracking branch 'origin/main' into brennanb2025/worker-o…
brennanb2025 Nov 17, 2026
431c668
fix(worker-threads): walk Map keys through built-in accessors, bound …
brennanb2025 Nov 17, 2026
3ae06af
refactor(native-chat): keep the items-by-kind payload lookup's SQLite…
brennanb2025 Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/main-sync-fs-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@
1 src/main/windows/windows-process-table.ts
1 src/main/worker-thread-child-process/worker-thread-child-process.ts
2 src/main/worker-threads/forked-child-entry-path.ts
# Worker threads only: one append before a rare large post, so it survives the receiver aborting.
3 src/main/worker-threads/worker-large-send-log.ts
4 src/main/workspace-hooks/hooks.ts
10 src/main/workspace-hooks/issue-command-file.ts
1 src/main/workspaces/catalog/folder-repo-git-conversion.ts
Expand Down
4 changes: 4 additions & 0 deletions config/tsconfig.tc.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"../src/main/pi/rpc/options/rpc-model-schema.ts",
"../src/main/pi/rpc/options/rpc-model-options.ts",
"../src/main/worker-threads/worker-thread-spawn.ts",
"../src/main/worker-threads/worker-thread-roles.ts",
"../src/main/worker-threads/worker-send-ledger.ts",
"../src/main/worker-threads/worker-message-shape.ts",
"../src/main/worker-threads/worker-large-send-log.ts",
"../src/main/worker-threads/worker-thread-entry-path.ts",
"../src/shared/**/*",
"../mobile/src/worktree/agent-lineage/worktree-agent-child-rows.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export type AgentIdentityClient = {
function spawnAgentIdentityWorker(): WorkerRequestTransport {
// A missing entry fails the spawned worker, which the queue reports as unavailable.
return spawnWorkerThread(
resolveWorkerThreadEntryPath(currentWorkerEntryLayout(__dirname), WORKER_ENTRY_FILENAME)
resolveWorkerThreadEntryPath(currentWorkerEntryLayout(__dirname), WORKER_ENTRY_FILENAME),
{ name: 'orca-agent-identity' }
)
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/agent-hooks/identity/agent-identity-worker-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
type AgentIdentityWorkerResponse,
type ReverseLookupUnavailable
} from './agent-identity-worker-protocol'
import { installWorkerSendLedger } from '../../worker-threads/worker-send-ledger'

installWorkerSendLedger('orca-agent-identity')

/** Bump only with additive DDL below; a newer file opens read-only, never rebuilt. */
const SCHEMA_VERSION = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ it('answers unavailable when the worker cannot load, or is stopped while loading
const exited = (worker: Worker) => worker.threadId === -1
let maxLive = 0
const spawn = () => {
const worker = spawnWorkerThread(missing)
const worker = spawnWorkerThread(missing, { name: 'orca-agent-identity' })
workers.push(worker)
maxLive = Math.max(maxLive, workers.filter((spawned) => !exited(spawned)).length)
return worker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export function sessionSearchWorkerFactory() {
if (!existsSync(path)) {
throw new Error(`Session search worker entry not found: ${path}`)
}
return spawnWorkerThread(path, { resourceLimits: { maxOldGenerationSizeMb: 256 } })
return spawnWorkerThread(path, {
name: 'orca-session-search',
resourceLimits: { maxOldGenerationSizeMb: 256 }
})
}

export class SessionSearchOperationError extends Error {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import type {
SearchWorkerResponse,
SessionSearchSnapshotRow
} from './session-search-worker-protocol'
import { installWorkerSendLedger } from '../../worker-threads/worker-send-ledger'

installWorkerSendLedger('orca-session-search')

setActiveSink({
push: (trace) => parentPort?.postMessage({ id: 0, trace }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ vi.mock('./session-search-worker-client', async (importOriginal) => {
spawnWorkerThread(
`require(${JSON.stringify(loader)}); require(${JSON.stringify(entry)})`,
{
name: 'orca-session-search',
eval: true,
execArgv: ['--conditions=orca-source']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if (!isMainThread) {
})
} else {
// Keep stdin and the hard deadline responsive while SQLite blocks its worker.
const worker = spawnWorkerThread(__filename)
const worker = spawnWorkerThread(__filename, { name: 'orca-opencode-sqlite-reader' })
let activeId: number | null = null
let deadline: ReturnType<typeof setTimeout> | undefined
const stop = (code: number): never => process.exit(code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function defaultWorkerFactory(): Worker {
if (!existsSync(workerPath)) {
throw new Error(`OpenCode SQLite worker entry not found: ${workerPath}`)
}
return spawnWorkerThread(workerPath)
return spawnWorkerThread(workerPath, { name: 'orca-opencode-sqlite-reader' })
}

let sharedClient: OpenCodeSqliteWorkerClient | null = null
Expand Down
3 changes: 3 additions & 0 deletions src/main/backend/backend-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { dropE2eSpawnLogOutsideE2e } from '../startup/testing/e2e-spawn-log-env'
import { ignoreInheritedWslHostsGateState } from '../../shared/remote-runtime/wsl-hosts/wsl-host-internal-gate'
import type { createUsageService } from './usage-service'
import type { UsageWorktreeCatalog } from '../usage/usage-store-host'
import { installFatalSignalListenerGuard } from '../crash-reporting/fatal-signal-listener-guard'

// A fatal V8 trap must crash, never spin on a JS fault-signal listener.
installFatalSignalListenerGuard()
dropE2eSpawnLogOutsideE2e()
clearWindowsStdHandleInheritance()
installWindowsIsolatedSpawner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { parentPort, workerData } from 'node:worker_threads'
import { ClaudeHookService } from '../../../claude/hook-service'
import { provisionClaudeAccountProfile } from './claude-profile-setup'
import type { ClaudeProfileSetupJob } from './claude-profile-setup-worker'
import { installWorkerSendLedger } from '../../../worker-threads/worker-send-ledger'

installWorkerSendLedger('orca-claude-profile-setup')

if (!parentPort) {
throw new Error('Claude account setup must run on a worker thread')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function runClaudeProfileSetupInWorker(
timeoutMs = 60_000
): Promise<ClaudeProfileSetupReport> {
return new Promise((resolve, reject) => {
const worker = spawnWorkerThread(path, { workerData: job })
const worker = spawnWorkerThread(path, { name: 'orca-claude-profile-setup', workerData: job })
// Bound the wait for launches blocked on this setup.
const timer = setTimeout(() => {
reject(new Error('Claude account setup timed out'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
isClaudeConversationEntry,
type ClaudeForkCheckpoint
} from './claude-conversation-fork-boundary'
import { installWorkerSendLedger } from '../../worker-threads/worker-send-ledger'

installWorkerSendLedger('orca-claude-rewind-transcript')

export type ClaudeConversationForkWork = {
sourcePath: string
Expand Down
2 changes: 1 addition & 1 deletion src/main/claude/transcripts/claude-rewind-transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ export function spawnClaudeConversationWorker(workerData: unknown) {
const entry = installed
? installed
: new URL('./claude-conversation-fork-worker-entry.ts', import.meta.url)
return spawnWorkerThread(entry, { workerData })
return spawnWorkerThread(entry, { name: 'orca-claude-rewind-transcript', workerData })
}
74 changes: 74 additions & 0 deletions src/main/crash-reporting/fatal-signal-listener-guard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { spawnSync } from 'node:child_process'
import { EventEmitter } from 'node:events'
import { createRequire } from 'node:module'
import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
import { installFatalSignalListenerGuard } from './fatal-signal-listener-guard'

const require = createRequire(import.meta.url)
const loader = require.resolve('tsx/cjs')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const guard = resolve('src/main/crash-reporting/fatal-signal-listener-guard.ts')

/**
* A real process with the shipped proper-lockfile (signal-exit). A listener is the hang's
* precondition: when the trap is the thread's own instruction, its JS handler never runs. A raised
* SIGTRAP lets the loop run, so the exit alone can't tell; the listener count does.
*/
function trapWithShippedLockfile(order: 'guard-first' | 'lockfile-first'): {
signal: NodeJS.Signals | null
listeners: { trap: number; term: number }
} {
const child = spawnSync(
process.execPath,
[
'-e',
`require(${JSON.stringify(loader)})
const { installFatalSignalListenerGuard } = require(${JSON.stringify(guard)})
if (process.argv[1] === 'guard-first') installFatalSignalListenerGuard()
require('proper-lockfile')
if (process.argv[1] === 'lockfile-first') installFatalSignalListenerGuard()
process.stdout.write(JSON.stringify({
trap: process.listenerCount('SIGTRAP'),
term: process.listenerCount('SIGTERM')
}))
process.kill(process.pid, 'SIGTRAP')
setTimeout(() => process.exit(0), 2000)`,
order
],
{ encoding: 'utf8', timeout: 20_000 }
)
return { signal: child.signal, listeners: JSON.parse(child.stdout) }
}

describe('installFatalSignalListenerGuard', () => {
it('never holds a fault-signal listener, before or after install, keeping others', () => {
const target = new EventEmitter()
const noop = (): void => {}
target.on('SIGABRT', noop)
installFatalSignalListenerGuard(target)
// What signal-exit registers when proper-lockfile loads, through every registration API.
target.on('SIGTRAP', noop)
target.addListener('SIGABRT', noop)
target.once('SIGIOT', noop)
target.prependListener('SIGSYS', noop)
target.prependOnceListener('SIGSEGV', noop)
target.on('SIGTERM', noop)
target.once('SIGINT', noop)

for (const signal of ['SIGTRAP', 'SIGABRT', 'SIGIOT', 'SIGSYS', 'SIGSEGV']) {
expect(target.listenerCount(signal)).toBe(0)
}
expect(target.listenerCount('SIGTERM')).toBe(1)
expect(target.listenerCount('SIGINT')).toBe(1)
})

// Windows has no SIGTRAP to raise; the listener guard itself is covered above.
it.skipIf(process.platform === 'win32').each(['guard-first', 'lockfile-first'] as const)(
'proper-lockfile leaves no SIGTRAP listener, keeps its SIGTERM cleanup, and SIGTRAP kills (%s)',
(order) => {
const { signal, listeners } = trapWithShippedLockfile(order)
expect(listeners).toEqual({ trap: 0, term: 1 })
expect(signal).toBe('SIGTRAP')
}
)
})
52 changes: 52 additions & 0 deletions src/main/crash-reporting/fatal-signal-listener-guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { EventEmitter } from 'node:events'

/**
* Signals raised by the faulting instruction itself. A JS listener on one (signal-exit, loaded by
* proper-lockfile, adds SIGTRAP and SIGABRT) makes libuv's handler return to that instruction, so
* Chromium's fatal OOM trap re-fires forever at full CPU instead of crashing with a report.
* The listener itself never runs: the faulting thread never returns to the event loop.
*/
const SYNCHRONOUS_FAULT_SIGNALS = [
'SIGTRAP',
'SIGABRT',
'SIGIOT',
'SIGSYS',
'SIGILL',
'SIGBUS',
'SIGFPE',
'SIGSEGV'
] as const
const FAULT_SIGNALS: ReadonlySet<unknown> = new Set(SYNCHRONOUS_FAULT_SIGNALS)

const LISTENER_METHODS = [
'on',
'addListener',
'once',
'prependListener',
'prependOnceListener'
] as const

/**
* Drops these listeners and refuses new ones before Node starts libuv's handler for them. Bundled
* externals (proper-lockfile) load before entry code, so their listeners exist at install; dropping
* them restores the default action, which the crash reporter started later still catches.
*/
export function installFatalSignalListenerGuard(target: EventEmitter = process): void {
for (const signal of SYNCHRONOUS_FAULT_SIGNALS) {
target.removeAllListeners(signal)
}
for (const method of LISTENER_METHODS) {
const original = target[method]
Object.defineProperty(target, method, {
configurable: true,
writable: true,
value: function (
this: EventEmitter,
event: string | symbol,
listener: (...args: unknown[]) => void
): EventEmitter {
return FAULT_SIGNALS.has(event) ? this : original.call(this, event, listener)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import type {
ForeignSqliteReaderRequest,
ForeignSqliteReaderResponse
} from './foreign-sqlite-reader-protocol'
import { installWorkerSendLedger } from '../worker-threads/worker-send-ledger'

installWorkerSendLedger('orca-foreign-sqlite-reader')
Comment thread
brennanb2025 marked this conversation as resolved.
Resolved

// Keep OpenCode dispatch separate because SSH/WSL relays bundle it without the other readers.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function defaultWorkerFactory(): Worker {
if (!existsSync(workerPath)) {
throw new Error(`Foreign SQLite reader entry not found: ${workerPath}`)
}
return spawnWorkerThread(workerPath)
return spawnWorkerThread(workerPath, { name: 'orca-foreign-sqlite-reader' })
}

let sharedClient: ForeignSqliteReaderClient | null = null
Expand Down
12 changes: 12 additions & 0 deletions src/main/hang-watchdog/hang-observation-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ export type HangPowerReceipt = {
receivedAt: number
}
export type CompletedHangContext = { name: string; startedAt: number; completedAt: number }
/** What a worker last posted to its parent; a stuck receive names its sender here. */
export type HangWorkerSend = {
role: string
kind: string
items: number
bytes: number
depth: number
agoMs: number
heapUsedMB: number
}
export const MAX_HANG_WORKER_SENDS = 4
export type HangObservation = {
id: string
kind: 'heartbeat-stall' | 'watchdog-gap'
Expand All @@ -46,6 +57,7 @@ export type HangObservation = {
mainJs?: MainJsCapture
native?: NativeHangCapture
watchdogGap?: { observedAt: number; durationMs: number; snapshot: HangSnapshot | null }
workerSends?: HangWorkerSend[]
}
export type HangObservationCollection = {
version: 1
Expand Down
7 changes: 6 additions & 1 deletion src/main/hang-watchdog/hang-observations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
parseMainJsCapture,
parseNativeHangCapture
} from './hang-capture-codec'
import { parseHangWorkerSends } from './hang-worker-sends'
export { MACHINE_FIELDS, SNAPSHOT_FIELDS } from './hang-observation-schema'
export type {
HangSnapshot,
Expand Down Expand Up @@ -117,6 +118,7 @@ function parseObservation(value: unknown): HangObservation | null {
}
}
const gap = object(data.watchdogGap)
const workerSends = parseHangWorkerSends(data.workerSends)
return {
id: data.id,
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the fixed observation-kind allowlist above validates this string union.
Expand Down Expand Up @@ -146,9 +148,11 @@ function parseObservation(value: unknown): HangObservation | null {
snapshot: numericFields(gap.snapshot, SNAPSHOT_FIELDS)
}
}
: {})
: {}),
...(workerSends ? { workerSends } : {})
}
}

export function emptyHangObservations(): HangObservationCollection {
return { version: 1, observations: [], omitted: 0 }
}
Expand Down Expand Up @@ -221,6 +225,7 @@ export function retainHangObservation(
resolution: old.resolution ?? record.resolution,
machine: old.machine ?? record.machine,
completedSpans: old.completedSpans ?? record.completedSpans,
workerSends: old.workerSends ?? record.workerSends,
mainJs: record.mainJs
? {
...record.mainJs,
Expand Down
Loading
Loading