Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Don't add PR comment about agent run cancel on PR merge

Tomas Valentaf51cd341e332
diff --git a/api-service/deployment/in_memory.py b/api-service/deployment/in_memory.py
index 21cd60158..c12c705ef 100644
--- a/api-service/deployment/in_memory.py
+++ b/api-service/deployment/in_memory.py
@@ -83,12 +83,11 @@ class InMemoryDeploymentManager(AgentDeploymentManager):
async def remove_deployment(self, id: str):
deployment = await self.get_deployment(id)
+ await db.update_deployment(id, enabled=False)
if deployment:
await deployment.agent.stop()
del self._deployments[deployment.id]
- await db.update_deployment(id, enabled=False)
-
async def get_deployment(self, id: str):
return self._deployments.get(id, None)
diff --git a/pages/api/agent/run.ts b/pages/api/agent/run.ts
index 2b69280df..00de42017 100644
--- a/pages/api/agent/run.ts
+++ b/pages/api/agent/run.ts
@@ -151,40 +151,41 @@ async function deleteRun(req: NextApiRequest, res: NextApiResponse) {
const authData = deployment.auth as unknown as DeploymentAuthData
const client = getGHInstallationClient({ installationID: authData.github.installation_id })
- // Add comment about the run being cancelled
- await addCommentToPR({
- body: `Cancelled smol developer [agent run](https://app.e2b.dev/logs/${deployment.projects.slug}-run-${deployment._count.log_files - 1}).`,
- client,
- owner: authData.github.owner,
- repo: authData.github.repo,
- pullNumber: authData.github.pr_number,
- })
-
- const users = deployment
- .projects
- .teams
- .users_teams
- .map(u => u.users)
- .flat()
-
- const result = await Promise.allSettled(users.map(async u => {
- posthog?.capture({
- distinctId: u.id,
- event: 'cancelled agent run',
- properties: {
- agent_deployment_id: deployment.id,
- agent: TemplateID.SmolDeveloper,
- repository: `${authData.github.owner}/${authData.github.repo}`,
- run_id,
-
- pr_number: authData.github.pr_number,
- },
+ if (deployment.enabled) {
+ // Add comment about the run being cancelled
+ await addCommentToPR({
+ body: `Cancelled smol developer [agent run](https://app.e2b.dev/logs/${deployment.projects.slug}-run-${deployment._count.log_files - 1}).`,
+ client,
+ owner: authData.github.owner,
+ repo: authData.github.repo,
+ pullNumber: authData.github.pr_number,
})
- }))
- await posthog?.shutdownAsync()
+ const users = deployment
+ .projects
+ .teams
+ .users_teams
+ .map(u => u.users)
+ .flat()
+
+ const result = await Promise.allSettled(users.map(async u => {
+ posthog?.capture({
+ distinctId: u.id,
+ event: 'cancelled agent run',
+ properties: {
+ agent_deployment_id: deployment.id,
+ agent: TemplateID.SmolDeveloper,
+ repository: `${authData.github.owner}/${authData.github.repo}`,
+ run_id,
+
+ pr_number: authData.github.pr_number,
+ },
+ })
+ }))
- console.log('Analytics logged', result)
+ await posthog?.shutdownAsync()
+ console.log('Analytics logged', result)
+ }
res.status(200).json({})
} catch (err: any) {