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(mobile): reconcile complete snapshots from canonical hosts

Chris0c96ac17a439
diff --git a/apps/mobile/src/__tests__/remoteSessionStore.test.ts b/apps/mobile/src/__tests__/remoteSessionStore.test.ts
index b2e3ef22c1..9ae066bf05 100644
--- a/apps/mobile/src/__tests__/remoteSessionStore.test.ts
+++ b/apps/mobile/src/__tests__/remoteSessionStore.test.ts
@@ -3077,10 +3077,13 @@ describe('remoteSessionStore', () => {
}
});
- it('clears a missed error and stale running state for a runtime absent from a complete snapshot', () => {
+ // Unit regression: after re-link, the physical shard can remain old while
+ // authoritative snapshots arrive from its canonical host. Preserve both paths.
+ it.each(['dev-1', 'new-dev-1'])('clears absent runtime state from complete snapshots on %s', (host) => {
remoteSessionStore.setDeviceSessions('dev-1', 'Mac', [session('s1')]);
+ if (host !== 'dev-1') remoteSessionStore.setDeviceIdentity([{ deviceId: host, name: 'Mac' }]);
remoteSessionStore.setDeviceSessions('dev-2', 'Mac mini', [session('s2')]);
- remoteSessionStore.applySessionActivity('dev-1', {
+ remoteSessionStore.applySessionActivity(host, {
sessionId: 's1', phase: 'error', attention: true,
});
remoteSessionStore.applySessionActivity('dev-2', {
@@ -3089,11 +3092,11 @@ describe('remoteSessionStore', () => {
remoteSessionStore.setSessionRunning('s1', true);
// A legacy host also returns an empty array, without claiming completeness.
- remoteSessionStore.setActiveSessionSnapshots('dev-1', []);
+ remoteSessionStore.setActiveSessionSnapshots(host, []);
expect(remoteSessionStore.getSessionLiveActivity('s1')).toMatchObject({ phase: 'error', attention: true });
expect(remoteSessionStore.isSessionRunning('s1')).toBe(true);
- remoteSessionStore.setActiveSessionSnapshots('dev-1', {
+ remoteSessionStore.setActiveSessionSnapshots(host, {
format: 'active-sessions-v2', sessions: [],
});
@@ -3102,14 +3105,15 @@ describe('remoteSessionStore', () => {
expect(remoteSessionStore.getSessionLiveActivity('s2')).toMatchObject({ phase: 'error', attention: true });
});
- it('does not let a delayed complete snapshot clear a newer activity push', () => {
+ it.each(['dev-1', 'new-dev-1'])('preserves newer activity across delayed complete snapshots on %s', (host) => {
remoteSessionStore.setDeviceSessions('dev-1', 'Mac', [session('s1')]);
+ if (host !== 'dev-1') remoteSessionStore.setDeviceIdentity([{ deviceId: host, name: 'Mac' }]);
const epoch = remoteSessionStore.captureActiveSessionSnapshotEpoch();
- remoteSessionStore.applySessionActivity('dev-1', {
+ remoteSessionStore.applySessionActivity(host, {
sessionId: 's1', phase: 'error', attention: true,
});
- remoteSessionStore.setActiveSessionSnapshots('dev-1', {
+ remoteSessionStore.setActiveSessionSnapshots(host, {
format: 'active-sessions-v2', sessions: [],
}, epoch);
diff --git a/apps/mobile/src/session/remoteSessionStore.ts b/apps/mobile/src/session/remoteSessionStore.ts
index eecb714273..3aecfe733e 100644
--- a/apps/mobile/src/session/remoteSessionStore.ts
+++ b/apps/mobile/src/session/remoteSessionStore.ts
@@ -4450,8 +4450,8 @@ export const remoteSessionStore = {
changed = writeSessionRunStatus(sessionId, next) || changed;
}
if (completeResponse) {
- for (const [sessionId, indexedDeviceId] of sessionDeviceIndex) {
- if (indexedDeviceId !== deviceId || snapshotStates.has(sessionId)
+ for (const sessionId of sessionDeviceIndex.keys()) {
+ if (!sessionStateWriteAllowed(sessionId, deviceId) || snapshotStates.has(sessionId)
|| (sessionMakerActivityEpochs.get(sessionId) ?? 0) > activityEpochAtFetchStart) continue;
// A runtime absent from a complete host snapshot has ended. Do not
// discard a newer live push that arrived while this read was in flight.