appconfig: an unset of keys already gone writes nothing
ApplyAtVersion with no sets and no unset present returns (0, nil) after the version check passes: no Put and no generation touch, so a no-op save leaves the bundle's version as other pages displayed it. applyAt's other callers are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/appconfig/bundleversion.go+6 −4internal/appconfig/store.go+19 −12internal/appconfig/store_test.go+19 −0
Intent
<task-notification> <task-id>b4kyrin05</task-id> <tool-use-id>toolu_01BsmqidHXB9Ym7Qn663pxDy</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/b4kyrin05.output</output-file> <status>failed</status> <summary>Background command "until [ "$(git log --oneline b00645f3..HEAD | wc -l)" -ge 3 ]; do sleep 20; done; git log --oneline -3" failed with exit code 1</summary> </task-notification>
Attributed to this commit: 15.1 g CO₂e (1,849,625 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/appconfig/bundleversion.go b/internal/appconfig/bundleversion.go| index fe0ab9f60..7556126eb 100644 |
| --- a/internal/appconfig/bundleversion.go |
| +++ b/internal/appconfig/bundleversion.go |
| @@ -85,17 +85,19 @@ func GetBundle(ctx context.Context, s release.Store, acct, app, envName string) |
| // applyEnvironment with an expectation: the write lands only while the |
| // bundle is still at want, else it returns release.ErrCASConflict and |
| // writes nothing. Otherwise it is their merge, their refusal to create a |
| -// bundle on an unset-only call, and their generation touch. Unsetting a |
| -// key that is already gone counts nothing and is not an error. |
| +// bundle on an unset-only call, and their generation touch. A call that |
| +// only unsets keys already gone writes nothing and touches nothing. |
| func claimRawApplyAtVersion(ctx context.Context, s release.Store, acct, app, envName string, want BundleVersion, sets map[string]Var, unsets []string) (int, error) { |
| key, bundle, err := bundleKey(acct, app, envName) |
| if err != nil { |
| return 0, err |
| } |
| - removed, _, err := applyAtExpecting(ctx, s, key, app, bundle, &want, sets, unsets) |
| + removed, _, wrote, err := applyAtExpecting(ctx, s, key, app, bundle, &want, sets, unsets) |
| if err != nil { |
| return 0, err |
| } |
| - touchLogged(ctx, s, acct, app) |
| + if wrote { |
| + touchLogged(ctx, s, acct, app) |
| + } |
| return removed, nil |
| } |
diff --git a/internal/appconfig/store.go b/internal/appconfig/store.go| index 174ef843b..5a205ee62 100644 |
| --- a/internal/appconfig/store.go |
| +++ b/internal/appconfig/store.go |
| @@ -160,7 +160,8 @@ func apply(ctx context.Context, s release.Store, acct, app, bundle string, sets |
| // existence rail. Sets still create, which is how a bundle is meant to come |
| // into being. |
| func applyAt(ctx context.Context, s release.Store, key, app, bundle string, sets map[string]Var, unsets []string) (int, string, error) { |
| - return applyAtExpecting(ctx, s, key, app, bundle, nil, sets, unsets) |
| + removed, newETag, _, err := applyAtExpecting(ctx, s, key, app, bundle, nil, sets, unsets) |
| + return removed, newETag, err |
| } |
| // applyAtExpecting is applyAt with an expectation: when want is not nil, |
| @@ -168,11 +169,15 @@ func applyAt(ctx context.Context, s release.Store, key, app, bundle string, sets |
| // nothing is written and the call returns release.ErrCASConflict. The |
| // check sits between the read and the write, and the write is at the read |
| // etag, so a change made after the read surfaces as the store's own CAS |
| -// conflict. applyAt passes nil, which is applyAt's behaviour unchanged. |
| -func applyAtExpecting(ctx context.Context, s release.Store, key, app, bundle string, want *BundleVersion, sets map[string]Var, unsets []string) (int, string, error) { |
| +// conflict. With an expectation, a call that sets nothing and finds none |
| +// of its unsets present writes nothing (the spec's "unsetting a variable |
| +// that is already gone is a no-op"), and wrote is false so the caller |
| +// skips the generation touch too. applyAt passes nil, which is applyAt's |
| +// behaviour unchanged. |
| +func applyAtExpecting(ctx context.Context, s release.Store, key, app, bundle string, want *BundleVersion, sets map[string]Var, unsets []string) (removed int, newETag string, wrote bool, err error) { |
| for k, v := range sets { |
| if !ValidVarName(k) { |
| - return 0, "", fmt.Errorf("config: invalid var name %q", k) |
| + return 0, "", false, fmt.Errorf("config: invalid var name %q", k) |
| } |
| // Env values are validated here, while the operator can still see |
| // the plaintext — a bad value that only failed at render time would |
| @@ -181,41 +186,43 @@ func applyAtExpecting(ctx context.Context, s release.Store, key, app, bundle str |
| // CLI, before sealing; by this point they're opaque envelopes. |
| if v.Kind == "env" { |
| if err := ValidVarValue(v.Value); err != nil { |
| - return 0, "", fmt.Errorf("config: var %s: %w", k, err) |
| + return 0, "", false, fmt.Errorf("config: var %s: %w", k, err) |
| } |
| } |
| } |
| m, etag, found, err := getForWriteAt(ctx, s, key, app) |
| if err != nil { |
| - return 0, "", err |
| + return 0, "", false, err |
| } |
| if want != nil && (found != want.Found || (found && etag != want.ETag)) { |
| - return 0, "", fmt.Errorf("config: %s %s bundle changed since it was read: %w", app, bundle, release.ErrCASConflict) |
| + return 0, "", false, fmt.Errorf("config: %s %s bundle changed since it was read: %w", app, bundle, release.ErrCASConflict) |
| } |
| if !found && len(sets) == 0 { |
| - return 0, "", fmt.Errorf("config: %s has no %s bundle — nothing to unset", app, bundle) |
| + return 0, "", false, fmt.Errorf("config: %s has no %s bundle — nothing to unset", app, bundle) |
| } |
| if m.Vars == nil { |
| m.Vars = map[string]Var{} |
| } |
| - removed := 0 |
| for _, k := range unsets { |
| if _, ok := m.Vars[k]; ok { |
| removed++ |
| } |
| delete(m.Vars, k) |
| } |
| + if want != nil && len(sets) == 0 && removed == 0 { |
| + return 0, etag, false, nil |
| + } |
| for k, v := range sets { |
| m.Vars[k] = v |
| } |
| // The new etag is returned because the instance layer's writer (design |
| // §6.5) has to hand it to whoever will later compare it with an agent's |
| // delivery ack. The other two bundles' callers ignore it. |
| - newETag, err := putManifestAt(ctx, s, key, app, &m, etag) |
| + newETag, err = putManifestAt(ctx, s, key, app, &m, etag) |
| if err != nil { |
| - return 0, "", err |
| + return 0, "", false, err |
| } |
| - return removed, newETag, nil |
| + return removed, newETag, true, nil |
| } |
| // putManifestAt is the ONE write of a manifest object: it stamps the app |
diff --git a/internal/appconfig/store_test.go b/internal/appconfig/store_test.go| index 92d497950..5c9fe3225 100644 |
| --- a/internal/appconfig/store_test.go |
| +++ b/internal/appconfig/store_test.go |
| @@ -456,10 +456,29 @@ func TestApplyAtVersionUnsetGoneIsNoop(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| + key := Key("bab", "keymail") |
| + if env != "" { |
| + key = EnvironmentKey("bab", "keymail", env) |
| + } |
| + before, beforeETag, err := s.Get(ctx, key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _, genBefore, err := s.Get(ctx, GenKey("bab", "keymail")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| removed, err := ApplyAtVersion(ctx, s, "bab", "keymail", env, shown, nil, []string{"GONE"}) |
| if err != nil || removed != 0 { |
| t.Fatalf("unset of a gone key = %d, %v, want 0, nil", removed, err) |
| } |
| + after, afterETag, err := s.Get(ctx, key) |
| + if err != nil || afterETag != beforeETag || string(after) != string(before) { |
| + t.Fatalf("a no-op unset rewrote the bundle: etag %q -> %q (%v)", beforeETag, afterETag, err) |
| + } |
| + if _, genAfter, err := s.Get(ctx, GenKey("bab", "keymail")); err != nil || genAfter != genBefore { |
| + t.Fatalf("a no-op unset touched the generation: %q -> %q (%v)", genBefore, genAfter, err) |
| + } |
| m, _, err := GetBundle(ctx, s, "bab", "keymail", env) |
| if err != nil || len(m.Vars) != 1 || m.Vars["A"].Value != "1" { |
| t.Fatalf("bundle = %+v %v", m, err) |