Skip to content

Commit 367517e

Browse files
authored
fix: force-refresh dev release data before triggering agent update (#56)
* fix: force-refresh dev release data before triggering agent update Rolling dev releases replace the binary at the download URL on every push to main. When the UI caches version/checksum data and a new build lands before the user clicks Update, the agent downloads the new binary but the checksum from the stale cache doesn't match — causing a silent update failure loop. Force-refresh dev release info server-side in triggerAgentUpdate so the checksum always matches the binary currently at the download URL. * fix: use const for non-reassigned downloadUrl * fix: throw error when dev release checksum lookup fails When the version has changed but the checksum can't be retrieved, fail fast instead of silently proceeding with a known-stale checksum that would cause the agent to hit a checksum mismatch on download.
1 parent d41f4da commit 367517e

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

src/server/routers/fleet.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { router, protectedProcedure, withTeamAccess } from "@/trpc/init";
44
import { prisma } from "@/lib/prisma";
55
import { LogLevel } from "@/generated/prisma";
66
import { withAudit } from "@/server/middleware/audit";
7+
import { checkDevAgentVersion } from "@/server/services/version-check";
78

89
export const fleetRouter = router({
910
list: protectedProcedure
@@ -251,14 +252,38 @@ export const fleetRouter = router({
251252
message: "Cannot auto-update Docker agents",
252253
});
253254
}
255+
256+
let { targetVersion, checksum } = input;
257+
const { downloadUrl } = input;
258+
259+
// Dev releases are rolling — the binary at the download URL may have been
260+
// replaced since the UI cached the version/checksum. Force-refresh to get
261+
// the current release data and avoid checksum mismatch on the agent.
262+
if (targetVersion.startsWith("dev-")) {
263+
const fresh = await checkDevAgentVersion(true);
264+
if (fresh.latestVersion && fresh.latestVersion !== targetVersion) {
265+
const binaryName = downloadUrl.split("/").pop() ?? "vf-agent-linux-amd64";
266+
const freshChecksum = fresh.checksums[binaryName];
267+
if (!freshChecksum) {
268+
throw new TRPCError({
269+
code: "INTERNAL_SERVER_ERROR",
270+
message:
271+
"Dev release has been updated but fresh checksum could not be retrieved. Please retry.",
272+
});
273+
}
274+
targetVersion = fresh.latestVersion;
275+
checksum = `sha256:${freshChecksum}`;
276+
}
277+
}
278+
254279
return prisma.vectorNode.update({
255280
where: { id: input.nodeId },
256281
data: {
257282
pendingAction: {
258283
type: "self_update",
259-
targetVersion: input.targetVersion,
260-
downloadUrl: input.downloadUrl,
261-
checksum: input.checksum,
284+
targetVersion,
285+
downloadUrl,
286+
checksum,
262287
},
263288
},
264289
});

0 commit comments

Comments
 (0)