An open-source, faster Devin alternative
TypeScript
dashboard: show a failed turn's reason in the session conversation
Igor Zalutski07a71d5bac46
diff --git a/web/src/managed-agents/Session.tsx b/web/src/managed-agents/Session.tsxindex 1a815be2..17460ec0 100644--- a/web/src/managed-agents/Session.tsx+++ b/web/src/managed-agents/Session.tsx@@ -19,7 +19,7 @@ import {getManagedProject,} from './api'import { AgentMarkdown } from './AgentMarkdown'-import { turnAssistantText } from './session-history'+import { turnAssistantText, turnFailureReason } from './session-history'function formatDate(value: string) {return new Date(value).toLocaleString()@@ -218,6 +218,10 @@ export default function ManagedSessionDetail() {events.data ?? [],turn.id,)+ const failureReason =+ turn.status === 'failed'+ ? turnFailureReason(events.data ?? [], turn.id)+ : undefinedconst running = !['completed', 'failed'].includes(turn.status)return (<div key={turn.id} className="space-y-6">@@ -253,6 +257,11 @@ export default function ManagedSessionDetail() {: `Turn ${turn.status.replace(/_/g, ' ')}.`}</p>)}+ {failureReason ? (+ <p className="text-status-error mt-2 text-sm">+ {failureReason}+ </p>+ ) : null}</div></div>)diff --git a/web/src/managed-agents/session-history.test.ts b/web/src/managed-agents/session-history.test.tsindex a414e6a6..de5e96c8 100644--- a/web/src/managed-agents/session-history.test.ts+++ b/web/src/managed-agents/session-history.test.ts@@ -9,6 +9,7 @@ import {playgroundSessionSearch,sessionsForEnvironment,turnAssistantText,+ turnFailureReason,} from './session-history'function deployment(@@ -131,3 +132,29 @@ describe('turnAssistantText', () => {).toBe('Finished response')})})++describe('turnFailureReason', () => {+ it("returns the failed turn's own reason and nothing for other turns", () => {+ const events: ManagedAgentEvent[] = [+ { seq: 1, turnId: 'turn-1', type: 'message.delta', data: { text: 'x' } },+ {+ seq: 2,+ turnId: 'turn-1',+ type: 'turn.failed',+ data: {+ message:+ 'The Workerd runtime rejects any useModel other than anthropic/claude-sonnet-4.6',+ },+ },+ { seq: 3, turnId: 'turn-2', type: 'turn.failed', data: {} },+ { seq: 4, turnId: 'turn-3', type: 'turn.completed', data: {} },+ ]+ expect(turnFailureReason(events, 'turn-1')).toBe(+ 'The Workerd runtime rejects any useModel other than anthropic/claude-sonnet-4.6',+ )+ expect(turnFailureReason(events, 'turn-2')).toBe(+ 'The agent could not complete this request.',+ )+ expect(turnFailureReason(events, 'turn-3')).toBeUndefined()+ })+})diff --git a/web/src/managed-agents/session-history.ts b/web/src/managed-agents/session-history.tsindex 4028fc85..f7dd7172 100644--- a/web/src/managed-agents/session-history.ts+++ b/web/src/managed-agents/session-history.ts@@ -43,3 +43,15 @@ export function turnAssistantText(events: ManagedAgentEvent[], turnId: string) {}return streamedText || completedText}++/** The reason a turn failed, as its `turn.failed` event carries it; undefined for any other outcome. */+export function turnFailureReason(events: ManagedAgentEvent[], turnId: string) {+ for (const event of events) {+ if (event.turnId === turnId && event.type === 'turn.failed') {+ return typeof event.data.message === 'string' && event.data.message+ ? event.data.message+ : 'The agent could not complete this request.'+ }+ }+ return undefined+}