π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(server-runtimes): fail loudly instead of fake-success when the target agent row is missing (#20744)
Arvin Xueac6afee6404
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentBuilder.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentBuilder.test.tsindex be64177211a..28f2bda5253 100644--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentBuilder.test.ts+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentBuilder.test.ts@@ -11,6 +11,7 @@ const {mockQueryPlugins,mockResolveConnectors,mockUpdatePlugin,+ mockExistsById,mockGetAgentConfigById,mockGetAiProviderList,mockGetAiProviderModelList,@@ -25,6 +26,7 @@ const {mockQueryPlugins: vi.fn(),mockResolveConnectors: vi.fn(),mockUpdatePlugin: vi.fn(),+ mockExistsById: vi.fn(),mockGetAgentConfigById: vi.fn(),mockGetAiProviderList: vi.fn(),mockGetAiProviderModelList: vi.fn(),@@ -48,6 +50,7 @@ vi.mock('@/server/services/agent', () => ({vi.mock('@/database/models/agent', () => ({AgentModel: vi.fn(function () {return {+ existsById: mockExistsById,getAgentConfigById: mockGetAgentConfigById,update: mockUpdateAgent,updateConfig: mockUpdateConfig,@@ -107,6 +110,7 @@ const createWorkspaceRuntime = () =>describe('agentBuilderRuntime', () => {beforeEach(() => {vi.clearAllMocks();+ mockExistsById.mockResolvedValue(true);mockServiceUpdateConfig.mockImplementation((...args) => mockUpdateConfig(...args));mockGetHiddenBuiltinModelsForUser.mockResolvedValue(undefined);mockResolveConnectors.mockResolvedValue([]);@@ -375,6 +379,38 @@ describe('agentBuilderRuntime', () => {});});+ describe('existence guard (0-row silent no-op)', () => {+ it('updatePrompt fails loudly when the editing agent no longer exists', async () => {+ mockExistsById.mockResolvedValue(false);++ const result = await createRuntime().updatePrompt(+ { prompt: 'orphan prompt' },+ { editingAgentId: 'agent-missing', toolManifestMap: {} },+ );++ expect(result.success).toBe(false);+ expect(result.content).toContain('not found');+ expect(mockUpdateAgent).not.toHaveBeenCalled();+ });++ // updateConfig's own entry guard (pre-existing) resolves via+ // getAgentConfigById β that read stays functionally needed for+ // togglePlugin, so this test exercises that path, not existsById.+ it('updateConfig meta-only writes fail loudly when the editing agent no longer exists', async () => {+ mockGetAgentConfigById.mockResolvedValue(undefined);++ const result = await createRuntime().updateConfig(+ { meta: { title: 'Ghost' } },+ { editingAgentId: 'agent-missing', toolManifestMap: {} },+ );++ expect(result.success).toBe(false);+ expect(result.content).toContain('not found');+ expect(mockUpdateConfig).not.toHaveBeenCalled();+ expect(mockUpdateAgent).not.toHaveBeenCalled();+ });+ });+describe('installPlugin', () => {it('flips an existing disabled builtin-tool entry back to pinned, without duplicating it', async () => {mockGetAgentConfigById.mockResolvedValue({diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.tsindex 5dc8d6c1394..1e87396042f 100644--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.ts+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/agentManagement.test.ts@@ -10,8 +10,10 @@ const {mockCountAgents,mockGetAssistantList,mockQueryAgents,+ mockExistsById,mockGetAgentConfigById,mockServiceUpdateConfig,+ mockUpdateAgent,mockUpdateConfig,mockFindById,mockCreatePlugin,@@ -27,10 +29,12 @@ const {mockQueryPlugins: vi.fn(),mockResolveConnectors: vi.fn(),mockUpdatePlugin: vi.fn(),+ mockExistsById: vi.fn(),mockGetAgentConfigById: vi.fn(),mockGetAssistantList: vi.fn(),mockQueryAgents: vi.fn(),mockServiceUpdateConfig: vi.fn(),+ mockUpdateAgent: vi.fn(),mockUpdateConfig: vi.fn(),}));@@ -44,8 +48,10 @@ vi.mock('@/database/models/agent', () => ({AgentModel: vi.fn(function () {return {countAgents: mockCountAgents,+ existsById: mockExistsById,getAgentConfigById: mockGetAgentConfigById,queryAgents: mockQueryAgents,+ update: mockUpdateAgent,updateConfig: mockUpdateConfig,};}),@@ -104,6 +110,7 @@ const makeAgents = (count: number, startIndex = 0) =>describe('agentManagementRuntime', () => {beforeEach(() => {vi.clearAllMocks();+ mockExistsById.mockResolvedValue(true);mockServiceUpdateConfig.mockImplementation((...args) => mockUpdateConfig(...args));mockResolveConnectors.mockResolvedValue([]);mockQueryPlugins.mockResolvedValue([]);@@ -139,6 +146,62 @@ describe('agentManagementRuntime', () => {expect(PluginModel).toHaveBeenCalledWith(expect.anything(), 'user-1', 'workspace-1');});+ describe('existence guard (0-row silent no-op)', () => {+ it('updateAgent fails loudly for an agent that does not exist', async () => {+ mockExistsById.mockResolvedValue(false);++ const result = await createRuntime().updateAgent({+ agentId: 'agent-missing',+ config: { model: 'gpt-4o' },+ });++ expect(result.success).toBe(false);+ expect(result.content).toContain('not found');+ expect(mockServiceUpdateConfig).not.toHaveBeenCalled();+ expect(mockUpdateAgent).not.toHaveBeenCalled();+ });++ it('updateAgent still writes meta once the guard passes', async () => {+ mockGetAgentConfigById.mockResolvedValue({ id: 'agent-1' });++ const result = await createRuntime().updateAgent({+ agentId: 'agent-1',+ meta: { title: 'Renamed' },+ });++ expect(result.success).toBe(true);+ expect(mockUpdateAgent).toHaveBeenCalledWith('agent-1', { title: 'Renamed' });+ });++ it('updatePrompt fails loudly for an agent that does not exist', async () => {+ mockExistsById.mockResolvedValue(false);++ const result = await createRuntime().updatePrompt({+ agentId: 'agent-missing',+ prompt: 'new prompt',+ });++ expect(result.success).toBe(false);+ expect(result.content).toContain('not found');+ expect(mockUpdateAgent).not.toHaveBeenCalled();+ });++ it('updatePrompt writes through once the guard passes', async () => {+ mockGetAgentConfigById.mockResolvedValue({ id: 'agent-1' });++ const result = await createRuntime().updatePrompt({+ agentId: 'agent-1',+ prompt: 'new prompt',+ });++ expect(result.success).toBe(true);+ expect(mockUpdateAgent).toHaveBeenCalledWith('agent-1', {+ editorData: null,+ systemRole: 'new prompt',+ });+ });+ });+describe('callAgent', () => {it('fails when the server sub-agent runner is unavailable', async () => {const runtime = createRuntime();diff --git a/apps/server/src/services/toolExecution/serverRuntimes/agentBuilder.ts b/apps/server/src/services/toolExecution/serverRuntimes/agentBuilder.tsindex 051eb2689ec..9bb245079b6 100644--- a/apps/server/src/services/toolExecution/serverRuntimes/agentBuilder.ts+++ b/apps/server/src/services/toolExecution/serverRuntimes/agentBuilder.ts@@ -292,6 +292,16 @@ export const agentBuilderRuntime: ServerRuntimeRegistration = {if (!agentId) return noEditingTargetResult;try {+ // Existence guard: a Drizzle UPDATE on a missing/foreign agent row is a+ // silent 0-row no-op, so the prompt write would "succeed" without+ // persisting anything. updateConfig already fails loudly; align it.+ // Lightweight existsById probe β getAgentConfigById would needlessly+ // enrich the row with knowledge associations just to test existence.+ const exists = await agentModel.existsById(agentId);+ if (!exists) {+ return { content: `Agent "${agentId}" not found.`, success: false };+ }+await agentModel.update(agentId, {editorData: null,systemRole: params.prompt,diff --git a/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.ts b/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.tsindex 847cc33006a..175a621d769 100644--- a/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.ts+++ b/apps/server/src/services/toolExecution/serverRuntimes/agentManagement.ts@@ -393,6 +393,17 @@ export const agentManagementRuntime: ServerRuntimeRegistration = {const { agentId } = params;let { config, meta } = params;+ // Existence guard: a Drizzle UPDATE on a missing/foreign agent row is a+ // silent 0-row no-op, so writes would "succeed" without persisting+ // anything. Fail loudly like the config path already does. Uses the+ // lightweight existsById probe instead of getAgentConfigById, which+ // needlessly enriches the row with knowledge associations just to+ // test existence.+ const exists = await agentModel.existsById(agentId);+ if (!exists) {+ return { content: `Agent "${agentId}" not found.`, success: false };+ }+// Guard against LLM double-encoding: parse strings if neededif (typeof config === 'string') {try {@@ -438,6 +449,14 @@ export const agentManagementRuntime: ServerRuntimeRegistration = {updatePrompt: async (params: UpdatePromptParams): Promise<ToolExecutionResult> => {try {const { agentId, prompt } = params;++ // Existence guard: same 0-row silent no-op hazard as updateAgent.+ // Lightweight existsById probe (see updateAgent note).+ const exists = await agentModel.existsById(agentId);+ if (!exists) {+ return { content: `Agent "${agentId}" not found.`, success: false };+ }+await agentModel.update(agentId, { editorData: null, systemRole: prompt } as Record<string,unknown