fix(computers): select latest task admission for previews

Integrate the production route correction from 5af1eb0762; its full route regression suite remains in the stacked acceptance PR.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-10 15:17:11 -05:00
1 parent 1b53cdce80
commit d22b935d29
1 file changed
+3 -1
+3 -1
View File
@@ -34,7 +34,9 @@ export function computerRoutes(db: Db, computers = computerService(db)) {
}
const [lease] = await db.select().from(environmentLeases)
.where(and(eq(environmentLeases.companyId, issue.companyId), eq(environmentLeases.issueId, issue.id), eq(environmentLeases.provider, "boat")))
.orderBy(desc(environmentLeases.updatedAt)).limit(1);
// Every computer admission inserts a lease. Finalization can update an older
// lease later, but must not make it the task's current authority again.
.orderBy(desc(environmentLeases.createdAt), desc(environmentLeases.id)).limit(1);
const [agent] = issue.assigneeAgentId ? await db.select().from(agents)
.where(and(eq(agents.companyId, issue.companyId), eq(agents.id, issue.assigneeAgentId))).limit(1) : [];
const environmentId = lease?.environmentId ?? agent?.defaultEnvironmentId ?? (await settings.get()).defaultEnvironmentId;