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): preserve remote tasks across account teardown

DavidShen226802f855fa
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
index 99ea835817..74085ffa9c 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
@@ -940,10 +940,13 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
it('account teardown reuses the Stop/closed finalizer and does not revive on A→B→A', () => {
const sid = `account-boundary-${Math.random().toString(36).slice(2, 8)}`;
+ const remoteSid = 'remote-account-boundary-' + Math.random().toString(36).slice(2, 8);
try {
setDataOwnerGeneration('account-a', 1);
makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, true));
applyTask(sid, { taskId: 't1', status: 'running', taskType: 'local_agent' });
+ makerChatStore.__applyStatusUpdateForTest(remoteSid, statusUpdate(remoteSid, true));
+ applyTask(remoteSid, { taskId: 'remote-t1', status: 'running', taskType: 'local_agent' });
expect(makerChatStore.getSnapshot(sid).agentStatus.startedAt).toBeTruthy();
// AuthContext invokes this synchronously when the outgoing owner enters
@@ -955,6 +958,7 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
// stop the task that still belongs to the active account.
expect(state.agentStatus.isRunning).toBe(true);
expect(state.agentStatus.startedAt).toBeTruthy();
+ expect(makerChatStore.getSnapshot(remoteSid).agentStatus.isRunning).toBe(true);
setDataOwnerGeneration('account-a', 3);
// A successful A→B commit finalizes the old owner exactly once.
@@ -966,6 +970,7 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
expect(state.agentStatus.isRunning).toBe(false);
expect(state.agentStatus.startedAt).toBeNull();
expect(state.taskUpdates?.get('t1')?.status).toBe('stopped');
+ expect(makerChatStore.getSnapshot(remoteSid).agentStatus.isRunning).toBe(true);
// Re-entering account A must observe the stopped snapshot, with no
// automatic continuation caused by the boundary cleanup.
@@ -977,6 +982,7 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
expect(state.agentStatus.startedAt).toBeNull();
} finally {
makerChatStore.purgeSession(sid);
+ makerChatStore.purgeSession(remoteSid);
dataOwnerGenerationTesting.reset();
}
});
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
index aa19e7a765..51a8c88382 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
@@ -5144,9 +5144,12 @@ describe('makerChatStore text delta batching', () => {
expect(makerChatStore.getSnapshot(SESSION_ID).queueInteractionLocks).toEqual([
'new-owner-lock',
]);
- // Account teardown reuses the Stop/closed finalizer, so an in-flight steer
- // marker cannot survive into the next owner generation.
- expect(makerChatStore.getSnapshot(SESSION_ID).steeringQueueClientIds).toEqual([]);
+ // This session remains sticky-remote even after the local remote-project
+ // projection is cleared. Account teardown must not finalize it locally:
+ // the controlled Desktop owns the running task and its steer marker.
+ expect(makerChatStore.getSnapshot(SESSION_ID).steeringQueueClientIds).toEqual([
+ 'already-steering',
+ ]);
expect(input.getProjection).not.toHaveBeenCalled();
});
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 7056a483f0..44487e69cd 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -2131,6 +2131,10 @@ export function cancelRemoteOptimisticSendsForDataOwnerBoundary(
*/
function finalizeSessionsForDataOwnerBoundary(): void {
for (const sessionId of sessions.keys()) {
+ // The local Maker teardown cannot stop a device-link session; its runtime
+ // remains authoritative on the controlled Desktop. Keep the cached remote
+ // state intact until that device reports its own terminal event.
+ if (isRemoteSessionSticky(sessionId)) continue;
const state = sessions.get(sessionId);
if (!state || !hasActiveTurnStateForOwnerBoundary(state)) continue;
bumpInteractionReconcileEpoch(sessionId);