mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-03 06:47:03 +00:00
Cursor ACP sessions can fail mid-turn with a transient model error that the agent reports inline rather than as an RPC rejection. HAPI treated those turns as successful, so the session went quiet with no banner, no push, and no way to resume without retyping the prompt. This adds the full path: - detect: classify inline/stderr model errors from the Cursor ACP stream, requiring strong signatures before typing a failure as a model error - surface: persist `lastModelError` on session metadata; render a chat banner and a session-list indicator, with the prompt text kept out of list/SSE summaries so they never ship up to 32 KB of user prompt - notify: deliver a push for an unacknowledged error, watermarked on the hub copy so a restart does not re-page the same eventId - bridge & retry: offer a one-shot recovery prompt that replays the failed turn, bound to the originating eventId and gated so a real user turn always supersedes it. Auto-bridge is opt-in and defaults to OFF, persisted in hub settings and fanned out to live Cursor CLIs. Re-cut onto current upstream/main. The branch had accumulated 108 iterative hardening commits against a 289-commit-older base; replaying them individually would have re-resolved the same conflicts ~100 times. The pre-re-cut tip was 2c28a1365 if the granular history is ever needed. Absorbing upstream required adapting to three refactors that landed meanwhile: - `MessageQueue2` grew an `internal?: boolean` control-message flag upstream while this branch added richer `internal` provenance. Unified on a tagged `QueueItemInternal` union (`control` | `model-error-bridge`) so one field carries one concept. `hasPendingNonBridgeTurn()` now treats *any* internal item as non-user: otherwise a queued `/auto-review` control slash would have counted as a user turn and wrongly superseded a live bridge. - `AcpSdkBackend.prompt()` gained a `timing` callback upstream; merged it with this branch's `shouldSend` gate into a single options object. - The hub settings route moved to a unified `updateSettings` transaction. `autoBridgeTransientModelErrors` is applied outside that transaction because SyncEngine owns its CLI fan-out and rollback under its own lock. via [HAPI](https://hapi.run) Co-authored-by: HAPI <noreply@hapi.run>
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
canShowModelErrorBridge,
|
||||
getModelErrorUiState,
|
||||
hasActiveModelError,
|
||||
hasRecoveredModelError,
|
||||
hasUrgentModelError,
|
||||
isBridgeSettling,
|
||||
shouldKeepPendingBridge,
|
||||
visibleBridgeFailureReason,
|
||||
type ModelErrorHolder
|
||||
} from './ModelErrorBanner'
|
||||
import { getEventPresentation } from '@/chat/presentation'
|
||||
|
||||
function holder(partial: NonNullable<ModelErrorHolder['lastModelError']>): ModelErrorHolder {
|
||||
return { lastModelError: partial }
|
||||
}
|
||||
|
||||
describe('model error UI states', () => {
|
||||
const base = {
|
||||
eventId: 'evt-1000',
|
||||
kind: 'transport_closed',
|
||||
transient: true,
|
||||
rawSnippet: 'WritableIterable is closed',
|
||||
atTs: 1000,
|
||||
priorAssistantClaimsDone: false
|
||||
}
|
||||
|
||||
it('treats unacked unrecovered errors as urgent', () => {
|
||||
const metadata = holder(base)
|
||||
expect(getModelErrorUiState(metadata)).toBe('unrecovered')
|
||||
expect(hasUrgentModelError(metadata)).toBe(true)
|
||||
expect(hasRecoveredModelError(metadata)).toBe(false)
|
||||
expect(canShowModelErrorBridge(metadata)).toBe(true)
|
||||
})
|
||||
|
||||
it('treats bridged errors as recovered (not urgent)', () => {
|
||||
const metadata = holder({ ...base, bridgedForEventId: 'evt-1000' })
|
||||
expect(getModelErrorUiState(metadata)).toBe('recovered')
|
||||
expect(hasUrgentModelError(metadata)).toBe(false)
|
||||
expect(hasRecoveredModelError(metadata)).toBe(true)
|
||||
expect(hasActiveModelError(metadata)).toBe(true)
|
||||
expect(canShowModelErrorBridge(metadata)).toBe(false)
|
||||
})
|
||||
|
||||
it('treats retriedAndFailed as bridge_failed / urgent', () => {
|
||||
const metadata = holder({ ...base, bridgedForEventId: 'evt-1000', retriedAndFailed: true })
|
||||
expect(getModelErrorUiState(metadata)).toBe('bridge_failed')
|
||||
expect(hasUrgentModelError(metadata)).toBe(true)
|
||||
expect(canShowModelErrorBridge(metadata)).toBe(false)
|
||||
})
|
||||
|
||||
it('hides acknowledged errors', () => {
|
||||
const metadata = holder({ ...base, acknowledgedAt: 2000 })
|
||||
expect(getModelErrorUiState(metadata)).toBeNull()
|
||||
expect(hasActiveModelError(metadata)).toBe(false)
|
||||
})
|
||||
|
||||
it('hides Bridge when a newer turn superseded the error', () => {
|
||||
const metadata = holder({ ...base, supersededByUserTurn: true })
|
||||
expect(getModelErrorUiState(metadata)).toBe('unrecovered')
|
||||
expect(canShowModelErrorBridge(metadata)).toBe(false)
|
||||
})
|
||||
|
||||
it('hides Bridge when bridgeable is explicitly false', () => {
|
||||
const metadata = holder({ ...base, bridgeable: false })
|
||||
expect(getModelErrorUiState(metadata)).toBe('unrecovered')
|
||||
expect(canShowModelErrorBridge(metadata)).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps Bridge settling after enqueue until metadata records an outcome', () => {
|
||||
const unrecovered = holder(base)
|
||||
expect(isBridgeSettling(unrecovered, 'evt-1000')).toBe(true)
|
||||
expect(isBridgeSettling(unrecovered, 'evt-other')).toBe(false)
|
||||
expect(isBridgeSettling(holder({ ...base, bridgedForEventId: 'evt-1000' }), 'evt-1000')).toBe(false)
|
||||
expect(isBridgeSettling(holder({ ...base, retriedAndFailed: true }), 'evt-1000')).toBe(false)
|
||||
expect(isBridgeSettling(holder({ ...base, supersededByUserTurn: true }), 'evt-1000')).toBe(false)
|
||||
expect(isBridgeSettling(holder({ ...base, acknowledgedAt: 2000 }), 'evt-1000')).toBe(false)
|
||||
expect(isBridgeSettling(unrecovered, null)).toBe(false)
|
||||
})
|
||||
|
||||
it('scopes a Bridge failure reason to the requested eventId', () => {
|
||||
const failure = { eventId: 'evt-1000', reason: 'not_bridgeable' }
|
||||
expect(visibleBridgeFailureReason(failure, 'evt-1000')).toBe('not_bridgeable')
|
||||
expect(visibleBridgeFailureReason(failure, 'evt-2000')).toBeNull()
|
||||
expect(visibleBridgeFailureReason(null, 'evt-1000')).toBeNull()
|
||||
})
|
||||
|
||||
it('drops local Bridge pending across a session disconnect', () => {
|
||||
expect(shouldKeepPendingBridge(true, true)).toBe(true)
|
||||
expect(shouldKeepPendingBridge(false, true)).toBe(false)
|
||||
expect(shouldKeepPendingBridge(true, false)).toBe(false)
|
||||
})
|
||||
|
||||
it('drops local Bridge pending after Abort even while still active and unrecovered', () => {
|
||||
expect(shouldKeepPendingBridge(true, true, true)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('model error chat event labels', () => {
|
||||
it('renders modelError and modelErrorBridged labels', () => {
|
||||
expect(getEventPresentation({
|
||||
type: 'modelError',
|
||||
kind: 'transport_closed',
|
||||
transient: true
|
||||
} as never).text).toContain('transport_closed')
|
||||
|
||||
expect(getEventPresentation({
|
||||
type: 'modelErrorBridged',
|
||||
kind: 'transport_closed',
|
||||
auto: true,
|
||||
eventId: 'evt-1'
|
||||
} as never).text).toContain('auto-bridged')
|
||||
|
||||
expect(getEventPresentation({
|
||||
type: 'modelErrorBridged',
|
||||
kind: 'transport_closed',
|
||||
auto: false,
|
||||
eventId: 'evt-1'
|
||||
} as never).text).toMatch(/HAPI bridged after/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,220 @@
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from '@/lib/use-translation'
|
||||
|
||||
// Minimal shape that both Metadata and SessionSummaryMetadata satisfy
|
||||
export type ModelErrorHolder = {
|
||||
lastModelError?: {
|
||||
eventId: string
|
||||
kind: string
|
||||
transient: boolean
|
||||
rawSnippet: string
|
||||
atTs: number
|
||||
priorAssistantClaimsDone: boolean
|
||||
bridgedForEventId?: string
|
||||
retriedAndFailed?: boolean
|
||||
supersededByUserTurn?: boolean
|
||||
bridgeable?: boolean
|
||||
acknowledgedAt?: number
|
||||
}
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export type ModelErrorUiState = 'unrecovered' | 'recovered' | 'bridge_failed'
|
||||
|
||||
export function getModelErrorUiState(metadata: ModelErrorHolder | null | undefined): ModelErrorUiState | null {
|
||||
const err = metadata?.lastModelError
|
||||
if (!err || err.acknowledgedAt) {
|
||||
return null
|
||||
}
|
||||
if (err.retriedAndFailed) {
|
||||
return 'bridge_failed'
|
||||
}
|
||||
if (err.bridgedForEventId === err.eventId) {
|
||||
return 'recovered'
|
||||
}
|
||||
return 'unrecovered'
|
||||
}
|
||||
|
||||
export function canShowModelErrorBridge(metadata: ModelErrorHolder | null | undefined): boolean {
|
||||
return getModelErrorUiState(metadata) === 'unrecovered'
|
||||
&& Boolean(metadata?.lastModelError?.transient)
|
||||
&& !metadata?.lastModelError?.supersededByUserTurn
|
||||
&& metadata?.lastModelError?.bridgeable !== false
|
||||
}
|
||||
|
||||
/**
|
||||
* True after the CLI accepted a Bridge enqueue for `pendingEventId` and before
|
||||
* metadata records recovered / failed / superseded / acknowledged / a new error.
|
||||
*/
|
||||
export function isBridgeSettling(
|
||||
metadata: ModelErrorHolder | null | undefined,
|
||||
pendingEventId: string | null
|
||||
): boolean {
|
||||
const err = metadata?.lastModelError
|
||||
if (!pendingEventId || !err || err.eventId !== pendingEventId) {
|
||||
return false
|
||||
}
|
||||
if (err.acknowledgedAt || err.retriedAndFailed || err.supersededByUserTurn) {
|
||||
return false
|
||||
}
|
||||
if (err.bridgedForEventId === pendingEventId) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export function shouldKeepPendingBridge(
|
||||
sessionActive: boolean,
|
||||
settling: boolean,
|
||||
aborted = false
|
||||
): boolean {
|
||||
return sessionActive && settling && !aborted
|
||||
}
|
||||
|
||||
export function visibleBridgeFailureReason(
|
||||
failure: { eventId: string; reason: string } | null,
|
||||
currentEventId: string | undefined
|
||||
): string | null {
|
||||
if (!failure || !currentEventId || failure.eventId !== currentEventId) {
|
||||
return null
|
||||
}
|
||||
return failure.reason
|
||||
}
|
||||
|
||||
/** Any unacknowledged model-error surface (error, recovered, or bridge failed). */
|
||||
export function hasActiveModelError(metadata: ModelErrorHolder | null | undefined): boolean {
|
||||
return getModelErrorUiState(metadata) !== null
|
||||
}
|
||||
|
||||
/** Amber pulse: unrecovered or bridge-failed. Not recovered. */
|
||||
export function hasUrgentModelError(metadata: ModelErrorHolder | null | undefined): boolean {
|
||||
const state = getModelErrorUiState(metadata)
|
||||
return state === 'unrecovered' || state === 'bridge_failed'
|
||||
}
|
||||
|
||||
export function hasRecoveredModelError(metadata: ModelErrorHolder | null | undefined): boolean {
|
||||
return getModelErrorUiState(metadata) === 'recovered'
|
||||
}
|
||||
|
||||
export function ModelErrorBanner({
|
||||
metadata,
|
||||
onDismiss,
|
||||
onBridge,
|
||||
isBridging = false,
|
||||
bridgeErrorReason = null
|
||||
}: {
|
||||
metadata: ModelErrorHolder | null | undefined
|
||||
onDismiss: () => void
|
||||
onBridge?: () => void
|
||||
isBridging?: boolean
|
||||
bridgeErrorReason?: string | null
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const [showRaw, setShowRaw] = useState(false)
|
||||
|
||||
const err = metadata?.lastModelError
|
||||
const uiState = getModelErrorUiState(metadata)
|
||||
if (!err || !uiState) {
|
||||
return null
|
||||
}
|
||||
|
||||
const transientLabel = err.transient
|
||||
? t('session.modelError.banner.subtitle.transient')
|
||||
: t('session.modelError.banner.subtitle.nonTransient')
|
||||
|
||||
const isRecovered = uiState === 'recovered'
|
||||
const isBridgeFailed = uiState === 'bridge_failed'
|
||||
|
||||
const title = isRecovered
|
||||
? t('session.modelError.banner.recoveredTitle', { kind: err.kind })
|
||||
: isBridgeFailed
|
||||
? t('session.modelError.banner.bridgeFailedTitle', { kind: err.kind })
|
||||
: t('session.modelError.banner.title', { kind: err.kind })
|
||||
|
||||
const bodyText = isRecovered
|
||||
? t('session.modelError.banner.recoveredBody')
|
||||
: isBridgeFailed
|
||||
? t('session.modelError.banner.bridgeFailedBody')
|
||||
: err.priorAssistantClaimsDone
|
||||
? t('session.modelError.banner.claimedDone')
|
||||
: t('session.modelError.banner.midExecution')
|
||||
|
||||
const showBridge = canShowModelErrorBridge(metadata) && onBridge
|
||||
|
||||
const shellClass = isRecovered
|
||||
? 'border-emerald-500/40 bg-emerald-500/10'
|
||||
: 'border-amber-500/40 bg-amber-500/10'
|
||||
|
||||
const titleClass = isRecovered
|
||||
? 'text-emerald-700 dark:text-emerald-400'
|
||||
: 'text-amber-600 dark:text-amber-400'
|
||||
|
||||
const icon = isRecovered ? '\u2713' : '\u26A0'
|
||||
|
||||
return (
|
||||
<div className="px-3 pt-3" data-testid="model-error-banner" data-state={uiState}>
|
||||
<div
|
||||
role="alert"
|
||||
aria-live="assertive"
|
||||
className={`mx-auto flex w-full max-w-content flex-col gap-2 rounded-md border p-3 text-sm text-[var(--app-text)] ${shellClass}`}
|
||||
>
|
||||
<div className="flex items-start gap-2">
|
||||
<span aria-hidden="true" className={`mt-0.5 shrink-0 ${titleClass}`}>
|
||||
{icon}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className={`font-semibold ${titleClass}`}>
|
||||
{title}{' '}
|
||||
{!isRecovered ? (
|
||||
<span className="text-xs font-normal opacity-70">
|
||||
({transientLabel})
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="mt-0.5 text-xs text-[var(--app-hint)]">
|
||||
{bodyText}
|
||||
</div>
|
||||
{showRaw && (
|
||||
<pre className="mt-2 max-h-24 overflow-auto rounded bg-black/10 p-2 text-xs font-mono whitespace-pre-wrap break-all dark:bg-white/5">
|
||||
{err.rawSnippet}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 pl-6">
|
||||
{showBridge ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onBridge}
|
||||
disabled={isBridging}
|
||||
className="rounded px-2 py-0.5 text-xs font-medium border border-amber-500/50 text-amber-700 hover:bg-amber-500/10 disabled:opacity-50 dark:text-amber-300 transition-colors"
|
||||
>
|
||||
{isBridging
|
||||
? t('session.modelError.banner.bridging')
|
||||
: t('session.modelError.banner.bridgeRetry')}
|
||||
</button>
|
||||
) : null}
|
||||
{bridgeErrorReason ? (
|
||||
<span className="text-xs text-amber-700 dark:text-amber-300">
|
||||
{t('session.modelError.banner.bridgeFailed')}
|
||||
</span>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
onClick={onDismiss}
|
||||
className="rounded px-2 py-0.5 text-xs font-medium border border-[var(--app-border)] hover:bg-[var(--app-subtle-bg)] transition-colors"
|
||||
>
|
||||
{t('session.modelError.banner.dismiss')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowRaw((v) => !v)}
|
||||
className="rounded px-2 py-0.5 text-xs font-medium text-[var(--app-hint)] hover:text-[var(--app-fg)] transition-colors"
|
||||
>
|
||||
{t('session.modelError.banner.viewRaw')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -97,6 +97,7 @@ import type { SendMessageAcceptance } from '@/hooks/mutations/useSendMessage'
|
||||
import { handoffComposerDraft, transferComposerDraftThenNavigate } from '@/lib/composer-draft-transfer'
|
||||
import { SessionHeader } from '@/components/SessionHeader'
|
||||
import { CursorMigrationBanner } from '@/components/CursorMigrationBanner'
|
||||
import { ModelErrorBanner, hasActiveModelError, isBridgeSettling, shouldKeepPendingBridge, visibleBridgeFailureReason } from '@/components/ModelErrorBanner'
|
||||
import { TeamPanel } from '@/components/TeamPanel'
|
||||
import { SessionStatusPanel } from '@/components/SessionStatusPanel'
|
||||
import { buildSessionStatusData } from '@/chat/sessionStatus'
|
||||
@@ -1559,6 +1560,63 @@ function SessionChatInner(props: SessionChatProps) {
|
||||
codexCollaborationModeSupported
|
||||
)
|
||||
|
||||
const handleAcknowledgeModelError = useCallback(async () => {
|
||||
const eventId = props.session.metadata?.lastModelError?.eventId
|
||||
if (typeof eventId !== 'string' || eventId.length === 0) {
|
||||
props.onRefresh()
|
||||
return
|
||||
}
|
||||
await props.api.acknowledgeModelError(props.session.id, eventId).catch(() => {})
|
||||
props.onRefresh()
|
||||
}, [props.api, props.session.id, props.session.metadata?.lastModelError?.eventId, props.onRefresh])
|
||||
|
||||
const [isBridgingModelError, setIsBridgingModelError] = useState(false)
|
||||
const [pendingBridgeEventId, setPendingBridgeEventId] = useState<string | null>(null)
|
||||
const [bridgeFailure, setBridgeFailure] = useState<{ eventId: string; reason: string } | null>(null)
|
||||
const currentModelError = props.session.metadata?.lastModelError
|
||||
const bridgePending = isBridgeSettling(props.session.metadata, pendingBridgeEventId)
|
||||
|
||||
useEffect(() => {
|
||||
if (pendingBridgeEventId && !shouldKeepPendingBridge(props.session.active, bridgePending)) {
|
||||
setPendingBridgeEventId(null)
|
||||
}
|
||||
}, [props.session.active, pendingBridgeEventId, bridgePending])
|
||||
|
||||
const handleBridgeModelError = useCallback(async () => {
|
||||
if (isBridgingModelError || bridgePending) {
|
||||
return
|
||||
}
|
||||
const eventId = currentModelError?.eventId
|
||||
if (typeof eventId !== 'string' || eventId.length === 0) {
|
||||
props.onRefresh()
|
||||
return
|
||||
}
|
||||
setIsBridgingModelError(true)
|
||||
setBridgeFailure(null)
|
||||
try {
|
||||
const result = await props.api.bridgeModelError(props.session.id, eventId)
|
||||
if (result.ok) {
|
||||
setPendingBridgeEventId(eventId)
|
||||
} else {
|
||||
setBridgeFailure({ eventId, reason: result.reason ?? 'not_bridgeable' })
|
||||
}
|
||||
props.onRefresh()
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'bridge_failed'
|
||||
setBridgeFailure({ eventId, reason: message })
|
||||
console.warn('[SessionChat] model error bridge failed:', error)
|
||||
} finally {
|
||||
setIsBridgingModelError(false)
|
||||
}
|
||||
}, [
|
||||
isBridgingModelError,
|
||||
bridgePending,
|
||||
currentModelError?.eventId,
|
||||
props.api,
|
||||
props.session.id,
|
||||
props.onRefresh
|
||||
])
|
||||
|
||||
// Voice assistant integration
|
||||
const voice = useVoiceOptional()
|
||||
const [voiceBackendReady, setVoiceBackendReady] = useState(false)
|
||||
@@ -2033,6 +2091,10 @@ function SessionChatInner(props: SessionChatProps) {
|
||||
// Abort handler
|
||||
const handleAbort = useCallback(async () => {
|
||||
await abortSession()
|
||||
// Abort cancels pending/in-flight Bridge without recovered/failed/superseded
|
||||
// metadata, and the session stays active — drop the local latch so Bridge
|
||||
// is not stuck as "Bridging…" until remount.
|
||||
setPendingBridgeEventId(null)
|
||||
props.onRefresh()
|
||||
}, [abortSession, props.onRefresh])
|
||||
|
||||
@@ -2270,6 +2332,16 @@ function SessionChatInner(props: SessionChatProps) {
|
||||
|
||||
{sessionStatus ? <SessionStatusPanel data={sessionStatus} /> : null}
|
||||
|
||||
<ModelErrorBanner
|
||||
metadata={props.session.metadata}
|
||||
onDismiss={handleAcknowledgeModelError}
|
||||
onBridge={agentFlavor === 'cursor' && props.session.active
|
||||
? handleBridgeModelError
|
||||
: undefined}
|
||||
isBridging={isBridgingModelError || bridgePending}
|
||||
bridgeErrorReason={visibleBridgeFailureReason(bridgeFailure, currentModelError?.eventId)}
|
||||
/>
|
||||
|
||||
<div className="flex flex-col min-h-0 flex-1">
|
||||
{props.session.teamState && (
|
||||
<TeamPanel teamState={props.session.teamState} />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { act, cleanup, render, screen } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { ReactNode } from 'react'
|
||||
import type { SessionSummary } from '@/types/api'
|
||||
import { I18nProvider } from '@/lib/i18n-context'
|
||||
import { markCodexSessionsImported } from '@/lib/codexImportedSessions'
|
||||
@@ -8,6 +9,10 @@ import { SessionRowSummary } from './SessionRowSummary'
|
||||
|
||||
afterEach(() => cleanup())
|
||||
|
||||
function renderWithI18n(children: ReactNode) {
|
||||
return render(<I18nProvider>{children}</I18nProvider>)
|
||||
}
|
||||
|
||||
function makeSummary(overrides: Partial<SessionSummary> = {}): SessionSummary {
|
||||
return {
|
||||
id: 'background-demo',
|
||||
@@ -648,3 +653,100 @@ describe('SessionRowSummary time label', () => {
|
||||
expect(screen.getByText('just imported from Codex')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('SessionRowSummary model-error + attention', () => {
|
||||
it('shows model-error and permission attention together', () => {
|
||||
const summary = makeSummary({
|
||||
id: 's-both',
|
||||
backgroundTaskCount: 0,
|
||||
pendingRequestsCount: 1,
|
||||
pendingRequestKinds: ['permission'],
|
||||
pendingRequests: [{ id: 'r1', kind: 'permission', tool: 'Bash', since: 0 }],
|
||||
metadata: {
|
||||
path: '/tmp/proj',
|
||||
lastModelError: {
|
||||
eventId: 'evt-row-1',
|
||||
kind: 'model_not_found',
|
||||
transient: false,
|
||||
rawSnippet: 'Unknown model',
|
||||
atTs: 1,
|
||||
priorAssistantClaimsDone: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
renderWithI18n(
|
||||
<SessionRowSummary
|
||||
session={summary}
|
||||
showDetailedStatus
|
||||
selected={false}
|
||||
nestedTooltips={false}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByLabelText(/Model error/i)).toBeTruthy()
|
||||
// Upstream #2402 renamed this label to "Approval required".
|
||||
expect(screen.getByLabelText('Approval required')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('keeps the model-error pulse while thinking (auto-bridge in flight)', () => {
|
||||
const summary = makeSummary({
|
||||
id: 's-bridge',
|
||||
thinking: true,
|
||||
backgroundTaskCount: 0,
|
||||
metadata: {
|
||||
path: '/tmp/proj',
|
||||
lastModelError: {
|
||||
eventId: 'evt-row-bridge',
|
||||
kind: 'rate_limited',
|
||||
transient: true,
|
||||
rawSnippet: 'rate limited',
|
||||
atTs: 1,
|
||||
priorAssistantClaimsDone: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
renderWithI18n(
|
||||
<SessionRowSummary
|
||||
session={summary}
|
||||
showDetailedStatus
|
||||
selected={false}
|
||||
nestedTooltips={false}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByLabelText(/Model error/i)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('hides the model-error pulse after a successful bridge even if still thinking', () => {
|
||||
const summary = makeSummary({
|
||||
id: 's-recovered',
|
||||
thinking: true,
|
||||
backgroundTaskCount: 0,
|
||||
metadata: {
|
||||
path: '/tmp/proj',
|
||||
lastModelError: {
|
||||
eventId: 'evt-row-ok',
|
||||
kind: 'rate_limited',
|
||||
transient: true,
|
||||
rawSnippet: 'rate limited',
|
||||
atTs: 1,
|
||||
priorAssistantClaimsDone: false,
|
||||
bridgedForEventId: 'evt-row-ok',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
renderWithI18n(
|
||||
<SessionRowSummary
|
||||
session={summary}
|
||||
showDetailedStatus
|
||||
selected={false}
|
||||
nestedTooltips={false}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.queryByLabelText(/Model error/i)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
formatAttachedJobProgress,
|
||||
isAttachedJobStale
|
||||
} from '@/lib/attachedJob'
|
||||
import { hasUrgentModelError } from '@/components/ModelErrorBanner'
|
||||
|
||||
function BulbIcon(props: { className?: string }) {
|
||||
return (
|
||||
@@ -153,6 +154,8 @@ export function SessionRowSummary(props: {
|
||||
const attentionLabel = attention ? getAttentionLabel(attention, t) : null
|
||||
const urgentAttention = attention !== null
|
||||
&& (attention.kind === 'permission' || attention.kind === 'input')
|
||||
const modelErrorActive = hasUrgentModelError(s.metadata)
|
||||
const modelErrorLabel = t('session.modelError.listIndicator')
|
||||
const scheduledLabel = s.futureScheduledMessageCount > 1
|
||||
? t('session.item.scheduledMessages', { count: s.futureScheduledMessageCount })
|
||||
: t('session.item.scheduledMessage')
|
||||
@@ -258,6 +261,19 @@ export function SessionRowSummary(props: {
|
||||
>
|
||||
{sessionName}
|
||||
</div>
|
||||
{/* Model error outranks activity/unread: the turn looked
|
||||
finished but failed, so this must not be collapsed
|
||||
into the combined indicator below. */}
|
||||
{modelErrorActive ? (
|
||||
<span
|
||||
className="relative inline-flex h-2 w-2 shrink-0"
|
||||
title={modelErrorLabel}
|
||||
aria-label={modelErrorLabel}
|
||||
>
|
||||
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-500 opacity-75" />
|
||||
<span className="relative inline-flex h-2 w-2 rounded-full bg-amber-500" />
|
||||
</span>
|
||||
) : null}
|
||||
{hasRunningWork ? (
|
||||
<span data-testid="session-activity" role="img" aria-label={activityLabel} title={activityLabel} className="inline-flex shrink-0">
|
||||
<LoaderIcon className={`h-3.5 w-3.5 animate-spin-slow ${isUnread ? 'text-blue-500' : 'text-[var(--app-hint)]'}`} />
|
||||
|
||||
@@ -54,8 +54,8 @@ function chatContext(overrides: Partial<HappyChatContextValue> = {}): HappyChatC
|
||||
sessionId: 'session-1',
|
||||
metadata: { path: '/home/ada/coding/hapi', host: 'local' },
|
||||
terminalToolDisplayMode: 'compact',
|
||||
disabled: false,
|
||||
showSessionSummaryInChat: false,
|
||||
disabled: false,
|
||||
onRefresh: () => {},
|
||||
hasMoreMessages: false,
|
||||
isSyncingTail: false,
|
||||
|
||||
Reference in New Issue
Block a user