@geonosis/gate
v3.9.0
Published
One heavy budget per machine: the slots every heavy command takes, the machine-wide heavy lock, and the opt-in gate daemon that runs a tier once per tree.
Maintainers
Readme
@geonosis/gate
One heavy budget per machine. Every heavy command the kit runs — geonosis verify,
geonosis ratchet, geonosis release smoke, the kit's own build — takes a slot from it before it
starts, so sessions sharing a laptop queue instead of CPU-starving each other into a red that is
about the machine. Beside the slots are the machine-wide heavy lock --exclusive holds and the
opt-in geonosis-gate daemon. This README is where the budget, the slots and the lock are
described; the other kit READMEs link here.
Install
pnpm add -D @geonosis/gateThe kit's tools already install it as a library. Add it by name only for the geonosis-gate
command, which starts the daemon: the geonosis door does not front it, and under pnpm a bin is a
command only where its package is a direct dependency.
The heavy slots
The budget is GEONOSIS_HEAVY_SLOTS when set, then geonosis.json → caps.heavy (a whole number of at
least 1), then the smaller of cores − 1 and memory ÷ geonosis.json → stack.memoryMbPerSlot (512 MB
when unset). GEONOSIS_HEAVY_MEMORY_MB replaces the machine's memory reading.
A slot is a file, slot-<n>.json, in $GEONOSIS_HEAVY_SLOT_DIR (or geonosis-heavy under the
temporary directory), holding the command, directory, pid and start time of its holder. A holder whose
process is gone is reaped. A child started with GEONOSIS_HEAVY_SLOT_HELD naming its parent's slot
runs in that slot instead of waiting on one its parent holds.
The heavy lock
acquireExclusive takes ~/.cache/geonosis/heavy.lock (under $XDG_CACHE_HOME when that is an
absolute path), writing the pid, cwd and start time into it. A second taker waits and says who holds
it; a holder whose process is gone is taken over with a printed note; the wait ends in an error at its
timeout. GEONOSIS_HEAVY_LOCK moves the lock file, for a sandbox with no writable home or for a
test. geonosis ratchet --exclusive and geonosis verify --exclusive hold it.
geonosis-gate: one tier run per tree, one budget per machine
geonosis-gate serve --detach # start the daemon in the background; `serve` runs it in this terminal
geonosis-gate status [--json] # slots, running tiers, the queue, the reports kept
geonosis-gate stop # a tier it is running is stopped with itgeonosis-gate --help prints the same. Exit 0 done, 1 when status or stop found no daemon, 2
when the command could not be run.
One daemon per machine, listening on gate.sock in the heavy-slot directory
($GEONOSIS_HEAVY_SLOT_DIR, or geonosis-heavy under the temporary directory), with its log
(gate.log), the runs it has going (gate-runs/) and the reports it kept (gate-cache/) beside it.
- A run is keyed by the tree.
geonosis verify <tier>asks the daemon, which keys the run by the directory, the tier, the flags that shape the report, a hash of the tree (HEAD, every uncommitted change, every untracked file, and the install record npm, pnpm or yarn writes undernode_modules) and thekeyEnvvalues andkeyFilescontentsgeonosis.jsonnames. Two verifies started together over one unchanged tree start one tier and each write the same report. One started after a green is answered the green the daemon kept, with when and at what load it was made. The daemon keeps no red: a red can come of the load or the environment, so the next ask runs the tier again. A tree that moved is a different key. A run that changed the tree it was asked about is not kept.geonosis verify --freshruns the tier again whatever the daemon holds.geonosis ledger landasks it the same way. - The queue is the heavy budget. A run, and every
geonosis ratchetor release run that takes a slot, waits in one first-come queue bounded by the budget of "The heavy slots" above. The slots are the same files the daemon-less path takes, so a client that cannot reach the daemon and one that can never share a slot. - Nothing depends on it. With no daemon every client takes the slot files itself and runs its own tier, as it did before. A daemon that goes away while it holds a client's run ends that client with exit 2 and the daemon's last log line; the run it started ends with it, and its slot is reaped.
- The Stop hook is a client. It reads a kept green for the current tree without running anything,
and hands the
fasttier to the daemon, under the key verify asks under, when there is none; without a daemon it launches the tier itself, detached.
The daemon accepts a command to run from any process of the same user that can open its socket (mode 0600), the way a shell does; it is not a service to expose.
Programmatic use
import { heavyBudget, takeSlot } from '@geonosis/gate'
const release = await takeSlot({ command: 'my heavy step', cwd: process.cwd() })
try {
// run with heavyBudget({ root: process.cwd() }).slots workers
} finally {
release()
}