carlos / platform Public

fix: drill counts stop drops from the prompt, reads last fleet table

Task 5 fix round 3, after the round 2 re-review (W1, W2).

W1: the disruption window opens when the operator is prompted to stop
box B, so a drop the stop causes before the operator confirms counts.
Survivor reads, heartbeats and the observation window still measure
from the confirmation.

W2: tip() reads the last complete BOX STATE VERSION table of carlos
fleets show, which prints a new snapshot while an operation is open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d848a6099aec0614cfac17b30b43cb6fb077d9de parent 7407740
2 files changed, +80 −22
  • scripts/stateless-replicas-drill/accounting_test.go +35 −0
  • scripts/stateless-replicas-drill/main.go +45 −22

CI failed — run details

Intent

Human

<task-notification> <task-id>br41gw0px</task-id> <tool-use-id>toolu_01Y7zZLsZJGKwUTRszsj2nWd</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/br41gw0px.output</output-file> <status>completed</status> <summary>Background command "Astra re-review of T5 round 2" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 49.1 g CO₂e (6,298,002 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-replicas-4, 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/scripts/stateless-replicas-drill/accounting_test.go b/scripts/stateless-replicas-drill/accounting_test.go
index 8baf67dfc..871d5e2eb 100644
--- a/scripts/stateless-replicas-drill/accounting_test.go
+++ b/scripts/stateless-replicas-drill/accounting_test.go
@@ -436,6 +436,20 @@ func TestReplicaDrillSocketEvidence(t *testing.T) {
}
})
}
+ // W1 (controller ruling, round 3): the disruption window opens at the
+ // stop prompt, not at the operator's confirmation. Prompt at T5, the
+ // box stops and the socket drops at T10, reconnects at T12, the
+ // operator presses Enter at T15: a real recovery, and it passes. A
+ // drop before the prompt still does not count.
+ prompt := at(5)
+ reviewer := socketResult{Pinned: "b", Conns: []socketConn{conn("b", 0, 10), conn("a", 12, -1)}}
+ if why := reviewer.verdict(cfg, prompt); why != "" {
+ t.Fatalf("stop at T10, reconnect at T12, Enter at T15: %s", why)
+ }
+ early := socketResult{Pinned: "b", Conns: []socketConn{conn("b", 0, 3), conn("a", 4, -1)}}
+ if why := early.verdict(cfg, prompt); why == "" {
+ t.Fatal("a drop before the stop prompt counted")
+ }
// N3: an upgrade naming no drill box is a failed dial.
for _, named := range []string{"a", "", "c"} {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -480,6 +494,27 @@ func TestReplicaDrillFleetVersions(t *testing.T) {
if v["box-a"] != "v0.35.0" || v["box-b"] != "unknown" || len(v) != 2 {
t.Fatalf("versions %v from\n%s", v, out.String())
}
+ // W2: while an operation is open the CLI prints successive snapshots;
+ // the last complete table decides.
+ var follow strings.Builder
+ snapshot := func(a, b string) {
+ follow.WriteString("pi\nOperation op-1: open\n")
+ tw := tabwriter.NewWriter(&follow, 0, 4, 2, ' ', 0)
+ fmt.Fprintln(tw, "BOX\tSTATE\tVERSION\tLAST ERROR")
+ fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", "box-a", "active", a, "")
+ fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", "box-b", "active", b, "")
+ tw.Flush()
+ fmt.Fprintf(&follow, " %s %s: %s %s\n", "box-a", "version", "pass", "")
+ }
+ snapshot("v0.34.46", "v0.34.46")
+ snapshot("v0.35.0", "unknown")
+ if v := fleetVersions(follow.String()); v["box-a"] != "v0.35.0" || v["box-b"] != "unknown" {
+ t.Fatalf("an obsolete snapshot decided: %v", v)
+ }
+ follow.WriteString("BOX STATE VERSION LAST ERROR\n")
+ if v := fleetVersions(follow.String()); v["box-a"] != "v0.35.0" {
+ t.Fatalf("a trailing header with no rows replaced the last table: %v", v)
+ }
if got := fleetVersions("box-a version: pass\nbox-b version: pass\n"); len(got) != 0 {
t.Fatalf("lines outside the table read as versions: %v", got)
}
diff --git a/scripts/stateless-replicas-drill/main.go b/scripts/stateless-replicas-drill/main.go
index 6d9969567..d1d8f430a 100644
--- a/scripts/stateless-replicas-drill/main.go
+++ b/scripts/stateless-replicas-drill/main.go
@@ -240,9 +240,14 @@ func (d *drill) run(ctx context.Context, report *drillReport) error {
for _, box := range []string{cfg.BoxA, cfg.BoxB} {
sockets[box] = d.watchSocket(ctx, box)
}
- var stopAt time.Time
+ // promptAt opens the disruption window: the operator may stop the box
+ // as soon as they are asked, before confirming. stopAt is the
+ // confirmation, the end of the action: survivor reads, heartbeats and
+ // the observation window measure from it (controller ruling, round 3).
+ var promptAt, stopAt time.Time
view := make(chan error, 1)
err = d.loadAround(ctx, phaseStop, stopObserve, func() error {
+ promptAt = time.Now()
if err := d.operator(ctx, "hard-stop %s now through the approved operator action, then press enter", cfg.BoxB); err != nil {
return err
}
@@ -267,7 +272,7 @@ func (d *drill) run(ctx context.Context, report *drillReport) error {
res := sockets[box].stop()
d.note("websocket pinned to %s: %+v", box, res)
report.MaxReconnect = max(report.MaxReconnect, res.longest())
- if why := res.verdict(cfg, stopAt); why != "" {
+ if why := res.verdict(cfg, promptAt); why != "" {
d.fail("websocket pinned to %s: %s", box, why)
}
}
@@ -450,27 +455,44 @@ func (d *drill) tip(ctx context.Context) (string, error) {
return a, nil
}
-// fleetVersions reads the BOX STATE VERSION table of carlos fleets show:
-// the rows under that header, up to the end of the table (a blank line or
-// an indented line, such as a box's check results, " <box> <key>: ..."),
-// as box to version. Nothing outside the table is read.
+// fleetVersions reads the last complete BOX STATE VERSION table of carlos
+// fleets show, as box to version. While a managed operation is open the
+// CLI prints a new snapshot each time the fleet changes, so earlier tables
+// are obsolete. A table is its rows under that header, up to a blank or
+// indented line (a box's check results, " <box> <key>: ...") or the end
+// of the output; a header with no rows is no table. Nothing outside a
+// table is read.
func fleetVersions(out string) map[string]string {
- versions := map[string]string{}
- in := false
+ var last, cur map[string]string
+ end := func() {
+ if len(cur) > 0 {
+ last = cur
+ }
+ cur = nil
+ }
for _, line := range strings.Split(out, "\n") {
f := strings.Fields(line)
- if !in {
- in = len(f) >= 3 && f[0] == "BOX" && f[1] == "STATE" && f[2] == "VERSION"
+ if len(f) >= 3 && f[0] == "BOX" && f[1] == "STATE" && f[2] == "VERSION" {
+ end()
+ cur = map[string]string{}
+ continue
+ }
+ if cur == nil {
continue
}
if len(f) == 0 || line[0] == ' ' || line[0] == '\t' {
- break
+ end()
+ continue
}
if len(f) >= 3 {
- versions[f[0]] = f[2]
+ cur[f[0]] = f[2]
}
}
- return versions
+ end()
+ if last == nil {
+ last = map[string]string{}
+ }
+ return last
}
// argv is a carlos command line: the command, its flags, the drill's
@@ -768,12 +790,13 @@ type socketResult struct {
const reconnectBound = time.Minute
// stopReconnect is the reconnect that exercised the stop: a connection on
-// stopped that dropped at or after stopAt, followed by the next
-// connection, on survivor, within reconnectBound. It returns that gap.
-func (r socketResult) stopReconnect(stopped, survivor string, stopAt time.Time) (time.Duration, bool) {
+// stopped that dropped at or after since (the moment the operator was
+// prompted to stop the box), followed by the next connection, on
+// survivor, within reconnectBound. It returns that gap.
+func (r socketResult) stopReconnect(stopped, survivor string, since time.Time) (time.Duration, bool) {
for i := 0; i+1 < len(r.Conns); i++ {
c, next := r.Conns[i], r.Conns[i+1]
- if c.Box != stopped || c.Dropped.IsZero() || c.Dropped.Before(stopAt) || next.Box != survivor {
+ if c.Box != stopped || c.Dropped.IsZero() || c.Dropped.Before(since) || next.Box != survivor {
continue
}
if gap := next.Connected.Sub(c.Dropped); gap <= reconnectBound {
@@ -796,9 +819,9 @@ func (r socketResult) longest() time.Duration {
// verdict is why the watch fails, or "": it never reached its pinned box,
// or its last connection dropped and never came back, or, for the socket
-// pinned to the stopped box, no drop after stopAt was followed by a
-// reconnect to the survivor within reconnectBound.
-func (r socketResult) verdict(cfg drillConfig, stopAt time.Time) string {
+// pinned to the stopped box, no drop at or after since (the stop prompt)
+// was followed by a reconnect to the survivor within reconnectBound.
+func (r socketResult) verdict(cfg drillConfig, since time.Time) string {
switch {
case len(r.Conns) == 0 || r.Conns[0].Box != r.Pinned:
return "never connected to its box: " + r.Err
@@ -806,8 +829,8 @@ func (r socketResult) verdict(cfg drillConfig, stopAt time.Time) string {
return "dropped and never reconnected: " + r.Err
}
if r.Pinned == cfg.BoxB {
- if _, ok := r.stopReconnect(cfg.BoxB, cfg.BoxA, stopAt); !ok {
- return fmt.Sprintf("no drop on %s after the stop was followed by a reconnect to %s within %s", cfg.BoxB, cfg.BoxA, reconnectBound)
+ if _, ok := r.stopReconnect(cfg.BoxB, cfg.BoxA, since); !ok {
+ return fmt.Sprintf("no drop on %s after the stop prompt was followed by a reconnect to %s within %s", cfg.BoxB, cfg.BoxA, reconnectBound)
}
}
return ""