forked from boos/BoosAPI
[codex] fix responses lifecycle parity and codex session serialization (#278)
* fix responses lifecycle parity * remove websocket test debug logging * fix responses proxy stream typecheck * update compact upstream response expectations * add community and deepwiki badges * update linuxdo banner link * fix responses review follow-ups * preserve whitespace in responses terminal deltas * fix responses stream reconciliation edges * fix responses lifecycle parity and codex session serialization * fix review follow-up edge cases --------- Co-authored-by: apple <apple@appledeMacBook-Pro.local>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const codexHttpSessionQueues = new Map<string, Promise<void>>();
|
||||
|
||||
export async function runCodexHttpSessionTask<T>(
|
||||
sessionId: string,
|
||||
task: () => Promise<T>,
|
||||
): Promise<T> {
|
||||
const normalizedSessionId = sessionId.trim();
|
||||
if (!normalizedSessionId) {
|
||||
return task();
|
||||
}
|
||||
|
||||
const previous = codexHttpSessionQueues.get(normalizedSessionId) || Promise.resolve();
|
||||
const run = previous
|
||||
.catch(() => undefined)
|
||||
.then(() => task());
|
||||
const tail = run.then(() => undefined, () => undefined);
|
||||
codexHttpSessionQueues.set(normalizedSessionId, tail);
|
||||
|
||||
try {
|
||||
return await run;
|
||||
} finally {
|
||||
if (codexHttpSessionQueues.get(normalizedSessionId) === tail) {
|
||||
codexHttpSessionQueues.delete(normalizedSessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function resetCodexHttpSessionQueue(): void {
|
||||
codexHttpSessionQueues.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user