Twenty agents, twenty downloads
Agents that work from the same big files, like a reference genome and its gene list, each download their own copy. Every agent is its own process, with no idea that another agent on the same machine already fetched the file. And a bucket is not a folder: to read a file, an agent has to download it first. When a new release lands mid-run, early agents keep the old files and later ones get the new ones, and their answers stop agreeing. Twenty agents ask for the same files, and the bucket sends them twenty times.
The usual fixes each bring a new problem. Bake the files into the machine image, and you rebuild the image for every new release. Put them on a shared network drive, and you run one more system, where any job can change a file by mistake. Write a small cache script, and you have to decide who updates it, when, and to which version.
The usual setup
What we’ll build
In this guide we’ll save the reference set once, as a version that cannot change under anyone. Each machine downloads it one time into a local folder, and every agent on that machine reads from there. When a new release comes out, machines download only the files that changed.
What we’re building
By the end, you’ll have:
- The reference set saved once in your own bucket, with every release kept.
- A read-only key, narrowed to this one disk, so no agent can change the files.
- Reads of just a slice of a big file, for agents that need only a little.
- One local copy per machine, shared by every agent on it.
- A way to ship a new release that sends machines only what changed.
You’ll need a Skywake API key and Node. Set SKYWAKE_API_KEY, then install the SDK with npm i skywake.
Step 1
Save the reference set once
Start with the folder you already download today. Ours holds a few chromosomes and a list of genes:
grch38/
- chr1.fa# large, read by every agent
- chr2.fa# the one a patch will change
- genes.gtf# where each gene sits
We’ll save it on a disk, a set of files with branches and history. It starts on a branch called main. A branch works like a Git branch for files: each save is a commit, a fixed version you can always come back to.
import { Skywake } from "skywake";
const sky = new Skywake();
const genome = sky.disk("genome");
await genome.upload("./grch38", { message: "GRCh38, first release" });
await genome.fork("grch38");upload sends every file as one commit. Big files go up in parts on their own, so you don’t need to split them. Then we fork main into a branch named after the release, grch38. Nobody writes to it again, so that name always means this exact version of the set.
Step 2
Make it read-only for agents
Reference data should never change by accident, so we give the agents their own key. It has the read role, and it only reaches this one disk.
const agents = await sky.createKey({
name: "agents",
role: "read",
only: ["genome"],
});
await saveSecret("AGENT_KEY", agents.key);agents.key is shown only this once, so we store it as a secret right away. saveSecret stands for your own secret store. From now on, a write with this key fails with “this needs the write role”.
Tip: one key per use
Give agents the read key and nothing else. Keep the key that ships releases in your release script. If an agent’s key ever leaks, the worst it can do is read.
Step 3
Read only the part you need
Every agent connects with the read key, on the release it should use. The release comes from REFS_RELEASE, which you set once per machine:
const refs = new Skywake({ key: process.env.AGENT_KEY }).disk("genome", {
branch: process.env.REFS_RELEASE,
});Some agents need only a small piece of a big file: one gene, one region. They don’t need the whole chromosome. A range read asks for just those bytes, so the agent can start work at once.
const piece = await refs.read("chr1.fa", {
offset: 120_000,
length: 600,
});refs reads the grch38 branch, and nobody writes to it. Even if a new release lands while the agent runs, it keeps reading the same version. Every agent you start with the same REFS_RELEASE sees the very same bytes.
Step 4
One copy per machine
Most agents read a lot of the set, again and again. For them, the best place for the files is the machine’s own disk. We’ll download the set once per machine, into one folder, and point every agent at that folder.
syncRefs does the work. On a new machine it downloads the whole release. It writes the release name into a small .release file. Next time, if that is still the release the machine should use, it does nothing.
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
const REFS = process.env.REFS_DIR ?? "/srv/refs";
async function syncRefs(dir = REFS) {
const mark = join(dir, ".release");
const have = await readFile(mark, "utf8").catch(() => "");
if (have === refs.branch) return;
if (!have) {
await refs.download(dir);
} else {
for (const { path, change } of await refs.diff(have)) {
const file = join(dir, path);
await rm(file, { force: true });
if (change === "removed") continue;
await mkdir(dirname(file), { recursive: true });
await writeFile(file, await refs.read(path, { as: "stream" }));
}
}
await writeFile(mark, refs.branch);
}Run it once when the machine starts, before any agent. Then each agent reads plain files from the folder, with no network at all:
await syncRefs();const genes = await readFile(join(REFS, "genes.gtf"), "utf8");That’s the twenty downloads gone. Twenty agents start, and the machine has already downloaded the set once. Start the machine again tomorrow and syncRefs sees the same release and downloads nothing.
Step 5
Ship a new release
A patch for chromosome 2 comes out, with a new file for chromosome Y. Each release gets its own branch, so we fork main into grch38-p2. A fork is a new branch that starts as an exact copy, and it copies no data.
We upload the new folder to the fork, then merge it into main, so main always holds the newest release. Machines on grch38 see nothing change.
const next = await genome.fork("grch38-p2");
await next.upload("./grch38-p2", { message: "GRCh38 patch 2" });
await next.mergeInto("main");We sent the whole new folder, but Skywake records only the files that differ: chr2.fa changed and chrY.fa is new. Set REFS_RELEASE to grch38-p2 on a machine. The next time it runs syncRefs, it asks for the changes since its .release and downloads just those two files:
syncRefs after patch 2
- chr1.faKept
- chr2.faDownloaded · changed
- chrY.faDownloaded · new
- genes.gtfKept
Machines still on grch38 keep reading the old chr2.fa. Every release stays as its own branch, so nothing they depend on disappears.
Running it for real
The steps above are all you need. A few things help once many machines use them:
- Each machine downloads once. A new machine fetches the full set on its first start. After that, it fetches only what a release changed, however many agents it runs.
- Update between jobs.
syncRefsreplaces changed files in place. If your agents never stop, sync into a new folder named after the release, then move agents to it. - Agents elsewhere read slices. An agent in a short-lived sandbox has no local copy to share. Give it the read key and let it use range reads, as in step 3.
- Every answer has a version. Log the
.releasename next to each result. Weeks later, you can read the exact files that answer came from. - It all stays yours. The files live in your own bucket. There is no network drive or extra server to run.