fix(sessions): address background activity review feedback

- keep shell state changed by events that arrive while a shell snapshot is in
  flight, so an exited shell is not restored and a new one is not dropped
- resolve session ancestry for the owners of running shells and for new shells
- follow already-known parent links when resolving ancestry
- sync running shells for repository directories added after the stream connects
- announce session and background activity to screen readers from the prompt bar
This commit is contained in:
Chris Scott committed 2026-10-12 01:08:58 +00:00
1 parent 5dbf9766a5
commit aec94db9fb
6 files changed
+384 -42

No files matched your search

@@ -33,6 +33,7 @@ const mocks = vi.hoisted(() => ({
useUserBash: vi.fn(),
useSessionAgentStore: vi.fn(),
useSendErrorStore: vi.fn(),
useHasBackgroundActivity: vi.fn(),
}))
const suggestionProps = vi.hoisted(() => ({ isOpen: false, selectedIndex: 0 }))
@@ -66,6 +67,10 @@ vi.mock('@/hooks/useSessionAgent', () => ({ useSessionAgent: mocks.useSessionAge
vi.mock('@/stores/userBashStore', () => ({ useUserBash: mocks.useUserBash }))
vi.mock('@/stores/sessionAgentStore', () => ({ useSessionAgentStore: mocks.useSessionAgentStore }))
vi.mock('@/stores/sendErrorStore', () => ({ useSendErrorStore: mocks.useSendErrorStore }))
vi.mock('@/stores/sessionStatusStore', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/stores/sessionStatusStore')>()
return { ...actual, useHasBackgroundActivity: mocks.useHasBackgroundActivity }
})
vi.mock('@/lib/toast', () => ({ showToast: mocks.showToast }))
vi.mock('@/contexts/EventContext', () => ({
@@ -206,6 +211,7 @@ describe('PromptInput command submission', () => {
mocks.useUserBash.mockImplementation((selector: (state: unknown) => unknown) => selector({ addUserBashCommand: vi.fn() }))
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: mocks.setAgent }))
mocks.useSendErrorStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ errors: {} }))
mocks.useHasBackgroundActivity.mockReturnValue(false)
suggestionProps.isOpen = false
suggestionProps.selectedIndex = 0
})
@@ -243,6 +249,27 @@ describe('PromptInput command submission', () => {
other.remove()
})
it('announces session activity changes to screen readers', async () => {
const queryClient = createTestQueryClient()
queryClient.setQueryData(['opencode', 'session', 'test-session', '/test'], sessionInfo())
const buildPrompt = (props: { isSessionActive?: boolean }) => (
<QueryClientProvider client={queryClient}>
<PromptInput {...defaultProps} {...props} />
</QueryClientProvider>
)
const { rerender } = render(buildPrompt({}))
await screen.findByPlaceholderText('Send a message...')
expect(screen.getByRole('status').textContent).toBe('')
rerender(buildPrompt({ isSessionActive: true }))
expect(screen.getByRole('status')).toHaveTextContent('Session working')
mocks.useHasBackgroundActivity.mockReturnValue(true)
rerender(buildPrompt({}))
expect(screen.getByRole('status')).toHaveTextContent('Background tasks running')
})
it('disables submit and does not run a command while the model is not ready', async () => {
mocks.useModelSelection.mockReturnValue({
model: null,
@@ -1473,8 +1473,17 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
const sessionActivityAnnouncement = isSessionActive
? 'Session working'
: hasBackgroundActivity
? 'Background tasks running'
: ''
return (
<div className={`relative isolate border border-border dark:border-border/30 rounded-xl p-2 md:p-3 mb-4 md:mb-1 w-full before:pointer-events-none before:absolute before:-inset-px before:-z-10 before:rounded-xl before:bg-background/95 before:backdrop-blur-md before:content-[''] ${hasPendingPermissionForSession ? 'border-highlight/50 ring-1 ring-highlight/30' : composerModeStyle?.frame ?? ''} ${isTakeoverOpen ? 'z-[60]' : ''}`}>
<div role="status" aria-live="polite" className="sr-only">
{sessionActivityAnnouncement}
</div>
{composerModeStyle && (
<span
data-testid="composer-mode-badge"