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: remove route context production log (#16632)

YuTengjingd65c61bb06bf
diff --git a/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts b/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts
index 8d0d044d067..23c1055212a 100644
--- a/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts
+++ b/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts
@@ -255,7 +255,7 @@ describe('createRouterRuntime', () => {
);
});
- it('should log missing route attempt context outside development without filtering by model', async () => {
+ it('should not log missing route attempt context outside development', async () => {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
const mockChat = vi.fn().mockResolvedValue('chat-response');
@@ -284,26 +284,7 @@ describe('createRouterRuntime', () => {
});
expect(result).toBe('chat-response');
- expect(consoleError).toHaveBeenCalledWith('[RouteAttemptMissingContext]', expect.any(String));
-
- const rawDiagnostic = consoleError.mock.calls[0][1] as string;
- const diagnostic = JSON.parse(rawDiagnostic);
-
- expect(diagnostic).toEqual(
- expect.objectContaining({
- apiType: 'openai',
- channelId: 'channel-1',
- metadataKeys: [],
- missingTrigger: true,
- missingUser: true,
- model: 'claude-3-sonnet',
- optionUserPresent: false,
- runtimeUserIdPresent: false,
- toolsCount: 1,
- }),
- );
- expect(rawDiagnostic).not.toContain('do-not-log');
- expect(rawDiagnostic).not.toContain('secret_tool');
+ expect(consoleError).not.toHaveBeenCalled();
});
it('should not attach route attempt metadata for non-lobehub runtime', async () => {
diff --git a/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts b/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
index 5cc26214685..cfcee752532 100644
--- a/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
+++ b/packages/model-runtime/src/core/RouterRuntime/createRuntime.ts
@@ -247,6 +247,7 @@ export const createRouterRuntime = ({
const traceId = typeof metadata?.traceId === 'string' ? metadata.traceId : undefined;
if (this._id !== 'lobehub' || (effectiveUserId && trigger)) return effectiveUserId;
+ if (process.env.NODE_ENV !== 'development') return effectiveUserId;
const diagnostic = {
apiType,
@@ -266,13 +267,7 @@ export const createRouterRuntime = ({
};
// Example bug: modelRuntime.chat(payload) without metadata would record trigger=null.
- if (process.env.NODE_ENV === 'development') {
- throw new Error(`[RouteAttemptMissingContext] ${JSON.stringify(diagnostic)}`);
- }
-
- console.error('[RouteAttemptMissingContext]', JSON.stringify(diagnostic));
-
- return effectiveUserId;
+ throw new Error(`[RouteAttemptMissingContext] ${JSON.stringify(diagnostic)}`);
}
constructor(options: LobeClientOptions & Record<string, any> = {}) {