[daily] keep codex continuation current across scope roundtrips (#416)
This commit is contained in:
@@ -126,4 +126,32 @@ describe('codexSessionResponseStore', () => {
|
||||
|
||||
resetCodexSessionResponseStore();
|
||||
});
|
||||
|
||||
it('keeps the latest continuation id when the same downstream session drifts back to an earlier scope', () => {
|
||||
resetCodexSessionResponseStore();
|
||||
|
||||
const originalScopedKey = buildCodexSessionResponseStoreKey({
|
||||
sessionId: 'session-roundtrip',
|
||||
siteId: 10,
|
||||
accountId: 20,
|
||||
channelId: 30,
|
||||
});
|
||||
const driftedScopedKey = buildCodexSessionResponseStoreKey({
|
||||
sessionId: 'session-roundtrip',
|
||||
siteId: 10,
|
||||
accountId: 21,
|
||||
channelId: 31,
|
||||
});
|
||||
|
||||
setCodexSessionResponseId(originalScopedKey, 'resp-roundtrip-1');
|
||||
|
||||
expect(getCodexSessionResponseId(driftedScopedKey)).toBe('resp-roundtrip-1');
|
||||
|
||||
setCodexSessionResponseId(driftedScopedKey, 'resp-roundtrip-2');
|
||||
|
||||
expect(getCodexSessionResponseId(driftedScopedKey)).toBe('resp-roundtrip-2');
|
||||
expect(getCodexSessionResponseId(originalScopedKey)).toBe('resp-roundtrip-2');
|
||||
|
||||
resetCodexSessionResponseStore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,6 +57,16 @@ function getSessionStoreKeys(sessionId: string): string[] {
|
||||
];
|
||||
}
|
||||
|
||||
function reconcileScopedSessionFallback(bareSessionKey: string): void {
|
||||
if (!bareSessionKey) return;
|
||||
|
||||
for (const key of codexSessionResponseIds.keys()) {
|
||||
if (key === bareSessionKey) continue;
|
||||
if (getBareSessionStoreKey(key) !== bareSessionKey) continue;
|
||||
codexSessionResponseIds.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeSessionId(sessionId: string): string {
|
||||
return sessionId.trim();
|
||||
}
|
||||
@@ -87,7 +97,10 @@ export function getCodexSessionResponseId(sessionId: string): string | null {
|
||||
|
||||
for (const fallbackKey of getFallbackSessionStoreKeys(normalized)) {
|
||||
const fallback = codexSessionResponseIds.get(fallbackKey);
|
||||
if (fallback) return fallback;
|
||||
if (fallback) {
|
||||
reconcileScopedSessionFallback(fallbackKey);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user