carlos / platform Public

config door: report where a write lands, bucket by bucket

The config door's restart answer gains the shared classifier's buckets
(self, yours, starting, unseen), additive and omitted when empty; the
legacy fields still come from WriteReach.Pending via restartWire. The
console gains reachFacts (provision records plus box reports joined
through remoteFacts) and classifyConfigWrite for the Save handler.

The CLI prints the buckets in place of the legacy hosts lines when a
console sends them, and an older console's answer exactly as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9b644546ed2dc05448b463059187e1592f106e9a parent 87660b1
6 files changed, +404 −15
  • apimode.go +17 −0
  • appconfig_cli.go +54 −1
  • appconfig_cli_test.go +106 −0
  • internal/console/apiconfig.go +41 −14
  • internal/console/apiconfigrestart_test.go +110 −0
  • internal/console/configreach.go +76 −0

Intent

Human

<task-notification> <task-id>addaddeb7f77aa259</task-id> <tool-use-id>toolu_01RQ8a4d7MwTmhrBvb5YUN86</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/addaddeb7f77aa259.output</output-file> <status>completed</status> <summary>Agent "Implement Task 4 shared validation" 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>Both Astra findings are fixed in commit 87660b1a. - **P1:** `writeConfig` now takes the raw input (`in map[string]configVarIn`) and validates it itself, so only checked vars reach the key check and the store. I didn't edit `apiconfig.go`: the JSON door never called `writeConfig`, because of its team path. It still runs its own early `checkConfigSets` and passes those vars to the store step, so its refusal order is unchanged. - **P1 tests:** new `TestWriteConfigValidatesItsInput` covers the four cases you named, with `want` nil and set. Each case asserts nothing was written to the bundle or the generation object. A writer that skips validation fails it. - **P2:** the default-bundle check in `teamcreds_test.go` now rejects `ApplyAtVersion` too. A temporary named-environment call in each of `apimail.go`, `scankeysync.go` and `apiscan.go` failed the guard, and each was reverted. - **Tests:** the `ConfigPut|APIConfig|CheckConfigSets|WriteConfig|ApplyCallers` run passes (20.8s); vet and gofmt are clean. Fix report appended to `task-4-report.md`.</result> <usage><subagent_tokens>145601</subagent_tokens><tool_uses>11</tool_uses><duration_ms>285809</duration_ms></usage> </task-notification>

