console: env Save treats a bundle read failing in the write as unread
Astra R3 P2-1: a read failure inside ApplyAtVersion is now its own refusal code (configRefusalRead; JSON door unchanged), and the form door shows the section unavailable with nothing drawn back.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/configwrite.go+37 −5internal/console/envcopy.go+1 −0internal/console/envformgate_test.go+43 −0internal/console/envsave.go+9 −0
CI failed — run details
Intent
<task-notification> <task-id>ac8b7cbdf42d58772</task-id> <tool-use-id>toolu_01ViYhcdSDaATw1iHSFVZ4pk</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/ac8b7cbdf42d58772.output</output-file> <status>completed</status> <summary>Agent "Fix round 2: refuse on read failure" 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. Under the refuse-up-front ruling, if any bundle read fails during a form post (default bundle, listing or any named bundle), the post is refused (409): nothing is written and nothing submitted comes back in the page. The envCarry path and its template branch are gone. envClassify now checks every non-empty env.*, newenv.* and addenv.* with CheckEnvelope, and keeps the fp.* pairing. Commit: 3eaf36e5 `console: env form refuses up front when any bundle read fails`. The fix report is appended to `.superpowers/sdd/2026-11-08-console-secrets/task-8-report.md` but not committed, because `.superpowers` is gitignored and no file in that folder is tracked. Tests: removed TestEnvSaveReadRefusalKeepsDraft. Added TestEnvFormUnreadDefaultRefusesAndEchoesNothing, TestEnvFormMalformedEnvelopeRefused (storage healthy) and TestEnvFormUnreadNamedBundleRefused (named-only edit, default plus named edits, and GET). Each checks there is no write, no generation touch and nothing echoed. Putting back the named-bundle skip makes the named test fail. Results: `-run 'Env|ConfigSeal|SettingsSection|SettingsPage'` ok in 79s; `-run ClaimConsole -timeout 25m` ok in 383s. Run together, the full pattern overran go test's default 10-minute timeout, so I ran it in two parts. gofmt and vet are clean. Concerns: GET is now unavailable too when any named bundle fails: the page shows the existing CouldNotRead line and a "Try again" link instead of a partial form. No new copy. I removed the EnvelopeStale string and the envRefuseEnvelope/envRefuseUnread codes because nothing can reach them now. The read-only Storage section's list of environments still skips an unreadable one.</result> <usage><subagent_tokens>123694</subagent_tokens><tool_uses>47</tool_uses><duration_ms>2421217</duration_ms></usage> </task-notification>
<task-notification> <task-id>buwwaeu1b</task-id> <tool-use-id>toolu_01EFsvc5sGk8Z1MqmakPjma2</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/buwwaeu1b.output</output-file> <status>completed</status> <summary>Background command "until [ -f .superpowers/sdd/2026-11-08-console-secrets/astra-t8-r3.done ]; do sleep 30; done; tail -2 .superpowers/sdd/2026-11-08-console-secrets/astra-t8-r3-findings.md" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>b9li5rnfz</task-id> <tool-use-id>toolu_01HnQKKo6fBzqqVkZJrqdR4s</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/b9li5rnfz.output</output-file> <status>completed</status> <summary>Background command "until [ -f .superpowers/sdd/2026-11-08-console-secrets/astra-census.done ]; do sleep 30; done; tail -3 .superpowers/sdd/2026-11-08-console-secrets/astra-census-findings.md" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 25.7 g CO₂e (3,119,226 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/internal/console/configwrite.go b/internal/console/configwrite.go| index a2d9a12c4..fba3fa10b 100644 |
| --- a/internal/console/configwrite.go |
| +++ b/internal/console/configwrite.go |
| @@ -23,6 +23,7 @@ import ( |
| "fmt" |
| "log" |
| "net/http" |
| + "os" |
| "sort" |
| "github.com/carlosframework/platform/internal/appconfig" |
| @@ -55,7 +56,12 @@ const ( |
| configRefusalConflict configRefusalCode = "conflict" |
| configRefusalNothingToRemove configRefusalCode = "nothing-to-remove" |
| configRefusalStore configRefusalCode = "store" |
| - configRefusalSealKey configRefusalCode = "seal-key" |
| + // configRefusalRead is a store failure on the bundle read inside the |
| + // write, before anything was written: the JSON door answers it exactly |
| + // as configRefusalStore; the settings form shows the section |
| + // unavailable, as for a failed read when the page was assembled. |
| + configRefusalRead configRefusalCode = "read" |
| + configRefusalSealKey configRefusalCode = "seal-key" |
| ) |
| // configRefusal is one refused config write: a code every door can render, |
| @@ -215,17 +221,38 @@ func (s *Server) writeConfig(ctx context.Context, acct *Account, app, envName st |
| // checkConfigSets call, are its only callers. |
| func (s *Server) configWriteBundle(ctx context.Context, unlock func(), acct *Account, app, envName string, want *appconfig.BundleVersion, sets map[string]appconfig.Var, unset []string) (int, *configRefusal) { |
| return s.configWriteStore(ctx, unlock, acct, app, envName, func(ctx context.Context) (int, error) { |
| + st := configReadTagStore{s.cfg.Releases} |
| switch { |
| case want != nil: |
| - return appconfig.ApplyAtVersion(ctx, s.cfg.Releases, acct.Sqid, app, envName, *want, sets, unset) |
| + return appconfig.ApplyAtVersion(ctx, st, acct.Sqid, app, envName, *want, sets, unset) |
| case envName == "": |
| - return appconfig.Apply(ctx, s.cfg.Releases, acct.Sqid, app, sets, unset) |
| + return appconfig.Apply(ctx, st, acct.Sqid, app, sets, unset) |
| default: |
| - return appconfig.ApplyEnvironment(ctx, s.cfg.Releases, acct.Sqid, app, envName, sets, unset) |
| + return appconfig.ApplyEnvironment(ctx, st, acct.Sqid, app, envName, sets, unset) |
| } |
| }) |
| } |
| +// configReadError is a store read that failed inside a config write. Its |
| +// text is the store error's own, so logs and every message built from it |
| +// are unchanged; configStoreRefusal tells it apart as configRefusalRead. |
| +type configReadError struct{ err error } |
| + |
| +func (e *configReadError) Error() string { return e.err.Error() } |
| +func (e *configReadError) Unwrap() error { return e.err } |
| + |
| +// configReadTagStore marks the write's read failures (configReadError). |
| +// A missing object is not a failure: it passes through untouched. |
| +type configReadTagStore struct{ release.Store } |
| + |
| +func (s configReadTagStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + b, etag, err := s.Store.Get(ctx, key) |
| + if err != nil && !errors.Is(err, os.ErrNotExist) { |
| + err = &configReadError{err} |
| + } |
| + return b, etag, err |
| +} |
| + |
| // configWriteBegin is a write's first half: the account lock, then the |
| // seal check under it. It returns the unlock (idempotent; a no-op when no |
| // lock was taken), which the caller must defer even on a refusal. |
| @@ -303,7 +330,12 @@ func configStoreRefusal(what string, err error) *configRefusal { |
| // nothing they didn't send. |
| return &configRefusal{Code: configRefusalNothingToRemove, Status: http.StatusConflict, Msg: err.Error()} |
| } |
| - return &configRefusal{Code: configRefusalStore, Status: http.StatusBadGateway, Msg: "could not store the config — try again"} |
| + code := configRefusalStore |
| + var rerr *configReadError |
| + if errors.As(err, &rerr) { |
| + code = configRefusalRead |
| + } |
| + return &configRefusal{Code: code, Status: http.StatusBadGateway, Msg: "could not store the config — try again"} |
| } |
| // configCheckSealedTo checks each sealed var of a write against the key the |
diff --git a/internal/console/envcopy.go b/internal/console/envcopy.go| index e6dfb6c0b..a7747db48 100644 |
| --- a/internal/console/envcopy.go |
| +++ b/internal/console/envcopy.go |
| @@ -344,6 +344,7 @@ func (c envPageCopy) refusal(ref *configRefusal, fleet string) string { |
| configRefusalConflict: c.RefConflict, |
| configRefusalNothingToRemove: c.RefNothingToRemove, |
| configRefusalStore: c.RefStore, |
| + configRefusalRead: c.RefStore, |
| configRefusalSealKey: c.RefSealKey, |
| }[ref.Code] |
| if line == "" { |
diff --git a/internal/console/envformgate_test.go b/internal/console/envformgate_test.go| index adf2a7675..7880fb011 100644 |
| --- a/internal/console/envformgate_test.go |
| +++ b/internal/console/envformgate_test.go |
| @@ -549,3 +549,46 @@ func TestEnvFormGateOrderAndBudget(t *testing.T) { |
| } |
| t.Fatalf("staging was never rate-limited in %d posts", cliWriteBurst+3) |
| } |
| + |
| +// A bundle read that fails inside the write (after the page read every |
| +// bundle) is the same refusal as one at page assembly (Astra R3 P2-1): no |
| +// write, no form, nothing posted drawn back. A write that fails keeps the |
| +// draft, as before. |
| +func TestEnvSaveLateBundleReadRefused(t *testing.T) { |
| + for _, target := range []string{"default", "staging"} { |
| + t.Run(target, func(t *testing.T) { |
| + e := newEnvFx(t) |
| + if _, err := appconfig.ApplyEnvironment(context.Background(), e.fx.rel, e.fx.sqid, "shop", "staging", |
| + map[string]appconfig.Var{"LOG_LEVEL": {Kind: "env", Value: "debug"}}, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + e.saving() |
| + key := appconfig.Key(e.fx.sqid, "shop") |
| + if target != "default" { |
| + key = appconfig.EnvironmentKey(e.fx.sqid, "shop", target) |
| + } |
| + f := envFields(t, e.page(t)) |
| + env := e.seal(t, "late-read") |
| + f.Set("new."+target+".MODE", "fast-r3") |
| + f.Set("newenv."+target+".NEW_SECRET", env) |
| + f.Set("fp."+target+".NEW_SECRET", f.Get("sealed_to")) |
| + f.Set("bundle", target) |
| + configPutBeforeApply = func() { e.failRead(key) } |
| + t.Cleanup(func() { configPutBeforeApply = nil }) |
| + status, body := e.post(t, f, "save") |
| + e.mustRefuseUnread(t, status, body, "fast-r3", "MODE", "NEW_SECRET", env, f.Get("sealed_to")) |
| + }) |
| + } |
| + t.Run("write failure keeps the draft", func(t *testing.T) { |
| + e := newEnvFx(t) // writes refused by the spy |
| + f := envFields(t, e.page(t)) |
| + f.Set("new.default.MODE", "fast-r3") |
| + f.Set("bundle", "default") |
| + status, body := e.post(t, f, "save") |
| + if status != http.StatusBadGateway { |
| + t.Fatalf("status = %d: %s", status, envBanner(body)) |
| + } |
| + mustContain(t, body, `name="new.default.MODE" value="fast-r3"`, "data-env-form") |
| + mustNotContain(t, body, envUnreadLine) |
| + }) |
| +} |
diff --git a/internal/console/envsave.go b/internal/console/envsave.go| index a3464d256..50d7231a9 100644 |
| --- a/internal/console/envsave.go |
| +++ b/internal/console/envsave.go |
| @@ -165,6 +165,15 @@ func (s *Server) envFormSave(w http.ResponseWriter, r *http.Request, p page, acc |
| return |
| } |
| } |
| + if ref.Code == configRefusalRead { |
| + // The bundle did not read inside the write: nothing was written, |
| + // and, as for a read that failed when the page was assembled, the |
| + // section is unavailable and nothing posted is drawn back. |
| + sv.Envs, sv.EnvsUnavailable = nil, true |
| + sv.EnvDraft, sv.EnvSummary, sv.EnvError = nil, "", "" |
| + s.render(w, http.StatusConflict, "app_settings", p) |
| + return |
| + } |
| if ref.Code == configRefusalConflict { |
| // Nothing was written. Drawn from the bundles as they are now, the |
| // ordinary changes put back on top, the sealed ones dropped: they |