carlos / platform Public

console: backups fix round 1, setup deadline, keep rule, claims (#898)

A deadline spent while opening the replica client is too_large_to_plan,
like a listing deadline, not unavailable.

Only answers that read a position, and too_large_to_plan, are kept for
five minutes. nothing_replicated and unavailable are read again by the
next caller, so a new instance's first copy shows within a minute.

With host claims on, backupsFor answers unavailable without reading:
the hibernate prefix is not the copy db pull reads in claim mode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 477cdc56a9233a7343108b05e3504d785ee75add parent cf2ef5d
2 files changed, +56 −8
  • internal/console/backups.go +19 −8
  • internal/console/backups_test.go +37 −0

CI failed — run details

Intent

Human

<task-notification> <task-id>aac22fe9ea88305c0</task-id> <tool-use-id>toolu_013AAZyEWppfGGcv8gu1K4Cy</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/aac22fe9ea88305c0.output</output-file> <status>completed</status> <summary>Agent "Implement slice 1 Task 2" 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_WITH_CONCERNS. One deliberate change from the brief (concern 1). Commit: `cf2ef5d9` "console: backups classifier and bounded, memoised read (#898)", not pushed. Tests: all 7 new tests pass, plus the existing ResolveReplica, ResolveDBSource, APIDB, demo-move and forward tests (47 passed, MinIO test skipped); `-race` on the new tests passes; vet, gofmt and `go build ./...` are clean. Concerns: 1. `resolveReplica` calls `replicaPlacement` (the pool and fleet half that `replicaIntrinsic` ends with), not `replicaIntrinsic` itself. Calling `replicaIntrinsic` would change its errors: a pooled instance that doesn't sleep would no longer get ErrPooled. Three mixed-case golden rows pin this; the literal version fails them. 2. A `nothing_replicated` answer is cached for 5 minutes, but the planned copy says "Check back in a minute". Not caching it is a one-line change. 3. Claim mode is not handled: with `HostClaim` on, `backupsFor` would read the wrong place. Claims are shelved, so I left it. 4. `written_at` and `history_from` carry milliseconds; Task 3 may want whole seconds. `internal/console` is not part of the root binary, so no census work. Go commands ran with the sandbox off because the Go cache is read-only inside it. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups-1/.superpowers/sdd/2026-11-11-member-backups-slice1/task-2-report.md</result> <usage><subagent_tokens>140269</subagent_tokens><tool_uses>38</tool_uses><duration_ms>944702</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>br6gbtm7h</task-id> <tool-use-id>toolu_012W6aTKh8TmzFQhRN77evx1</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/br6gbtm7h.output</output-file> <status>completed</status> <summary>Background command "Ledger rulings; Astra review of Task 2" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 15.4 g CO₂e (1,928,798 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on member-backups-1, 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/console/backups.go b/internal/console/backups.go
index 6f45888a7..8a896796c 100644
--- a/internal/console/backups.go
+++ b/internal/console/backups.go
@@ -133,9 +133,10 @@ type backupsPosition struct {
// backupsFor is what the console knows about rec's copy. A record the
// classifier does not admit is answered from the record alone, and the
-// bucket is never touched. An admitted one is read once per host per
-// backupsMemoTTL (s.backups): one PositionAndHistory over at most
-// backupsMaxFiles files within backupsDeadline.
+// bucket is never touched. An admitted one is read through s.backups: one
+// PositionAndHistory over at most backupsMaxFiles files within
+// backupsDeadline, one read in flight per host, and a position or a
+// too-large answer kept for backupsMemoTTL (readBackups says which).
func (s *Server) backupsFor(ctx context.Context, rec provision.Record) backupsView {
var v backupsView
class, reason := classifyBackups(rec, s.cfg.Region)
@@ -158,11 +159,17 @@ func (s *Server) backupsFor(ctx context.Context, rec provision.Record) backupsVi
return v
}
-// readBackups is one read of rec's copy. keep is false for a read that
-// failed rather than answered, so the next caller tries again.
+// readBackups is one read of rec's copy. keep is true only for an answer
+// that is a fact about the copy for the next five minutes: a position read,
+// or a copy too large to plan. Nothing replicated yet (a new instance's
+// first copy is a minute away) and a failed read are asked again by the
+// next caller.
func (s *Server) readBackups(ctx context.Context, rec provision.Record) (v backupsView, keep bool) {
notShown := func(reason string) backupsView { return backupsView{Class: backupNotShown, Reason: reason} }
- if s.cfg.HibernateBucket == "" || s.dbReplica == nil {
+ // With host claims on, db pull reads the claim holder's copy, not the
+ // hibernate prefix, so reading the prefix here could show the wrong
+ // copy. Claims are shelved; answer unavailable rather than resolve one.
+ if s.cfg.HostClaim || s.cfg.HibernateBucket == "" || s.dbReplica == nil {
return notShown(backupReasonUnavailable), false
}
prefix, err := s.resolveReplica(rec, rec.Host)
@@ -171,14 +178,18 @@ func (s *Server) readBackups(ctx context.Context, rec provision.Record) (v backu
return notShown(backupReasonUnavailable), false
}
rd, err := s.dbReplica(ctx, prefix)
- if err != nil {
+ switch {
+ case errors.Is(err, context.DeadlineExceeded):
+ // The deadline is the read's whole budget, setup included.
+ return notShown(backupReasonTooLarge), true
+ case err != nil:
log.Printf("console: backups %s: replica client: %v", rec.Host, err)
return notShown(backupReasonUnavailable), false
}
plan, from, known, err := dbdoor.PositionAndHistory(ctx, rd, backupsMaxFiles)
switch {
case errors.Is(err, dbdoor.ErrNothingReplicated):
- return notShown(backupReasonNothing), true
+ return notShown(backupReasonNothing), false
case errors.Is(err, dbdoor.ErrTooManyFiles), errors.Is(err, context.DeadlineExceeded):
return notShown(backupReasonTooLarge), true
case err != nil:
diff --git a/internal/console/backups_test.go b/internal/console/backups_test.go
index ab9ac6d2f..c3f55423a 100644
--- a/internal/console/backups_test.go
+++ b/internal/console/backups_test.go
@@ -281,6 +281,28 @@ func TestBackupsForNothingReplicated(t *testing.T) {
if fx.opens.Load() != 1 {
t.Fatalf("dbReplica opened %d times, want 1", fx.opens.Load())
}
+ // Not kept: a new instance's first copy is a minute away, so the next
+ // call within five minutes reads again.
+ v = fx.srv.backupsFor(t.Context(), provision.Record{Host: dbTestHost, Region: fx.srv.cfg.Region, Hibernate: backupsYes()})
+ if v.Reason != "nothing_replicated" || fx.opens.Load() != 2 {
+ t.Fatalf("second call = %+v after %d opens, want nothing_replicated read again (2)", v, fx.opens.Load())
+ }
+}
+
+// With host claims on, the hibernate prefix is not the copy db pull reads,
+// so the door does not read it.
+func TestBackupsForHostClaimReadsNothing(t *testing.T) {
+ fx := dbFixture(t)
+ fx.replicate(t, dbTestHost, 1)
+ fx.srv.cfg.HostClaim = true
+ fx.srv.dbReplica = func(context.Context, string) (replicaReader, error) {
+ t.Error("dbReplica called with host claims on")
+ return nil, errors.New("no")
+ }
+ v := fx.srv.backupsFor(t.Context(), provision.Record{Host: dbTestHost, Region: fx.srv.cfg.Region, Hibernate: backupsYes()})
+ if v.Class != backupNotShown || v.Reason != "unavailable" || v.CopiedTo != nil {
+ t.Fatalf("view = %+v, want not_shown/unavailable", v)
+ }
}
// listedReplica lists n level-0 files, transactions 1..n one each, and
@@ -392,6 +414,21 @@ func TestBackupsForBounds(t *testing.T) {
}
})
+ t.Run("deadline during replica setup", func(t *testing.T) {
+ fx := dbFixture(t)
+ fx.srv.backups.deadline = 50 * time.Millisecond
+ opens := new(atomic.Int32)
+ fx.srv.dbReplica = func(ctx context.Context, _ string) (replicaReader, error) {
+ opens.Add(1)
+ <-ctx.Done()
+ return nil, ctx.Err()
+ }
+ v := fx.srv.backupsFor(t.Context(), rec("setup"))
+ if v.Class != backupNotShown || v.Reason != "too_large_to_plan" {
+ t.Fatalf("setup past the deadline = %+v, want not_shown/too_large_to_plan", v)
+ }
+ })
+
t.Run("one read per host, memoised", func(t *testing.T) {
fx := dbFixture(t)
now := at