🤯 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): user id context missing in tool outcome for signal (#14749)
Nekoa12079d3386d
diff --git a/src/server/services/agentSignal/procedure/__tests__/toolOutcome.test.ts b/src/server/services/agentSignal/procedure/__tests__/toolOutcome.test.tsindex 39ee1ca8334..bcf38efd975 100644--- a/src/server/services/agentSignal/procedure/__tests__/toolOutcome.test.ts+++ b/src/server/services/agentSignal/procedure/__tests__/toolOutcome.test.ts@@ -220,6 +220,7 @@ describe('tool outcome procedure handler', () => {accumulator: createSelfReflectionAccumulator(),getWindowStart: ({ decision }) => decision.windowStart ?? 'missing-window-start',service: { requestSelfReflection },+ userId: 'user-1',},ttlSeconds: 3600,});@@ -266,6 +267,61 @@ describe('tool outcome procedure handler', () => {});});+ /**+ * @example+ * workflow-built tool outcome sources can trigger self-reflection without a hydrated source scope.+ */+ it('uses self-reflection wiring user id when workflow source has no scope', async () => {+ const requestSelfReflection = vi.fn(async () => ({ enqueued: true, sourceId: 'reflect-1' }));+ const handler = createToolOutcomeSourceHandler({+ accumulator: { appendRecord: async () => {} },+ markerStore: { write: async () => {} },+ now: () => 100,+ receiptStore: { append: async () => {} },+ recordStore: { write: async () => {} },+ selfReflection: {+ accumulator: createSelfReflectionAccumulator(),+ getWindowStart: ({ decision }) => decision.windowStart ?? 'missing-window-start',+ service: { requestSelfReflection },+ userId: 'user-from-workflow',+ },+ ttlSeconds: 3600,+ });+ const createFailedSource = (sourceId: string, timestamp: number) =>+ ({+ chain: { chainId: `chain:${sourceId}`, rootSourceId: sourceId },+ payload: {+ agentId: 'agent-1',+ domainKey: 'skill:market-skill',+ intentClass: 'tool_command',+ operationId: 'operation-1',+ outcome: { action: 'import', errorReason: 'network', status: 'failed' },+ tool: { apiName: 'importFromMarket', identifier: 'lobe-skill-store' },+ topicId: 'topic-1',+ },+ scopeKey: 'topic:topic-1',+ sourceId,+ sourceType: AGENT_SIGNAL_SOURCE_TYPES.toolOutcomeFailed,+ timestamp,+ }) as SourceToolOutcomeFailed;++ await handler.handle(createFailedSource('source_failed_no_scope_1', 2000), {+ now: () => 2000,+ scopeKey: 'topic:topic-1',+ } as never);+ await handler.handle(createFailedSource('source_failed_no_scope_2', 3000), {+ now: () => 3000,+ scopeKey: 'topic:topic-1',+ } as never);++ expect(requestSelfReflection).toHaveBeenCalledWith(+ expect.objectContaining({+ reason: 'same_tool_failure_count',+ userId: 'user-from-workflow',+ }),+ );+ });+/*** @example* a single completed outcome stays below self-reflection thresholds.@@ -282,6 +338,7 @@ describe('tool outcome procedure handler', () => {accumulator: createSelfReflectionAccumulator(),getWindowStart: () => '2026-05-04T00:00:00.000Z',service: { requestSelfReflection },+ userId: 'user-1',},ttlSeconds: 3600,});@@ -332,6 +389,7 @@ describe('tool outcome procedure handler', () => {accumulator: createSelfReflectionAccumulator(),getWindowStart: () => '2026-05-04T00:00:00.000Z',service: { requestSelfReflection },+ userId: 'user-1',},ttlSeconds: 3600,});@@ -396,6 +454,7 @@ describe('tool outcome procedure handler', () => {accumulator: createSelfReflectionAccumulator(),getWindowStart: () => '2026-05-04T00:00:00.000Z',service: { requestSelfReflection },+ userId: 'user-1',},ttlSeconds: 3600,});diff --git a/src/server/services/agentSignal/procedure/toolOutcome.ts b/src/server/services/agentSignal/procedure/toolOutcome.tsindex 12bb7c51b0a..57cd8899ba1 100644--- a/src/server/services/agentSignal/procedure/toolOutcome.ts+++ b/src/server/services/agentSignal/procedure/toolOutcome.ts@@ -40,6 +40,8 @@ export interface ToolOutcomeSelfReflectionDeps {getWindowStart: (input: ToolOutcomeSelfReflectionWindowInput) => string;/** Emits self-reflection requests when an accumulator threshold crosses. */service: SelfReflectionService;+ /** Stable workflow user id used when the source renderer does not carry a hydrated scope. */+ userId: string;}/**@@ -153,7 +155,7 @@ const handleSelfReflectionToolOutcome = async (input: {const { selfReflection } = input.deps;if (!selfReflection) return;- const userId = input.source.scope?.userId;+ const userId = input.source.scope?.userId ?? selfReflection.userId;const agentId = input.payload.agentId ?? input.source.scope?.agentId;const status = input.payload.outcome?.status;if (!userId || !agentId || !status) return;diff --git a/src/server/services/agentSignal/services/selfIteration/reflection/server.ts b/src/server/services/agentSignal/services/selfIteration/reflection/server.tsindex b5407928015..9677a704608 100644--- a/src/server/services/agentSignal/services/selfIteration/reflection/server.ts+++ b/src/server/services/agentSignal/services/selfIteration/reflection/server.ts@@ -630,6 +630,7 @@ export const createServerProcedurePolicyOptions = ({});},}),+ userId,},ttlSeconds: 7 * 24 * 60 * 60,});