Let Idunn assign the state root, and make the routed transport http

Writing the operator binding surfaced two recipe defects that only the
real admit() could catch.

The recipe declared transport = "rudp", copied from Odin's. Heimdall's
routed surface is HTTP -- the CultNet private command plane is separate and
Idunn does not route it -- and the transport decides the scheme used to
derive the candidate endpoint, so this would have produced a nonsense bind
address. Now http.

Second, a recipe with state slots is a stateful workload, and admit()
requires the state root to arrive as a launch argument rather than an
environment variable: "stateful workload has no state_root argument
binding". That is the better ownership anyway. Idunn owns where a target's
state lives, the recipe declares slots relative to it, and the binding
supplies the absolute path. Heimdall now takes --state-root, requires it to
be absolute, and prefers it over GC_ACCESS_DATA_ROOT, which survives for
runs outside Idunn. GC_ACCESS_DATA_ROOT is correspondingly gone from the
binding's environment, so there is one owner for that path instead of two
spellings of it.

Verified against a real Linux Idunn rather than assumed: `idunn validate`
on Windows cannot check a Linux binding at all, because Path::is_absolute()
wants a drive prefix and /srv/build/Heimdall fails as "checkout must be
absolute". Built Idunn on yggdrasil in a rust:1.95-bookworm container --
the cached rust:1.89 image is too old, redb 4.2 requires 1.90 -- and
validated there: recipe ok, binding admits.

52 tests across 11 files; tsc clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-06 15:16:18 +02:00
commit 0610683295
3 changed files with 67 additions and 3 deletions

View file

@ -94,9 +94,12 @@ executable = false
executable_artifact = "heimdall-dist"
arguments = [
{ kind = "literal", value = "dist/src/index.js" },
{ kind = "literal", value = "--state-root" },
{ kind = "binding", name = "state_root" },
]
transport = "rudp"
transport = "http"
route_required = true
optional_environment = []
required_environment = [
"GAMECULT_IDUNN_RUNTIME_BUNDLE",
"GAMECULT_IDUNN_CANDIDATE_BIND",

View file

@ -140,9 +140,38 @@ function readOptionalString(envValue: string | undefined): string | undefined {
return value ? value : undefined;
}
export function loadConfig(env: NodeJS.ProcessEnv = process.env): HeimdallConfig {
/**
* `--state-root PATH`, the directory Idunn assigns for this target's persistent
* state. Idunn owns that location: the recipe declares state slots relative to
* it and the operator binding supplies the absolute path, so the service is
* told rather than choosing. Absent outside Idunn, where GC_ACCESS_DATA_ROOT
* and the repo-local default still apply.
*/
function readStateRootArgument(argv: readonly string[]): string | undefined {
const index = argv.indexOf("--state-root");
if (index === -1) {
return undefined;
}
const value = argv[index + 1];
if (!value || value.startsWith("--")) {
throw new Error("--state-root requires a path");
}
if (!path.isAbsolute(value)) {
throw new Error(`--state-root must be absolute: ${value}`);
}
return value;
}
export function loadConfig(
env: NodeJS.ProcessEnv = process.env,
argv: readonly string[] = process.argv.slice(2)
): HeimdallConfig {
const sourceRoot = fileURLToPath(new URL("../", import.meta.url));
const workspaceRoot = path.resolve(sourceRoot, "..");
const stateRootArgument = readStateRootArgument(argv);
// Where Heimdall listens and what Heimdall advertises are two different
// authorities, and Idunn is the reason they must not be conflated. Under
// Idunn a candidate and the incumbent run at once, so the candidate is told
@ -163,7 +192,8 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): HeimdallConfig
const publicBaseUrl = trimTrailingSlash(env.GC_ACCESS_BASE_URL ?? `http://${host}:${port}`);
const issuer = trimTrailingSlash(env.GC_ACCESS_ISSUER ?? publicBaseUrl);
const dataRoot = env.GC_ACCESS_DATA_ROOT ?? path.join(workspaceRoot, ".heimdall-data");
const dataRoot =
stateRootArgument ?? env.GC_ACCESS_DATA_ROOT ?? path.join(workspaceRoot, ".heimdall-data");
const storageBackend =
env.GC_ACCESS_STORAGE_BACKEND === "postgres" || env.GC_ACCESS_DATABASE_URL ? "postgres" : "memory";
const providersConfig = Object.fromEntries(

View file

@ -1,3 +1,4 @@
import path from "node:path";
import { describe, expect, it } from "vitest";
import { loadConfig } from "../src/config.js";
@ -65,3 +66,33 @@ describe("Idunn candidate bind", () => {
expect(config.port).toBe(18833);
});
});
describe("Idunn state root argument", () => {
it("takes --state-root over GC_ACCESS_DATA_ROOT", () => {
// Idunn owns where state lives: the recipe declares slots relative to
// state_root and the binding supplies the absolute path as a launch
// argument. The env var remains for runs outside Idunn.
const config = loadConfig({ GC_ACCESS_DATA_ROOT: "/tmp/ignored" }, [
"--state-root",
"/var/lib/gamecult/heimdall",
]);
expect(config.dataRoot).toBe("/var/lib/gamecult/heimdall");
expect(config.cultCachePath).toContain("heimdall.service.cc");
expect(config.cultCachePath).toBe(
path.join(config.dataRoot, "cultcache", "heimdall.service.cc")
);
});
it("falls back to GC_ACCESS_DATA_ROOT when the argument is absent", () => {
expect(loadConfig({ GC_ACCESS_DATA_ROOT: "/srv/heimdall/state" }, []).dataRoot).toBe(
"/srv/heimdall/state"
);
});
it("rejects a missing or relative --state-root", () => {
expect(() => loadConfig({}, ["--state-root"])).toThrow(/requires a path/);
expect(() => loadConfig({}, ["--state-root", "--other"])).toThrow(/requires a path/);
expect(() => loadConfig({}, ["--state-root", "relative/path"])).toThrow(/must be absolute/);
});
});