chore(runtime): keep liveness broker under line limit

This commit is contained in:
Jinwoo-H
2026-08-23 22:49:23 -04:00
parent 0cd915e824
commit 1396777e8a
2 changed files with 33 additions and 21 deletions
@@ -0,0 +1,31 @@
import type { PtyProcessEvidenceEntry } from './pty-process-liveness-broker-types'
import type { PtyProcessLivenessEvidence } from './pty-process-inspection'
export function waitForPtyProcessProbe(
entries: ReadonlyMap<string, PtyProcessEvidenceEntry>,
ptyId: string,
entry: PtyProcessEvidenceEntry,
timeoutMs: number | null
): Promise<PtyProcessLivenessEvidence> {
const probe = entry.probe
if (!probe) {
return Promise.resolve(
entry.evidence ?? { status: 'unverifiable', reason: 'process inspection unavailable' }
)
}
if (timeoutMs === null) {
return probe
}
return new Promise((resolve) => {
const timeout = setTimeout(() => {
if (entries.get(ptyId) === entry && entry.probe === probe) {
entry.timedOut = true
}
resolve({ status: 'unverifiable', reason: 'process inspection timed out' })
}, timeoutMs)
void probe.then((evidence) => {
clearTimeout(timeout)
resolve(evidence)
})
})
}
@@ -16,6 +16,7 @@ import type {
PtyProcessEvidenceEntry,
PtyProcessLivenessBrokerOptions
} from './pty-process-liveness-broker-types'
import { waitForPtyProcessProbe } from './pty-process-liveness-broker-wait'
export type { PtyProcessLivenessBrokerOptions } from './pty-process-liveness-broker-types'
export type {
PtyProcessInspectionSource,
@@ -263,27 +264,7 @@ export class PtyProcessLivenessBroker {
entry: PtyProcessEvidenceEntry,
timeoutMs: number | null
): Promise<PtyProcessLivenessEvidence> {
const probe = entry.probe
if (!probe) {
return Promise.resolve(
entry.evidence ?? { status: 'unverifiable', reason: 'process inspection unavailable' }
)
}
if (timeoutMs === null) {
return probe
}
return new Promise((resolve) => {
const timeout = setTimeout(() => {
if (this.entries.get(ptyId) === entry && entry.probe === probe) {
entry.timedOut = true
}
resolve({ status: 'unverifiable', reason: 'process inspection timed out' })
}, timeoutMs)
void probe.then((evidence) => {
clearTimeout(timeout)
resolve(evidence)
})
})
return waitForPtyProcessProbe(this.entries, ptyId, entry, timeoutMs)
}
private unavailableBackoffMs(failureCount: number): number {
const base = this.options.unavailableBackoffBaseMs ?? DEFAULT_UNAVAILABLE_BACKOFF_BASE_MS