fix(scheduler): prevent stale tool re-publication and fix stuck UI state (#17227)

This commit is contained in:
Abhi
2026-01-21 17:39:20 -05:00
committed by GitHub
parent 1c9a57c3c2
commit 2219bac16d
2 changed files with 18 additions and 0 deletions

View File

@@ -188,8 +188,13 @@ describe('SchedulerStateManager', () => {
errorType: undefined,
};
vi.mocked(onUpdate).mockClear();
stateManager.updateStatus(call.request.callId, 'success', response);
expect(onUpdate).toHaveBeenCalledTimes(1);
vi.mocked(onUpdate).mockClear();
stateManager.finalizeCall(call.request.callId);
expect(onUpdate).toHaveBeenCalledTimes(1);
expect(stateManager.isActive).toBe(false);
expect(stateManager.completedBatch).toHaveLength(1);
@@ -455,6 +460,7 @@ describe('SchedulerStateManager', () => {
createValidatingCall('2'),
]);
vi.mocked(onUpdate).mockClear();
stateManager.cancelAllQueued('Batch cancel');
expect(stateManager.queueLength).toBe(0);
@@ -462,6 +468,13 @@ describe('SchedulerStateManager', () => {
expect(
stateManager.completedBatch.every((c) => c.status === 'cancelled'),
).toBe(true);
expect(onUpdate).toHaveBeenCalledTimes(1);
});
it('should not notify if cancelAllQueued is called on an empty queue', () => {
vi.mocked(onUpdate).mockClear();
stateManager.cancelAllQueued('Batch cancel');
expect(onUpdate).not.toHaveBeenCalled();
});
it('should clear batch and notify', () => {

View File

@@ -130,6 +130,7 @@ export class SchedulerStateManager {
if (this.isTerminalCall(call)) {
this._completedBatch.push(call);
this.activeCalls.delete(callId);
this.emitUpdate();
}
}
@@ -160,6 +161,10 @@ export class SchedulerStateManager {
}
cancelAllQueued(reason: string): void {
if (this.queue.length === 0) {
return;
}
while (this.queue.length > 0) {
const queuedCall = this.queue.shift()!;
if (queuedCall.status === 'error') {