An open-source, faster Devin alternative
TypeScript
fix(web): align deployment recovery with live truth
Igor Zalutski4948282bb9f5
diff --git a/web/src/api/client-errors.test.ts b/web/src/api/client-errors.test.tsnew file mode 100644index 00000000..c101c4ca--- /dev/null+++ b/web/src/api/client-errors.test.ts@@ -0,0 +1,40 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import { ApiError, apiFetch } from './client'++afterEach(() => {+ vi.unstubAllGlobals()+})++describe('api errors', () => {+ it('preserves structured recovery details without weakening the typed error', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(() =>+ Promise.resolve(+ Response.json(+ {+ error: {+ type: 'source_already_linked',+ message: 'this repository path is already linked to an agent',+ existing_agent: { id: 'agt_existing', name: 'Support triage' },+ },+ },+ { status: 409 },+ ),+ ),+ ),+ )++ const error = await apiFetch('/v3/agents/import').catch(+ (caught: unknown) => caught,+ )+ expect(error).toBeInstanceOf(ApiError)+ expect(error).toMatchObject({+ status: 409,+ type: 'source_already_linked',+ details: {+ existing_agent: { id: 'agt_existing', name: 'Support triage' },+ },+ })+ })+})diff --git a/web/src/api/client.ts b/web/src/api/client.tsindex 2a779302..296b9d18 100644--- a/web/src/api/client.ts+++ b/web/src/api/client.ts@@ -91,13 +91,25 @@ function errorMessage(body: unknown, status: number): string {function errorType(body: unknown): string | undefined {if (body && typeof body === 'object') {const err = (body as Record<string, unknown>).error- if (err && typeof err === 'object' && typeof (err as Record<string, unknown>).type === 'string') {+ if (+ err &&+ typeof err === 'object' &&+ typeof (err as Record<string, unknown>).type === 'string'+ ) {return (err as Record<string, unknown>).type as string}}return undefined}+function errorDetails(body: unknown): Record<string, unknown> | undefined {+ if (!body || typeof body !== 'object') return undefined+ const error = (body as Record<string, unknown>).error+ return error && typeof error === 'object' && !Array.isArray(error)+ ? (error as Record<string, unknown>)+ : undefined+}+/** An error carrying the HTTP status + the API's typed reason, so callers can branch* (e.g. 404 = not-found; 402 `insufficient_credits` = out of credits → top-up CTA). */export class ApiError extends Error {@@ -105,6 +117,7 @@ export class ApiError extends Error {message: string,readonly status: number,readonly type?: string,+ readonly details?: Record<string, unknown>,) {super(message)this.name = 'ApiError'@@ -142,7 +155,12 @@ export async function apiFetch<T>(if (!res.ok) {const body: unknown = await res.json().catch(() => ({}))- throw new ApiError(errorMessage(body, res.status), res.status, errorType(body))+ throw new ApiError(+ errorMessage(body, res.status),+ res.status,+ errorType(body),+ errorDetails(body),+ )}if (res.status === 204) {diff --git a/web/src/components/status-badge.tsx b/web/src/components/status-badge.tsxindex 5e1ecdbd..090d7323 100644--- a/web/src/components/status-badge.tsx+++ b/web/src/components/status-badge.tsx@@ -64,6 +64,12 @@ const STATUS: Record<string, Meta> = {icon: Loader2,spin: true,},+ updating: {+ tone: 'pending',+ label: 'Updating',+ icon: Loader2,+ spin: true,+ },deploying: {tone: 'pending',label: 'Deploying',diff --git a/web/src/lib/agent-deployment-outcome.test.ts b/web/src/lib/agent-deployment-outcome.test.tsnew file mode 100644index 00000000..bfb4334e--- /dev/null+++ b/web/src/lib/agent-deployment-outcome.test.ts@@ -0,0 +1,100 @@+import { describe, expect, it } from 'vitest'+import type { AgentDeployment } from '@/api/client'+import { agentDeploymentOutcome } from './agent-deployment-outcome'++function deployment(patch: Partial<AgentDeployment> = {}): AgentDeployment {+ return {+ id: 'dep_old',+ state: 'failed',+ phase: 'Deploy',+ terminal: true,+ result: 'failed',+ input_type: 'github',+ revision_id: null,+ revision: null,+ source: null,+ source_relation: null,+ actor: null,+ ref: 'main',+ sha: 'a'.repeat(40),+ error: null,+ error_class: 'deploy_failed',+ build: null,+ configuration: null,+ log_bytes: 0,+ log_truncated: false,+ live_touched: true,+ agent_live: null,+ restore_eligibility: 'none',+ redeploy_of: null,+ allowed_actions: [],+ active: false,+ timing: {+ accepted_at: null,+ started_at: null,+ finished_at: null,+ cancel_requested_at: null,+ queue_ms: null,+ run_ms: null,+ total_ms: null,+ },+ created_at: '2026-07-14T00:00:00Z',+ updated_at: '2026-07-14T00:00:00Z',+ started_at: null,+ finished_at: null,+ ...patch,+ }+}++describe('agentDeploymentOutcome', () => {+ it('does not call a recovered historical failure currently unverified', () => {+ const result = agentDeploymentOutcome(+ deployment({+ agent_live: {+ deployment_id: 'dep_new',+ status: 'verified',+ },+ }),+ )+ expect(result.title).toBe('Deployment failed')+ expect(result.description).toContain('later verified deployment')+ })++ it('does not call an inactive historical success ready to run', () => {+ const result = agentDeploymentOutcome(+ deployment({+ state: 'ready',+ result: 'ready',+ revision: {+ id: 'rev_old',+ number: 1,+ digest: 'sha256:old',+ created_at: '2026-07-14T00:00:00Z',+ },+ agent_live: {+ deployment_id: 'dep_new',+ status: 'verified',+ },+ }),+ )+ expect(result.title).toBe('Deployment succeeded')+ expect(result.description).toContain('another revision is active')+ })++ it('calls only an active, startable revision ready', () => {+ const result = agentDeploymentOutcome(+ deployment({+ state: 'ready',+ result: 'ready',+ active: true,+ allowed_actions: ['start_session'],+ agent_live: {+ deployment_id: 'dep_old',+ status: 'verified',+ },+ }),+ )+ expect(result.kind).toBe('success')+ expect(result.title).toBe('Deployment ready')+ })+})diff --git a/web/src/lib/agent-deployment-outcome.ts b/web/src/lib/agent-deployment-outcome.tsnew file mode 100644index 00000000..bd0872af--- /dev/null+++ b/web/src/lib/agent-deployment-outcome.ts@@ -0,0 +1,115 @@+import type { AgentDeployment } from '@/api/client'++export type AgentDeploymentOutcome = {+ kind: 'success' | 'error' | 'info' | 'progress'+ title: string+ description: string+}++function revisionLabel(deployment: AgentDeployment): string {+ return deployment.revision?.number+ ? `Revision #${deployment.revision.number}`+ : 'The built revision'+}++function failureMessage(deployment: AgentDeployment): string | undefined {+ return deployment.error?.message+}++/**+ * Describe this immutable attempt against the agent's current live pointer.+ * Historical rows must not claim that they are still active or unverified after+ * a later deployment changed the live truth.+ */+export function agentDeploymentOutcome(+ deployment: AgentDeployment,+): AgentDeploymentOutcome {+ const live = deployment.agent_live+ const liveBelongsToAttempt = live?.deployment_id === deployment.id+ const canStart = deployment.allowed_actions.includes('start_session')++ if (deployment.state === 'ready') {+ if (deployment.active && canStart) {+ return {+ kind: 'success',+ title: 'Deployment ready',+ description: `${revisionLabel(deployment)} is active and ready to run.`,+ }+ }+ if (!deployment.active) {+ return {+ kind: 'info',+ title: 'Deployment succeeded',+ description: `${revisionLabel(deployment)} was created, but another revision is active.`,+ }+ }+ return {+ kind: 'error',+ title: 'Active deployment is not verified',+ description:+ liveBelongsToAttempt && live?.status === 'updating'+ ? 'The live Worker is still updating. New sessions remain paused until verification finishes.'+ : 'The revision is active, but the current live Worker is not verified for new sessions.',+ }+ }++ if (deployment.state === 'failed') {+ const message = failureMessage(deployment)+ if (+ deployment.live_touched &&+ (liveBelongsToAttempt || !live) &&+ live?.status !== 'verified'+ ) {+ return {+ kind: 'error',+ title: 'Live deployment could not be verified',+ description:+ message ??+ 'The live Worker may have changed. Check the persisted log before starting new work.',+ }+ }++ const currentTruth =+ live?.status === 'verified'+ ? ' A later verified deployment is now live.'+ : live && !liveBelongsToAttempt+ ? ' A later deployment currently requires attention before new sessions can start.'+ : ''+ return {+ kind: 'error',+ title: 'Deployment failed',+ description:+ (message ??+ (deployment.live_touched+ ? 'This attempt changed the live Worker before it failed.'+ : 'The live agent was not changed. Fix the repository before deploying again.')) ++ currentTruth,+ }+ }++ if (+ deployment.state === 'canceled' ||+ deployment.state === 'superseded' ||+ deployment.state === 'skipped'+ ) {+ return {+ kind: 'info',+ title:+ deployment.state === 'skipped'+ ? 'No changes to deploy'+ : deployment.state === 'canceled'+ ? 'Deployment canceled'+ : 'Deployment superseded',+ description:+ deployment.state === 'skipped'+ ? 'The built result matches the active revision, so the live agent was left unchanged.'+ : 'This attempt ended without producing a new revision.',+ }+ }++ return {+ kind: 'progress',+ title: 'Deployment in progress',+ description: 'This page polls the durable deployment record and build log.',+ }+}diff --git a/web/src/lib/agent-deployment-status.test.ts b/web/src/lib/agent-deployment-status.test.tsindex 257d182c..cb1ec8ac 100644--- a/web/src/lib/agent-deployment-status.test.ts+++ b/web/src/lib/agent-deployment-status.test.ts@@ -31,6 +31,23 @@ describe('agent deployment display status', () => {).toBe('unverified')})+ it('uses the live updating state rather than the artifact-uploading phase', () => {+ expect(+ agentDeploymentDisplayStatus({+ ...baseAgent,+ deployment_status: {+ deployment_id: 'dep_123',+ state: 'ready',+ result: 'created',+ error_class: null,+ live_touched: true,+ live_status: 'updating',+ updated_at: '2026-07-14T20:00:00.000Z',+ },+ }),+ ).toBe('updating')+ })+it('keeps a terminal failure visible even when an older live revision exists', () => {expect(agentDeploymentDisplayStatus({diff --git a/web/src/lib/agent-deployment-status.ts b/web/src/lib/agent-deployment-status.tsindex 47e1acd3..9901b249 100644--- a/web/src/lib/agent-deployment-status.ts+++ b/web/src/lib/agent-deployment-status.ts@@ -21,7 +21,7 @@ export function agentDeploymentDisplayStatus(const liveWasTouched = deployment?.live_touched ?? agent.flue?.live != nullif (status === 'ready' && liveWasTouched && liveStatus !== 'verified') {- return liveStatus === 'uploading' ? 'uploading' : 'unverified'+ return liveStatus === 'updating' ? 'updating' : 'unverified'}return statusdiff --git a/web/src/pages/AgentDeployment.tsx b/web/src/pages/AgentDeployment.tsxindex aedec1be..2eb18bfe 100644--- a/web/src/pages/AgentDeployment.tsx+++ b/web/src/pages/AgentDeployment.tsx@@ -33,6 +33,7 @@ import {PanelTitle,} from '@/components/panel'import { StatusBadge } from '@/components/status-badge'+import { agentDeploymentOutcome } from '@/lib/agent-deployment-outcome'import { cn } from '@/lib/utils'const PHASES = [@@ -87,11 +88,6 @@ function stableCommandKey(return key}-function errorMessage(deployment: AgentDeployment): string | undefined {- if (deployment.error?.message) return deployment.error.message- return undefined-}-function failedPhase(deployment: AgentDeployment): string | undefined {const phase = deployment.error?.phase?.toLowerCase()if (phase) return phase@@ -248,58 +244,35 @@ function formatBytes(value: number | undefined): string {}function Outcome({ deployment }: { deployment: AgentDeployment }) {- if (deployment.state === 'ready') {+ const outcome = agentDeploymentOutcome(deployment)++ if (outcome.kind === 'success') {return (<Alert className="bg-status-running-bg text-status-running border-status-running/25"><Check className="size-4" />- <AlertTitle>Deployment ready</AlertTitle>+ <AlertTitle>{outcome.title}</AlertTitle><AlertDescription className="text-status-running">- {deployment.revision?.number- ? `Revision #${deployment.revision.number} is ready to run.`- : 'The agent passed verification and is ready to run.'}+ {outcome.description}</AlertDescription></Alert>)}- if (deployment.state === 'failed') {+ if (outcome.kind === 'error') {return (<Alert variant="destructive"><CircleAlert className="size-4" />- <AlertTitle>- {deployment.live_touched- ? 'Live deployment could not be verified'- : 'Deployment failed'}- </AlertTitle>- <AlertDescription>- {errorMessage(deployment) ??- (deployment.live_touched- ? 'The live Worker may have changed. Check the persisted log before starting new work.'- : 'The live agent was not changed. Check the persisted log and fix the repository before deploying again.')}- </AlertDescription>+ <AlertTitle>{outcome.title}</AlertTitle>+ <AlertDescription>{outcome.description}</AlertDescription></Alert>)}- if (- deployment.state === 'canceled' ||- deployment.state === 'superseded' ||- deployment.state === 'skipped'- ) {+ if (outcome.kind === 'info') {return (<Alert>- <AlertTitle>- {deployment.state === 'skipped'- ? 'No changes to deploy'- : deployment.state === 'canceled'- ? 'Deployment canceled'- : 'Deployment superseded'}- </AlertTitle>- <AlertDescription>- {deployment.state === 'skipped'- ? 'The built result matches the active revision, so the live agent was left unchanged.'- : 'This attempt ended without producing a new revision.'}- </AlertDescription>+ <AlertTitle>{outcome.title}</AlertTitle>+ <AlertDescription>{outcome.description}</AlertDescription></Alert>)}@@ -307,10 +280,8 @@ function Outcome({ deployment }: { deployment: AgentDeployment }) {return (<Alert><Loader2 className="size-4 animate-spin motion-reduce:animate-none" />- <AlertTitle>Deployment in progress</AlertTitle>- <AlertDescription>- This page polls the durable deployment record and build log.- </AlertDescription>+ <AlertTitle>{outcome.title}</AlertTitle>+ <AlertDescription>{outcome.description}</AlertDescription></Alert>)}diff --git a/web/src/pages/AgentDetail.tsx b/web/src/pages/AgentDetail.tsxindex 9d00304a..6d6821da 100644--- a/web/src/pages/AgentDetail.tsx+++ b/web/src/pages/AgentDetail.tsx@@ -305,7 +305,7 @@ export default function AgentDetail() {agent.deployment_status?.live_status ?? agent.flue?.live?.status ?? nullconst canStartNewSession =activeRev !== null &&- (agent.runtime !== 'flue' || !liveStatus || liveStatus === 'verified')+ (agent.runtime !== 'flue' || liveStatus === 'verified')return (<div className="mx-auto max-w-5xl">diff --git a/web/src/pages/AgentNew.tsx b/web/src/pages/AgentNew.tsxindex c0fcf324..4d6fed51 100644--- a/web/src/pages/AgentNew.tsx+++ b/web/src/pages/AgentNew.tsx@@ -12,6 +12,7 @@ import {Search,} from 'lucide-react'import {+ ApiError,getDeployApp,importAgentFromGithub,inspectFlueRepository,@@ -40,6 +41,24 @@ const IMPORT_COMMAND_STORAGE = 'oc.flue-import-command.v1'type ImportBody = Parameters<typeof importAgentFromGithub>[0]type ImportCommand = { fingerprint: string; key: string }+function existingAgentFromError(+ error: unknown,+): { id: string; name: string } | null {+ if (+ !(error instanceof ApiError) ||+ (error.type !== 'name_conflict' && error.type !== 'source_already_linked')+ ) {+ return null+ }+ const existing = error.details?.existing_agent+ if (!existing || typeof existing !== 'object' || Array.isArray(existing))+ return null+ const row = existing as Record<string, unknown>+ return typeof row.id === 'string' && typeof row.name === 'string'+ ? { id: row.id, name: row.name }+ : null+}+function isValidRoot(root: string): boolean {if (root.includes('\0') || root.includes('\\') || root.startsWith('/'))return false@@ -284,6 +303,7 @@ function GithubImport() {}const inspection = inspectMutation.data+ const existingAgent = existingAgentFromError(importMutation.error)const canInspect =!!selectedRepo &&!!productionRef.trim() &&@@ -585,6 +605,15 @@ function GithubImport() {? importMutation.error.message: 'The import request failed. You can retry without creating a duplicate.'}</AlertDescription>+ {existingAgent ? (+ <div className="mt-3">+ <Button size="sm" variant="outline" asChild>+ <Link to={`/agents/${existingAgent.id}`}>+ Open {existingAgent.name}+ </Link>+ </Button>+ </div>+ ) : null}</Alert>) : null}<div className="flex justify-end">diff --git a/web/src/pages/Agents.tsx b/web/src/pages/Agents.tsxindex a41b52d1..71cce981 100644--- a/web/src/pages/Agents.tsx+++ b/web/src/pages/Agents.tsx@@ -22,7 +22,12 @@ export default function Agents() {key: 'name',header: 'Name',cell: (agent) => (- <span className="text-foreground font-medium">{agent.name}</span>+ <Link+ to={`/agents/${agent.id}`}+ className="text-foreground font-medium underline-offset-4 hover:underline"+ >+ {agent.name}+ </Link>),},{@@ -55,8 +60,6 @@ export default function Agents() {to={`/agents/${agent.id}/deployments/${deploymentId}`}aria-label={`Open latest deployment for ${agent.name}: ${status.replace(/_/g, ' ')}`}className="focus-visible:ring-ring/50 inline-flex rounded-md outline-none focus-visible:ring-3"- onClick={(event) => event.stopPropagation()}- onKeyDown={(event) => event.stopPropagation()}><StatusBadge status={status} /></Link>@@ -114,7 +117,6 @@ export default function Agents() {columns={columns}rows={agents ?? []}rowKey={(agent) => agent.id}- onRowClick={(agent) => void navigate(`/agents/${agent.id}`)}loading={isLoading}empty={<EmptyState