carlos / platform Public

activator: Astra R1 fixes for the wake-failure journal line

1. Another holder's lease and config this box cannot provide, which a
   binary row's errors carry unmarked, are not journalled as failures.
2. Failure notes expire after ten minutes, so the map stays bounded for
   hosts that never wake again.
3. The seed and worker argv parse errors name the value's size, not the
   value, which can carry a credential and now reaches the journal.

Tests also hold that the kill's reason is logged before the kill. (#861)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2f3db0f357b28ae31e87339e4541c36667b3c88b parent 614024f
4 files changed, +107 −5
  • internal/activator/activator.go +1 −1
  • internal/activator/backend_exec.go +5 −2
  • internal/activator/startkill_log_test.go +68 −0
  • internal/activator/wakefaillog.go +33 −2

CI cancelled — superseded by a newer push — run details

diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index 8dd51694d..7292f4a0f 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -2164,7 +2164,7 @@ func (a *Service) wake(e *actEntry) {
} else if msg, ok := a.wakeFailureEvent(e, err); ok && !errors.Is(err, ErrDutyDeferred) {
emitEvent(a.Logs, e.route, "error", msg)
}
- if !genStartUnproven(err) && !errors.Is(err, errRootfsNotAdmitted) && !errors.Is(err, ErrDutyDeferred) && residentFailure(err) {
+ if journalledWakeFailure(err) {
a.logWakeFailure(e.host, err)
}
} else {
diff --git a/internal/activator/backend_exec.go b/internal/activator/backend_exec.go
index 64a4cb8a0..0b187ca31 100644
--- a/internal/activator/backend_exec.go
+++ b/internal/activator/backend_exec.go
@@ -1219,7 +1219,9 @@ func seedArgv(rt registry.Route, dbPath string) ([]string, error) {
if err := json.Unmarshal([]byte(rt.Seed), &seedArgs); err != nil {
// Never a silent skip: a mangled seed column must fail the wake
// loudly, not boot an empty instance that looks healthy.
- return nil, fmt.Errorf("parse seed argv for %s (%q): %w", rt.Host, rt.Seed, err)
+ // The column's value stays out of the error: an argv can carry a
+ // credential, and this text reaches the journal (#861).
+ return nil, fmt.Errorf("parse seed argv for %s (%d bytes): %w", rt.Host, len(rt.Seed), err)
}
if len(seedArgs) == 0 {
return nil, nil
@@ -3671,7 +3673,8 @@ func (b *ExecBackend) StartWorkerStaged(ctx context.Context, rt registry.Route,
}
var argv []string
if err := json.Unmarshal([]byte(rt.Args), &argv); err != nil || len(argv) == 0 {
- return nil, release.StagedIdentity{}, fmt.Errorf("worker %s: no runnable argv in args %q", rt.Host, rt.Args)
+ // The value stays out of the error, as seedArgv's (#861).
+ return nil, release.StagedIdentity{}, fmt.Errorf("worker %s: no runnable argv in args (%d bytes)", rt.Host, len(rt.Args))
}
var id release.StagedIdentity
if onto == nil {
diff --git a/internal/activator/startkill_log_test.go b/internal/activator/startkill_log_test.go
index 441297ff2..a46dcbf4e 100644
--- a/internal/activator/startkill_log_test.go
+++ b/internal/activator/startkill_log_test.go
@@ -84,6 +84,15 @@ func TestARefusedRootfsGenerationStartSaysWhyBeforeItsKill(t *testing.T) {
b.CgroupEvents = func(string, string) (bool, bool, error) { return false, false, nil }
tc.set(b, ctl)
rt := rootfsRoute(b)
+ // The reason is in the journal before the kill is asked for.
+ loggedFirst := false
+ prevHook := ctl.stopHook
+ ctl.stopHook = func(host string, role instancectl.Role) {
+ loggedFirst = len(logs.lines("killing it")) == 1
+ if prevHook != nil {
+ prevHook(host, role)
+ }
+ }
if _, _, err := b.StartGen(context.Background(), rt, 4, true); err == nil {
t.Fatal("started")
}
@@ -93,6 +102,9 @@ func TestARefusedRootfsGenerationStartSaysWhyBeforeItsKill(t *testing.T) {
if len(got) != 1 || !strings.Contains(got[0], unit) || !strings.Contains(got[0], tc.want) {
t.Errorf("kill-site lines = %q, want one naming %s and %q", got, unit, tc.want)
}
+ if !loggedFirst {
+ t.Error("the kill was asked for before its reason was logged")
+ }
})
}
}
@@ -176,3 +188,59 @@ func TestAFailedWakeIsLoggedAndRateLimited(t *testing.T) {
t.Errorf("a fence refusal was logged as a failed wake: %q", got)
}
}
+
+// Another holder's lease and config this box cannot provide are routine
+// on an HA box, and a binary row's errors carry them unmarked: neither is
+// a failed wake in the journal (Astra R1 1). A plain start error is.
+func TestRoutineOwnershipRefusalsAreNotJournalledAsFailures(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ err error
+ want bool
+ }{
+ {"lease held", fmt.Errorf("wake: %w", &errLeaseHeld{holder: "box-2", retryAfter: time.Second}), false},
+ {"config refused", fmt.Errorf("wake: %w", &errConfigRefused{err: errors.New("no key")}), false},
+ {"fenced", fmt.Errorf("start: %w", ErrFenced), false},
+ {"duty deferred", ErrDutyDeferred, false},
+ {"start failure", errors.New("start unit: boom"), true},
+ } {
+ if got := journalledWakeFailure(tc.err); got != tc.want {
+ t.Errorf("%s: journalledWakeFailure = %v, want %v", tc.name, got, tc.want)
+ }
+ }
+}
+
+// A host's note does not outlive wakeFailureForget: a host that failed and
+// never woke again (deleted, say) is dropped on the next failure anywhere
+// (Astra R1 2).
+func TestWakeFailureNotesExpire(t *testing.T) {
+ _ = captureLogLocked(t)
+ a, _, clk, reg := testActivator(t, time.Minute)
+ defer reg.Close()
+ a.logWakeFailure("gone.example.com", errors.New("boom"))
+ clk.advance(wakeFailureForget)
+ a.logWakeFailure("other.example.com", errors.New("boom"))
+ a.wakeFailMu.Lock()
+ defer a.wakeFailMu.Unlock()
+ if _, ok := a.wakeFailLogged["gone.example.com"]; ok || len(a.wakeFailLogged) != 1 {
+ t.Errorf("notes = %v, want only other.example.com", a.wakeFailLogged)
+ }
+}
+
+// A malformed seed or worker argv fails the wake, and that error reaches
+// the journal: it names the column's size, never its value, which can
+// carry a credential (Astra R1 3).
+func TestMalformedArgvErrorsDoNotQuoteTheirValue(t *testing.T) {
+ const secret = "tok_SECRET_123"
+ rt := testRoute("shop.example.com")
+ rt.Seed = `["seed","--token=` + secret
+ if _, err := seedArgv(rt, "/tmp/x.db"); err == nil || strings.Contains(err.Error(), secret) || !strings.Contains(err.Error(), "parse seed argv") {
+ t.Errorf("seedArgv error = %v, want a failure that does not quote the value", err)
+ }
+ b := testExecBackend(t)
+ w := testWorkerRoute("worker.example.com")
+ w.Args = `["run","--token=` + secret
+ if _, _, err := b.StartWorkerStaged(context.Background(), w, nil, nil); err == nil || strings.Contains(err.Error(), secret) || !strings.Contains(err.Error(), "no runnable argv") {
+ t.Errorf("StartWorkerStaged error = %v, want a failure that does not quote the value", err)
+ }
+}
diff --git a/internal/activator/wakefaillog.go b/internal/activator/wakefaillog.go
index d2f90e982..4c2188d33 100644
--- a/internal/activator/wakefaillog.go
+++ b/internal/activator/wakefaillog.go
@@ -1,6 +1,7 @@
package activator
import (
+ "errors"
"log"
"time"
)
@@ -11,6 +12,12 @@ import (
// would otherwise write a line per attempt.
const wakeFailureLogEvery = time.Minute
+// wakeFailureForget is how long a host's note outlives its last journalled
+// line. Older notes are dropped on the next failure anywhere, so the map
+// holds only hosts that failed recently, whether or not they ever wake
+// again or stay in the registry (Astra R1 2).
+const wakeFailureForget = 10 * wakeFailureLogEvery
+
// wakeFailNote is one host's last journalled failure and the failures
// since that were not logged.
type wakeFailNote struct {
@@ -18,19 +25,43 @@ type wakeFailNote struct {
suppressed int
}
+// journalledWakeFailure is whether a failed wake's error belongs in the
+// journal: a real failure (residentFailure, which leaves out a fence,
+// shutdown, cancellation and another box's ownership of a runtime row),
+// and never another holder's lease or config this box cannot provide yet,
+// which a binary row's errors carry unmarked (markOwnershipRefusal) and
+// which are routine on an HA box (Astra R1 1). genStartUnproven and
+// errRootfsNotAdmitted have journal lines of their own; ErrDutyDeferred
+// is not a failure.
+func journalledWakeFailure(err error) bool {
+ var held *errLeaseHeld
+ var refused *errConfigRefused
+ switch {
+ case errors.As(err, &held), errors.As(err, &refused):
+ return false
+ case genStartUnproven(err), errors.Is(err, errRootfsNotAdmitted), errors.Is(err, ErrDutyDeferred):
+ return false
+ }
+ return residentFailure(err)
+}
+
// logWakeFailure writes a failed wake's reason to the journal (#861):
// before this, a wake that failed after root was asked left only the
// member's event, and on a box the operator read nothing but systemd's
// "SIGKILL ... on client request". The first failure logs at once; after
// that at most one line per wakeFailureLogEvery, counting the failures in
-// between. Callers pass only real failures (residentFailure), never a
-// routine refusal such as a fence or another box's lease.
+// between. Callers pass only journalledWakeFailure errors.
func (a *Service) logWakeFailure(host string, err error) {
now := a.now()
a.wakeFailMu.Lock()
if a.wakeFailLogged == nil {
a.wakeFailLogged = map[string]*wakeFailNote{}
}
+ for h, n := range a.wakeFailLogged {
+ if now.Sub(n.at) >= wakeFailureForget {
+ delete(a.wakeFailLogged, h)
+ }
+ }
n := a.wakeFailLogged[host]
if n != nil && now.Sub(n.at) < wakeFailureLogEvery {
n.suppressed++