🤯 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(page-collab): keep personal pages out of collaboration rooms (#22434)
Innei56436616c9a7
diff --git a/apps/server/src/services/pageCollab/__tests__/sessions.test.ts b/apps/server/src/services/pageCollab/__tests__/sessions.test.tsindex 76a214db402..2823c07629c 100644--- a/apps/server/src/services/pageCollab/__tests__/sessions.test.ts+++ b/apps/server/src/services/pageCollab/__tests__/sessions.test.ts@@ -3,10 +3,11 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { createPageSessions } from '../index';-const { allowed, meta, roomOpen, row, storedOpen } = vi.hoisted(() => ({+const { allowed, meta, roomOpen, roomOpenLive, row, storedOpen } = vi.hoisted(() => ({allowed: new Set<string>(),meta: { value: null as null | { userId: string; workspaceId: string | null } },roomOpen: vi.fn(),+ roomOpenLive: vi.fn(),row: { value: undefined as undefined | Record<string, unknown> },storedOpen: vi.fn(),}));@@ -26,6 +27,7 @@ vi.mock('../config', () => ({ isPageCollabEnabled: () => true }));vi.mock('../roomSession', () => ({RoomPageSessions: class {+ openLiveSession = roomOpenLive;openSession = roomOpen;},}));@@ -47,8 +49,9 @@ describe('createPageSessions', () => {beforeEach(() => {allowed.clear();meta.value = { userId: 'u1', workspaceId: 'ws_1' };- row.value = { fileType: 'custom/document', id: 'doc_1' };+ row.value = { fileType: 'custom/document', id: 'doc_1', workspaceId: 'ws_1' };roomOpen.mockReset();+ roomOpenLive.mockReset();storedOpen.mockReset();});@@ -77,4 +80,33 @@ describe('createPageSessions', () => {expect(roomOpen).toHaveBeenCalledWith('doc_1');});++ it('edits a personal page on its stored row without opening a room', async () => {+ meta.value = { userId: 'u2', workspaceId: null };+ row.value = { fileType: 'custom/document', id: 'doc_1', workspaceId: null };+ const personalWriter = { ...writer, workspaceId: undefined };++ await createPageSessions({} as any, personalWriter).openSession('doc_1', {+ expectedVersion: 3,+ });++ expect(roomOpen).not.toHaveBeenCalled();+ expect(storedOpen).toHaveBeenCalledWith('doc_1', { expectedVersion: 3 });+ });++ it('keeps writing a personal page through a room an older client still has open', async () => {+ meta.value = { userId: 'u2', workspaceId: null };+ row.value = { fileType: 'custom/document', id: 'doc_1', workspaceId: null };+ const live = { commit: vi.fn() };+ roomOpenLive.mockResolvedValue(live);++ const session = await createPageSessions({} as any, {+ ...writer,+ workspaceId: undefined,+ }).openSession('doc_1');++ expect(session).toBe(live);+ expect(roomOpen).not.toHaveBeenCalled();+ expect(storedOpen).not.toHaveBeenCalled();+ });});diff --git a/apps/server/src/services/pageCollab/index.ts b/apps/server/src/services/pageCollab/index.tsindex f7d7eabb49b..cf00cef8c42 100644--- a/apps/server/src/services/pageCollab/index.ts+++ b/apps/server/src/services/pageCollab/index.ts@@ -35,6 +35,11 @@ export const createPageSessions = (db: LobeChatDatabase, writer: PageWriter): Paif ((await resolvePageAccess(db, writer.userId, documentId)) !== 'edit') {throw new Error(`No permission to edit page: ${documentId}`);}+ if (!row.workspaceId) {+ // Only workspace pages get rooms. A client released before that rule may+ // still hold one open; a write around it would be projected over.+ return (await room.openLiveSession(documentId)) ?? stored.openSession(documentId, options);+ }return room.openSession(documentId);},};diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/pageAgent.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/pageAgent.test.tsindex ff98c8b6a19..1a9c554440f 100644--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/pageAgent.test.ts+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/pageAgent.test.ts@@ -8,6 +8,7 @@ import { pageAgentRuntime } from '../pageAgent';const room = vi.hoisted(() => ({ bootstrapped: false, doc: null as any, pushes: [] as any[] }));const env = vi.hoisted(() => ({ ENABLE_PAGE_COLLAB: true }));+const meta = vi.hoisted(() => ({ workspaceId: 'ws_1' as string | null }));const store = vi.hoisted(() => ({row: null as any,updates: [] as { id: string; params: any }[],@@ -37,7 +38,7 @@ vi.mock('@/server/services/pageCollab/roomClient', async (importOriginal) => {vi.mock('@/server/services/resourcePermission', () => ({canPerformResourceAction: async () => true,- getResourceMeta: async () => ({ userId: 'owner', workspaceId: 'ws_1' }),+ getResourceMeta: async () => ({ userId: 'u1', workspaceId: meta.workspaceId }),}));vi.mock('@/server/services/document', () => ({@@ -69,12 +70,14 @@ beforeEach(() => {room.doc = new Y.Doc();room.pushes = [];room.bootstrapped = false;+ meta.workspaceId = 'ws_1';store.updates = [];store.row = {content: 'para one\n',editorData: null,title: 'Page',updatedAt: new Date('2026-01-01T00:00:00Z'),+ workspaceId: 'ws_1',};});@@ -108,6 +111,25 @@ describe('pageAgentRuntime initPage with collaboration', () => {});expect(store.updates[0].params.content).toContain('new body');});++ it('writes a personal page on its stored row without opening a room', async () => {+ meta.workspaceId = null;+ store.row = { ...store.row, workspaceId: null };++ const result = await createRuntime().initPage({ markdown: '# Fresh\n\nnew body' }, ctx);++ expect(result.success).toBe(true);+ expect(room.pushes).toHaveLength(0);+ expect(store.updates).toHaveLength(1);+ expect(store.updates[0].params).toMatchObject({+ expectedUpdatedAt: store.row.updatedAt,+ history: { agentId: 'agt_1', editorIds: ['u1'], operationId: 'op_root' },+ saveSource: 'llm_call',+ title: 'Fresh',+ });+ expect(store.updates[0].params.origin).toBeUndefined();+ expect(store.updates[0].params.content).toContain('new body');+ });});describe('pageAgentRuntime initPage without collaboration', () => {diff --git a/src/features/PageEditor/collab/usePageCollab.ts b/src/features/PageEditor/collab/usePageCollab.tsindex ba3795ad8cf..948ebaa5ce5 100644--- a/src/features/PageEditor/collab/usePageCollab.ts+++ b/src/features/PageEditor/collab/usePageCollab.ts@@ -45,14 +45,20 @@ const readGatewayUrl = () => {export const usePageCollabEnabled = () => !!readGatewayUrl();/**- * Whether this document edits through a room. A SKILL.md saves its frontmatter- * alongside the body over HTTP, so it never joins one, which carries the body alone.+ * Whether this document edits through a room. Only workspace pages do: a+ * personal page has a single editor, so a room adds nothing but its costs. A+ * SKILL.md saves its frontmatter alongside the body over HTTP, so it never joins+ * one, which carries the body alone.*/export const usePageCollabEligible = (documentId: string | undefined) => {const isSkillMarkdown = useDocumentStore((s) =>documentId ? s.documents[documentId]?.contentFormat === 'skillMarkdown' : false,);- return usePageCollabEnabled() && !!documentId && !isSkillMarkdown;+ const isPersonalPage = useDocumentStore((s) => {+ const document = documentId ? s.documentDetailMap[documentId]?.document : undefined;+ return !!document && !document.workspaceId;+ });+ return usePageCollabEnabled() && !!documentId && !isSkillMarkdown && !isPersonalPage;};export const usePageCollab = (documentId: string | undefined, onReset?: () => void) => {diff --git a/src/features/PageEditor/collab/usePageCollabEligible.test.ts b/src/features/PageEditor/collab/usePageCollabEligible.test.tsnew file mode 100644index 00000000000..5bb409409ab--- /dev/null+++ b/src/features/PageEditor/collab/usePageCollabEligible.test.ts@@ -0,0 +1,41 @@+import { renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useDocumentStore } from '@/store/document';++import { usePageCollabEligible } from './usePageCollab';++vi.mock('@/store/serverConfig', async (importOriginal) => ({+ ...((await importOriginal()) as Record<string, unknown>),+ getServerConfigStoreState: () => ({+ serverConfig: { agentGatewayUrl: 'wss://gateway.example.com', enablePageCollab: true },+ }),+}));++const loadDocument = (workspaceId: string | null) =>+ useDocumentStore.setState({+ documentDetailMap: { doc_1: { document: { id: 'doc_1', workspaceId } as any } as any },+ documents: { doc_1: { content: '', editorData: null, isDirty: false } as any },+ });++describe('usePageCollabEligible', () => {+ beforeEach(() => {+ useDocumentStore.setState({ documentDetailMap: {}, documents: {} });+ });++ it('puts a workspace page in a room', () => {+ loadDocument('ws_1');++ expect(renderHook(() => usePageCollabEligible('doc_1')).result.current).toBe(true);+ });++ it('keeps a personal page out of rooms', () => {+ loadDocument(null);++ expect(renderHook(() => usePageCollabEligible('doc_1')).result.current).toBe(false);+ });++ it('leaves the room path only once the page is known to be personal', () => {+ expect(renderHook(() => usePageCollabEligible('doc_1')).result.current).toBe(true);+ });+});diff --git a/src/store/tool/slices/builtin/executors/pageEdits.test.ts b/src/store/tool/slices/builtin/executors/pageEdits.test.tsindex 79d5cfc712e..762e4b4b836 100644--- a/src/store/tool/slices/builtin/executors/pageEdits.test.ts+++ b/src/store/tool/slices/builtin/executors/pageEdits.test.ts@@ -56,7 +56,20 @@ describe('page edit hooks', () => {await executor.onAfterCall!({ ...call(), result: { success: true } } as any);expect(documentState.endAgentEdit).toHaveBeenCalledWith('doc_1');- expect(invalidateSpy).toHaveBeenCalledWith({ cause: 'document-service', documentId: 'doc_1' });+ expect(invalidateSpy).toHaveBeenCalledWith(+ expect.objectContaining({ cause: 'document-service', documentId: 'doc_1' }),+ );+ });++ it('reloads the resource copy of the page, which the page header takes its title from', async () => {+ await withPageEditHooks(sandboxExecutor as any).onAfterCall!({+ ...call(),+ result: { success: true },+ } as any);++ expect(invalidateSpy).toHaveBeenCalledWith(+ expect.objectContaining({ documentId: 'doc_1', refreshResources: true }),+ );});it('keeps the executor own hooks', async () => {diff --git a/src/store/tool/slices/builtin/executors/pageEdits.ts b/src/store/tool/slices/builtin/executors/pageEdits.tsindex 02ca031b67b..92b0b9757e9 100644--- a/src/store/tool/slices/builtin/executors/pageEdits.ts+++ b/src/store/tool/slices/builtin/executors/pageEdits.ts@@ -49,7 +49,11 @@ const pageEditHooks = {if (!documentId) return;useDocumentStore.getState().endAgentEdit(documentId);- await invalidateDocumentMutation({ cause: 'document-service', documentId });+ await invalidateDocumentMutation({+ cause: 'document-service',+ documentId,+ refreshResources: true,+ });},onBeforeCall: (ctx: ToolHookContext) => {const documentId = resolveStoredPageEdit(ctx);