mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix: complete scheduled runs and harden background task status
- Route directory-less OpenCode session events (session.execution.*, session.usage.updated) to backend listeners by remembering each session's directory in the SSE aggregator, so scheduled runs finish and failure push notifications fire; browser delivery is unchanged. - Resolve background shell status from the transcript completion notice when OpenCode no longer lists the shell, keep the first terminal status so a kill is not reported as completed, and share one status icon and colour mapping between the transcript and background bar. - Reconcile child sessions only while unknown or running, trigger it from the EventProvider alone, refresh children that drop to unknown after a poll, and forget deleted sessions. - Fetch the model list and default concurrently while waiting for the schedule model, share configured-model selection, and consolidate schedule startup cancellation cleanup. - Reduce background work re-renders, prune shell exit records, remove dead exports, and document background work in the chat guide.
This commit is contained in:
1 parent
a75d86c339
commit
409f2c4999
31 files changed
+1197
-279
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import type { ConfigEntry, ModelInfo, ModelRef } from '@opencode-manager/shared/opencode'
|
||||
import { formatOpenCodeModelRef, openCodeLocation, parseOpenCodeModelRef } from '@opencode-manager/shared/opencode'
|
||||
import type { ModelInfo, ModelRef } from '@opencode-manager/shared/opencode'
|
||||
import { formatOpenCodeModelRef, openCodeLocation, parseOpenCodeModelRef, selectConfiguredModelRef } from '@opencode-manager/shared/opencode'
|
||||
import type { OpenCodeClient } from './opencode/client'
|
||||
|
||||
export interface ResolvedOpenCodeModel {
|
||||
@@ -17,8 +17,6 @@ export interface ResolveOpenCodeModelOptions {
|
||||
export const MODEL_LOAD_TIMEOUT_MS = 15_000
|
||||
export const MODEL_LOAD_POLL_MS = 500
|
||||
|
||||
type ConfigDocumentModel = Extract<ConfigEntry, { type: 'document' }>['info']['model']
|
||||
|
||||
function normalizeModelCandidate(model: string | null | undefined): string | null {
|
||||
if (!model) {
|
||||
return null
|
||||
@@ -70,22 +68,6 @@ function resolveFromLoadedModels(
|
||||
return fallback ? toResolvedModel({ providerID: fallback.providerID, id: fallback.id }) : null
|
||||
}
|
||||
|
||||
function toConfiguredRef(model: ConfigDocumentModel): ModelRef | undefined {
|
||||
if (!model) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (typeof model === 'string') {
|
||||
return parseOpenCodeModelRef(model)
|
||||
}
|
||||
|
||||
return {
|
||||
providerID: model.providerID,
|
||||
id: model.model,
|
||||
...(model.variant ? { variant: model.variant } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms: number, signal: AbortSignal): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
if (signal.aborted) {
|
||||
@@ -154,11 +136,7 @@ async function readConfiguredRef(
|
||||
signal: AbortSignal,
|
||||
): Promise<ModelRef | undefined> {
|
||||
const entries = await client.api.config.get(location, { signal })
|
||||
const model = entries.reduce<ConfigDocumentModel>(
|
||||
(current, entry) => (entry.type === 'document' && entry.info.model ? entry.info.model : current),
|
||||
undefined,
|
||||
)
|
||||
return toConfiguredRef(model)
|
||||
return selectConfiguredModelRef(entries)
|
||||
}
|
||||
|
||||
export async function resolveOpenCodeModel(
|
||||
@@ -193,31 +171,30 @@ export async function resolveOpenCodeModel(
|
||||
break
|
||||
}
|
||||
|
||||
const listResult = await runPollingRequest(
|
||||
() => client.api.model.list(location, { signal }),
|
||||
external,
|
||||
timeoutController.signal,
|
||||
)
|
||||
if (!listResult.ok) {
|
||||
break
|
||||
}
|
||||
models = listResult.value.data
|
||||
const [listResult, defaultResult] = await Promise.all([
|
||||
runPollingRequest(
|
||||
() => client.api.model.list(location, { signal }),
|
||||
external,
|
||||
timeoutController.signal,
|
||||
),
|
||||
runPollingRequest(
|
||||
() => client.api.model.default(location, { signal }),
|
||||
external,
|
||||
timeoutController.signal,
|
||||
),
|
||||
])
|
||||
|
||||
external?.throwIfAborted()
|
||||
|
||||
if (timeoutController.signal.aborted) {
|
||||
break
|
||||
if (listResult.ok) {
|
||||
models = listResult.value.data
|
||||
}
|
||||
|
||||
const defaultResult = await runPollingRequest(
|
||||
() => client.api.model.default(location, { signal }),
|
||||
external,
|
||||
timeoutController.signal,
|
||||
)
|
||||
if (!defaultResult.ok) {
|
||||
if (defaultResult.ok) {
|
||||
defaultModel = defaultResult.value.data
|
||||
}
|
||||
|
||||
if (!listResult.ok || !defaultResult.ok) {
|
||||
break
|
||||
}
|
||||
defaultModel = defaultResult.value.data
|
||||
|
||||
external?.throwIfAborted()
|
||||
|
||||
|
||||
Reference in new issue
Block a user