Each of the four is core. Every state that named no cap names one, from its live fill read 2026-11-22 01:4x CET (mesh-broker show, nats_streams on novox): mesh-build-go steps 16.0 MiB (16,783,695 bytes) -> 128 MiB; mesh-build-node steps 2.35 MiB (2,463,833 bytes) -> 16 MiB; every other state under 2 MiB -> 8 MiB (largest: distribution holds 1,844,287 bytes, mesh-build-go detected-steps 868,554, distribution transfers 846,359, findings 668,161, idle 401,736, mesh-build-go pauses 254,366). The Go build module's finding-events is 8 MiB for 7 days. The objects stores already name their caps; none keeps a log. The Go and Node build modules prune their state detected-steps (each key an artifact's steps as detected, detected again when gone) at their own writes, past prune-mark 70 % down to prune-target 50 %, and serve <module>_state_prune_now and <module>_state_keep; no other state of the four is prunable (each is truth: running steps, pauses, keys, toolchains, findings, holds, transfers, windows, mirrors, taken asks). Builds: design 47 H2 §812, §820; H-A-411 (1), (2), (3), H-A-437
109 lines
4.5 KiB
Go
109 lines
4.5 KiB
Go
// mesh-build-node: the Node and TypeScript build module (novox/hq ADR 0405, ADR 0466 §1, ADR 0469, ADR 0470; design
|
|
// 47 R4c-3, issue 1488). A Go tools bundle the node's runtime launches as the module's own account (runs-as). It names
|
|
// the one Node version it builds with, installs the TypeScript toolchain its own lock names, writes the Node version
|
|
// it finds to <node>.typescript of its `toolchains` state at start and before every step, and refuses every step on
|
|
// a node that has another: its health is then unhealthy, so the controller raises the node's condition. What it
|
|
// says, it says on stderr; stdout is the MCP channel.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/user"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode"
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
dforgekey "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/forgekey"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
"git.novox.be/novox/mesh-sdk/go/busstate"
|
|
)
|
|
|
|
// CacheDir is the cache directory, outside the account's home (ADR 0466 §1; module.json resource `cache`).
|
|
const CacheDir = "/var/lib/mesh-build-node-cache"
|
|
|
|
// WorkDir is the work directory, outside the home (module.json resource `work`).
|
|
const WorkDir = "/var/lib/mesh-build-node-work"
|
|
|
|
func logf(format string, a ...any) { fmt.Fprintf(os.Stderr, "[mesh-build-node] "+format+"\n", a...) }
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
home := ""
|
|
if u, err := user.Current(); err == nil {
|
|
home = u.HomeDir
|
|
}
|
|
paths := Paths{Home: home, Cache: CacheDir}
|
|
registry := func() (Registry, error) {
|
|
return ReadRegistry(filepath.Join(home, "package-registry.json"))
|
|
}
|
|
m := &Module{
|
|
SayEvent: stdio.SeatPublish,
|
|
Node: strings.TrimSpace(os.Getenv("MESH_NODE")),
|
|
Reload: func() (Recipe, error) { return ReadRecipe(paths.LockPath()) },
|
|
Probe: ProbeNode,
|
|
Toolchain: &Toolchain{Paths: paths, Run: dforgekey.ExecRunnerClean(0), Registry: registry},
|
|
Toolchains: stdio.State(seat.StateToolchains).Put,
|
|
SayToolchain: stdio.SeatPublish,
|
|
Steps: stdio.State(seat.StateSteps).Put,
|
|
ReadSteps: readOf(stdio.State(seat.StateSteps)),
|
|
Detected: prunedDetected().Put,
|
|
ReadDetected: readOf(stdio.State(seat.StateDetectedSteps)).Get,
|
|
ForgetDetected: stdio.State(seat.StateDetectedSteps).Delete,
|
|
RecordAct: handActRecorder,
|
|
Pauses: stdio.State(sdkstep.PausesState).Put,
|
|
ReadPauses: readOf(stdio.State(sdkstep.PausesState)),
|
|
ForgetPause: stdio.State(sdkstep.PausesState).Delete,
|
|
WatchPauses: stdio.State(sdkstep.PausesState).Watch,
|
|
ReadToolchainsState: readOf(stdio.State(seat.StateToolchains)),
|
|
Work: WorkDir,
|
|
Run: dforgekey.ExecRunnerClean(0),
|
|
Ctx: ctx,
|
|
Say: logf,
|
|
Bubblewrap: ProbeBubblewrap,
|
|
}
|
|
m.Floor = floorOf(m.Node)
|
|
m.Settings = filepath.Join(home, "settings.json")
|
|
m.ArtifactStoreFile = filepath.Join(home, "artifact-store.json")
|
|
// Outside a launch by the runtime — a build, a check — there is no node and no state to write.
|
|
if m.Node != "" {
|
|
go m.Start(ctx)
|
|
}
|
|
go startKeeper(ctx)
|
|
// Every state it keeps, said on the bus before it serves (ADR 0495 §2; issue 1790).
|
|
if err := keepStates(); err != nil {
|
|
logf("announcing the states it keeps: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
m.Answers = busstate.ObjectsOf(steprun.AnswersStore)
|
|
steps := m.StepTools()
|
|
booted := time.Now()
|
|
puller := m.Puller(steps, nil)
|
|
// A step whose fetch or publish met its holder away is given again after again-delays (design 47 H2 §799; H-A-390).
|
|
againSetting, _ := stdio.Setting(steprun.AgainDelaysSetting)
|
|
againDelay, againErr := steprun.AgainDelays(againSetting)
|
|
if againErr != nil {
|
|
logf("the setting %s: %v", steprun.AgainDelaysSetting, againErr)
|
|
os.Exit(1)
|
|
}
|
|
puller.Delay = againDelay
|
|
m.Held = puller
|
|
if m.Node != "" {
|
|
// A step a previous process left running is ended (issue 1890): one that names another owner, or none and
|
|
// started before booted.
|
|
go m.endLeftRunning(ctx, m.stepScan(), booted, logf)
|
|
}
|
|
if m.Node != "" {
|
|
// The seat's asks, pulled once Serve has the runtime's channel; a pull before it is said and tried again.
|
|
go func() { _ = puller.Pull(ctx) }()
|
|
}
|
|
if err := stdio.Serve("", append(m.Tools(steps), m.SeatTools(puller)...)); err != nil {
|
|
logf("%v", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|