From 4cd4323d4644f592fe90acb1e78696b9a595ef98 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Fri, 27 Nov 2026 16:44:16 +0000 Subject: [PATCH 1/3] fix(commitrequest): list a source cluster's CommitRequests again at once when a watch ends The source-cluster watch ends every 5 minutes by design (commitRequestRelist), but the loop then waited commitRequestReconnect (10 s) before listing again, error or not. For those 10 s nothing watched the namespace, so a CommitRequest created then waited up to 10 s to be claimed, longer than a client that waits for registration before writing may wait. A session that ends cleanly, or on 410 Gone, now lists again at once. The next watch starts from that list's resourceVersion, so nothing goes unseen in between. A failure still waits, and so does a watch that closes within a second, so a server that closes every watch at once is not listed in a loop. The clean end is logged at V(1). Co-Authored-By: Claude Opus 5.5 --- internal/controller/commitrequest_server.go | 47 +++++-- .../controller/commitrequest_server_test.go | 123 +++++++++++++++++- .../controller/commitrequest_settle_test.go | 2 +- 3 files changed, 157 insertions(+), 15 deletions(-) diff --git a/internal/controller/commitrequest_server.go b/internal/controller/commitrequest_server.go index 895f73795..3d9ae108b 100644 --- a/internal/controller/commitrequest_server.go +++ b/internal/controller/commitrequest_server.go @@ -48,8 +48,12 @@ const ( // commitRequestProviderResync is how often the server looks again at which KubeProviders to serve, // what they lend, and whether their clusters serve the CRD. commitRequestProviderResync = 10 * time.Second - // commitRequestReconnect is the wait before a watch of a cluster's CommitRequests opens again. + // commitRequestReconnect is the wait before a watch of a cluster's CommitRequests opens again after + // it failed, or closed within commitRequestShortWatch. A watch that ends cleanly lists again at once. commitRequestReconnect = 10 * time.Second + // commitRequestShortWatch is how long a watch must have run for its clean end to list again at once. + // One that a server or proxy closes sooner waits commitRequestReconnect, rather than list in a loop. + commitRequestShortWatch = time.Second // commitRequestEventBuffer is how many report changes wait for the KubeProvider reconciler. commitRequestEventBuffer = 256 // commitRequestRelist ends a watch this often, so every request is looked at again: one waiting for @@ -501,20 +505,37 @@ func (s *CommitRequestServer) clusterClient( } } -// watchNamespace lists and watches one namespace's CommitRequests, or every namespace's, reconnecting -// after a failure, until ctx ends. +// watchNamespace lists and watches one namespace's CommitRequests, or every namespace's, until ctx ends. +// A session that ends cleanly, as every one does after commitRequestRelist, or on 410 Gone, lists again +// at once: the next watch starts from that list's resourceVersion, so no request goes unseen in between. +// A failure waits commitRequestReconnect first, and so does a session that ended that way within +// commitRequestShortWatch, so a server that closes every watch at once is not listed in a loop. func (s *CommitRequestServer) watchNamespace( ctx context.Context, log logr.Logger, watcher *commitRequestWatcher, resource dynamic.NamespaceableResourceInterface, namespace string, ) { + label := namespaceLabel(namespace) for ctx.Err() == nil { - err := s.session(ctx, watcher, resource.Namespace(namespace), namespaceLabel(namespace)) - if apierrors.IsForbidden(err) { - watcher.mark(watcher.forbidden, namespaceLabel(namespace), true) + started := time.Now() + err := s.session(ctx, watcher, resource.Namespace(namespace), label) + if ctx.Err() != nil { + return } - if err != nil && ctx.Err() == nil { - log.Info("The watch of CommitRequests ended; reconnecting", "namespace", namespaceLabel(namespace), - "err", err.Error()) + ran := time.Since(started) + relist := err == nil || apierrors.IsResourceExpired(err) || apierrors.IsGone(err) + switch { + case relist && ran >= commitRequestShortWatch: + log.V(1).Info("The watch of CommitRequests ended; listing again", "namespace", label, + "ran", ran.Round(time.Second).String(), "err", errString(err)) + continue + case relist: + log.Info("The watch of CommitRequests closed at once; reconnecting", "namespace", label, + "err", errString(err)) + default: + if apierrors.IsForbidden(err) { + watcher.mark(watcher.forbidden, label, true) + } + log.Info("The watch of CommitRequests ended; reconnecting", "namespace", label, "err", err.Error()) } select { case <-ctx.Done(): @@ -523,6 +544,14 @@ func (s *CommitRequestServer) watchNamespace( } } +// errString is err's message, or "" for nil. +func errString(err error) string { + if err == nil { + return "" + } + return err.Error() +} + // session lists the requests and watches them, until the watch ends. A list that succeeds clears a // denial reported for the namespace, so a Role granted since is reported at once. func (s *CommitRequestServer) session( diff --git a/internal/controller/commitrequest_server_test.go b/internal/controller/commitrequest_server_test.go index 672156344..311c2fd23 100644 --- a/internal/controller/commitrequest_server_test.go +++ b/internal/controller/commitrequest_server_test.go @@ -7,6 +7,7 @@ import ( "errors" "slices" "sync" + "sync/atomic" "testing" "time" @@ -14,12 +15,14 @@ import ( "github.com/go-logr/logr" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + apierrors "k8s.io/apimachinery/pkg/api/errors" apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" + k8swatch "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" fakediscovery "k8s.io/client-go/discovery/fake" "k8s.io/client-go/dynamic" @@ -249,13 +252,13 @@ func (r *rotatingClusters) SourceDiscovery(context.Context, string) (discovery.D return r.discovery, r.credential, nil } -// sourceCommitRequest is a CommitRequest as it is stored on a source cluster. -func sourceCommitRequest(namespace, name string) *unstructured.Unstructured { +// sourceCommitRequest is a CommitRequest as it is stored on a source cluster, in namespace default. +func sourceCommitRequest(name string) *unstructured.Unstructured { u := &unstructured.Unstructured{Object: map[string]any{ "apiVersion": "configbutler.ai/v1alpha3", "kind": "CommitRequest", "metadata": map[string]any{ - "namespace": namespace, "name": name, "uid": "uid-" + name, "resourceVersion": "1", + "namespace": "default", "name": name, "uid": "uid-" + name, "resourceVersion": "1", "creationTimestamp": time.Now().UTC().Format(time.RFC3339), }, "spec": map[string]any{ @@ -276,7 +279,7 @@ func TestCommitRequestServer_ServesARequestOnASourceCluster(t *testing.T) { c := newCommitRequestClient(t, nil, mirroringTarget("edge"), provider) gvr := commitRequestGVR() source := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), - map[schema.GroupVersionResource]string{gvr: "CommitRequestList"}, sourceCommitRequest("default", "save")) + map[schema.GroupVersionResource]string{gvr: "CommitRequestList"}, sourceCommitRequest("save")) f := committed() s := &CommitRequestServer{ Client: c, Finalizer: f, TTL: time.Hour, Log: logr.Discard(), @@ -330,7 +333,7 @@ func TestCommitRequestServer_ARotatedCredentialMovesTheWatcher(t *testing.T) { listKinds := map[schema.GroupVersionResource]string{gvr: "CommitRequestList"} before := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), listKinds) after := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), listKinds, - sourceCommitRequest("default", "save")) + sourceCommitRequest("save")) clusters := &rotatingClusters{ discovery: fakeDiscovery(nil, commitRequestResources("configbutler.ai/v1alpha3", "commitrequests")), credential: "v1", @@ -414,3 +417,113 @@ func TestCommitRequestServer_StepsShareTheFactStreams(t *testing.T) { first := s.core().streams assert.Same(t, first, s.core().streams, "every step shares one set of streams") } + +// commitRequestWatchEnds are the ways a watch of a source cluster's CommitRequests ends without failing: +// cleanly, as every one does after commitRequestRelist, and with 410 Gone. +var commitRequestWatchEnds = []struct { + name string + end func(*k8swatch.FakeWatcher) +}{ + {name: "clean end", end: func(w *k8swatch.FakeWatcher) { w.Stop() }}, + {name: "410 Gone", end: func(w *k8swatch.FakeWatcher) { + w.Error(&apierrors.NewResourceExpired("too old resource version").ErrStatus) + }}, +} + +// countCommitRequestLists counts the Lists of CommitRequests on source. +func countCommitRequestLists(source *dynamicfake.FakeDynamicClient) *atomic.Int32 { + var lists atomic.Int32 + source.PrependReactor("list", "commitrequests", func(clienttesting.Action) (bool, runtime.Object, error) { + lists.Add(1) + return false, nil, nil + }) + return &lists +} + +// A watch that ends without failing lists again at once, rather than leave the namespace unwatched for +// commitRequestReconnect: a request created right after the end is served well within that wait. +func TestCommitRequestServer_AWatchThatEndsListsAgainAtOnce(t *testing.T) { + for _, tc := range commitRequestWatchEnds { + t.Run(tc.name, func(t *testing.T) { + provider := kubeconfigProvider("edge", true) + c := newCommitRequestClient(t, nil, mirroringTarget("edge"), provider) + gvr := commitRequestGVR() + source := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), + map[schema.GroupVersionResource]string{gvr: "CommitRequestList"}) + lists := countCommitRequestLists(source) + first := k8swatch.NewFake() + var watches atomic.Int32 + source.PrependWatchReactor("commitrequests", + func(clienttesting.Action) (bool, k8swatch.Interface, error) { + if watches.Add(1) == 1 { + return true, first, nil + } + return false, nil, nil + }) + s := &CommitRequestServer{ + Client: c, Finalizer: committed(), Log: logr.Discard(), + Clusters: fakeClusters{dynamic: source, discovery: fakeDiscovery(nil, + commitRequestResources("configbutler.ai/v1alpha3", "commitrequests"))}, + } + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + s.syncProviders(ctx) + require.Eventually(t, func() bool { return watches.Load() == 1 }, 5*time.Second, 10*time.Millisecond, + "the first session watches") + time.Sleep(commitRequestShortWatch) // the watch has run long enough to count as a whole one + + tc.end(first) + request := sourceCommitRequest("relisted") + request.SetResourceVersion("") + _, err := source.Resource(gvr).Namespace("default").Create(ctx, request, metav1.CreateOptions{}) + require.NoError(t, err) + + require.Eventually(t, func() bool { + u, getErr := source.Resource(gvr).Namespace("default").Get(ctx, "relisted", metav1.GetOptions{}) + if getErr != nil { + return false + } + cr, convErr := commitRequestFromUnstructured(u) + if convErr != nil { + return false + } + ready := apimeta.FindStatusCondition(cr.Status.Conditions, ConditionTypeReady) + return ready != nil && ready.Reason == crReasonCommitted + }, commitRequestReconnect/2, 20*time.Millisecond, + "a request created as the watch ends is served without waiting commitRequestReconnect") + assert.GreaterOrEqual(t, lists.Load(), int32(2), "the namespace was listed again") + }) + } +} + +// A watch a server closes at once, cleanly or with 410 Gone, waits commitRequestReconnect before listing +// again, so such a server is not listed in a loop. +func TestCommitRequestServer_AWatchClosedAtOnceWaitsBeforeListingAgain(t *testing.T) { + for _, tc := range commitRequestWatchEnds { + t.Run(tc.name, func(t *testing.T) { + source := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), + map[schema.GroupVersionResource]string{commitRequestGVR(): "CommitRequestList"}) + lists := countCommitRequestLists(source) + source.PrependWatchReactor("commitrequests", + func(clienttesting.Action) (bool, k8swatch.Interface, error) { + w := k8swatch.NewFakeWithChanSize(1, false) + tc.end(w) + return true, w, nil + }) + s := &CommitRequestServer{Log: logr.Discard()} + watcher := &commitRequestWatcher{forbidden: map[string]bool{}, undeletable: map[string]bool{}} + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan struct{}) + go func() { + defer close(done) + s.watchNamespace(ctx, logr.Discard(), watcher, source.Resource(commitRequestGVR()), "default") + }() + + require.Eventually(t, func() bool { return lists.Load() == 1 }, 5*time.Second, 10*time.Millisecond) + time.Sleep(2 * commitRequestShortWatch) + assert.Equal(t, int32(1), lists.Load(), "no second list before commitRequestReconnect") + cancel() + <-done + }) + } +} diff --git a/internal/controller/commitrequest_settle_test.go b/internal/controller/commitrequest_settle_test.go index 76084cf1c..eee32aee7 100644 --- a/internal/controller/commitrequest_settle_test.go +++ b/internal/controller/commitrequest_settle_test.go @@ -240,7 +240,7 @@ func TestCommitRequestsInFlight_ASourceClusterRequestIsSettledOnItsCluster(t *te c := newCommitRequestClient(t, nil, mirroringTarget("edge"), provider, controlTarget, withInProgress(control)) gvr := commitRequestGVR() source := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), - map[schema.GroupVersionResource]string{gvr: "CommitRequestList"}, sourceCommitRequest("default", "save")) + map[schema.GroupVersionResource]string{gvr: "CommitRequestList"}, sourceCommitRequest("save")) worker := &drainingWorker{} inFlight := &CommitRequestsInFlight{Log: logr.Discard()} s := &CommitRequestServer{ From fd6b9594540e5011778e997f5f0d4c8394232911 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Fri, 27 Nov 2026 17:07:06 +0000 Subject: [PATCH 2/3] fix(commitrequest): time the short-watch guard from the watch opening, not the list A list slower than commitRequestShortWatch counted toward the watch's run, so a server that closes every watch at once was relisted in a loop whenever its list was slow. session now reports how long the watch itself ran. Co-Authored-By: Claude Opus 5.5 --- internal/controller/commitrequest_server.go | 27 ++++---- .../controller/commitrequest_server_test.go | 66 +++++++++++-------- 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/internal/controller/commitrequest_server.go b/internal/controller/commitrequest_server.go index 3d9ae108b..5a78eba5a 100644 --- a/internal/controller/commitrequest_server.go +++ b/internal/controller/commitrequest_server.go @@ -508,20 +508,19 @@ func (s *CommitRequestServer) clusterClient( // watchNamespace lists and watches one namespace's CommitRequests, or every namespace's, until ctx ends. // A session that ends cleanly, as every one does after commitRequestRelist, or on 410 Gone, lists again // at once: the next watch starts from that list's resourceVersion, so no request goes unseen in between. -// A failure waits commitRequestReconnect first, and so does a session that ended that way within -// commitRequestShortWatch, so a server that closes every watch at once is not listed in a loop. +// A failure waits commitRequestReconnect first, and so does a watch that ended that way within +// commitRequestShortWatch of opening, so a server that closes every watch at once is not listed in a loop, +// however long its list takes. func (s *CommitRequestServer) watchNamespace( ctx context.Context, log logr.Logger, watcher *commitRequestWatcher, resource dynamic.NamespaceableResourceInterface, namespace string, ) { label := namespaceLabel(namespace) for ctx.Err() == nil { - started := time.Now() - err := s.session(ctx, watcher, resource.Namespace(namespace), label) + ran, err := s.session(ctx, watcher, resource.Namespace(namespace), label) if ctx.Err() != nil { return } - ran := time.Since(started) relist := err == nil || apierrors.IsResourceExpired(err) || apierrors.IsGone(err) switch { case relist && ran >= commitRequestShortWatch: @@ -552,14 +551,15 @@ func errString(err error) string { return err.Error() } -// session lists the requests and watches them, until the watch ends. A list that succeeds clears a -// denial reported for the namespace, so a Role granted since is reported at once. +// session lists the requests and watches them, until the watch ends, and says how long the watch ran: +// zero when it never opened. A list that succeeds clears a denial reported for the namespace, so a Role +// granted since is reported at once. func (s *CommitRequestServer) session( ctx context.Context, watcher *commitRequestWatcher, resource dynamic.ResourceInterface, namespace string, -) error { +) (time.Duration, error) { list, err := resource.List(ctx, metav1.ListOptions{}) if err != nil { - return err + return 0, err } watcher.mark(watcher.forbidden, namespace, false) for i := range list.Items { @@ -570,16 +570,17 @@ func (s *CommitRequestServer) session( ResourceVersion: list.GetResourceVersion(), AllowWatchBookmarks: true, TimeoutSeconds: &timeout, }) if err != nil { - return err + return 0, err } defer w.Stop() + opened := time.Now() for { select { case <-ctx.Done(): - return nil + return time.Since(opened), nil case ev, ok := <-w.ResultChan(): if !ok { - return nil + return time.Since(opened), nil } switch ev.Type { case k8swatch.Added, k8swatch.Modified: @@ -587,7 +588,7 @@ func (s *CommitRequestServer) session( s.consider(ctx, watcher, u) } case k8swatch.Error: - return apierrors.FromObject(ev.Object) + return time.Since(opened), apierrors.FromObject(ev.Object) case k8swatch.Deleted, k8swatch.Bookmark: } } diff --git a/internal/controller/commitrequest_server_test.go b/internal/controller/commitrequest_server_test.go index 311c2fd23..3ee0340cf 100644 --- a/internal/controller/commitrequest_server_test.go +++ b/internal/controller/commitrequest_server_test.go @@ -497,33 +497,47 @@ func TestCommitRequestServer_AWatchThatEndsListsAgainAtOnce(t *testing.T) { } // A watch a server closes at once, cleanly or with 410 Gone, waits commitRequestReconnect before listing -// again, so such a server is not listed in a loop. +// again, so such a server is not listed in a loop: also when its list takes longer than +// commitRequestShortWatch, since only the watch's own run counts. func TestCommitRequestServer_AWatchClosedAtOnceWaitsBeforeListingAgain(t *testing.T) { for _, tc := range commitRequestWatchEnds { - t.Run(tc.name, func(t *testing.T) { - source := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), - map[schema.GroupVersionResource]string{commitRequestGVR(): "CommitRequestList"}) - lists := countCommitRequestLists(source) - source.PrependWatchReactor("commitrequests", - func(clienttesting.Action) (bool, k8swatch.Interface, error) { - w := k8swatch.NewFakeWithChanSize(1, false) - tc.end(w) - return true, w, nil - }) - s := &CommitRequestServer{Log: logr.Discard()} - watcher := &commitRequestWatcher{forbidden: map[string]bool{}, undeletable: map[string]bool{}} - ctx, cancel := context.WithCancel(context.Background()) - done := make(chan struct{}) - go func() { - defer close(done) - s.watchNamespace(ctx, logr.Discard(), watcher, source.Resource(commitRequestGVR()), "default") - }() - - require.Eventually(t, func() bool { return lists.Load() == 1 }, 5*time.Second, 10*time.Millisecond) - time.Sleep(2 * commitRequestShortWatch) - assert.Equal(t, int32(1), lists.Load(), "no second list before commitRequestReconnect") - cancel() - <-done - }) + for _, slowList := range []bool{false, true} { + name := tc.name + if slowList { + name += ", slow list" + } + t.Run(name, func(t *testing.T) { + source := dynamicfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), + map[schema.GroupVersionResource]string{commitRequestGVR(): "CommitRequestList"}) + lists := countCommitRequestLists(source) + if slowList { + source.PrependReactor("list", "commitrequests", + func(clienttesting.Action) (bool, runtime.Object, error) { + time.Sleep(commitRequestShortWatch + 100*time.Millisecond) + return false, nil, nil + }) + } + source.PrependWatchReactor("commitrequests", + func(clienttesting.Action) (bool, k8swatch.Interface, error) { + w := k8swatch.NewFakeWithChanSize(1, false) + tc.end(w) + return true, w, nil + }) + s := &CommitRequestServer{Log: logr.Discard()} + watcher := &commitRequestWatcher{forbidden: map[string]bool{}, undeletable: map[string]bool{}} + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan struct{}) + go func() { + defer close(done) + s.watchNamespace(ctx, logr.Discard(), watcher, source.Resource(commitRequestGVR()), "default") + }() + + require.Eventually(t, func() bool { return lists.Load() == 1 }, 5*time.Second, 10*time.Millisecond) + time.Sleep(3 * commitRequestShortWatch) + assert.Equal(t, int32(1), lists.Load(), "no second list before commitRequestReconnect") + cancel() + <-done + }) + } } } From d392f3b2a911b26d517c787e6c7fb2ea2736b753 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Fri, 27 Nov 2026 17:40:18 +0000 Subject: [PATCH 3/3] docs: update the gitops-api open asks to their revision 21 The team's text as sent, with only the changes the earlier revisions carry: links into the gitops-api repository made absolute, *emphasis* as _emphasis_, the diagram's fence tagged text, and one line broken before a long link. Co-Authored-By: Claude Opus 5.5 --- docs/future/gitops-api-open-asks.md | 151 +++++++++------------------- 1 file changed, 46 insertions(+), 105 deletions(-) diff --git a/docs/future/gitops-api-open-asks.md b/docs/future/gitops-api-open-asks.md index b486c0107..647ab5c5b 100644 --- a/docs/future/gitops-api-open-asks.md +++ b/docs/future/gitops-api-open-asks.md @@ -1,38 +1,31 @@ # gitops-reverser in production: how we use it, and what we'd still like -_From the [gitops-api](https://github.com/ConfigButler/gitops-api) team. **Revision 19, 2026-10-28** +_From the [gitops-api](https://github.com/ConfigButler/gitops-api) team. **Revision 21, 2026-11-27** (first sent 2026-07-09). Written to be readable from the gitops-reverser repo — no gitops-api knowledge assumed. Every ask is traced to something we measured on a running system. **We run -`v0.55.0`.**_ +`v0.57.0`.**_ ## Where this stands -**`0.55.0` closed both our open asks and the `kube-root-ca.crt` vote, and we adopted it the day it -was tagged.** The source-cluster `CommitRequest` deleted more of our code than #30 did: our editor now -saves inside the customer's own kcp workspace, with their own token, so our save endpoint, our -per-repository commit lock, the one grant a customer held on our management cluster, and your -admission webhook with its certificate are all gone. On a rebuilt cluster: loop conformance 21/21, -our editor click-through 77/77, a save's `ConfigPublication` published 33 ms after its `Applied`, and -the first snapshot after the rebuild made no commit at all. Adoption write-up: -[reverser-0.55-adoption.md](https://github.com/ConfigButler/gitops-api/blob/main/docs/design/reverser-0.55-adoption.md). - -**Six asks are new since then.** Three are small and came from the adoption. The other three came -from tuning the editor's save the day after. **#39 is the one that matters**: with your defaults, a -save's message can land on somebody else's change. +**`0.56.0` answered four of our six asks, and we adopted `0.57.0` the day after it was tagged.** A +save is reported as the worker reaches each phase (#40), its push skips the cooldown (#41), a +misdirected request ends `NotAllowed` (#38), and your answer to #39 came with a regression test. On a +rebuilt cluster: loop conformance 21/21, our editor click-through 81/81, and a save now commits +**4–5 s** after it is filed, where it took ~6.8 s on `0.55.0`. `0.57.0`'s object `status.author` +lets the editor name the saver as the Git author header does ("authored by Simon Koudijs"); kcp +carries the name and email claims onto the save's own audit event. Adoption write-up: +[reverser-0.56-adoption.md](https://github.com/ConfigButler/gitops-api/blob/main/docs/design/reverser-0.56-adoption.md). | Open | What it is | |---|---| -| **39** 🟠 new | `CurrentOrNext` gives a save's message to an earlier, unclaimed write of the same author, and your defaults do it too | -| **40** 🟡 new | A request's progress is reported on a fixed 2 s poll, so a save's latency moves in 2 s steps | -| **41** 🟡 new | A push that resolves a `CommitRequest` waits out the 5 s `PushCooldown` | -| **38** 🟡 new | A source-cluster request naming a `GitTarget` that does not mirror that cluster gets no status at all | -| **37** ⚪ new | Default `gitTargetRef.namespace` on a source cluster to the serving `KubeProvider`'s namespace | -| **36** ⚪ new | `AuthorUnresolved` as a failure (`Ready=False`), not a success | +| **43** 🟠 new, a bug | A source cluster's `CommitRequest`s go unseen for 10 s every 5 min 10 s ([report](https://github.com/ConfigButler/gitops-api/blob/main/hack/spikes/BUG-commitrequest-watch-reconnect-gap.md)) | +| **42** ⚪ new | Tell a `CommitRequest` when a `path_conflict` closed its window early | +| **37** ⚪ | Default `gitTargetRef.namespace` on a source cluster to the serving `KubeProvider`'s namespace | +| **36** ⚪ | `AuthorUnresolved` as a failure (`Ready=False`), not a success | | **10** ⚪ | Sibling inference can place an object in another namespace's directory — cosmetic | | **28** ⏸ | Two instances on one config-plane cluster — deferred, by agreement | -Plus two **votes for items already on your list**: the durable worker queue, and -`concurrent-author-windows.md`. +Plus one **vote for an item already on your list**: the durable worker queue. ## Who we are @@ -77,79 +70,29 @@ when they part. ## Open asks -### 39. `CurrentOrNext` gives a save's message to somebody else's writes - -**Ask.** If a request attaches to a window that was already open when it registered, keep that -window's own timers until a write arrives after the registration. Alternatively make `Next` the -default. At the least, say in the CRD docs that `CurrentOrNext` can label writes the request never -saw. - -**Why.** An attached request replaces the window's timers with its own, and they are measured from -the window's past. Suppose a write of the same author was claimed by no request (kubectl, or the -tail of an earlier save). It leaves a window open on the `GitTarget`'s 5 s idle timer. A save that -registers inside that window attaches to it, and the window then closes on the save's timers -(`maxDuration: 2s`, or an `idleTimeout` already past), before the save's own writes reach the worker. -The result, measured with a write made just before the request was filed: - -- the request's message is committed on the earlier write; -- the save's own writes commit under the generated message; -- the request reports `Committed`. - -**Your defaults do it too**, not just our tuning. Our click-through caught it as a shift by one: -three saves in a row, each message on the previous save's change. We now file `attach: Next`, which -fixes it. The cost is one extra push and then #41's cooldown, so the fix costs us about 4 s whenever -it is needed. - -**Answer (gitops-reverser, PR #465): fixed by #40, and the window rule stays.** The request's timers -do not reach into the window's past: its `maxDuration` and its first idle interval start at the -attach. The shift by one came from #40's poll. Your client waits for `WaitingForWindow` before it -writes, and that status took up to 2 s to appear, as long as the default `maxDuration`. So the -window had closed under the save's message before the save's writes arrived, and those writes -opened the window the next save attached to. With #40 the registration reaches the client in about -56 ms. `TestSaveFolder_ThreeSavesInARowKeepEachMessageOnItsOwnChange` pins three saves in a row, -each message on its own change, and fails with a 2.1 s client delay. - -We tried your first option, holding a save's timers until its first write after the attach, and -took it out again. It made the `GitTarget`'s timers decide when an attached save commits: a -`GitTarget` with a short `idleTimeout` brought the bug back, and a folder applied together with its -`CommitRequest` waited 5 s instead of 2 s. `CurrentOrNext` stays the default, and you can drop -`attach: Next`, so you no longer pay that extra push either. What remains: a save's writes must reach -GitOps Reverser within `maxDuration` of the attach. On a slow audit pipeline, raise `maxDuration`. - -### 40. Report a request's progress without the 2 s poll - -**Ask.** Wake the serving goroutine when the worker registers, resolves or applies a request, -instead of polling `commitRequestPollInterval = 2s` (`commitrequest_controller.go:63`, -`recordPhase` in `commitrequest_core.go`). Failing that, poll at ~100 ms while the phase is still -`""`. - -**Why.** A save's visible latency moves in 2 s steps. Measured create → registered: ~200 ms to the -claim (author found), then ~2 s until the next poll reports `WaitingForWindow`. The same 2 s comes -again between push and `Ready`, and on the `Applied` follow. Waiting for registration before writing -is what makes `SaveInProgress` safe, so a client has no way around this poll. About 3 s of our ~6.8 s -save is this poll. - -### 41. Skip `PushCooldown` for a push a `CommitRequest` waits on - -**Ask.** Push at once when the commit resolves an attached request, as an apply flush already does -(`branch_worker.go`, `PushCooldown = 5s`). - -**Why.** A person is watching that push. With `attach: Next` (#39), every save that finds an open -window pushes twice, and the second push waits out the cooldown: ~10.8 s instead of ~6.8 s. Two -saves in a row hit it the same way. - -### 38. Refuse a source-cluster request whose `GitTarget` does not mirror that cluster - -**Ask.** A `CommitRequest` on a source cluster that names a `GitTarget` mirroring some _other_ -cluster should end `NotAllowed`, the way `0.55.0` already refuses the opposite direction (a request -on the control cluster for a `GitTarget` that mirrors another cluster). - -**Why.** Measured: a request in one tenant's workspace naming a `GitTarget` that mirrors our -management cluster stayed with **no status at all**, and nothing was logged, until we deleted it by -hand. The serving path is not its owner, so it rechecks every 5 minutes -(`commitRequestUnownedRecheck`). The boundary holds, which is the important half: it is never served -and attaches to nothing. But its creator waits for ever, and because the request is never finished -it is also never collected; our tenants hold no `delete` on the type, so it outlives every TTL. +### 43. A source cluster's `CommitRequest`s go unseen for 10 s every 5 min 10 s + +**Ask.** In `CommitRequestServer.watchNamespace`, wait `commitRequestReconnect` only after a watch +that ended in an error; after a clean end (the 5-minute `TimeoutSeconds`), list and watch again at +once, or resume from the last resourceVersion. + +**Why.** Every clean end is followed by a 10 s wait in which nothing watches the namespace, so a +request created then is claimed up to 10 s late: ~3% of our saves. Reproduced on demand by filing +requests inside predicted gaps (9.5 s against 0.6 s outside them), and it is not audit lag (the +create's fact was published the same second). A client that waits for registration before writing, +as the protocol asks, can time out and lose its message. Full report, evidence and a suggested test: +[BUG-commitrequest-watch-reconnect-gap.md](https://github.com/ConfigButler/gitops-api/blob/main/hack/spikes/BUG-commitrequest-watch-reconnect-gap.md). + +### 42. Tell a `CommitRequest` when a `path_conflict` closed its window early + +**Ask.** When a window an attached request holds is closed by `path_conflict` (another author's write +overlapped its footprint), say so on the request: a condition reason, or a line in `Ready`'s message. + +**Why.** It was our open question 4 on `concurrent-author-windows.md`, and `0.56.0` shipped the +stage without it: `path_conflict` is a close reason on `git_commit_windows_total` and nothing on the +request (**checked** in `v0.57.0`: `window_admission.go` finalizes the window, the request sees an +ordinary close). A save that commits less than its author meant to save, silently, is the bug we +once built our own lock for. Today each tenant has one human, so it is polish until that changes. ### 37. Default `gitTargetRef.namespace` on a source cluster @@ -199,11 +142,6 @@ open commit window is dropped, and a save made in that window loses the message It is the last item standing between us and "a deploy of the reverser is invisible to the people editing". -**`concurrent-author-windows.md`**, for when our tenants get several editors. Today each has one -human, so `SaveInProgress` covers us. Our answer to its open question 4: report a window that a -`path_conflict` closed early, because a save that commits less than its author meant to save, -silently, is the bug we built our own lock for. - ## Process notes - **Retire a field by rejecting it first.** `0.44.0` kept `eventTemplate`/`groupTemplate` in the @@ -254,6 +192,10 @@ One line each: what happened, and whether we are happy. | 33 | Say why `prefetch` is false | `0.54.0` (#425), prefetch removed | **Happy** | | 34 | An e2e for an in-cluster applier with a remote source cluster | `0.55.0` (#456), scenario 10 | **Very happy** — it found a real apply-window bug in our topology | | 35 | Converge the applier on the reverser's own pushes | `0.55.0` (#456), `FluxClaim.spec.catchUpAfter` + `CommitRequest.spec.catchUp: AfterPush` | **Happier than asked** — a save is published 33 ms after its apply | +| 38 | Refuse a source-cluster request whose `GitTarget` does not mirror that cluster | `0.56.0` (#465), `NotAllowed` naming both clusters | **Happy** — and it is collected after the TTL now | +| 39 | `CurrentOrNext` labels an earlier write | `0.56.0` (#465): the shift was #40's poll, with a regression test | **Happy** — we keep `attach: Next` until we have measured both | +| 40, 41 | Report a request's phases without the poll; skip `PushCooldown` for a save's push | `0.56.0` (#465) | **Very happy** — create → `Committed` 6.8 s → 4–5 s | +| — | `concurrent-author-windows.md` stage 2 (a vote) | `0.56.0` (#467, #469, #470) | **Happy** — question 4 is now #42 | | — | Filter `kube-root-ca.crt` (a vote) | `0.55.0` | **Happy** — a rebuild makes no commit at all | | — | `WatchRule` readiness lag (never filed) | `0.44.0` (#343) | **Happy** — rule readiness is usable as an alert | @@ -278,8 +220,7 @@ So a wishlist does not become a blame list: ## Suggested order -1. **#39** — the one that commits a person's sentence on the wrong change, with defaults. -2. **#38** — small, and the only one where a client can wait for ever. -3. **#40** and **#41** — together they are about half of a save's latency. -4. The two votes, in whichever order your plan already has them. -5. **#36**, **#37** and **#10** — polish, whenever. +0. **#43**, the watch gap: a bug, small to fix, and every saving client feels it. +1. **The durable worker queue** (our vote) — the last thing that makes a reverser deploy visible to + someone editing. +2. **#36**, **#37**, **#42** and **#10** — polish, whenever.