Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): active-Orca rehydrate 关旧 runtime 前先按 DB 对账 resumeSessionId (#2882) (#3818)

fico-hubab805af81f3a
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
index 81ae33a234..460c8caf3e 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
@@ -1425,6 +1425,73 @@ describe('maker SEND transaction', () => {
expect(newSession.send).toHaveBeenCalled();
});
+ it('reconciles createOpts against DB before closing the old runtime on active Orca rehydrate (#2882)', async () => {
+ const oldSession = createSession({ id: 'orca-session', workDir: 'C:\\repo' });
+ const newSession = createSession({ id: 'orca-session', workDir: 'C:\\repo' });
+ const reconcileCreateOptsWithDb = vi.fn(async (_sessionId: string, co: MakerSessionCreateOpts) => {
+ co.resumeSessionId = 'db-sdk-session-id';
+ });
+ const { deps } = createDeps({
+ getSession: vi.fn(() => oldSession),
+ isOrcaMcpHydrated: vi.fn(() => false),
+ synthesizeOrcaVendorOptionsFromDb: vi.fn(async () => true),
+ reconcileCreateOptsWithDb,
+ bootstrapSession: vi.fn(async () => ({
+ session: newSession,
+ didInjectOrcaInstructions: true,
+ didInjectProjectContext: false,
+ })),
+ });
+ const transaction = createMakerSendTransaction(deps);
+
+ await expect(
+ transaction.sendToAgentAccepted('orca-session', 'hello', {
+ id: 'orca-session',
+ agentKind: 'pi',
+ workingDir: 'C:\\repo',
+ model: 'k3',
+ // caller 快照携带陈旧 resume:DB 权威值必须胜出,而不是仅在缺省时补值。
+ resumeSessionId: 'stale-caller-resume',
+ }),
+ ).resolves.toMatchObject({ accepted: true });
+
+ expect(reconcileCreateOptsWithDb).toHaveBeenCalledOnce();
+ // 对账必须发生在 closeSession 之前:DB 读失败时旧 runtime 不能已被关闭。
+ expect(reconcileCreateOptsWithDb.mock.invocationCallOrder[0]).toBeLessThan(
+ vi.mocked(deps.closeSession).mock.invocationCallOrder[0]!,
+ );
+ expect(deps.bootstrapSession).toHaveBeenCalledWith(
+ expect.objectContaining({ resumeSessionId: 'db-sdk-session-id' }),
+ );
+ expect(newSession.send).toHaveBeenCalled();
+ });
+
+ it('fails rehydrate without closing the old runtime when DB reconciliation throws (#2882)', async () => {
+ const oldSession = createSession({ id: 'orca-session', workDir: 'C:\\repo' });
+ const { deps } = createDeps({
+ getSession: vi.fn(() => oldSession),
+ isOrcaMcpHydrated: vi.fn(() => false),
+ synthesizeOrcaVendorOptionsFromDb: vi.fn(async () => true),
+ reconcileCreateOptsWithDb: vi.fn(async () => {
+ throw new Error('db unavailable');
+ }),
+ });
+ const transaction = createMakerSendTransaction(deps);
+
+ await expect(
+ transaction.sendToAgentAccepted('orca-session', 'hello', {
+ id: 'orca-session',
+ agentKind: 'pi',
+ workingDir: 'C:\\repo',
+ model: 'k3',
+ }),
+ ).resolves.toMatchObject({ accepted: false, reason: 'REHYDRATE_FAILED' });
+
+ expect(deps.closeSession).not.toHaveBeenCalled();
+ expect(deps.bootstrapSession).not.toHaveBeenCalled();
+ expect(oldSession.send).not.toHaveBeenCalled();
+ });
+
it('returns rehydrate failure without sending when active Orca rehydrate fails', async () => {
const oldSession = createSession({ id: 'orca-session', workDir: 'C:\\repo' });
const { deps } = createDeps({
diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
index 51d42b3761..868fac30c5 100644
--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
@@ -641,6 +641,12 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Make
}
await loadExtraDirsIfNeeded(sessionId, createOpts, 'active-orca-rehydrate');
try {
+ // 关旧 runtime 前先按 DB 权威口径对账执行字段(与 lazy-create 同源):caller /
+ // 队列的 createOpts 快照常不带 resumeSessionId(或带旧引擎的陈旧值),直接
+ // close+bootstrap 会启动一个没有旧 transcript 的全新原生会话(#2882:Pi 会话
+ // 中途 start_team 后丢失全部对话历史)。DB 读失败时 reconcile 抛错 → 落入下方
+ // REHYDRATE_FAILED,此时尚未 closeSession,旧 runtime 不受损。
+ await deps.reconcileCreateOptsWithDb?.(sessionId, createOpts);
const session = await deps.withRehydrateCloseSuppressed(sessionId, async () => {
await deps.closeSession(sessionId);
// close 后重新 bootstrap,避免旧 SDK handle 缺 Orca MCP vendorOptions。