Skip to content

Commit b3012e0

Browse files
committed
fix(cloud-workers): keep seed freshness on the store clock and cover slow captures
1 parent 308215f commit b3012e0

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎extensions/crabbox/src/crabbox-worker-warm-image.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ describe("Crabbox profile warm images", () => {
745745
store.register(image.key, {
746746
...image.value,
747747
checkpointId: "",
748-
createdAtMs: Date.now() - 360_001,
748+
// Reservation staleness covers the slowest (machine0) capture budget twice over.
749+
createdAtMs: Date.now() - 1_200_001,
749750
});
750751

751752
const restarted = createWarmProvider(undefined, initial.stateDir);

‎extensions/crabbox/src/crabbox-worker-warm-image.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ const WARM_IMAGE_COMMAND_TIMEOUT_MS = 60_000;
3838
const WARM_IMAGE_CAPTURE_TIMEOUT_MS = 180_000;
3939
// Machine0 image save stops the source and waits for image availability even with --wait=false.
4040
const WARM_IMAGE_MACHINE0_CAPTURE_TIMEOUT_MS = 600_000;
41-
const WARM_IMAGE_CAPTURE_RESERVATION_TIMEOUT_MS = 2 * WARM_IMAGE_CAPTURE_TIMEOUT_MS;
41+
// Reservation staleness must cover the slowest provider capture budget: stealing a
42+
// live capture's reservation lets the finished capture overwrite the thief's record
43+
// and orphan its provider checkpoint outside retention cleanup.
44+
const WARM_IMAGE_CAPTURE_RESERVATION_TIMEOUT_MS = 2 * WARM_IMAGE_MACHINE0_CAPTURE_TIMEOUT_MS;
4245
const WARM_IMAGE_MAX_ENTRIES = 128;
4346
const CHECKPOINT_ID_PATTERN = /^chk_[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
4447

‎src/gateway/worker-environments/node-worker-workspace-fallback.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ export function createNodeWorkerWorkspaceFallback(exec: WorkspaceExec) {
292292
} catch (error) {
293293
if (error instanceof Error && error.message.includes("INVALID_REQUEST")) {
294294
supportsSeeds = false;
295+
} else {
296+
// Seeded failure self-heals through the clone path; without this line the
297+
// degradation would be invisible behind an ordinary "published-origin" sync.
298+
workspaceSyncLog.info("node worker workspace seeded sync failed; cloning", {
299+
error: boundedWorkerError(error),
300+
});
295301
}
296302
}
297303
}

‎src/node-host/node-worker-workspace-seeds.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ export async function runNodeWorkerWorkspaceSeed(params: {
9494
return "absent" as const;
9595
}
9696
await fsp.cp(seedDir, workspaceDir, { recursive: true, verbatimSymlinks: true });
97-
const now = new Date();
98-
await fsp.utimes(seedDir, now, now);
97+
// Apply must not bump the seed mtime: it is the store-freshness clock. Active
98+
// seeds refresh it through the periodic re-store; bumping on use would mark a
99+
// stale seed permanently "fresh" and its content would never be replaced.
99100
return "applied" as const;
100101
}
101102
if (!(await readSeedDirectory(path.dirname(workspaceDir), workspaceDir))) {

‎src/node-host/node-worker-workspace.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ describe("node worker workspace seeds", () => {
7474
expect(await fsp.readdir(workspace)).toEqual([".git", "link.txt", "tracked.txt"]);
7575
expect(await fsp.readFile(path.join(workspace, "tracked.txt"), "utf8")).toBe("original");
7676
expect(await fsp.readlink(path.join(workspace, "link.txt"))).toBe("tracked.txt");
77-
expect((await fsp.stat(seedDir)).mtimeMs).toBeGreaterThan(old.getTime());
77+
// Apply leaves the store-freshness clock untouched so a used seed still refreshes.
78+
expect((await fsp.stat(seedDir)).mtimeMs).toBeLessThanOrEqual(old.getTime());
7879
expect(await git("rev-parse", "HEAD")).toBe(commit);
7980
expect(await git("status", "--porcelain")).toBe("");
8081
await fsp.writeFile(path.join(workspace, "tracked.txt"), "later edit");

0 commit comments

Comments
 (0)