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(topic-auto-summary): make the workflow opt-in and route it through the branded provider (#18171)

Arvin Xu72d79fa83f95
diff --git a/apps/server/src/services/topicAutoSummary/index.test.ts b/apps/server/src/services/topicAutoSummary/index.test.ts
index 5389374c461..a5a331c30d3 100644
--- a/apps/server/src/services/topicAutoSummary/index.test.ts
+++ b/apps/server/src/services/topicAutoSummary/index.test.ts
@@ -59,7 +59,9 @@ const createDb = () => {
describe('TopicAutoSummaryService', () => {
beforeEach(() => {
vi.clearAllMocks();
- mocks.getUserSettings.mockResolvedValue({});
+ mocks.getUserSettings.mockResolvedValue({
+ systemAgent: { topicAutoSummary: { enabled: true } },
+ });
mocks.generateObject.mockResolvedValue({ description: 'Next steps', summary: 'Combined' });
mocks.updateSummaryIfCurrent.mockResolvedValue(true);
});
@@ -76,4 +78,26 @@ describe('TopicAutoSummaryService', () => {
);
expect(request.messages[1].content).toContain('Recent conversation:\nUSER: What is next?');
});
+
+ it('skips a user who never opted in', async () => {
+ mocks.getUserSettings.mockResolvedValue({});
+ const service = new TopicAutoSummaryService(createDb(), 'user-1');
+
+ const result = await service.summarize('topic-1');
+
+ expect(result).toEqual({ reason: 'disabled', summarized: false });
+ expect(mocks.generateObject).not.toHaveBeenCalled();
+ });
+
+ it('still summarizes an opted-out user when forced', async () => {
+ mocks.getUserSettings.mockResolvedValue({
+ systemAgent: { topicAutoSummary: { enabled: false } },
+ });
+ const service = new TopicAutoSummaryService(createDb(), 'user-1');
+
+ const result = await service.summarize('topic-1', { force: true });
+
+ expect(result).toEqual({ summarized: true });
+ expect(mocks.generateObject).toHaveBeenCalled();
+ });
});
diff --git a/apps/server/src/services/topicAutoSummary/index.ts b/apps/server/src/services/topicAutoSummary/index.ts
index cc4f1f01cd1..7ac714168bd 100644
--- a/apps/server/src/services/topicAutoSummary/index.ts
+++ b/apps/server/src/services/topicAutoSummary/index.ts
@@ -57,7 +57,9 @@ export class TopicAutoSummaryService {
const settings = await new UserModel(this.db, this.userId).getUserSettings();
const systemAgent = settings?.systemAgent as Partial<UserSystemAgentConfig> | undefined;
const config = systemAgent?.topicAutoSummary as Partial<SystemAgentItem> | undefined;
- if (!options.force && config?.enabled === false)
+ // Opt-in, so an absent setting means disabled — the dispatch query filters on
+ // the same default, and this guard also covers replays that skip dispatch.
+ if (!options.force && config?.enabled !== true)
return { reason: 'disabled', summarized: false };
const ownership = this.workspaceId
diff --git a/packages/const/src/settings/systemAgent.ts b/packages/const/src/settings/systemAgent.ts
index cc37acf09e3..58ec9e10766 100644
--- a/packages/const/src/settings/systemAgent.ts
+++ b/packages/const/src/settings/systemAgent.ts
@@ -39,10 +39,13 @@ export const DEFAULT_FOLLOW_UP_ACTION_SYSTEM_AGENT_ITEM: SystemAgentItem = {
provider: DEFAULT_MINI_SYSTEM_AGENT_ITEM.provider,
};
+// Opt-in: summarizing runs unattended in the background and spends the user's
+// own budget, so it stays off until they turn it on. Model/provider follow the
+// branded defaults rather than a hardcoded pair, so the deployment's own
+// gateway resolves the credentials instead of a per-provider server env key.
export const DEFAULT_TOPIC_AUTO_SUMMARY_SYSTEM_AGENT_ITEM: SystemAgentItem = {
- enabled: true,
- model: 'deepseek-v4-flash',
- provider: 'deepseek',
+ ...DEFAULT_SYSTEM_AGENT_ITEM,
+ enabled: false,
};
export const DEFAULT_USER_MEMORY_EMBEDDING_SYSTEM_AGENT_ITEM: SystemAgentItem = {
diff --git a/packages/database/src/models/__tests__/topicSummary.test.ts b/packages/database/src/models/__tests__/topicSummary.test.ts
index b0bfe20b207..83eb5544f51 100644
--- a/packages/database/src/models/__tests__/topicSummary.test.ts
+++ b/packages/database/src/models/__tests__/topicSummary.test.ts
@@ -11,19 +11,25 @@ const db: LobeChatDatabase = await getTestDB();
const model = new TopicSummaryModel(db);
const userId = 'topic-summary-user';
const otherUserId = 'topic-summary-other';
+// Never touched the setting — the feature is opt-in, so this user stays out.
+const unsetUserId = 'topic-summary-unset';
const now = new Date('2026-07-31T12:00:00.000Z');
describe('TopicSummaryModel', () => {
beforeEach(async () => {
await db.delete(users);
- await db.insert(users).values([{ id: userId }, { id: otherUserId }]);
+ await db.insert(users).values([{ id: userId }, { id: otherUserId }, { id: unsetUserId }]);
+ await db.insert(userSettings).values({
+ id: userId,
+ systemAgent: { topicAutoSummary: { enabled: true } },
+ });
});
afterEach(async () => {
await db.delete(users);
});
- it('lists only enabled, stale candidates inside the rolling lookback window', async () => {
+ it('lists only opted-in, stale candidates inside the rolling lookback window', async () => {
await db.insert(userSettings).values({
id: otherUserId,
systemAgent: { topicAutoSummary: { enabled: false } },
@@ -32,6 +38,7 @@ describe('TopicSummaryModel', () => {
{ createdAt: new Date('2026-07-31T00:00:00Z'), id: 'eligible', userId },
{ createdAt: new Date('2026-07-29T00:00:00Z'), id: 'too-old', userId },
{ createdAt: new Date('2026-07-31T00:00:00Z'), id: 'disabled', userId: otherUserId },
+ { createdAt: new Date('2026-07-31T00:00:00Z'), id: 'unset', userId: unsetUserId },
{ createdAt: new Date('2026-07-31T00:00:00Z'), id: 'active', status: 'running', userId },
]);
await db.insert(messages).values([
@@ -59,6 +66,14 @@ describe('TopicSummaryModel', () => {
updatedAt: new Date('2026-07-31T10:00:00Z'),
userId: otherUserId,
},
+ {
+ content: 'c2',
+ id: 'm-unset',
+ role: 'user',
+ topicId: 'unset',
+ updatedAt: new Date('2026-07-31T10:00:00Z'),
+ userId: unsetUserId,
+ },
{
content: 'd',
id: 'm-active',
diff --git a/packages/database/src/models/topicSummary.ts b/packages/database/src/models/topicSummary.ts
index 5e2eb5dc140..c91e94a28bb 100644
--- a/packages/database/src/models/topicSummary.ts
+++ b/packages/database/src/models/topicSummary.ts
@@ -42,7 +42,9 @@ export interface TopicSummaryCandidate {
workspaceId: string | null;
}
-const isTopicAutoSummaryEnabled = sql<boolean>`COALESCE((${userSettings.systemAgent}->'topicAutoSummary'->>'enabled')::boolean, true) = true`;
+// Mirrors `DEFAULT_TOPIC_AUTO_SUMMARY_SYSTEM_AGENT_ITEM.enabled`: users who have
+// never touched the setting are opted out, so the missing-value default is false.
+const isTopicAutoSummaryEnabled = sql<boolean>`COALESCE((${userSettings.systemAgent}->'topicAutoSummary'->>'enabled')::boolean, false) = true`;
const SYSTEM_TOPIC_TRIGGERS = ['cron', 'eval', 'task_manager', 'task', 'document'];
export const topicSummaryEligibleMessage = and(
diff --git a/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap b/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap
index e28138092c8..58ee0204c71 100644
--- a/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap
+++ b/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap
@@ -100,7 +100,7 @@ exports[`settingsSelectors > currentSystemAgent > should merge DEFAULT_SYSTEM_AG
"provider": "openai",
},
"topicAutoSummary": {
- "enabled": true,
+ "enabled": false,
"model": "deepseek-v4-flash",
"provider": "deepseek",
},