mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix: stabilize scheduled runs and background task tracking (#365)
* fix: stabilize scheduled runs and background task tracking * 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. * fix: hide finished background tasks and clip long dialog titles
This commit is contained in:
1 parent
e80016cc22
commit
304f636516
35 files changed
+4272
-254
No files matched your search
@@ -1,26 +1,54 @@
|
||||
import { useMemo } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { listShells, removeShell, type ShellInfo } from '@/api/opencode'
|
||||
import { listShells, removeShell } from '@/api/opencode'
|
||||
import { applyShellExit, recordShellExit, reconcileShellList, type ShellRecord } from '@/lib/backgroundWork'
|
||||
import { shellsQueryKey } from '@/lib/queryInvalidation'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
export function useSessionShells(sessionID: string | undefined, directory: string | undefined) {
|
||||
const query = useQuery({
|
||||
function useShellListQuery<TData = ShellRecord[]>(
|
||||
directory: string | undefined,
|
||||
enabled: boolean,
|
||||
select?: (shells: ShellRecord[]) => TData,
|
||||
) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useQuery<ShellRecord[], Error, TData>({
|
||||
queryKey: shellsQueryKey(directory),
|
||||
queryFn: () => listShells(directory ?? ''),
|
||||
enabled: Boolean(directory),
|
||||
queryFn: async (): Promise<ShellRecord[]> => {
|
||||
const fetchStartedAt = Date.now()
|
||||
const fetched = await listShells(directory ?? '')
|
||||
const existing = queryClient.getQueryData<ShellRecord[]>(shellsQueryKey(directory)) ?? []
|
||||
return reconcileShellList(existing, fetched, fetchStartedAt, directory ?? '')
|
||||
},
|
||||
enabled,
|
||||
staleTime: Infinity,
|
||||
select,
|
||||
})
|
||||
}
|
||||
|
||||
export function useSessionShells(sessionID: string | undefined, directory: string | undefined) {
|
||||
const query = useShellListQuery(directory, Boolean(directory))
|
||||
|
||||
const shells = useMemo(
|
||||
() =>
|
||||
(query.data ?? []).filter(
|
||||
(shell) => shell.status === 'running' && shell.metadata.sessionID === sessionID,
|
||||
),
|
||||
() => (query.data ?? []).filter((shell) => shell.metadata.sessionID === sessionID),
|
||||
[query.data, sessionID],
|
||||
)
|
||||
|
||||
return shells
|
||||
const listLoaded = query.isSuccess
|
||||
|
||||
return { shells, listLoaded }
|
||||
}
|
||||
|
||||
export function useShell(shellID: string | undefined, directory: string | undefined) {
|
||||
const query = useShellListQuery<ShellRecord | undefined>(
|
||||
directory,
|
||||
Boolean(directory && shellID),
|
||||
(shells) => shells.find((candidate) => candidate.id === shellID),
|
||||
)
|
||||
|
||||
const listLoaded = query.isSuccess
|
||||
|
||||
return { shell: query.data, listLoaded }
|
||||
}
|
||||
|
||||
export function useKillShell(directory: string | undefined) {
|
||||
@@ -29,8 +57,9 @@ export function useKillShell(directory: string | undefined) {
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => removeShell(id, directory ?? ''),
|
||||
onSuccess: (_result, id) => {
|
||||
queryClient.setQueryData<ShellInfo[]>(shellsQueryKey(directory), (current) =>
|
||||
current?.filter((shell) => shell.id !== id),
|
||||
recordShellExit(directory ?? '', { id, status: 'killed' })
|
||||
queryClient.setQueryData<ShellRecord[]>(shellsQueryKey(directory), (current) =>
|
||||
current && applyShellExit(current, { id, status: 'killed' }),
|
||||
)
|
||||
},
|
||||
onError: (error) => {
|
||||
|
||||
Reference in new issue
Block a user