🤯 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(topic): keep runtime metadata writes server-owned (#20192)
Bryanb43caaad0a96
diff --git a/packages/types/src/topic/topic.test.ts b/packages/types/src/topic/topic.test.tsindex 153cc6d7f69..17992e7abaa 100644--- a/packages/types/src/topic/topic.test.ts+++ b/packages/types/src/topic/topic.test.ts@@ -59,7 +59,7 @@ describe('chatTopicMetadataUpdateSchema', () => {expect(chatTopicMetadataUpdateSchema.parse(metadata)).toEqual(metadata);});- it('preserves orchestration roles on running operations', () => {+ it('rejects client-written orchestration roles on running operations', () => {const metadata = {runningOperation: {assistantMessageId: 'assistant-supervisor',@@ -75,6 +75,58 @@ describe('chatTopicMetadataUpdateSchema', () => {},};+ expect(chatTopicMetadataUpdateSchema.safeParse(metadata).success).toBe(false);+ });++ it('accepts clearing a stale running operation and omitting it', () => {+ expect(chatTopicMetadataUpdateSchema.parse({ runningOperation: null })).toEqual({+ runningOperation: null,+ });+ expect(chatTopicMetadataUpdateSchema.parse({})).toEqual({});+ });++ const operation = { assistantMessageId: 'assistant-1', operationId: 'operation-1' };+ const hooks = [+ {+ id: 'client-hook',+ type: 'onComplete',+ webhook: { body: { userId: 'client-supplied' }, url: 'https://example.com/hook' },+ },+ ];++ it.each([+ ['root hooks', { ...operation, hooks }],+ ['child hooks', { ...operation, childOperations: [{ ...operation, hooks }] }],+ ['operation identifiers without hooks', operation],+ ['empty object', {}],+ ['array', []],+ ['string', 'operation-1'],+ ['boolean', false],+ ['number', 1],+ ])('rejects %s instead of silently stripping runtime state', (_, runningOperation) => {+ const result = chatTopicMetadataUpdateSchema.safeParse({+ model: 'test-model',+ runningOperation,+ });++ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.issues.some((issue) => issue.path[0] === 'runningOperation')).toBe(true);+ }+ });++ it('preserves supported metadata patches alongside a stale-marker clear', () => {+ const metadata = {+ boundDeviceId: 'device-1',+ model: 'test-model',+ onboardingSession: { phase: 'summary', finishedAt: '2026-09-29T00:00:00.000Z' },+ provider: 'test-provider',+ reasoningConfig: { gpt5ReasoningEffort: 'high' },+ repos: ['owner/repo'],+ runningOperation: null,+ workingDirectory: '/repo',+ };+expect(chatTopicMetadataUpdateSchema.parse(metadata)).toEqual(metadata);});diff --git a/packages/types/src/topic/topic.ts b/packages/types/src/topic/topic.tsindex c88095cfc7f..3ddec6d6a69 100644--- a/packages/types/src/topic/topic.ts+++ b/packages/types/src/topic/topic.ts@@ -4,7 +4,6 @@ import { z } from 'zod';import type { HeterogeneousReasoningEffort } from '../agent/heteroSelectorCapabilities';import type { SerializedAgentHook } from '../agentHook';-import { serializedAgentHookSchema } from '../agentHook';import type { WorkingDirConfig } from '../device';import { workingDirConfigSchema } from '../device';import type { BaseDataModel } from '../meta';@@ -554,37 +553,8 @@ export const chatTopicMetadataUpdateSchema = z.object({lastSettledOperationId: z.string().optional(),reasoningConfig: AiModelReasoningConfigSchema.optional(),repos: z.array(z.string()).optional(),- runningOperation: z- .object({- assistantMessageId: z.string(),- childOperations: z- .array(- z.object({- assistantMessageId: z.string(),- deviceId: z.string().optional(),- deviceUserId: z.string().optional(),- deviceWorkspaceId: z.string().optional(),- heteroType: z.string().nullable().optional(),- hooks: z.array(serializedAgentHookSchema).optional(),- operationId: z.string(),- orchestrationRole: z.enum(['supervisor', 'member']).optional(),- scope: z.string().optional(),- threadId: z.string().nullish(),- }),- )- .optional(),- deviceId: z.string().optional(),- deviceUserId: z.string().optional(),- deviceWorkspaceId: z.string().optional(),- heteroType: z.string().nullable().optional(),- hooks: z.array(serializedAgentHookSchema).optional(),- operationId: z.string(),- orchestrationRole: z.enum(['supervisor', 'member']).optional(),- scope: z.string().optional(),- threadId: z.string().nullish(),- })- .nullable()- .optional(),+ // Runtime state and hooks are server-owned; clients may only clear a stale marker.+ runningOperation: z.null().optional(),taskCallbackReservation: z.object({messageId: z.string(),@@ -597,6 +567,9 @@ export const chatTopicMetadataUpdateSchema = z.object({workingDirectoryConfig: workingDirConfigSchema.optional(),});+/** Public topic metadata patch, distinct from the full persisted metadata. */+export type UpdateTopicMetadataInput = z.input<typeof chatTopicMetadataUpdateSchema>;+/*** Metadata a client may seed when creating a topic: the pinned reasoning* snapshot taken alongside the pinned model (see `snapshotAgentModel`).diff --git a/src/services/topic/index.ts b/src/services/topic/index.tsindex 4fb0ba185cb..adafec3c0a5 100644--- a/src/services/topic/index.ts+++ b/src/services/topic/index.ts@@ -2,6 +2,7 @@ import type {HeteroSessionImportPayload,HeteroSessionImportResult,HeteroSessionImportStatus,+ UpdateTopicMetadataInput,} from '@lobechat/types';import { INBOX_SESSION_ID } from '@/const/session';@@ -44,12 +45,6 @@ export interface TopicListItem extends ChatTopic {export type TopicBatchDeleteScope = 'own' | 'workspace';-type OnboardingSessionMetadataPatch = Partial<NonNullable<ChatTopicMetadata['onboardingSession']>>;--type UpdateTopicMetadataInput = Omit<Partial<ChatTopicMetadata>, 'onboardingSession'> & {- onboardingSession?: OnboardingSessionMetadataPatch;-};-export class TopicService {cancelRateLimitContinuation = (id: string) =>lambdaClient.topic.cancelRateLimitContinuation.mutate({ id });diff --git a/src/store/chat/slices/topic/action.ts b/src/store/chat/slices/topic/action.tsindex c9483d3ec21..f35731b4b16 100644--- a/src/store/chat/slices/topic/action.ts+++ b/src/store/chat/slices/topic/action.ts@@ -12,6 +12,7 @@ import {type MessageMapScope,RequestTrigger,type UIChatMessage,+ type UpdateTopicMetadataInput,} from '@lobechat/types';import { toast } from '@lobehub/ui/base-ui';import isEqual from 'fast-deep-equal';@@ -461,7 +462,10 @@ export class ChatTopicActionImpl {);};- updateTopicMetadata = async (id: string, metadata: Partial<ChatTopicMetadata>): Promise<void> => {+ updateTopicMetadata = async (+ id: string,+ metadata: UpdateTopicMetadataInput & Pick<ChatTopicMetadata, 'onboardingSession'>,+ ): Promise<void> => {const topic = topicSelectors.getTopicById(id)(this.#get());if (!topic) {await topicService.updateTopicMetadata(id, metadata);