mirror of
https://github.com/stablyai/orca.git
synced 2026-10-23 08:03:39 +00:00
chore(runtime): keep liveness broker under line limit
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user