1
0
forked from boos/BoosAPI

[daily] keep codex continuation current across scope roundtrips (#416)

This commit is contained in:
Cita
2026-04-05 17:29:42 +08:00
committed by GitHub
parent 63f6b07842
commit b3e987a2f5
2 changed files with 42 additions and 1 deletions
@@ -126,4 +126,32 @@ describe('codexSessionResponseStore', () => {
resetCodexSessionResponseStore(); 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 { function normalizeSessionId(sessionId: string): string {
return sessionId.trim(); return sessionId.trim();
} }
@@ -87,7 +97,10 @@ export function getCodexSessionResponseId(sessionId: string): string | null {
for (const fallbackKey of getFallbackSessionStoreKeys(normalized)) { for (const fallbackKey of getFallbackSessionStoreKeys(normalized)) {
const fallback = codexSessionResponseIds.get(fallbackKey); const fallback = codexSessionResponseIds.get(fallbackKey);
if (fallback) return fallback; if (fallback) {
reconcileScopedSessionFallback(fallbackKey);
return fallback;
}
} }
return null; return null;