Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auth): 区域提交时立即发布新的账号代次
xd-bobo5173345c4fc3
diff --git a/apps/desktop/src/main/__tests__/appSessionBoundary.test.ts b/apps/desktop/src/main/__tests__/appSessionBoundary.test.tsindex 3aaea4b3e7..969e616921 100644--- a/apps/desktop/src/main/__tests__/appSessionBoundary.test.ts+++ b/apps/desktop/src/main/__tests__/appSessionBoundary.test.ts@@ -1,4 +1,7 @@import { describe, expect, it, vi } from 'vitest';+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import ts from 'typescript';const ghostBoundary = vi.hoisted(() => ({ stable: false }));@@ -38,7 +41,25 @@ import {clearAllSessionRuntimeControlStates,sessionRuntimeControlOwnerEpochMatches,} from '../maker-ipc/sessionRuntimeControl.js';-import { isDataOwnerPushCurrent, setDataOwnerGeneration } from '../../renderer/contexts/dataOwnerGeneration';+import { getDataOwnerGeneration, isDataOwnerGenerationCurrent, isDataOwnerPushCurrent, setDataOwnerGeneration } from '../../renderer/contexts/dataOwnerGeneration';++// Execute the actual private auth commit with real session state and an IPC+// queue double, without importing credentials or the full Electron runtime.+const authSource = readFileSync(resolve(process.cwd(), 'src/main/authManager.ts'), 'utf8').replace(/\r\n/g, '\n');+const commitStart = authSource.indexOf('function commitCloudAppSession(');+const commitSource = authSource.slice(commitStart, authSource.indexOf('\n}\n', commitStart) + 2);+const compiledCommit = ts.transpileModule(commitSource, {+ compilerOptions: { target: ts.ScriptTarget.ES2022 },+}).outputText;+const createCloudCommit = new Function(+ 'isPassiveSharedUserDataInstance', 'commitVolatileAppSession', 'commitActiveAppSession', 'notifyRenderer',+ `${compiledCommit}\nreturn commitCloudAppSession;`,+) as (+ passive: () => boolean,+ volatileCommit: typeof commitVolatileAppSession,+ activeCommit: typeof commitActiveAppSession,+ notify: () => void,+) => (ownerId: string, authRealmChanged: boolean) => void;describe('application session boundary isolation', () => {it('does not treat a different durable Ghost projection owner as an App transition', () => {@@ -140,3 +161,37 @@ describe('application session boundary isolation', () => {}});});++describe('cloud session realm publication', () => {+ it.each([false, true])('publishes a realm generation before yielding to post-commit work (passive=%s)', async (passive) => {+ commitActiveAppSession('cloud', 'shared-membership-id');+ const previous = getActiveAppSession();+ setDataOwnerGeneration(previous.dataOwnerId, previous.generation);+ const oldRendererOwner = getDataOwnerGeneration();+ const frames: ReturnType<typeof getActiveAppSession>[] = [];+ const commit = createCloudCommit(+ () => passive, commitVolatileAppSession, commitActiveAppSession,+ () => { frames.push(getActiveAppSession()); },+ );+ let finishMigration!: () => void;+ const migration = new Promise<void>((resolve) => { finishMigration = resolve; });+ const transition = (async () => {+ commit('shared-membership-id', true);+ await migration;+ })();+ // No process-local boundary is needed on the stable same-owner fast path.+ // The auth frame must already precede any response to a new-realm read.+ expect(isAppSessionBoundaryPending()).toBe(false);+ expect(frames).toEqual([{ ...previous, generation: previous.generation + 1 }]);+ for (const frame of frames) setDataOwnerGeneration(frame.dataOwnerId, frame.generation);+ expect(isDataOwnerGenerationCurrent(oldRendererOwner)).toBe(false);+ const current = getActiveAppSession();+ frames.length = 0;+ commit('shared-membership-id', false);+ expect(getActiveAppSession()).toEqual(current);+ expect(frames).toEqual([]);+ finishMigration();+ await transition;+ });++});diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.tsindex 1026586af3..303d0d850d 100644--- a/apps/desktop/src/main/authManager.ts+++ b/apps/desktop/src/main/authManager.ts@@ -2720,6 +2720,10 @@ function commitCloudAppSession(ownerId: string, authRealmChanged = false): void} else {commitActiveAppSession('cloud', ownerId, authRealmChanged);}+ // Publish the new generation in the same synchronous commit as the token+ // and endpoint switch, before any post-commit migration/projection await.+ // Same-id realm moves do not necessarily enter a Ghost owner boundary.+ if (authRealmChanged) notifyRenderer();}/**diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 38dd600e30..f9ac3d5176 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -121,6 +121,8 @@进度回调与 IPC 标记之间同步复核发起代次,不能给旧发布重新标上当前账号。认证区域变化也是代次边界,即使 membership ID 相同:显式登录、恢复和运行期刷新均推进 owner generation,主实例与共享 userData 的被动实例一致;同区域普通刷新不推进。+ 区域、令牌与代次同步提交时立即发送新认证快照,不等后续迁移或投影收尾的 await;+ 即使同 owner 的稳定投影不进入 teardown 边界,新区域请求返回前也已发布新代次。因此现有请求 scope 与推送 stamp 即可拒绝旧区域反馈,无需修改 wire 字段或持久账号键。已打开的自动结果也保存 owner snapshot,在新代次的首次渲染中隐藏旧反馈;同 ID跨区域切换不依赖按 dataOwnerId 重挂路由,普通同代次刷新仍保留当前结果。