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:
Chris Scott authored and GitHub committed 2026-09-28 23:55:01 -04:00
1 parent e80016cc22
commit 304f636516
35 files changed
+4272 -254

No files matched your search

@@ -1,5 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { render as rtlRender, screen, fireEvent } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import type { ReactElement } from 'react'
import { MessageThread } from './MessageThread'
import { useUIState } from '@/stores/uiStateStore'
import { applySessionEvent, emptySessionTranscript } from '@/lib/session-projection'
@@ -47,6 +49,12 @@ vi.mock('@/hooks/useTTS', () => ({
}),
}))
vi.mock('@/api/opencode', async (importOriginal) => ({
...(await importOriginal<typeof import('@/api/opencode')>()),
getSession: () => new Promise(() => {}),
listShells: () => Promise.resolve([]),
}))
interface MockSettingsReturn {
preferences: {
simpleChatMode: boolean
@@ -63,6 +71,11 @@ const setupSettings = (preferences: MockSettingsReturn['preferences']) => {
})
}
const render = (ui: ReactElement) => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
return rtlRender(<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>)
}
const project = (events: V2Event[]): SessionMessageInfo[] =>
events.reduce(applySessionEvent, emptySessionTranscript).messages
@@ -191,6 +204,43 @@ describe('MessageThread', () => {
expect(onChildSessionClick).toHaveBeenCalledWith('child-1')
})
it('resolves a background shell tool from its completion notice', () => {
setupSettings({ simpleChatMode: false, showReasoning: false })
const messages: SessionMessageInfo[] = [
userMessage('1', 'Hello'),
assistantMessage('2', [
{
type: 'tool',
id: 'tool_shell',
name: 'shell',
state: {
status: 'completed',
input: { command: 'npm run dev' },
content: [{ type: 'text', text: 'started in the background' }],
metadata: { status: 'running', shellID: 'sh_notice' },
},
time: { created: Date.now(), completed: Date.now() + 100 },
},
]),
{
id: 'syn-shell',
type: 'synthetic',
text: '',
metadata: { source: 'shell', shellID: 'sh_notice', state: 'completed', exit: 0 },
time: { created: Date.now() },
},
]
const { container } = render(
<MessageThread sessionID="test-session" messages={messages} pending={[]} />,
)
expect(screen.getByText('completed')).toBeInTheDocument()
expect(screen.queryByText('unavailable')).not.toBeInTheDocument()
expect(container.querySelector('.animate-spin')).toBeNull()
})
it('renders a synthetic message that only carries text', () => {
setupSettings({ simpleChatMode: false, showReasoning: false })