Skip to content

🤯 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.

🐛 fix(server): forward run workspaceId in declareSelfFeedbackIntent enqueue scope (#21210)

Arvin Xue95ce3c4bc4f
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/selfFeedbackIntent.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/selfFeedbackIntent.test.ts
index aa20a925f77..4864ce277cc 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/selfFeedbackIntent.test.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/selfFeedbackIntent.test.ts
@@ -92,10 +92,63 @@ describe('selfFeedbackIntentRuntime', () => {
sourceId: 'self-feedback-intent:user-1:agent-1:operation:operation-1:tool-call-1',
sourceType: 'agent.self_feedback_intent.declared',
}),
- { agentId: 'agent-1', userId: 'user-1' },
+ { agentId: 'agent-1', userId: 'user-1', workspaceId: undefined },
);
});
+ /**
+ * @example
+ * A workspace-scoped run forwards its workspaceId to the enqueue boundary, so
+ * `assertAgentUsableBy` resolves the agent inside the team workspace instead of
+ * failing the personal-mode lookup with "Agent not found" (T-888).
+ */
+ it('forwards the run workspaceId to the enqueue boundary', async () => {
+ const runtime = selfFeedbackIntentRuntime.factory({
+ toolManifestMap: {},
+ workspaceId: 'workspace-1',
+ });
+
+ const result = await runtime.declareSelfFeedbackIntent(createInput(), {
+ agentId: 'agent-1',
+ toolCallId: 'tool-call-ws',
+ toolManifestMap: {},
+ topicId: 'topic-1',
+ userId: 'user-1',
+ });
+
+ expect(result.success).toBe(true);
+ expect(enqueueAgentSignalSourceEvent).toHaveBeenCalledWith(
+ expect.objectContaining({
+ payload: expect.objectContaining({ agentId: 'agent-1', userId: 'user-1' }),
+ sourceType: 'agent.self_feedback_intent.declared',
+ }),
+ { agentId: 'agent-1', userId: 'user-1', workspaceId: 'workspace-1' },
+ );
+ });
+
+ /**
+ * @example
+ * A personal run (no workspaceId) keeps enqueueing without a workspace scope.
+ */
+ it('omits the workspace scope for personal runs', async () => {
+ const runtime = selfFeedbackIntentRuntime.factory({ toolManifestMap: {} });
+
+ const result = await runtime.declareSelfFeedbackIntent(createInput(), {
+ agentId: 'agent-1',
+ toolCallId: 'tool-call-personal',
+ toolManifestMap: {},
+ topicId: 'topic-1',
+ userId: 'user-1',
+ });
+
+ expect(result.success).toBe(true);
+ expect(enqueueAgentSignalSourceEvent).toHaveBeenCalledWith(expect.anything(), {
+ agentId: 'agent-1',
+ userId: 'user-1',
+ workspaceId: undefined,
+ });
+ });
+
/**
* @example
* Missing runtime identity context returns a tool failure instead of enqueueing a source.
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/selfFeedbackIntent.ts b/apps/server/src/services/toolExecution/serverRuntimes/selfFeedbackIntent.ts
index 6f58cbadaab..8fbc5a3b99e 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/selfFeedbackIntent.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/selfFeedbackIntent.ts
@@ -8,24 +8,9 @@ import {
createSelfFeedbackIntentService,
} from '@/server/services/agentSignal/services/selfFeedbackIntent';
+import type { ToolExecutionContext } from '../types';
import type { ServerRuntimeRegistration } from './types';
-const sharedSelfFeedbackIntentService = createSelfFeedbackIntentService({
- // Serverless instances do not share memory, so the per-scope declaration
- // limit lives in Redis to hold across processes.
- declarationLimiter: createRedisDeclarationLimiter(),
- enqueueSource: (sourceEvent) =>
- enqueueAgentSignalSourceEvent(sourceEvent, {
- agentId: sourceEvent.payload.agentId,
- userId: sourceEvent.payload.userId,
- }),
- nextToolCallId: () => nanoid(),
-});
-
-const runtime = new SelfFeedbackIntentExecutionRuntime({
- service: sharedSelfFeedbackIntentService,
-});
-
/**
* Registers the self-feedback intent builtin server runtime.
*
@@ -36,12 +21,28 @@ const runtime = new SelfFeedbackIntentExecutionRuntime({
*
* Expects:
* - The package ExecutionRuntime validates per-call `agentId`, `userId`, and `topicId`
- * - The shared service enforces the per-scope declaration limit through Redis
+ * - The shared service enforces the per-scope declaration limit through Redis (the limiter
+ * state lives in Redis, so rebuilding it per request preserves the cross-process limit)
*
* Returns:
- * - A shared runtime instance backed by the server Agent Signal enqueue boundary
+ * - A per-request runtime backed by the server Agent Signal enqueue boundary. Built per call
+ * because `enqueueAgentSignalSourceEvent` resolves agent ownership through the run's
+ * `workspaceId` — a workspace agent enqueued without it fails the `assertAgentUsableBy`
+ * personal-mode lookup and the tool reports "Agent not found" (see T-888).
*/
export const selfFeedbackIntentRuntime: ServerRuntimeRegistration = {
- factory: () => runtime,
+ factory: (context: ToolExecutionContext) =>
+ new SelfFeedbackIntentExecutionRuntime({
+ service: createSelfFeedbackIntentService({
+ declarationLimiter: createRedisDeclarationLimiter(),
+ enqueueSource: (sourceEvent) =>
+ enqueueAgentSignalSourceEvent(sourceEvent, {
+ agentId: sourceEvent.payload.agentId,
+ userId: sourceEvent.payload.userId,
+ workspaceId: context.workspaceId,
+ }),
+ nextToolCallId: () => nanoid(),
+ }),
+ }),
identifier: SELF_FEEDBACK_INTENT_IDENTIFIER,
};