agents-relay 1.0.57 → 1.0.59

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.
Files changed (2) hide show
  1. package/dist/reconciler.js +28 -8
  2. package/package.json +1 -1
@@ -61,6 +61,7 @@ The ChatGPT/Codex conversation or process exit is never the task result.
61
61
  Before your final return, verify that a terminal event for this exact Job/Task was published.
62
62
  If no terminal event has been published, publish task.failed before exiting.`;
63
63
  }
64
+ const taskLaunchClaims = new Set();
64
65
  export class Reconciler {
65
66
  store;
66
67
  options;
@@ -468,15 +469,34 @@ export class Reconciler {
468
469
  await this.store.saveTask(task);
469
470
  return;
470
471
  }
471
- const leaseMs = Math.max(this.options.leaseMs ?? 300000, task.timeoutMs);
472
- const startedAt = (this.options.now ?? new Date()).getTime();
473
- transitionTask(task, 'RUNNING');
474
- task.attempt += 1;
475
- task.leaseOwner = this.options.owner;
476
- task.leaseExpiresAt = new Date(startedAt + leaseMs).toISOString();
477
- task.executionId = randomUUID();
472
+ const claimKey = `${job.repository}#${job.prNumber}:${task.id}`;
473
+ if (taskLaunchClaims.has(claimKey))
474
+ return;
475
+ taskLaunchClaims.add(claimKey);
476
+ let claimedTask = null;
477
+ try {
478
+ const freshJob = await this.store.load(job.id);
479
+ const freshTask = freshJob.tasks.find(item => item.id === task.id);
480
+ if (!freshTask || freshTask.state !== 'QUEUED' || !dependencyReady(freshTask, new Map(freshJob.tasks.map(item => [item.id, item]))))
481
+ return;
482
+ const leaseMs = Math.max(this.options.leaseMs ?? 300000, freshTask.timeoutMs);
483
+ const startedAt = (this.options.now ?? new Date()).getTime();
484
+ transitionTask(freshTask, 'RUNNING');
485
+ freshTask.attempt += 1;
486
+ freshTask.leaseOwner = this.options.owner;
487
+ freshTask.leaseExpiresAt = new Date(startedAt + leaseMs).toISOString();
488
+ freshTask.executionId = randomUUID();
489
+ await this.store.saveTask(freshTask);
490
+ claimedTask = freshTask;
491
+ }
492
+ finally {
493
+ taskLaunchClaims.delete(claimKey);
494
+ }
495
+ if (!claimedTask)
496
+ return;
497
+ task = claimedTask;
498
+ const startedAt = Date.now();
478
499
  const durableExecutionId = task.executionId;
479
- await this.store.saveTask(task);
480
500
  const controller = new AbortController();
481
501
  let execution;
482
502
  const workerTask = { ...task, input: workerInput, routing: task.routing ? { ...task.routing, cwd: task.routing.cwd ?? executionContext.project.path } : task.routing };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-relay",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "description": "Durable async agent jobs coordinated through GitHub pull requests",
5
5
  "type": "module",
6
6
  "bin": {