Fix routine run assignment wakeups
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -115,7 +115,20 @@ describe("routine service live-execution coalescing", () => {
|
||||
}
|
||||
});
|
||||
|
||||
async function seedFixture() {
|
||||
async function seedFixture(opts?: {
|
||||
wakeup?: (
|
||||
agentId: string,
|
||||
wakeupOpts: {
|
||||
source?: string;
|
||||
triggerDetail?: string;
|
||||
reason?: string | null;
|
||||
payload?: Record<string, unknown> | null;
|
||||
requestedByActorType?: "user" | "agent" | "system";
|
||||
requestedByActorId?: string | null;
|
||||
contextSnapshot?: Record<string, unknown>;
|
||||
},
|
||||
) => Promise<unknown>;
|
||||
}) {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const projectId = randomUUID();
|
||||
@@ -161,9 +174,9 @@ describe("routine service live-execution coalescing", () => {
|
||||
|
||||
const svc = routineService(db, {
|
||||
heartbeat: {
|
||||
wakeup: async (agentId, opts) => {
|
||||
wakeups.push({ agentId, opts });
|
||||
return null;
|
||||
wakeup: async (wakeupAgentId, wakeupOpts) => {
|
||||
wakeups.push({ agentId: wakeupAgentId, opts: wakeupOpts });
|
||||
return opts?.wakeup ? opts.wakeup(wakeupAgentId, wakeupOpts) : null;
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -258,6 +271,22 @@ describe("routine service live-execution coalescing", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("waits for the assignee wakeup to be queued before returning the routine run", async () => {
|
||||
let wakeupResolved = false;
|
||||
const { routine, svc } = await seedFixture({
|
||||
wakeup: async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
wakeupResolved = true;
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
const run = await svc.runRoutine(routine.id, { source: "manual" });
|
||||
|
||||
expect(run.status).toBe("issue_created");
|
||||
expect(wakeupResolved).toBe(true);
|
||||
});
|
||||
|
||||
it("coalesces only when the existing routine issue has a live execution run", async () => {
|
||||
const { agentId, companyId, issueSvc, routine, svc } = await seedFixture();
|
||||
const previousRunId = randomUUID();
|
||||
|
||||
@@ -782,7 +782,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
|
||||
details: { title: issue.title, identifier: issue.identifier },
|
||||
});
|
||||
|
||||
queueIssueAssignmentWakeup({
|
||||
void queueIssueAssignmentWakeup({
|
||||
heartbeat,
|
||||
issue,
|
||||
reason: "issue_assigned",
|
||||
|
||||
@@ -29,7 +29,7 @@ export function queueIssueAssignmentWakeup(input: {
|
||||
}) {
|
||||
if (!input.issue.assigneeAgentId || input.issue.status === "backlog") return;
|
||||
|
||||
void input.heartbeat
|
||||
return input.heartbeat
|
||||
.wakeup(input.issue.assigneeAgentId, {
|
||||
source: "assignment",
|
||||
triggerDetail: "system",
|
||||
|
||||
@@ -619,7 +619,8 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeup
|
||||
status: "issue_created",
|
||||
linkedIssueId: createdIssue.id,
|
||||
});
|
||||
queueIssueAssignmentWakeup({
|
||||
// Ensure the wake request is durably queued before reporting the routine run as created.
|
||||
await queueIssueAssignmentWakeup({
|
||||
heartbeat,
|
||||
issue: createdIssue,
|
||||
reason: "issue_assigned",
|
||||
|
||||
Reference in New Issue
Block a user