Fix early Live choice queue ownership

AI-assisted: Codex
This commit is contained in:
Paul Bakaus
2026-07-13 09:54:23 -07:00
parent 78b1b5878d
commit 8a6c4ab486
2 changed files with 72 additions and 0 deletions
+19
View File
@@ -290,6 +290,22 @@ function acknowledgePendingEvent(id, sourceEventType) {
return acknowledged;
}
function retirePendingGeneration(id) {
if (!id) return 0;
let retired = 0;
for (let index = state.pendingEvents.length - 1; index >= 0; index -= 1) {
const event = state.pendingEvents[index]?.event;
if (event?.id !== id || event.type !== 'generate') continue;
state.pendingEvents.splice(index, 1);
retired += 1;
}
if (retired > 0) {
scheduleLeaseFlush();
broadcastAgentPollingIfChanged();
}
return retired;
}
function findPendingEventById(id, sourceEventType) {
if (!id) return null;
const entry = state.pendingEvents.find((item) => (
@@ -823,6 +839,9 @@ function createRequestHandler({ detectScript, liveScriptParts }) {
return;
}
}
if (msg.type === 'accept' || msg.type === 'discard') {
retirePendingGeneration(msg.id);
}
recordGenerationCheckpoint(msg);
if (msg.type === 'exit') {
cleanupSvelteComponentSessionsBeforeExit();