fix(desktop): prevent background tile reconcile from starving pool slots (#103375)
Passive tile reconciles (reconcileTileTranscripts on every sessions.changed tick) were cold-starting pooled backends for every open bot tile, including hidden ones, and holding each spawned slot for its lifetime via the 10s touch loop. With 15-20+ profiles this permanently saturated the Warm Bot Backends pool so interactive opens timed out. Add a passive read intent: getLatestSessionMessages now accepts a passive flag forwarded as HermesApiRequest.passive. The Electron main process honors it by serving only already-warm pool entries and failing fast otherwise, without spawning or bumping lastActiveAt. reconcileTileTranscripts uses passive reads so background refresh never consumes a pool slot; interactive opens keep the normal spawn path.
This commit is contained in:
@@ -16590,6 +16590,32 @@ async function dispatchRegistryApiRequest(
|
||||
routeProfile = request?.profile,
|
||||
requestProfile = request?.profile
|
||||
) {
|
||||
// Passive tile reconcile must never cold-start a pooled backend (#103375):
|
||||
// fail fast when no warm entry exists instead of spawning a child and
|
||||
// starving the pool. Interactive opens (passive:false) keep the normal spawn.
|
||||
if (request?.passive) {
|
||||
const poolKey = backendScopeKey(registryConnectionId, routeProfile)
|
||||
const entry = backendPool.get(poolKey)
|
||||
|
||||
if (!entry) {
|
||||
throw new Error(`Passive read: no warm backend for "${poolKey}"`)
|
||||
}
|
||||
|
||||
const connection = await entry.connectionPromise
|
||||
const requestPath = pathForRegistryBackendRequest(request.path, requestProfile, connection)
|
||||
|
||||
const response = await fetchJsonForBackend(connection, requestPath, {
|
||||
method: request?.method,
|
||||
body: request?.body,
|
||||
upload: request?.upload,
|
||||
timeoutMs: resolveTimeoutMs(request?.timeoutMs, DEFAULT_FETCH_TIMEOUT_MS)
|
||||
})
|
||||
|
||||
return (request?.method || 'GET').toUpperCase() === 'GET'
|
||||
? tagRegistrySessionResponse(requestPath, response, registryConnectionId)
|
||||
: response
|
||||
}
|
||||
|
||||
// Claim-guarded (#90812): every registry-scoped REST call funnels through
|
||||
// here, so it can race a renderer's own WS reconnect dial for the same
|
||||
// (connectionId, profile) scope; coalescing avoids bootstrapping a second
|
||||
@@ -16681,7 +16707,26 @@ async function handleHermesApiRequest(request) {
|
||||
let response
|
||||
|
||||
try {
|
||||
const connection = await ensureBackend(routeProfile)
|
||||
// Passive reads (tile reconciles) must not spawn pool backends (#103375).
|
||||
// If the target is pooled and has no warm entry, fail fast without
|
||||
// consuming a slot; interactive reads keep the normal ensureBackend path.
|
||||
// Primary route (backendProfile === null) always has a backend (startHermes).
|
||||
const isPassivePooled = Boolean(request?.passive && routeProfile && apiRoute.backendProfile)
|
||||
|
||||
let connection
|
||||
|
||||
if (isPassivePooled) {
|
||||
const key = String(routeProfile).trim()
|
||||
const entry = backendPool.get(key) || backendPool.get(backendScopeKey(null, key))
|
||||
|
||||
if (!entry) {
|
||||
throw new Error(`Passive read: no warm backend for profile "${key}"`)
|
||||
}
|
||||
|
||||
connection = await entry.connectionPromise
|
||||
} else {
|
||||
connection = await ensureBackend(routeProfile)
|
||||
}
|
||||
const timeoutMs = resolveTimeoutMs(request?.timeoutMs, DEFAULT_FETCH_TIMEOUT_MS)
|
||||
|
||||
const url = `${connection.baseUrl}${apiRoute.requestPath}`
|
||||
|
||||
@@ -396,7 +396,8 @@ export function getSession(id: string, profile?: ProfileScope): Promise<SessionI
|
||||
export function getSessionMessages(
|
||||
id: string,
|
||||
profile?: ProfileScope,
|
||||
page: { limit?: number; offset?: number; order?: 'latest' | 'oldest'; includeCompacted?: boolean } = {}
|
||||
page: { limit?: number; offset?: number; order?: 'latest' | 'oldest'; includeCompacted?: boolean } = {},
|
||||
options: { passive?: boolean } = {}
|
||||
): Promise<SessionMessagesResponse> {
|
||||
const query = new URLSearchParams()
|
||||
|
||||
@@ -426,7 +427,8 @@ export function getSessionMessages(
|
||||
|
||||
return hermesApi<SessionMessagesResponse>({
|
||||
...sessionScope,
|
||||
path: `/api/sessions/${encodeURIComponent(id)}/messages${suffix}`
|
||||
path: `/api/sessions/${encodeURIComponent(id)}/messages${suffix}`,
|
||||
...(options.passive ? { passive: true } : {})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -439,15 +441,20 @@ export function getSessionMessages(
|
||||
*/
|
||||
export const LATEST_SESSION_MESSAGES_LIMIT = 120
|
||||
|
||||
export function getLatestSessionMessages(id: string, profile?: ProfileScope): Promise<SessionMessagesResponse> {
|
||||
export function getLatestSessionMessages(id: string, profile?: ProfileScope, passive = false): Promise<SessionMessagesResponse> {
|
||||
// includeCompacted: durable display history must include rows preserved by
|
||||
// in-place compaction (active=0, compacted=1); without them the transcript
|
||||
// silently ends at the compaction boundary and earlier turns are unreachable.
|
||||
return getSessionMessages(id, profile, {
|
||||
limit: LATEST_SESSION_MESSAGES_LIMIT,
|
||||
order: 'latest',
|
||||
includeCompacted: true
|
||||
}).then(page => {
|
||||
return getSessionMessages(
|
||||
id,
|
||||
profile,
|
||||
{
|
||||
limit: LATEST_SESSION_MESSAGES_LIMIT,
|
||||
order: 'latest',
|
||||
includeCompacted: true
|
||||
},
|
||||
passive ? { passive: true } : {}
|
||||
).then(page => {
|
||||
// Record whether the tail was truncated (page came back full) and where
|
||||
// the next older page starts, so "Show earlier" can backfill over REST
|
||||
// (app/chat/transcript-backfill). Keyed under both the requested id and
|
||||
|
||||
@@ -160,7 +160,7 @@ export async function reconcileTileTranscripts({
|
||||
const signatureKey = tileTranscriptSignatureKey(tile)
|
||||
|
||||
try {
|
||||
const latest = await getLatestSessionMessages(storedSessionId, profileScope)
|
||||
const latest = await getLatestSessionMessages(storedSessionId, profileScope, true)
|
||||
|
||||
if (
|
||||
requestId !== requestSequenceRef.current ||
|
||||
|
||||
Vendored
+5
@@ -1238,6 +1238,11 @@ export interface HermesApiRequest {
|
||||
// through the owning connection, not the local profile pool. Omit / '' to
|
||||
// keep the legacy profile-routed path; explicit 'local' forces this device.
|
||||
connectionId?: string | null
|
||||
// Passive background read that must never cold-start a pooled backend (#103375).
|
||||
// When true and the target profile has no warm pool entry, the main process
|
||||
// fails fast without spawning a child or consuming a pool slot, so background
|
||||
// tile reconciles cannot starve interactive opens.
|
||||
passive?: boolean
|
||||
}
|
||||
|
||||
export interface HermesPreviewTarget {
|
||||
|
||||
Reference in New Issue
Block a user