carlos / platform Public

dbverify: keep the last known identity; hold streaks when not reached

Task 4 fix round 1 (#898). A verdict with no identity now carries the
prior verdict's last known identity forward, so passed A, unknown, then
B starts B's history over instead of inheriting A's FirstSeen,
LastDecidedAt and streak. not_reached and the new no_assignment reason
hold UnverifiedRuns rather than resetting it. KeyFor uses
boxself.ValidRef in place of a copy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7af5822e4b85428b4f1b838428706d07866457cb parent 750bd28
2 files changed, +84 −36
  • internal/dbverify/dbverify.go +30 −30
  • internal/dbverify/dbverify_test.go +54 −6

CI failed — run details

Intent

Human

<task-notification> <task-id>a11baaeb200927c29</task-id> <tool-use-id>toolu_01VGAH84qY5VMUseA6Q3UdKA</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/a11baaeb200927c29.output</output-file> <status>completed</status> <summary>Agent "Implement slice 2a Task 4" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE (commit 750bd288 on member-backups-2a, not pushed). **Tests:** The targeted dbverify, release, hostops and moves tests went from failing to passing. `go build ./...` and `go vet` are clean, the internal/host and internal/ops tests compile, and the ops hibernate tests and the root moves-copy scan pass. `TestPlan9B8RecordWriteCensus` fails as expected, and `OfflineManifest` in internal/moves/offline.go is pinned there too, so Task 9 needs to cover it. **Callers adapted:** - `ops.go`: `ref := boxLabel()` is passed to Load, Merge and the log lines. - `hibernate_verify.go` and its test: the build broke here too, so it now writes v2 verdicts. - `movespass.go:576`: wired to `RemoveHost(ctx, s, cfg.Box, h)`. - `movesland_test.go`: lines 348, 420 and 655 updated. - The `movescutguard` and `movesinstall` test stubs needed no change. **Concerns:** 1. An identity counts as changed only when both sides are known and differ. A literal reading of the brief would restart the 7-day clock when the first known identity replaces a `not_reached` placeholder. 2. `not_reached` sets `UnverifiedRuns` to 0 rather than holding the streak, as the brief says. Only that exact reason is exempt, so if Task 5 records `no_assignment` as its own reason, those runs will count toward the streak. 3. I kept the `Detail` free-text field (the error text) even though the brief's field list leaves it out. Without it the restore error text is lost, and an existing test checks it. 4. The reason codes the ops adapter writes are placeholders until Task 5. **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups-2a/.superpowers/sdd/2026-11-11-member-backups-slice2a/task-4-report.md</result> <usage><subagent_tokens>151389</subagent_tokens><tool_uses>59</tool_uses><duration_ms>736037</duration_ms></usage> </task-notification>

Attributed to this commit: 13.7 g CO₂e (1,716,644 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on member-backups-2a, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/dbverify/dbverify.go b/internal/dbverify/dbverify.go
index 8aebd9ecc..254a90b09 100644
--- a/internal/dbverify/dbverify.go
+++ b/internal/dbverify/dbverify.go
@@ -21,8 +21,8 @@ import (
"fmt"
"os"
"time"
- "unicode"
+ "github.com/carlosframework/platform/internal/boxself"
"github.com/carlosframework/platform/internal/release"
)
@@ -36,30 +36,15 @@ var ErrInvalidRef = errors.New("dbverify: not a valid box reference")
// KeyFor is the key of ref's record, control/verify/<ref>.json. Each box
// writes only its own, so two boxes publishing at once never erase each
-// other's verdicts. An invalid ref (validRef) gets "", which Load, Publish
-// and RemoveHost refuse with ErrInvalidRef.
+// other's verdicts. A ref boxself.ValidRef refuses gets "", which Load,
+// Publish and RemoveHost refuse with ErrInvalidRef.
func KeyFor(ref string) string {
- if !validRef(ref) {
+ if !boxself.ValidRef(ref) {
return ""
}
return keyPrefix + ref + ".json"
}
-// validRef is boxself.ValidRef, repeated so this leaf package imports
-// nothing new: non-empty, at most 128 bytes, printable, with no space,
-// slash or backslash, and not "." or "..".
-func validRef(ref string) bool {
- if ref == "" || len(ref) > 128 || ref == "." || ref == ".." {
- return false
- }
- for _, r := range ref {
- if r == '/' || r == '\\' || unicode.IsSpace(r) || !unicode.IsPrint(r) {
- return false
- }
- }
- return true
-}
-
// The three results.
const (
ResultPassed = "passed"
@@ -77,9 +62,13 @@ const (
)
// ReasonNotReached is an unverified verdict for a host the run did not
-// get to, or abandoned when it ran out of time. It learned nothing about the replica, so it does not count
-// toward UnverifiedRuns.
-const ReasonNotReached = "not_reached"
+// get to, or abandoned when it ran out of time; ReasonNoAssignment is one
+// for a group box's host that no usable assignment gave this box. Neither
+// learned anything about the replica, so neither moves UnverifiedRuns.
+const (
+ ReasonNotReached = "not_reached"
+ ReasonNoAssignment = "no_assignment"
+)
// Identity is the instance a verdict is about. It mirrors dbreads.Identity
// field for field (the drill converts one to the other), so a host deleted and
@@ -103,8 +92,8 @@ type Verdict struct {
// Reason says why a verdict is failed or unverified, as a code
// (ReasonNotReached and the drill's own).
Reason string `json:"reason,omitempty"`
- // Identity is the instance the bracket captured; zero when the
- // capture itself could not decide one.
+ // Identity is the instance the bracket captured. When the capture
+ // could not decide one, Merge keeps the last known identity.
Identity Identity `json:"identity"`
// Prefix is the replica prefix restored from.
Prefix string `json:"prefix,omitempty"`
@@ -127,8 +116,9 @@ type Verdict struct {
// The bookkeeping Merge keeps, whatever the caller set.
//
- // UnverifiedRuns is how many runs in a row ended unverified for a
- // reason other than not_reached; any other result sets it to 0.
+ // UnverifiedRuns is how many runs in a row ended unverified, not
+ // counting not_reached or no_assignment runs, which leave it as it
+ // was; passed or failed sets it to 0.
UnverifiedRuns int `json:"unverified_runs"`
// FirstSeen is the first run that counted this host, for this
// identity.
@@ -169,9 +159,11 @@ type Record struct {
//
// For each result, Merge keeps the host's bookkeeping: FirstSeen carries
// over, LastDecidedAt advances only on passed or failed, and
-// UnverifiedRuns counts unverified runs (not not_reached ones) in a row.
+// UnverifiedRuns counts unverified runs in a row: passed or failed resets
+// it, not_reached and no_assignment hold it, any other reason adds one.
// A result about a different identity than the prior verdict starts all
-// three over. A zero identity on either side is unknown, not different.
+// three over. A result with no identity (zero) keeps the prior verdict's
+// last known one; a prior with none is never "different".
func Merge(prior *Record, ref string, now time.Time, fleet []string, results map[string]Verdict) *Record {
now = now.UTC()
rec := &Record{V: 2, Box: ref, CheckedAt: now, Hosts: map[string]Verdict{}}
@@ -195,7 +187,13 @@ func Merge(prior *Record, ref string, now time.Time, fleet []string, results map
}
func mergeOne(p Verdict, had bool, r Verdict, now time.Time) Verdict {
- if had && p.Identity != (Identity{}) && r.Identity != (Identity{}) && p.Identity != r.Identity {
+ // An unknown identity is not evidence of another instance: it keeps
+ // the last known one, so a later known identity is still compared
+ // against it.
+ if r.Identity == (Identity{}) && had {
+ r.Identity = p.Identity
+ }
+ if had && p.Identity != (Identity{}) && r.Identity != p.Identity {
had = false
}
if !had {
@@ -214,7 +212,9 @@ func mergeOne(p Verdict, had bool, r Verdict, now time.Time) Verdict {
r.LastDecidedAt = now
}
case ResultUnverified:
- if r.Reason != ReasonNotReached {
+ if r.Reason == ReasonNotReached || r.Reason == ReasonNoAssignment {
+ r.UnverifiedRuns = p.UnverifiedRuns // held: nothing was tried
+ } else {
r.UnverifiedRuns = p.UnverifiedRuns + 1
}
}
diff --git a/internal/dbverify/dbverify_test.go b/internal/dbverify/dbverify_test.go
index 671a2b6b7..2a2191f82 100644
--- a/internal/dbverify/dbverify_test.go
+++ b/internal/dbverify/dbverify_test.go
@@ -152,12 +152,37 @@ func TestMergeUnverifiedRuns(t *testing.T) {
if got := run(failed(idA, day)).UnverifiedRuns; got != 0 {
t.Fatalf("a failure left UnverifiedRuns = %d", got)
}
- run(unverified(idA, "moving", day))
- if got := run(unverified(idA, ReasonNotReached, day)).UnverifiedRuns; got != 0 {
- t.Fatalf("not_reached counted toward the streak: %d", got)
- }
- if got := run(unverified(idA, ReasonNotReached, day)).UnverifiedRuns; got != 0 {
- t.Fatalf("two not_reached runs counted: %d", got)
+}
+
+// A run that never reached the host (not_reached, or no_assignment on a
+// group box) learned nothing: it neither adds to the streak nor ends it.
+func TestMergeNotReachedHoldsTheStreak(t *testing.T) {
+ for _, reason := range []string{ReasonNotReached, ReasonNoAssignment} {
+ fleet := []string{"a.example.com"}
+ day := at("2026-08-01T03:00:00Z")
+ var rec *Record
+ run := func(v Verdict) int {
+ rec = Merge(rec, "box-a", day, fleet, map[string]Verdict{"a.example.com": v})
+ day = day.Add(24 * time.Hour)
+ return rec.Hosts["a.example.com"].UnverifiedRuns
+ }
+ run(unverified(idA, "record_changed", day))
+ run(unverified(idA, "record_changed", day))
+ if got := run(unverified(idA, reason, day)); got != 2 {
+ t.Fatalf("%s: UnverifiedRuns = %d, want the streak held at 2", reason, got)
+ }
+ if got := run(unverified(idA, "record_changed", day)); got != 3 {
+ t.Fatalf("%s: unverified, unverified, %s, unverified gave %d, want 3", reason, reason, got)
+ }
+ if got := run(unverified(idA, reason, day)); got != 3 {
+ t.Fatalf("%s: a second hold gave %d, want 3", reason, got)
+ }
+ if got := run(passed(idA, day)); got != 0 {
+ t.Fatalf("%s: a pass left %d", reason, got)
+ }
+ if got := run(unverified(idA, reason, day)); got != 0 {
+ t.Fatalf("%s: a hold after a pass gave %d, want 0", reason, got)
+ }
}
}
@@ -234,6 +259,10 @@ func TestMergeUnknownIdentityIsNotAChange(t *testing.T) {
t.Fatalf("an unknown identity reset the host: %+v", v)
}
+ if v.Identity != idA {
+ t.Fatalf("identity after A, unknown, A: %+v", v.Identity)
+ }
+
placeholder := Merge(nil, "box-a", first, fleet, nil)
v = Merge(placeholder, "box-a", n1, fleet, map[string]Verdict{"a.example.com": unverified(idA, "nothing_replicated", n1)}).Hosts["a.example.com"]
if !v.FirstSeen.Equal(first) || v.UnverifiedRuns != 1 {
@@ -503,3 +532,22 @@ func (r releaseStoreFunc) Put(ctx context.Context, key string, body []byte, ifMa
}
return r.Store.Put(ctx, key, body, ifMatch)
}
+
+// An unknown identity carries the last known one forward, so a later
+// verdict about a different incarnation is still recognised as one: A
+// passes, a night cannot capture, then B appears. B starts over.
+func TestMergeUnknownIdentityKeepsTheLastKnown(t *testing.T) {
+ fleet := []string{"a.example.com"}
+ first := at("2026-08-01T03:00:00Z")
+ rec := Merge(nil, "box-a", first, fleet, map[string]Verdict{"a.example.com": passed(idA, first)})
+ n1 := first.Add(24 * time.Hour)
+ rec = Merge(rec, "box-a", n1, fleet, map[string]Verdict{"a.example.com": unverified(Identity{}, "moving", n1)})
+ if v := rec.Hosts["a.example.com"]; v.Identity != idA || v.UnverifiedRuns != 1 || !v.LastDecidedAt.Equal(first) {
+ t.Fatalf("the unknown night lost A: %+v", v)
+ }
+ n2 := first.Add(48 * time.Hour)
+ v := Merge(rec, "box-a", n2, fleet, map[string]Verdict{"a.example.com": unverified(idB, "nothing_replicated", n2)}).Hosts["a.example.com"]
+ if v.Identity != idB || !v.FirstSeen.Equal(n2) || !v.LastDecidedAt.IsZero() || v.UnverifiedRuns != 1 {
+ t.Fatalf("A, unknown, B kept A's history for B: %+v", v)
+ }
+}