feat(gateway): add interrupt preemption telemetry and requester notice

This commit is contained in:
William Valentin
2026-02-19 11:48:41 -08:00
parent 6b56d9e223
commit 01cd726d7c
8 changed files with 82 additions and 11 deletions
+21 -1
View File
@@ -49,6 +49,7 @@ describe('createAgentHandlers command fast-path', () => {
registerBuiltinCommands(commandRegistry);
const mockAuditLogger = {
userAction: vi.fn(),
queuePreempt: vi.fn(),
};
const handlers = createAgentHandlers({
@@ -364,6 +365,16 @@ describe('createAgentHandlers command fast-path', () => {
});
describe('createAgentHandlers queue policy resolution', () => {
const mockAuditLogger = {
userAction: vi.fn(),
queuePreempt: vi.fn(),
};
beforeEach(() => {
vi.clearAllMocks();
initAuditLogger(mockAuditLogger as any);
});
it('passes resolved per-request queue policy into lane enqueue', async () => {
const mockAgent = {
process: vi.fn(async () => 'ok'),
@@ -554,6 +565,15 @@ describe('createAgentHandlers queue policy resolution', () => {
expect(sessionBridge.cancelSession).toHaveBeenCalledWith('ws:s1');
expect(sessionBridge.cancel).not.toHaveBeenCalled();
expect((sent[0] as GatewayEvent).event).toBe('done');
expect(mockAuditLogger.queuePreempt).toHaveBeenCalledWith(expect.objectContaining({
session_id: 'ws:s1',
lane_id: 'ws:s1',
request_id: '7',
mode: 'interrupt',
cancelled_active_run: true,
}));
expect((sent[0] as GatewayEvent).event).toBe('content');
expect(((sent[0] as GatewayEvent).data as { text: string }).text).toContain('Interrupt mode');
expect((sent[1] as GatewayEvent).event).toBe('done');
});
});