tuna-agent 0.1.166 → 0.1.168

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -221,6 +221,15 @@ export async function startDaemon(config) {
221
221
  }
222
222
  // Per-agent concurrency: if busy, queue instead of rejecting.
223
223
  const agentId = task.agentId || '__default__';
224
+ // Dedup: the API sweep re-dispatches queued tasks every 30s. Without this,
225
+ // a task sent repeatedly while the agent is busy piles up as duplicates in
226
+ // the queue (and would run N times). Ignore if already running or queued.
227
+ const alreadyRunning = Array.from(activeAgentTasks.values()).includes(task.id);
228
+ const alreadyQueued = (agentQueues.get(agentId) || []).some((it) => it.kind === 'task' && it.task.id === task.id);
229
+ if (alreadyRunning || alreadyQueued) {
230
+ console.log(`[Daemon] Task ${task.id} already running/queued — ignoring duplicate dispatch`);
231
+ break;
232
+ }
224
233
  if (activeAgentTasks.has(agentId)) {
225
234
  enqueueForAgent(agentId, { kind: 'task', task });
226
235
  break;
@@ -224,6 +224,18 @@ export class AgentWebSocketClient {
224
224
  return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
225
225
  }
226
226
  _connect() {
227
+ // Tear down any previous socket first. Without this, a reconnect could leak the
228
+ // old connection: it stays half-open on the server (readyState OPEN) and becomes
229
+ // a zombie the API keeps sending to, while this daemon listens on the new one.
230
+ if (this.ws) {
231
+ try {
232
+ this.ws.removeAllListeners();
233
+ this.ws.terminate();
234
+ }
235
+ catch { /* ignore */ }
236
+ this.ws = null;
237
+ }
238
+ this._stopHeartbeat();
227
239
  try {
228
240
  this.ws = new WebSocket(this.config.wsUrl, {
229
241
  headers: { 'Authorization': `Bearer ${this.config.agentToken}` },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuna-agent",
3
- "version": "0.1.166",
3
+ "version": "0.1.168",
4
4
  "description": "Tuna Agent - Run AI coding tasks on your machine",
5
5
  "bin": {
6
6
  "tuna-agent": "dist/cli/index.js"