A tool runner is no longer restarted by a build of the engine: owned paths name the directory of every build, and a restart names its cause (issue 1966)
The tool runner's unit carries the paths modules own, for the holder of node-files. The engine's own archive is unpacked into a place named for its build, so every engine replacement changed that word and restarted the tool runner with nothing of it changed (novox 21:16, 22:25, 22:38 on 2026-11-09). A resource unpacked into a place named for its build now owns the directory holding every build. The restart line now names the unit's directive, word and key that differ, never a value. Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
@@ -4,10 +4,13 @@ import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -260,6 +263,9 @@ func applyProcess(ctx context.Context, r *declaration.Process, run Runner,
|
||||
}
|
||||
if because != "" {
|
||||
out.Detail += ", restarted because " + because + " changed"
|
||||
} else if what := unitDifference(previous.Wrote, want); what != "" {
|
||||
// Said, so a restart nobody asked for names its cause (issue 1966): the file and the input of it, never a value.
|
||||
out.Detail += ", restarted because " + what + " changed"
|
||||
}
|
||||
if placing.Detail != "" {
|
||||
out.Detail += "; " + placing.Detail
|
||||
@@ -553,3 +559,111 @@ func digestWritten(wrote string) string {
|
||||
|
||||
// DaemonRoot is where unpacked daemons live — and what a witness keeps beside them.
|
||||
func DaemonRoot() string { return daemonRoot }
|
||||
|
||||
// unitDifference names what differs between what a process's record says was written and what is wanted now, both
|
||||
// "sha256:<hex> <unit>": its bundle when the digest differs, and in the unit file each directive and each environment
|
||||
// word that differs, with inside a word the keys of a JSON object (and, one level down, of its objects) or the names of
|
||||
// the name=value entries of a list that differ. Names only, never a value, so a secret in a word is never said. Empty
|
||||
// when nothing differs or there was no record.
|
||||
func unitDifference(was, want string) string {
|
||||
if was == "" {
|
||||
return ""
|
||||
}
|
||||
wasDigest, wasUnit, _ := strings.Cut(was, " ")
|
||||
wantDigest, wantUnit, _ := strings.Cut(want, " ")
|
||||
var names []string
|
||||
if wasDigest != wantDigest {
|
||||
names = append(names, "its bundle")
|
||||
}
|
||||
before, after := unitDirectives(wasUnit), unitDirectives(wantUnit)
|
||||
keys := map[string]bool{}
|
||||
for k := range before {
|
||||
keys[k] = true
|
||||
}
|
||||
for k := range after {
|
||||
keys[k] = true
|
||||
}
|
||||
for _, k := range slices.Sorted(maps.Keys(keys)) {
|
||||
if before[k] != after[k] {
|
||||
names = append(names, "its unit's "+k+valueDifference(before[k], after[k], 2))
|
||||
}
|
||||
}
|
||||
return strings.Join(names, ", ")
|
||||
}
|
||||
|
||||
// unitDirectives is a unit's directives by name: "Environment <word>" for an environment word, the directive's own
|
||||
// name for the rest, each with its value as written (an environment word's value unescaped, as unitValue escapes it).
|
||||
func unitDirectives(unit string) map[string]string {
|
||||
out := map[string]string{}
|
||||
for _, line := range strings.Split(unit, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, "[") {
|
||||
continue
|
||||
}
|
||||
key, value, _ := strings.Cut(line, "=")
|
||||
if key == "Environment" && strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) {
|
||||
word, rest, _ := strings.Cut(value[1:len(value)-1], "=")
|
||||
rest = strings.NewReplacer(`\\`, `\`, `\"`, `"`, "%%", "%").Replace(rest)
|
||||
out["Environment "+word] = rest
|
||||
continue
|
||||
}
|
||||
out[key] += value
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// valueDifference is what differs inside one directive's value, as " (a, b)": the keys of a JSON object whose value
|
||||
// differs (going down depth levels), else the names of the name=value entries of a comma-separated list that were
|
||||
// added, removed or changed. Empty when the value says nothing more than that it differs.
|
||||
func valueDifference(was, now string, depth int) string {
|
||||
var a, b map[string]json.RawMessage
|
||||
if depth > 0 && json.Unmarshal([]byte(was), &a) == nil && json.Unmarshal([]byte(now), &b) == nil && (a != nil || b != nil) {
|
||||
all := map[string]bool{}
|
||||
for k := range a {
|
||||
all[k] = true
|
||||
}
|
||||
for k := range b {
|
||||
all[k] = true
|
||||
}
|
||||
var names []string
|
||||
for _, k := range slices.Sorted(maps.Keys(all)) {
|
||||
if string(a[k]) == string(b[k]) {
|
||||
continue
|
||||
}
|
||||
inner := ""
|
||||
var x, y string
|
||||
if json.Unmarshal(a[k], &x) == nil && json.Unmarshal(b[k], &y) == nil {
|
||||
inner = valueDifference(x, y, 0)
|
||||
} else {
|
||||
inner = valueDifference(string(a[k]), string(b[k]), depth-1)
|
||||
}
|
||||
names = append(names, k+inner)
|
||||
}
|
||||
return " (" + strings.Join(names, ", ") + ")"
|
||||
}
|
||||
entries := func(list string) map[string]string {
|
||||
m := map[string]string{}
|
||||
for _, e := range strings.Split(list, ",") {
|
||||
if name, _, ok := strings.Cut(e, "="); ok {
|
||||
m[e] = name
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
before, after := entries(was), entries(now)
|
||||
named := map[string]bool{}
|
||||
for e, name := range before {
|
||||
if _, ok := after[e]; !ok {
|
||||
named[name] = true
|
||||
}
|
||||
}
|
||||
for e, name := range after {
|
||||
if _, ok := before[e]; !ok {
|
||||
named[name] = true
|
||||
}
|
||||
}
|
||||
if len(named) == 0 {
|
||||
return ""
|
||||
}
|
||||
return " (" + strings.Join(slices.Sorted(maps.Keys(named)), ", ") + ")"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user