Skip to content

Commit 28f7b42

Browse files
fix(plugin-sdk): clear ambiguous recovery moves
1 parent 3330313 commit 28f7b42

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎src/plugin-sdk/session-store-runtime.key-move.test.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ describe("session-store-runtime whole-store key moves", () => {
6666
cycleId: "ambiguous-key-move-cycle",
6767
revision: 4,
6868
},
69+
restartRecoveryRuns: [
70+
{
71+
lifecycleGeneration: "ambiguous-key-move-generation",
72+
runId: "ambiguous-key-move-run",
73+
},
74+
],
6975
sessionId: "ambiguous-key-move-session",
76+
status: "running",
7077
updatedAt: 10,
7178
} as InternalSessionEntry);
7279

@@ -81,9 +88,14 @@ describe("session-store-runtime whole-store key moves", () => {
8188
);
8289

8390
for (const sessionKey of [firstNewKey, secondNewKey]) {
84-
expect(
85-
loadInternalSessionEntry({ agentId: "main", sessionKey, storePath }),
86-
).not.toHaveProperty("mainRestartRecovery");
91+
const entry = loadInternalSessionEntry({ agentId: "main", sessionKey, storePath });
92+
expect(entry).toMatchObject({
93+
abortedLastRun: false,
94+
sessionId: "ambiguous-key-move-session",
95+
status: "running",
96+
});
97+
expect(entry).not.toHaveProperty("mainRestartRecovery");
98+
expect(entry).not.toHaveProperty("restartRecoveryRuns");
8799
}
88100
});
89101
});

‎src/plugins/runtime/session-store-facade.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,30 @@ export function reconcilePluginSessionStore(params: {
164164
for (const [sessionKey, publicEntry] of Object.entries(params.publicStore)) {
165165
const projectedEntry = projectPluginSessionEntry(publicEntry as InternalSessionEntry);
166166
const originalEntry = originalStore[sessionKey];
167+
let hasSameSessionSource = originalEntry?.sessionId === projectedEntry.sessionId;
167168
let existingRecovery = activeRecoveryFieldsForSameSession(
168169
originalEntry,
169170
projectedEntry.sessionId,
170171
);
171-
if (!existingRecovery && projectedEntry.sessionId) {
172+
if (!hasSameSessionSource && projectedEntry.sessionId) {
172173
const originalKeys = originalKeysBySessionId.get(projectedEntry.sessionId);
173174
const publicKeys = publicKeysBySessionId.get(projectedEntry.sessionId);
174175
if (originalKeys?.length === 1 && publicKeys?.length === 1) {
176+
hasSameSessionSource = true;
175177
existingRecovery = activeRecoveryFieldsForSameSession(
176178
originalStore[originalKeys[0]!],
177179
projectedEntry.sessionId,
178180
);
179181
}
180182
}
181-
params.internalStore[sessionKey] =
182-
originalEntry && originalEntry.sessionId !== projectedEntry.sessionId
183-
? existingRecovery
184-
? { ...projectedEntry, ...existingRecovery }
185-
: { ...projectedEntry, ...MAIN_SESSION_RECOVERY_CLEAR_PATCH }
186-
: existingRecovery
187-
? { ...projectedEntry, ...existingRecovery }
188-
: projectedEntry;
183+
const mustClearRecovery = originalEntry
184+
? originalEntry.sessionId !== projectedEntry.sessionId
185+
: !hasSameSessionSource;
186+
params.internalStore[sessionKey] = existingRecovery
187+
? { ...projectedEntry, ...existingRecovery }
188+
: mustClearRecovery
189+
? { ...projectedEntry, ...MAIN_SESSION_RECOVERY_CLEAR_PATCH }
190+
: projectedEntry;
189191
}
190192
}
191193

0 commit comments

Comments
 (0)