An open-source, faster Devin alternative
TypeScript
fix: recognize reused agents in PR previews
Mohamed Habib6b845ca30c5c
diff --git a/web/src/managed-agents/Detail.tsx b/web/src/managed-agents/Detail.tsxindex cc1df6f6..0f25e2bb 100644--- a/web/src/managed-agents/Detail.tsx+++ b/web/src/managed-agents/Detail.tsx@@ -62,6 +62,7 @@ import {getManagedAgents,getManagedAgentSessions,getManagedAgentSessionsPage,+ getManagedDeploymentSource,latestManagedAgentModelRoute,type ManagedAgentEvent,type ManagedAgentInputMode,@@ -106,6 +107,7 @@ import { ManagedProjectLinear } from './Linear'import { ManagedProjectServiceConnections } from './ProjectServiceConnections'import { ManagedProjectSettings } from './Settings'import { AgentMarkdown } from './AgentMarkdown'+import { projectAgentPreviewReady } from './preview-state'import {projectCloneCommand,templateFirstRunPrompt,@@ -688,6 +690,12 @@ export default function ManagedAgentDetail({const [newSessionKey, setNewSessionKey] = useState(() => crypto.randomUUID())const [adoptedPlaygroundId, setAdoptedPlaygroundId] = useState<string>()const projectId = project?.project.id+ const deploymentSource = useQuery({+ queryKey: ['managed-deployment-source', projectId],+ queryFn: () => getManagedDeploymentSource(projectId!),+ enabled: Boolean(projectId && previewAlias),+ refetchInterval: previewAlias ? 1_500 : false,+ })// On the project Sessions tab the agent selector offers "All agents"; an// explicit ?agent= narrows it. Every other tab needs a concrete agent.const sessionsAgentFilter =@@ -945,14 +953,12 @@ export default function ManagedAgentDetail({...(project ? ([{ id: 'byok', label: 'BYOK' }] as const) : []),...(project ? ([{ id: 'settings', label: 'Settings' }] as const) : []),]- const previewDeployed =- previewAlias !== undefined &&- Boolean(- project?.deployments.some(- (deployment) =>- deployment.alias === previewAlias && deployment.agentId === agentId,- ),- )+ const previewDeployed = projectAgentPreviewReady({+ alias: previewAlias,+ agentId,+ deployments: project?.deployments ?? [],+ previews: deploymentSource.data?.previews ?? [],+ })if (project && !resolvedEnvironment.ok && previewAlias === undefined) {return (diff --git a/web/src/managed-agents/preview-state.test.ts b/web/src/managed-agents/preview-state.test.tsnew file mode 100644index 00000000..10685d1b--- /dev/null+++ b/web/src/managed-agents/preview-state.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from 'vitest'+import { projectAgentPreviewReady } from './preview-state'++describe('projectAgentPreviewReady', () => {+ it('accepts a ready project preview when an unchanged agent reused a development deployment', () => {+ expect(+ projectAgentPreviewReady({+ alias: 'pr-1',+ agentId: 'summarizer',+ deployments: [{ agentId: 'summarizer', alias: 'development' }],+ previews: [{ alias: 'pr-1', state: 'ready' }],+ }),+ ).toBe(true)+ })++ it('does not advertise a preview while its build is incomplete', () => {+ expect(+ projectAgentPreviewReady({+ alias: 'pr-1',+ agentId: 'summarizer',+ deployments: [{ agentId: 'summarizer', alias: 'development' }],+ previews: [{ alias: 'pr-1', state: 'building' }],+ }),+ ).toBe(false)+ })++ it('keeps supporting an alias represented directly by a deployment row', () => {+ expect(+ projectAgentPreviewReady({+ alias: 'pr-2',+ agentId: 'coder',+ deployments: [{ agentId: 'coder', alias: 'pr-2' }],+ previews: [],+ }),+ ).toBe(true)+ })+})diff --git a/web/src/managed-agents/preview-state.ts b/web/src/managed-agents/preview-state.tsnew file mode 100644index 00000000..c2ce4665--- /dev/null+++ b/web/src/managed-agents/preview-state.ts@@ -0,0 +1,34 @@+type DeploymentAlias = {+ agentId: string+ alias: string+}++type PreviewBuild = {+ alias: string+ state: string+}++/**+ * A ready project preview publishes its alias for every project member, even+ * when an unchanged member reuses an older immutable deployment row whose+ * original alias was development. Prefer the project build as the authority;+ * retain the deployment-row check for previews published outside Git deploys.+ */+export function projectAgentPreviewReady(input: {+ alias: string | undefined+ agentId: string+ deployments: readonly DeploymentAlias[]+ previews: readonly PreviewBuild[]+}): boolean {+ if (!input.alias) return false+ return (+ input.previews.some(+ (preview) => preview.alias === input.alias && preview.state === 'ready',+ ) ||+ input.deployments.some(+ (deployment) =>+ deployment.agentId === input.agentId &&+ deployment.alias === input.alias,+ )+ )+}