From 10d4506d3080bc52eac79cf8e491f0396ab5f7f8 Mon Sep 17 00:00:00 2001 From: Robin Braumann Date: Tue, 15 Sep 2026 11:48:38 +0200 Subject: [PATCH] fix(core): scope agent name lookup to the project Co-authored-by: Cursor --- .../agents/__tests__/agent-execution.service.test.ts | 2 +- .../src/modules/agents/agent-turn-queue.service.ts | 11 ++++++----- .../modules/agents/repositories/agent.repository.ts | 6 ++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/modules/agents/__tests__/agent-execution.service.test.ts b/packages/cli/src/modules/agents/__tests__/agent-execution.service.test.ts index 383c55e7cec..381ab758169 100644 --- a/packages/cli/src/modules/agents/__tests__/agent-execution.service.test.ts +++ b/packages/cli/src/modules/agents/__tests__/agent-execution.service.test.ts @@ -102,7 +102,7 @@ describe('AgentExecutionService', () => { async function recordExecution(params: RecordMessageParams): Promise { const { record, ...startParams } = params; const executionId = await service.startExecutionRecording( - { ...startParams, agentName: 'Agent' }, + { ...startParams, agentName: startParams.agentName ?? 'Agent' }, new Date(record.startTime), ); return await service.finalizeExecution(executionId, params); diff --git a/packages/cli/src/modules/agents/agent-turn-queue.service.ts b/packages/cli/src/modules/agents/agent-turn-queue.service.ts index 804ff1c41c7..bf9e1b53f09 100644 --- a/packages/cli/src/modules/agents/agent-turn-queue.service.ts +++ b/packages/cli/src/modules/agents/agent-turn-queue.service.ts @@ -123,11 +123,12 @@ export class AgentTurnQueueService { private async withAgentName( turn: AgentTurnSubmission, ): Promise { - const [agent] = await this.agentRepository.findSummariesByIds([turn.agentId]); - if (!agent || agent.projectId !== turn.projectId) { - throw new UserError(`Agent "${turn.agentId}" not found`); - } - return { ...turn, agentName: agent.name }; + const agentName = await this.agentRepository.findNameByIdAndProjectId( + turn.agentId, + turn.projectId, + ); + if (agentName === null) throw new UserError(`Agent "${turn.agentId}" not found`); + return { ...turn, agentName }; } private async requestWake(threadId: string): Promise { diff --git a/packages/cli/src/modules/agents/repositories/agent.repository.ts b/packages/cli/src/modules/agents/repositories/agent.repository.ts index 047ec8cba81..b1350cc9da1 100644 --- a/packages/cli/src/modules/agents/repositories/agent.repository.ts +++ b/packages/cli/src/modules/agents/repositories/agent.repository.ts @@ -210,6 +210,12 @@ export class AgentRepository extends Repository { return await this.exists({ where: { id, projectId } }); } + /** Scoped to the project so ownership is enforced by the query; `null` when the agent is not in it. */ + async findNameByIdAndProjectId(id: string, projectId: string): Promise { + const agent = await this.findOne({ select: ['id', 'name'], where: { id, projectId } }); + return agent?.name ?? null; + } + async findByIdsAndProjectId( ids: string[], projectId: string,