feat: add BoardWebhook updates on agent deletion

This commit is contained in:
Abhimanyu Saharan
2026-02-16 00:21:21 +05:30
parent b702ade0cc
commit cd68446c42
3 changed files with 24 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ from app.db import crud
from app.models.activity_events import ActivityEvent from app.models.activity_events import ActivityEvent
from app.models.agents import Agent from app.models.agents import Agent
from app.models.approvals import Approval from app.models.approvals import Approval
from app.models.board_webhooks import BoardWebhook
from app.models.gateways import Gateway from app.models.gateways import Gateway
from app.models.tasks import Task from app.models.tasks import Task
from app.schemas.gateways import GatewayTemplatesSyncResult from app.schemas.gateways import GatewayTemplatesSyncResult
@@ -340,6 +341,14 @@ class GatewayAdminLifecycleService(OpenClawDBService):
agent_id=None, agent_id=None,
commit=False, commit=False,
) )
await crud.update_where(
self.session,
BoardWebhook,
col(BoardWebhook.agent_id) == agent_id,
agent_id=None,
updated_at=now,
commit=False,
)
async def sync_templates( async def sync_templates(
self, self,

View File

@@ -31,6 +31,7 @@ from app.models.activity_events import ActivityEvent
from app.models.agents import Agent from app.models.agents import Agent
from app.models.approvals import Approval from app.models.approvals import Approval
from app.models.board_memory import BoardMemory from app.models.board_memory import BoardMemory
from app.models.board_webhooks import BoardWebhook
from app.models.boards import Board from app.models.boards import Board
from app.models.gateways import Gateway from app.models.gateways import Gateway
from app.models.organizations import Organization from app.models.organizations import Organization
@@ -1849,6 +1850,14 @@ class AgentLifecycleService(OpenClawDBService):
agent_id=None, agent_id=None,
commit=False, commit=False,
) )
await crud.update_where(
self.session,
BoardWebhook,
col(BoardWebhook.agent_id) == agent.id,
agent_id=None,
updated_at=now,
commit=False,
)
await self.session.delete(agent) await self.session.delete(agent)
await self.session.commit() await self.session.commit()

View File

@@ -11,6 +11,7 @@ import pytest
from fastapi import HTTPException, status from fastapi import HTTPException, status
import app.services.openclaw.provisioning_db as agent_service import app.services.openclaw.provisioning_db as agent_service
from app.models.board_webhooks import BoardWebhook
from app.services.openclaw.gateway_rpc import GatewayConfig as GatewayClientConfig from app.services.openclaw.gateway_rpc import GatewayConfig as GatewayClientConfig
@@ -110,7 +111,10 @@ async def test_delete_agent_as_lead_removes_board_agent(
_ = (_self, agent, gateway, delete_files, delete_session) _ = (_self, agent, gateway, delete_files, delete_session)
return None return None
async def _fake_update_where(*_args, **_kwargs) -> None: update_models: list[type[object]] = []
async def _fake_update_where(_session, model, *_args, **_kwargs) -> None:
update_models.append(model)
return None return None
monkeypatch.setattr(service, "require_board", _fake_require_board) monkeypatch.setattr(service, "require_board", _fake_require_board)
@@ -130,6 +134,7 @@ async def test_delete_agent_as_lead_removes_board_agent(
assert result.ok is True assert result.ok is True
assert session.deleted and session.deleted[0] == target assert session.deleted and session.deleted[0] == target
assert BoardWebhook in update_models
@pytest.mark.asyncio @pytest.mark.asyncio