fix(sandbox): guard enable path and harden UI rendering performance (#341)

* fix(sandbox): guard enable path and harden UI rendering performance

* chore(deps): allow esbuild postinstall in pnpm onlyBuiltDependencies

* fix(sandbox): align availability reporting and address PR review feedback

* fix(sandbox): block planning without process attestation
This commit is contained in:
Chris Scott authored and GitHub committed 2026-08-27 08:58:23 -04:00
1 parent ba8e8f4b29
commit d63198ec8a
19 files changed
+501 -82

No files matched your search

@@ -528,4 +528,49 @@ describe('EventProvider questions', () => {
expect(screen.getByTestId('healthy')).toHaveTextContent('false')
})
})
it('does not re-render consumers for health notifications that only change lastEventAt', async () => {
let onHealthChange: (state: { isConnected: boolean; isHealthy: boolean; lastEventAt: number | null; isStalled: boolean }) => void = () => {}
mocks.subscribeGlobalMonitor.mockImplementation(({ onHealthChange: handler }) => {
onHealthChange = handler
return {
dispose: vi.fn(),
updateDirectories: vi.fn(),
reconnect: vi.fn(),
reportVisibility: vi.fn(),
}
})
let renderCount = 0
const Probe = () => {
renderCount += 1
const { isConnected } = useSSEHealth()
return <div data-testid="probe-connected">{String(isConnected)}</div>
}
render(<Probe />, { wrapper: createWrapper() })
await waitFor(() => {
expect(screen.getByTestId('probe-connected')).toHaveTextContent('false')
})
const initialRenderCount = renderCount
act(() => {
onHealthChange({ isConnected: true, isHealthy: true, lastEventAt: 1, isStalled: false })
})
await waitFor(() => {
expect(screen.getByTestId('probe-connected')).toHaveTextContent('true')
})
const afterBooleanChange = renderCount
act(() => {
onHealthChange({ isConnected: true, isHealthy: true, lastEventAt: 2, isStalled: false })
onHealthChange({ isConnected: true, isHealthy: true, lastEventAt: 3, isStalled: false })
})
expect(afterBooleanChange).toBe(initialRenderCount + 1)
expect(renderCount).toBe(afterBooleanChange)
})
})
+18 -5
View File
@@ -13,6 +13,7 @@ import { invalidateRepoGitCachesDebounced } from '@/lib/queryInvalidation'
type PermissionsBySession = Record<string, PermissionRequest[]>
type QuestionsBySession = Record<string, QuestionRequest[]>
type SSEHealthState = Pick<EventStreamHealthState, 'isConnected' | 'isHealthy' | 'isStalled'>
type SessionScopedItem = { id: string; sessionID: string }
@@ -163,7 +164,7 @@ interface EventContextValue {
navigateToCurrent: () => void
syncForSession: (directory: string, sessionID: string) => Promise<void>
}
sseHealth: EventStreamHealthState
sseHealth: SSEHealthState
getRepoIdForSession: (sessionID: string) => number | null
getClient: (sessionID: string) => OpenCodeClient | null
}
@@ -175,7 +176,10 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
const navigate = useNavigate()
const [sshHostKeyRequest, setSSHHostKeyRequest] = useState<SSHHostKeyRequest | null>(null)
const [sseHealth, setSseHealth] = useState<EventStreamHealthState>(() => openCodeEventStream.getHealth())
const [sseHealth, setSseHealth] = useState<SSEHealthState>(() => {
const { isConnected, isHealthy, isStalled } = openCodeEventStream.getHealth()
return { isConnected, isHealthy, isStalled }
})
const respondToSSHHostKey = useCallback(async (requestId: string, approved: boolean) => {
try {
@@ -187,6 +191,15 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
}
}, [])
const handleHealthChange = useCallback((next: EventStreamHealthState) => {
setSseHealth((prev) => {
if (prev.isConnected === next.isConnected && prev.isHealthy === next.isHealthy && prev.isStalled === next.isStalled) {
return prev
}
return { isConnected: next.isConnected, isHealthy: next.isHealthy, isStalled: next.isStalled }
})
}, [])
const [permissionsBySession, setPermissionsBySession] = useState<PermissionsBySession>({})
const [questionsBySession, setQuestionsBySession] = useState<QuestionsBySession>({})
const [showPermissionDialog, setShowPermissionDialog] = useState(true)
@@ -552,7 +565,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
directories: initialDirectories,
onEvent: handleSSEMessage,
onStatusChange: handleStatusChange,
onHealthChange: setSseHealth,
onHealthChange: handleHealthChange,
})
subscriptionRef.current = subscription
@@ -560,7 +573,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
subscription.dispose()
subscriptionRef.current = null
}
}, [addPermission, removePermission, addQuestion, removeQuestion, rememberSessionDirectory, fetchInitialPendingData, queryClient, setSseHealth])
}, [addPermission, removePermission, addQuestion, removeQuestion, rememberSessionDirectory, fetchInitialPendingData, queryClient, handleHealthChange])
useEffect(() => {
reposRef.current = repos
@@ -658,6 +671,6 @@ export function useQuestions() {
return questions
}
export function useSSEHealth(): EventStreamHealthState {
export function useSSEHealth(): SSEHealthState {
return useEventContext().sseHealth
}