Attributed to this commit: 7.21 g CO₂e (835,752 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-console-secrets, 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/apimode.go b/apimode.go
index 15b8e0e09..e6ba404e7 100644
--- a/apimode.go
+++ b/apimode.go
@@ -3058,6 +3058,23 @@ type apiConfigRestart struct {
// sends neither and this binary prints nothing for them.
Undelivered []string `json:"undelivered,omitempty"`
Blocked []apiConfigBlockedHost `json:"blocked,omitempty"`
+ // Self, Yours, Starting and Unseen are the console's classifier
+ // buckets, additive: an older console sends none of them, and this
+ // binary then prints Hosts exactly as before. When any is present they
+ // are printed instead of Hosts (Hosts ⊆ Yours).
+ Self []apiConfigReachHost `json:"self,omitempty"`
+ Yours []apiConfigReachHost `json:"yours,omitempty"`
+ Starting []apiConfigReachHost `json:"starting,omitempty"`
+ Unseen []string `json:"unseen,omitempty"`
+}
+
+// apiConfigReachHost is one route in a bucket: How on Yours ("addr",
+// "sidecar"), Why on Starting ("asleep", "not-running"). A value this
+// binary does not know gets the bucket's general sentence.
+type apiConfigReachHost struct {
+ Host string `json:"host"`
+ How string `json:"how,omitempty"`
+ Why string `json:"why,omitempty"`
}
// apiConfigBlockedHost is a stamped route the root pass will refuse, with
diff --git a/appconfig_cli.go b/appconfig_cli.go
index 6b4683225..398262904 100644
--- a/appconfig_cli.go
+++ b/appconfig_cli.go
@@ -42,6 +42,16 @@ import (
type restartAnswer struct {
known bool
pending appconfig.RestartPending
+ // The console's classifier buckets, when it sent any (restartFromAPI).
+ // Direct mode leaves them empty and prints the legacy notice.
+ self, yours, starting []apiConfigReachHost
+ unseen []string
+}
+
+// buckets reports whether the answer carries the classifier's buckets, in
+// which case they are printed in place of pending.Hosts.
+func (a *restartAnswer) buckets() bool {
+ return len(a.self) > 0 || len(a.yours) > 0 || len(a.starting) > 0 || len(a.unseen) > 0
}
// restartFromAPI converts the console's answer, preserving the nil case.
@@ -58,6 +68,7 @@ func restartFromAPI(r *apiConfigRestart) *restartAnswer {
for _, b := range r.Blocked {
out.pending.Blocked = append(out.pending.Blocked, appconfig.BlockedHost{Host: b.Host, Reason: b.Reason})
}
+ out.self, out.yours, out.starting, out.unseen = r.Self, r.Yours, r.Starting, r.Unseen
return out
}
@@ -109,10 +120,45 @@ func printRestartNotice(w io.Writer, app string, a *restartAnswer) {
fmt.Fprintf(w, "%s %s\n", c.warn("note:"), restartCopyUnknown)
return
}
- if a.pending.Empty() {
+ if a.pending.Empty() && !a.buckets() {
return
}
+ // A console that sent buckets has said everything Hosts says, and more
+ // precisely, so Hosts is not printed again. A legacy host no bucket
+ // names (a route the classifier sent elsewhere, such as an addr route
+ // whose config file name collides) is still printed the old way, so a
+ // newer console never makes a host vanish from the notice.
+ named := map[string]bool{}
+ if a.buckets() {
+ for _, h := range a.self {
+ named[h.Host] = true
+ fmt.Fprintf(w, "%s %s\n", c.warn("note:"), fmt.Sprintf(restartCopySelf, h.Host))
+ }
+ for _, h := range a.yours {
+ named[h.Host] = true
+ line := fmt.Sprintf(restartCopyPlain, h.Host)
+ if h.How == string(appconfig.ReachHowSidecar) {
+ line = fmt.Sprintf(restartCopyYoursSidecar, h.Host)
+ }
+ fmt.Fprintf(w, "%s %s\n", c.warn("note:"), line)
+ }
+ for _, h := range a.starting {
+ named[h.Host] = true
+ line := fmt.Sprintf(restartCopyStarting, h.Host)
+ if h.Why == string(appconfig.ReachWhyAsleep) {
+ line = fmt.Sprintf(restartCopyAsleep, h.Host)
+ }
+ fmt.Fprintf(w, "%s %s\n", c.warn("note:"), line)
+ }
+ for _, h := range a.unseen {
+ named[h] = true
+ fmt.Fprintf(w, "%s %s\n", c.warn("note:"), fmt.Sprintf(restartCopyUnseen, h))
+ }
+ }
for _, h := range a.pending.Hosts {
+ if named[h.Host] {
+ continue
+ }
line := fmt.Sprintf(restartCopyPlain, h.Host)
if h.Unit != "" {
line = fmt.Sprintf(restartCopyUnit, h.Host, app, h.Unit)
@@ -171,6 +217,13 @@ const (
restartCopyScope = "(this machine's routes only)"
restartCopyUndelivered = "this write did not reach %s. No pass delivers config to it. If a systemd unit runs its process, name it on the box (carlos route --unit); if the app's own supervisor reads a delivered file, opt the bundle in (carlos env exec-delivery --app %s file)."
restartCopyBlocked = "delivery to %s is blocked: %s"
+ // The classifier's buckets, from a console that sends them. Not yet
+ // through a copy pass.
+ restartCopySelf = "%s gets the new values. carlos restarts it."
+ restartCopyYoursSidecar = "%s has the file, but nothing on its box restarts it. Check that it is running the new values."
+ restartCopyAsleep = "%s is asleep. It picks up the new values when it wakes."
+ restartCopyStarting = "%s is not running. It picks up the new values when it starts."
+ restartCopyUnseen = "could not tell whether %s picked this up. It is not on this machine."
)
const envUsage = `usage: carlos env <command>
diff --git a/appconfig_cli_test.go b/appconfig_cli_test.go
new file mode 100644
index 000000000..e5300cf14
--- /dev/null
+++ b/appconfig_cli_test.go
@@ -0,0 +1,106 @@
+package main
+
+// printRestartNotice against the console's classifier buckets: additive,
+// so an older console's answer prints exactly what it always printed, and a
+// newer one's buckets replace the legacy hosts lines rather than repeat
+// them. printRestartNotice is a pure writer, so these call it directly.
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+)
+
+// TestRestartNoticeOldConsoleUnchanged pins today's output byte for byte
+// for an answer with only the legacy fields.
+func TestRestartNoticeOldConsoleUnchanged(t *testing.T) {
+ var b bytes.Buffer
+ printRestartNotice(&b, "relay", restartFromAPI(&apiConfigRestart{Known: true,
+ Hosts: []apiConfigRestartHost{
+ {Host: "addr.shop.example.com"},
+ {Host: "unit.shop.example.com", Unit: "shop.service"},
+ },
+ Unresolved: []string{"bad.shop.example.com"},
+ Undelivered: []string{"plain.shop.example.com"},
+ Blocked: []apiConfigBlockedHost{{Host: "stamp.shop.example.com", Reason: "socket"}},
+ }))
+ want := "note: addr.shop.example.com has the file but is still running the old values. carlos routes to this process without owning it. Restart to fix.\n" +
+ "note: unit.shop.example.com has the file but is still running the old values. carlos restart --app relay cycles shop.service.\n" +
+ "note: could not tell whether bad.shop.example.com picked this up. Its config bundle would not load.\n" +
+ "note: this write did not reach plain.shop.example.com. No pass delivers config to it. If a systemd unit runs its process, name it on the box (carlos route --unit); if the app's own supervisor reads a delivered file, opt the bundle in (carlos env exec-delivery --app relay file).\n" +
+ "note: delivery to stamp.shop.example.com is blocked: socket\n" +
+ "(this machine's routes only)\n"
+ if got := b.String(); got != want {
+ t.Fatalf("legacy notice changed:\ngot:\n%s\nwant:\n%s", got, want)
+ }
+}
+
+// TestRestartNoticeNewBuckets: each bucket's host is printed once, in
+// bucket order (self, yours, starting, unseen); a legacy host a bucket
+// already names is not printed again, and one no bucket names still is.
+func TestRestartNoticeNewBuckets(t *testing.T) {
+ var b bytes.Buffer
+ printRestartNotice(&b, "relay", restartFromAPI(&apiConfigRestart{Known: true,
+ Hosts: []apiConfigRestartHost{{Host: "addr.shop.example.com"}, {Host: "stray.shop.example.com"}},
+ Self: []apiConfigReachHost{{Host: "sock.shop.example.com"}},
+ Yours: []apiConfigReachHost{
+ {Host: "addr.shop.example.com", How: "addr"},
+ {Host: "worker.shop.example.com", How: "sidecar"},
+ },
+ Starting: []apiConfigReachHost{
+ {Host: "nap.shop.example.com", Why: "asleep"},
+ {Host: "boot.shop.example.com", Why: "not-running"},
+ },
+ Unseen: []string{"remote.shop.example.com"},
+ Undelivered: []string{"plain.shop.example.com"},
+ }))
+ got := b.String()
+ order := []string{
+ "sock.shop.example.com gets the new values",
+ "addr.shop.example.com has the file but is still running the old values",
+ "worker.shop.example.com has the file, but nothing on its box restarts it",
+ "nap.shop.example.com is asleep",
+ "boot.shop.example.com is not running",
+ "could not tell whether remote.shop.example.com picked this up. It is not on this machine.",
+ "stray.shop.example.com has the file",
+ "did not reach plain.shop.example.com",
+ restartCopyScope,
+ }
+ at := -1
+ for _, want := range order {
+ i := strings.Index(got, want)
+ if i < 0 {
+ t.Fatalf("output lacks %q:\n%s", want, got)
+ }
+ if i < at {
+ t.Fatalf("%q is out of order:\n%s", want, got)
+ }
+ at = i
+ }
+ for _, h := range []string{"sock", "addr", "worker", "nap", "boot", "remote", "stray", "plain"} {
+ if n := strings.Count(got, h+".shop.example.com"); n != 1 {
+ t.Errorf("%s named %d times, want once:\n%s", h, n, got)
+ }
+ }
+ if n := strings.Count(got, "\n"); n != len(order) {
+ t.Errorf("output has %d lines, want %d:\n%s", n, len(order), got)
+ }
+ for _, dash := range []string{"\u2014", "\u2013"} {
+ for _, s := range []string{restartCopySelf, restartCopyYoursSidecar, restartCopyAsleep, restartCopyStarting, restartCopyUnseen} {
+ if strings.Contains(s, dash) {
+ t.Errorf("copy %q carries a dash", s)
+ }
+ }
+ }
+}
+
+// A bucket-only answer (nothing in the legacy fields) still speaks: a
+// socket route that delivery restarts is news worth a line.
+func TestRestartNoticeBucketsAloneAreNotEmpty(t *testing.T) {
+ var b bytes.Buffer
+ printRestartNotice(&b, "relay", restartFromAPI(&apiConfigRestart{Known: true,
+ Self: []apiConfigReachHost{{Host: "sock.shop.example.com"}}}))
+ if !strings.Contains(b.String(), "sock.shop.example.com") {
+ t.Fatalf("bucket-only answer printed %q", b.String())
+ }
+}
diff --git a/internal/console/apiconfig.go b/internal/console/apiconfig.go
index 41f5b10cd..cdae6687b 100644
--- a/internal/console/apiconfig.go
+++ b/internal/console/apiconfig.go
@@ -551,6 +551,26 @@ type apiConfigRestart struct {
// Both omitted when empty so an older CLI sees exactly what it saw.
Undelivered []string `json:"undelivered,omitempty"`
Blocked []apiConfigBlockedHost `json:"blocked,omitempty"`
+
+ // The shared classifier's buckets (appconfig.ClassifyWrite), additive
+ // and omitted when empty, so an older CLI sees exactly what it saw and
+ // a newer one prints these in place of Hosts (Hosts ⊆ Yours). Self:
+ // delivery restarts it. Yours: the file lands, nothing here restarts
+ // it (How says how to). Starting: it picks the write up when it starts
+ // (Why says why it is not running). Unseen: a provision record with no
+ // route in this box's registry, so this box cannot say.
+ Self []apiConfigReachHost `json:"self,omitempty"`
+ Yours []apiConfigReachHost `json:"yours,omitempty"`
+ Starting []apiConfigReachHost `json:"starting,omitempty"`
+ Unseen []string `json:"unseen,omitempty"`
+}
+
+// apiConfigReachHost is one route in a bucket. How is set on Yours ("addr",
+// "sidecar"), Why on Starting ("asleep", "not-running").
+type apiConfigReachHost struct {
+ Host string `json:"host"`
+ How string `json:"how,omitempty"`
+ Why string `json:"why,omitempty"`
}
type apiConfigRestartHost struct {
@@ -574,23 +594,30 @@ type apiConfigBlockedHost struct {
// fleetapi (#145) is the eventual fix. The CLI says what it looked at
// rather than letting a short list read as a complete one.
func (s *Server) configRestartNotice(ctx context.Context, acct, app, envName string, keys []string) apiConfigRestart {
- if s.cfg.Registry == "" {
- // Opening "" would hand sqlite a throwaway temp DB and answer
- // "no routes" having created a file to say it — handleAPIRoutes'
- // twin guard, and the same reasoning.
- return apiConfigRestart{}
- }
- reg, err := openRegistry(s.cfg.Registry)
- if err != nil {
- log.Printf("console: api config: registry %s: %v", s.cfg.Registry, err)
+ r, ok := s.classifyConfigWrite(ctx, acct, app, envName, keys)
+ if !ok {
return apiConfigRestart{}
}
- routes, err := reg.List()
- if err != nil {
- log.Printf("console: api config: registry list: %v", err)
- return apiConfigRestart{}
+ return reachWire(r)
+}
+
+// reachWire is the wire shape of one WriteReach: the legacy fields from its
+// Pending projection (restartWire, unchanged), then the buckets. Pure.
+func reachWire(r appconfig.WriteReach) apiConfigRestart {
+ out := restartWire(r.Pending())
+ out.Self = reachHostsWire(r.Self)
+ out.Yours = reachHostsWire(r.Yours)
+ out.Starting = reachHostsWire(r.Starting)
+ out.Unseen = r.Unseen
+ return out
+}
+
+func reachHostsWire(l []appconfig.ReachHost) []apiConfigReachHost {
+ var out []apiConfigReachHost
+ for _, h := range l {
+ out = append(out, apiConfigReachHost{Host: h.Host, How: string(h.How), Why: string(h.Why)})
}
- return restartWire(appconfig.AwaitingRestart(ctx, s.cfg.Releases, routes, acct, app, envName, keys))
+ return out
}
// restartWire is the wire shape of one RestartPending, Known: this box
diff --git a/internal/console/apiconfigrestart_test.go b/internal/console/apiconfigrestart_test.go
index 4cd98f43b..394256603 100644
--- a/internal/console/apiconfigrestart_test.go
+++ b/internal/console/apiconfigrestart_test.go
@@ -8,12 +8,18 @@ package console
import (
"context"
+ "fmt"
"net/http"
+ "reflect"
"strings"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/appconfig"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
)
// restartOf pulls the `restart` object out of a config PUT's response.
@@ -206,3 +212,107 @@ func TestAPIConfigPutAcceptsOneByteSecret(t *testing.T) {
t.Fatal("stored envelope is not the one that was sent")
}
}
+
+// TestConfigPutRestartBuckets: the door's answer carries the shared
+// classifier's buckets beside the legacy fields. A socket route is
+// restarted by delivery (self); an opted-in addr route and a sidecar no
+// report says is managed are the operator's to restart (yours); a host
+// with a provision record and no route on this box is unseen. The legacy
+// hosts list says what it always said: the addr route only.
+func TestConfigPutRestartBuckets(t *testing.T) {
+ fx, token := configFixture(t, "code-restart-buckets")
+ ctx := context.Background()
+ reg, err := registry.Open(fx.regPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, rt := range []registry.Route{
+ {Host: "sock.shop.example.com", Kind: "instance", Status: "ready", App: "titogo", Account: "bab", Socket: "/run/carlos/sock.sock"},
+ {Host: "addr.shop.example.com", Kind: "instance", Status: "ready", App: "titogo", Account: "bab", Addr: "127.0.0.1:9001"},
+ {Host: "worker.shop.example.com", Kind: "sidecar", Status: "ready", App: "titogo", Account: "bab"},
+ } {
+ if err := reg.Upsert(rt); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := provision.CreateRecord(ctx, fx.rel, provision.Record{Schema: 1, Host: "remote.shop.example.com", Slug: "remote",
+ App: "titogo", Account: "bab", Channel: "stable", CreatedAt: time.Now().UTC(), CreatedBy: "paul@keymail.dev"}); err != nil {
+ t.Fatal(err)
+ }
+ optIn(t, fx, "titogo")
+
+ code, out := putJSON(t, configURL(fx, "titogo"), map[string]any{
+ "set": map[string]any{"LOG_LEVEL": map[string]any{"kind": "env", "value": "debug"}},
+ }, token)
+ if code != http.StatusOK {
+ t.Fatalf("PUT = %d %v", code, out)
+ }
+ r, ok := restartOf(t, out)
+ if !ok || r["known"] != true {
+ t.Fatalf("restart = %v, want a known answer", out["restart"])
+ }
+ bucket := func(name string) []string {
+ raw, _ := r[name].([]any)
+ var l []string
+ for _, e := range raw {
+ if s, ok := e.(string); ok {
+ l = append(l, s)
+ continue
+ }
+ m, _ := e.(map[string]any)
+ l = append(l, fmt.Sprintf("%v/%v%v", m["host"], m["how"], m["why"]))
+ }
+ return l
+ }
+ for name, want := range map[string][]string{
+ "self": {"sock.shop.example.com/<nil><nil>"},
+ "yours": {"addr.shop.example.com/addr<nil>", "worker.shop.example.com/sidecar<nil>"},
+ "unseen": {"remote.shop.example.com"},
+ } {
+ if got := bucket(name); !reflect.DeepEqual(got, want) {
+ t.Errorf("%s = %v, want %v", name, got, want)
+ }
+ }
+ if _, ok := r["starting"]; ok {
+ t.Errorf("starting = %v, want it omitted when empty", r["starting"])
+ }
+ if got := restartHosts(t, r); !reflect.DeepEqual(got, []string{"addr.shop.example.com"}) {
+ t.Errorf("legacy hosts = %v, want just the addr route", got)
+ }
+}
+
+// TestReachFactsFromRecordsAndReports: host facts come from a box report
+// joined to a record through remoteFacts. A managed entry that is not awake
+// is asleep; a managed awake one is not; a host no report names has no
+// fact at all (unknown), not a zero one asserted.
+func TestReachFactsFromRecordsAndReports(t *testing.T) {
+ fx, _ := configFixture(t, "code-reach-facts")
+ ctx := context.Background()
+ created := time.Now().UTC().Add(-time.Hour)
+ for _, h := range []string{"asleep.shop.example.com", "awake.shop.example.com", "silent.shop.example.com"} {
+ if err := provision.CreateRecord(ctx, fx.rel, provision.Record{Schema: 1, Host: h, Slug: strings.SplitN(h, ".", 2)[0],
+ App: "titogo", Account: "bab", Channel: "stable", Environment: "", CreatedAt: created, CreatedBy: "paul@keymail.dev"}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ box := status.CollectBox(nil, status.Probes{MachineID: "box1"}, time.Now())
+ box.Metrics = &status.BoxMetrics{Rollout: &status.RolloutReport{Hosts: map[string]status.HostRollout{
+ "asleep.shop.example.com": {Account: "bab", App: "titogo", Managed: true},
+ "awake.shop.example.com": {Account: "bab", App: "titogo", Managed: true, Awake: true},
+ }}}
+ if err := status.WriteBox(ctx, fx.rel, box); err != nil {
+ t.Fatal(err)
+ }
+
+ f := fx.srv.reachFacts(ctx, "bab", "titogo")
+ if !f.RecordsComplete || len(f.Records) != 3 {
+ t.Fatalf("records = %+v complete=%v, want all three, complete", f.Records, f.RecordsComplete)
+ }
+ want := map[string]appconfig.HostFact{
+ "asleep.shop.example.com": {Managed: true, Asleep: true},
+ "awake.shop.example.com": {Managed: true},
+ }
+ if !reflect.DeepEqual(f.Hosts, want) {
+ t.Fatalf("hosts = %+v, want %+v", f.Hosts, want)
+ }
+}
diff --git a/internal/console/configreach.go b/internal/console/configreach.go
new file mode 100644
index 000000000..a7f1b62ec
--- /dev/null
+++ b/internal/console/configreach.go
@@ -0,0 +1,76 @@
+package console
+
+import (
+ "context"
+ "log"
+
+ "github.com/carlosframework/platform/internal/appconfig"
+)
+
+// reachFacts gathers what the shared write classifier (appconfig.
+// ClassifyWrite) needs beyond this box's registry: the app's provision
+// records, fleet-wide, and what a qualifying box report says about each
+// record's host.
+//
+// Both sources may be short, and each says so in the only way the
+// classifier reads: a listing that failed or was truncated is
+// RecordsComplete false, and a host no report can be joined to has no
+// HostFact at all, which the classifier reads as unknown (never asleep,
+// never managed). Reports are joined through remoteFacts' one accessor
+// (TestRemoteFactsOneAccessor), so this answer and every page agree about
+// which report belongs to a host.
+func (s *Server) reachFacts(ctx context.Context, acct, app string) appconfig.ReachFacts {
+ facts := appconfig.ReachFacts{Hosts: map[string]appconfig.HostFact{}}
+ recs, truncated, err := s.listRecords(ctx, acct, app, instanceListMax)
+ if err != nil {
+ log.Printf("console: config reach %s/%s: records: %v", acct, app, err)
+ }
+ facts.RecordsComplete = err == nil && !truncated
+ if len(recs) == 0 {
+ return facts
+ }
+ remote := s.remoteFacts(ctx, acct, app)
+ for _, rec := range recs {
+ facts.Records = append(facts.Records, appconfig.ReachRecord{Host: rec.Host, Environment: rec.Environment})
+ rep := remote.host(rec)
+ if rep == nil {
+ continue
+ }
+ // Asleep only on a managed entry's word: an unmanaged process's
+ // awake bit is not a sleep claim, and a down or mid-transition
+ // host is not asleep either, it is something else.
+ facts.Hosts[rec.Host] = appconfig.HostFact{
+ Managed: rep.managed,
+ Asleep: rep.managed && !rep.awake && !rep.transient && !rep.down,
+ }
+ }
+ return facts
+}
+
+// classifyConfigWrite is ClassifyWrite for one write to acct/app's envName
+// bundle ("" = the default), over this box's registry and reachFacts. ok is
+// false when this console has not looked: no registry configured, or one
+// that will not open or list. A caller renders that as "could not tell",
+// never as an empty answer.
+//
+// SCOPE: the registry is this console's OWN box's; routes on other boxes
+// are not in it, which is what Unseen and the CLI's scope line are for.
+func (s *Server) classifyConfigWrite(ctx context.Context, acct, app, envName string, keys []string) (appconfig.WriteReach, bool) {
+ if s.cfg.Registry == "" {
+ // Opening "" would hand sqlite a throwaway temp DB and answer
+ // "no routes" having created a file to say it: handleAPIRoutes'
+ // twin guard, and the same reasoning.
+ return appconfig.WriteReach{}, false
+ }
+ reg, err := openRegistry(s.cfg.Registry)
+ if err != nil {
+ log.Printf("console: api config: registry %s: %v", s.cfg.Registry, err)
+ return appconfig.WriteReach{}, false
+ }
+ routes, err := reg.List()
+ if err != nil {
+ log.Printf("console: api config: registry list: %v", err)
+ return appconfig.WriteReach{}, false
+ }
+ return appconfig.ClassifyWrite(ctx, s.cfg.Releases, routes, s.reachFacts(ctx, acct, app), acct, app, envName, keys), true
+}