Heimdall/deployment/idunn/recipe.toml

213 lines
8 KiB
TOML
Raw Normal View History

Honour the Idunn process write lease, and stop claiming active while warming During a deployment two Heimdall processes exist at once under distinct UIDs and namespaces, and both are configured with the same CultCache store path. Exactly one may write it. Idunn decides which by publishing a lease record naming an incarnation; nothing in Heimdall read it, so both generations would have written heimdall.service.cc. src/process-write-lease.ts answers one question -- may this process write state right now -- by reading the lease and the runtime bundle's expected.cc, and comparing incarnation identity. It grants nothing and throws nothing outward: every failure is a decision of mayWrite:false with a reason, because for a warming candidate "not yet my turn" is the expected condition and crashing would turn it into a failed deployment. Records are decoded as the canonical positional MessagePack Idunn writes (14 fields for the lease, schema-checked), and the tests build the same envelope bytes rather than convenient objects. publishHeimdallVerseState is the single writer, so that is the only place gated. Outside Idunn no lease path is configured and writes proceed unconditionally, which keeps developer runs and the current plain unit working. Second defect found while wiring it: health publication hardcoded state "active". A candidate would have claimed active from its first pulse, which is both untrue and structurally broken -- Idunn must observe `warming` presence before it fences the incumbent, so a candidate that never reports warming cannot be promoted. State is now derived from the lease: warming until held, active after, with the reason carried in the detail string. 49 tests across 11 files; tsc clean under exactOptionalPropertyTypes. The recipe's status banner now records the contract as implemented, with the honest caveat that none of it has been through a live `idunn up` -- the daemon on yggdrasil is still the previous generation, so the first deployment remains the real verification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 02:25:38 +02:00
# The runtime contract below is implemented as of 2026-09-06.
#
Honour the Idunn process write lease, and stop claiming active while warming During a deployment two Heimdall processes exist at once under distinct UIDs and namespaces, and both are configured with the same CultCache store path. Exactly one may write it. Idunn decides which by publishing a lease record naming an incarnation; nothing in Heimdall read it, so both generations would have written heimdall.service.cc. src/process-write-lease.ts answers one question -- may this process write state right now -- by reading the lease and the runtime bundle's expected.cc, and comparing incarnation identity. It grants nothing and throws nothing outward: every failure is a decision of mayWrite:false with a reason, because for a warming candidate "not yet my turn" is the expected condition and crashing would turn it into a failed deployment. Records are decoded as the canonical positional MessagePack Idunn writes (14 fields for the lease, schema-checked), and the tests build the same envelope bytes rather than convenient objects. publishHeimdallVerseState is the single writer, so that is the only place gated. Outside Idunn no lease path is configured and writes proceed unconditionally, which keeps developer runs and the current plain unit working. Second defect found while wiring it: health publication hardcoded state "active". A candidate would have claimed active from its first pulse, which is both untrue and structurally broken -- Idunn must observe `warming` presence before it fences the incumbent, so a candidate that never reports warming cannot be promoted. State is now derived from the lease: warming until held, active after, with the reason carried in the detail string. 49 tests across 11 files; tsc clean under exactOptionalPropertyTypes. The recipe's status banner now records the contract as implemented, with the honest caveat that none of it has been through a live `idunn up` -- the daemon on yggdrasil is still the previous generation, so the first deployment remains the real verification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 02:25:38 +02:00
# GAMECULT_IDUNN_CANDIDATE_BIND src/config.ts takes the candidate socket
# over HOST/PORT, requires loopback and a
# usable port, and refuses to start unless
# GC_ACCESS_BASE_URL is set, so an
# ephemeral port can never become the
# provider-registered OAuth callback.
# GAMECULT_IDUNN_PROCESS_WRITE_LEASE src/process-write-lease.ts. The single
# writer of heimdall.service.cc declines
# unless the lease names this incarnation.
# GAMECULT_IDUNN_RUNTIME_BUNDLE read for expected.cc, which is how the
# process learns which incarnation it is.
#
Honour the Idunn process write lease, and stop claiming active while warming During a deployment two Heimdall processes exist at once under distinct UIDs and namespaces, and both are configured with the same CultCache store path. Exactly one may write it. Idunn decides which by publishing a lease record naming an incarnation; nothing in Heimdall read it, so both generations would have written heimdall.service.cc. src/process-write-lease.ts answers one question -- may this process write state right now -- by reading the lease and the runtime bundle's expected.cc, and comparing incarnation identity. It grants nothing and throws nothing outward: every failure is a decision of mayWrite:false with a reason, because for a warming candidate "not yet my turn" is the expected condition and crashing would turn it into a failed deployment. Records are decoded as the canonical positional MessagePack Idunn writes (14 fields for the lease, schema-checked), and the tests build the same envelope bytes rather than convenient objects. publishHeimdallVerseState is the single writer, so that is the only place gated. Outside Idunn no lease path is configured and writes proceed unconditionally, which keeps developer runs and the current plain unit working. Second defect found while wiring it: health publication hardcoded state "active". A candidate would have claimed active from its first pulse, which is both untrue and structurally broken -- Idunn must observe `warming` presence before it fences the incumbent, so a candidate that never reports warming cannot be promoted. State is now derived from the lease: warming until held, active after, with the reason carried in the detail string. 49 tests across 11 files; tsc clean under exactOptionalPropertyTypes. The recipe's status banner now records the contract as implemented, with the honest caveat that none of it has been through a live `idunn up` -- the daemon on yggdrasil is still the previous generation, so the first deployment remains the real verification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 02:25:38 +02:00
# Health reports `warming` until the lease is held and `active` after, because
# Idunn must observe warming presence before it fences the incumbent.
#
# Still untested against a live Idunn: nothing here has been through an actual
# `idunn up heimdall`, and the daemon on yggdrasil is still the previous
# generation. Treat the first deployment as the real verification.
schema = "gamecult.idunn.target_declaration.v1"
target = "heimdall"
source_stamp_environment = "HEIMDALL_BUILD_COMMIT"
required_gitlinks = ["vendor/CultLib"]
# CultLib's TypeScript packages resolve through main/types to dist/, which a
# fresh checkout does not have. They must be built before Heimdall's own
# typecheck can resolve cultcache-ts, cultnet-ts or cultmesh-ts. This used to
# live in a shell manifest on the host; it belongs here, where the source seal
# covers it.
[[steps]]
id = "install-cultlib"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["npm", "ci", "--ignore-scripts", "--prefix", "vendor/CultLib"]
[[steps]]
id = "build-cultcache-ts"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["npm", "run", "build", "--prefix", "vendor/CultLib", "--workspace=packages/cultcache-ts"]
[[steps]]
id = "build-cultnet-ts"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["npm", "run", "build", "--prefix", "vendor/CultLib", "--workspace=packages/cultnet-ts"]
[[steps]]
id = "build-cultmesh-ts"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["npm", "run", "build", "--prefix", "vendor/CultLib", "--workspace=packages/cultmesh-ts"]
[[steps]]
id = "install-heimdall"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["corepack", "pnpm", "install", "--frozen-lockfile", "--config.node-linker=hoisted"]
[[steps]]
id = "test-heimdall"
phase = "test"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["corepack", "pnpm", "test"]
[[steps]]
id = "build-heimdall"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["corepack", "pnpm", "build"]
# The release is one self-contained executable. node_modules is a build
# input, not an artifact: pnpm lays it out as symlinks into .pnpm, which
# Idunn refuses to seal, and shipping a dependency tree to run a service is
# a larger liability than bundling it.
[[steps]]
id = "bundle-heimdall"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["corepack", "pnpm", "bundle"]
# The unit runs dist/src/index.js, and Node resolves its imports at runtime, so
# the release is the compiled output plus the production dependency tree. These
# are the two artifacts; nothing else from the build tree is installed.
[[steps]]
id = "stage-node"
phase = "build"
runner = "node-build"
required_environment = ["NPM_CONFIG_CACHE", "HOME", "COREPACK_HOME"]
argv = ["node", "-e", "require('fs').copyFileSync(process.execPath, 'dist/node')"]
# Idunn compares the running process's executable inode against the sealed
# artifact, so the executed inode must live inside the release. A shebang script
# cannot satisfy that: the kernel execs the interpreter, and the process's
# executable is /usr/bin/node rather than anything sealed. Shipping the runner
# image's own node as the executable brings the interpreter inside the seal and
# pins it to the runner image digest, which is a stronger guarantee than
# depending on whatever node the host happens to have.
[[artifacts]]
id = "node"
source_kind = "runner-output"
runner = "node-build"
source = "dist/node"
destination = "node"
executable = true
[[artifacts]]
id = "heimdall-bundle"
source_kind = "runner-output"
runner = "node-build"
source = "dist/heimdall"
destination = "heimdall.mjs"
executable = false
[service]
executable_artifact = "node"
arguments = [
{ kind = "literal", value = "heimdall.mjs" },
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>
2026-09-06 15:16:18 +02:00
{ kind = "literal", value = "--state-root" },
{ kind = "binding", name = "state_root" },
]
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>
2026-09-06 15:16:18 +02:00
transport = "http"
route_required = true
# A secret input is declared only as its `*_FILE` name. The binding binds it
# under [workload.secret_files] to a root:root 0400 credential file, so the value
# never sits in the binding, the unit or a plan. Idunn refuses a binding that
# sets an undeclared name, so a plaintext secret has nowhere to go.
optional_environment = [
"CULTMESH_URI_ODIN_RUDP",
"GC_ACCESS_APP_BIFROST_BACKEND_CALLBACK_URLS",
"GC_ACCESS_APP_BIFROST_SHARED_SECRET_FILE",
"GC_ACCESS_APP_GHOSTLIGHT_BACKEND_CALLBACK_URLS",
"GC_ACCESS_APP_GHOSTLIGHT_RUNTIME_IDS",
"GC_ACCESS_APP_GHOSTLIGHT_SHARED_SECRET_FILE",
"GC_ACCESS_APP_REPIXELIZER_SHARED_SECRET_FILE",
"GC_ACCESS_APP_STREAMPIXELS_SHARED_SECRET_FILE",
"GC_ACCESS_APPLY_SCHEMA_ON_STARTUP",
"GC_ACCESS_BIFROST_PATRON_SUPPORT_ENDPOINT",
"GC_ACCESS_BIFROST_PATRON_SUPPORT_SECRET_FILE",
"GC_ACCESS_COMPLETION_TTL_SECONDS",
"GC_ACCESS_IDUNN_HEALTH_CONTRACT",
"GC_ACCESS_IDUNN_RUDP_HEALTH",
"GC_ACCESS_ISSUER",
"GC_ACCESS_ODIN_CULTMESH_URI",
"GC_ACCESS_PRIVATE_COMMAND_HOST",
"GC_ACCESS_PRIVATE_COMMAND_PORT",
"GC_ACCESS_PROVIDER_DISCORD_CLIENT_ID",
"GC_ACCESS_PROVIDER_DISCORD_CLIENT_SECRET_FILE",
"GC_ACCESS_PROVIDER_GITHUB_CLIENT_SECRET_FILE",
"GC_ACCESS_PROVIDER_JOYSTICK_CLIENT_ID",
"GC_ACCESS_PROVIDER_JOYSTICK_CLIENT_SECRET_FILE",
"GC_ACCESS_PROVIDER_PATREON_CLIENT_ID",
"GC_ACCESS_PROVIDER_PATREON_CLIENT_SECRET_FILE",
"GC_ACCESS_PROVIDER_SPOTIFY_CLIENT_SECRET_FILE",
"GC_ACCESS_PROVIDER_TWITCH_CLIENT_ID",
"GC_ACCESS_PROVIDER_TWITCH_CLIENT_SECRET_FILE",
"GC_ACCESS_PROVIDER_YOUTUBE_CLIENT_ID",
"GC_ACCESS_PROVIDER_YOUTUBE_CLIENT_SECRET_FILE",
"GC_ACCESS_SESSION_TTL_SECONDS",
"GC_ACCESS_SIGNING_KEY_ID",
"GC_ACCESS_SIGNING_PRIVATE_KEY_BOOTSTRAP",
"GC_ACCESS_SIGNING_PRIVATE_KEY_PATH",
"GC_ACCESS_STATE_TTL_SECONDS",
"GC_ACCESS_STORAGE_BACKEND",
"GC_ACCESS_TOKEN_ENCRYPTION_KEY_BASE64_FILE",
]
required_environment = [
"GAMECULT_IDUNN_RUNTIME_BUNDLE",
"GAMECULT_IDUNN_CANDIDATE_BIND",
"GAMECULT_IDUNN_PROCESS_WRITE_LEASE",
Take the Idunn candidate socket, and keep it out of the advertised URL Heimdall bound config.port unconditionally, so it could not warm alongside itself: Idunn runs candidate and incumbent at once under distinct UIDs and namespaces, and two generations on 4100 is EADDRINUSE. src/config.ts now prefers GAMECULT_IDUNN_CANDIDATE_BIND, requiring loopback and a usable port, and falls back to HOST/PORT so developer runs and the current plain unit are unaffected. The part worth the care: publicBaseUrl defaulted to `http://${host}:${port}`, and it builds the OAuth callback URL registered with each provider. Left alone, a candidate would have advertised its ephemeral port as that callback -- a URL that stops resolving the moment the candidate is promoted or discarded, breaking logins in a way that would look like a provider problem. Listening address and advertised address are separate authorities, so GC_ACCESS_BASE_URL is now mandatory whenever a candidate bind is present, and startup fails loudly rather than advertising a disappearing port. Six tests cover it, including that regression by name and rejection of non-loopback, zero-port and malformed values. 41 pass across 10 files. Recipe corrected while here: required_environment named HEIMDALL_DATABASE_URL, which does not exist. The real name is GC_ACCESS_DATABASE_URL, confirmed in src/config.ts and in /srv/heimdall/env/service.env; that would have failed at first deploy. HOST and PORT are dropped, since the candidate bind supersedes them under Idunn, and GC_ACCESS_BASE_URL added as required. The recipe's status banner now lists what is done and what is pending rather than saying the contract is unimplemented. The write lease is the remaining blocker: the state slot is process-bound-single-writer and the service does not read the lease, so two generations could both open heimdall.service.cc. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 02:16:41 +02:00
"GC_ACCESS_BASE_URL",
"GC_ACCESS_DATABASE_URL_FILE",
]
[service.health]
contract = "heimdall.cultnet-rudp-access-health"
[state]
schema_generation = "heimdall-v1"
[[state.slots]]
id = "service"
relative_path = "heimdall.service.cc"
kind = "cultcache-file"
schema = "heimdall.service_state.v1"
writer = "process-bound-single-writer"
recovery = "preserve"
startup = "create-or-open-after-write-lease"
[[provides]]
capability = "gamecult.shared-auth"
schema = "heimdall.access-discovery.v1"
compatibility = "v1"
# Heimdall publishes its presence to Odin over CultMesh RUDP and never answers
# an Idunn route challenge, so it declares the Odin dependency: Idunn admits it
# as Ready on Odin's correlation, not on a challenge it will not answer.
[[dependencies]]
kind = "shared-infrastructure"
capability = "odin.verse-rendezvous"
schema = "odin.verse-topology.v1"
compatibility = "v1"
startup = "before-promotion"