Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 1721545

Browse files
committed
More tweaks
Properly handle cancelling, detect double clicks better
1 parent 4cd7285 commit 1721545

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

packages/bytebot-agent/src/agent/agent.processor.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ export class AgentProcessor {
9898
}
9999
}
100100

101+
@OnEvent('task.cancel')
102+
async handleTaskCancel({ taskId }: { taskId: string }) {
103+
this.logger.log(`Task cancel event received for task ID: ${taskId}`);
104+
105+
await this.stopProcessing();
106+
}
107+
101108
processTask(taskId: string) {
102109
this.logger.log(`Starting processing for task ID: ${taskId}`);
103110

@@ -379,12 +386,6 @@ export class AgentProcessor {
379386
// Signal any in-flight async operations to abort
380387
this.abortController?.abort();
381388

382-
if (this.currentTaskId) {
383-
await this.tasksService.update(this.currentTaskId, {
384-
status: TaskStatus.CANCELLED,
385-
});
386-
}
387-
388389
this.isProcessing = false;
389390
this.currentTaskId = null;
390391
}

packages/bytebot-agent/src/google/google.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
TextContentBlock,
77
ToolUseContentBlock,
88
} from '@bytebot/shared';
9-
import { AGENT_SYSTEM_PROMPT } from '../agent/agent.constants';
109
import {
1110
BytebotAgentService,
1211
BytebotAgentInterrupt,

packages/bytebot-agent/src/tasks/tasks.service.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,10 @@ export class TasksService {
339339
where: { id: taskId },
340340
data: {
341341
status: TaskStatus.CANCELLED,
342-
control: Role.USER,
343342
},
344343
});
345344

346-
try {
347-
await fetch(
348-
`${this.configService.get<string>('BYTEBOT_DESKTOP_BASE_URL')}/input-tracking/stop`,
349-
{ method: 'POST' },
350-
);
351-
} catch (error) {
352-
this.logger.error('Failed to stop input tracking', error as any);
353-
}
354-
355-
// Broadcast cancel event so AgentProcessor can react
345+
// Broadcast cancel event so AgentProcessor can cancel processing
356346
this.eventEmitter.emit('task.cancel', { taskId });
357347

358348
this.logger.log(`Task ${taskId} cancelled and marked as failed`);

packages/bytebotd/src/input-tracking/input-tracking.service.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,14 @@ export class InputTrackingService implements OnModuleDestroy {
130130
if (this.clickMouseActionTimeout) {
131131
clearTimeout(this.clickMouseActionTimeout);
132132
}
133+
133134
this.clickMouseActionTimeout = setTimeout(async () => {
134-
if (this.clickMouseActionBuffer.length === 1) {
135-
await this.logAction(this.clickMouseActionBuffer[0]);
136-
}
135+
// pick the event with the largest clickCount in the burst
136+
const final = this.clickMouseActionBuffer.reduce((a, b) =>
137+
b.clickCount > a.clickCount ? b : a,
138+
);
139+
await this.logAction(final); // emit exactly once
137140

138-
if (this.clickMouseActionBuffer.length > 1) {
139-
this.clickMouseActionBuffer.forEach(async (action) => {
140-
// Skip single click actions
141-
if (action.clickCount > 1) {
142-
await this.logAction(action);
143-
}
144-
});
145-
}
146141
this.clickMouseActionTimeout = null;
147142
this.clickMouseActionBuffer = [];
148143
}, this.CLICK_DEBOUNCE_MS);

0 commit comments

Comments
 (0)