Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/rfc/stovepipe/fix-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ For example, a formatter accepts two issues from one request under `fix_id=run-4

## Retry and deployment boundaries

Each report has its own poll budget and terminal outcome (`succeeded`, `failed`, `skipped`, or `inconclusive`). One terminal report does not close the fix to later reports. Progress for the fix is versioned together so concurrent reports cannot erase each other's verified links. An unavailable tracker or an exhausted polling budget yields `inconclusive`; the dead-letter worker preserves verified links without calling the executor again.
Each report has its own poll budget and terminal outcome (`succeeded`, `failed`, `skipped`, or `inconclusive`). One terminal report does not close the fix to later reports. Progress for the fix is versioned together so concurrent reports cannot erase each other's verified links. An unavailable tracker or an exhausted polling budget yields `inconclusive`; the [dead-letter worker](../../../stovepipe/controller/fixtrack/README.md) preserves verified links without calling the executor again.

The [reference host](../../../service/stovepipe/README.md) uses a no-op fixer and restricts the callback RPC to loopback. A custom host must authorize its executor workloads. Deploy the [storage schema](../../../stovepipe/extension/storage/README.md), RPC writers, and primary and dead-letter workers before enabling callbacks. In particular, drain workers that do not understand `report_id` before sending named reports: they interpret a named task as the unnamed report.
1 change: 1 addition & 0 deletions service/stovepipe/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_library(
"//stovepipe/controller/buildsignal:go_default_library",
"//stovepipe/controller/dlq:go_default_library",
"//stovepipe/controller/fix:go_default_library",
"//stovepipe/controller/fixtrack:go_default_library",
"//stovepipe/controller/issueagemetrics:go_default_library",
"//stovepipe/controller/issuetrack:go_default_library",
"//stovepipe/controller/periodicmetrics:go_default_library",
Expand Down
20 changes: 20 additions & 0 deletions service/stovepipe/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"github.com/uber/submitqueue/stovepipe/controller/buildsignal"
"github.com/uber/submitqueue/stovepipe/controller/dlq"
"github.com/uber/submitqueue/stovepipe/controller/fix"
"github.com/uber/submitqueue/stovepipe/controller/fixtrack"
"github.com/uber/submitqueue/stovepipe/controller/issueagemetrics"
"github.com/uber/submitqueue/stovepipe/controller/issuetrack"
"github.com/uber/submitqueue/stovepipe/controller/periodicmetrics"
Expand Down Expand Up @@ -498,6 +499,11 @@ func registerPrimaryControllers(
}
count++

if err := c.Register(fixtrack.NewController(store, repairExecutors, "stovepipe-fixtrack")); err != nil {
return count, fmt.Errorf("failed to register fix tracking controller: %w", err)
}
count++

projectController := projectanalysis.NewController(logger, scope, store, materializer, projectstatusnoop.New(), projectissuesnoop.New(), registry, stovepipemq.TopicKeyProjectAnalysis, "stovepipe-projectanalysis")
if err := c.Register(projectController); err != nil {
return count, fmt.Errorf("failed to register projectanalysis controller: %w", err)
Expand Down Expand Up @@ -562,6 +568,11 @@ func registerDLQControllers(
}
count++

if err := c.Register(fixtrack.NewDLQController(logger, store, dlq.TopicKey(stovepipemq.TopicKeyFixTrack), "stovepipe-fixtrack-dlq")); err != nil {
return count, fmt.Errorf("register fix tracking DLQ: %w", err)
}
count++

fixDLQController := fix.NewDLQController(logger, scope, store, materializer, repairExecutors, dlq.TopicKey(stovepipemq.TopicKeyFix), "stovepipe-fix-dlq")
if err := c.Register(fixDLQController); err != nil {
return count, fmt.Errorf("failed to register fix dlq controller: %w", err)
Expand Down Expand Up @@ -602,6 +613,7 @@ func newTopicRegistry(q extqueue.Queue, subscriberName string) (consumer.TopicRe
issueAgeSubscription.Retry.MaxAttempts = 0
issueAgeSubscription.DLQ.Enabled = false

fixTrackingSubscription := extqueue.SingleMessageSubscriptionConfig(subscriberName, "stovepipe-fixtrack")
return consumer.NewTopicRegistry([]consumer.TopicConfig{
{
Key: stovepipemq.TopicKeyQueueHealthMetrics,
Expand Down Expand Up @@ -701,6 +713,14 @@ func newTopicRegistry(q extqueue.Queue, subscriberName string) (consumer.TopicRe
Queue: q,
Subscription: extqueue.DLQSubscriptionConfig(subscriberName, "stovepipe-issuetrack-dlq"),
},
{Key: dlq.TopicKey(stovepipemq.TopicKeyFixTrack), Name: "fixtrack_dlq", Queue: q,
Subscription: extqueue.DLQSubscriptionConfig(subscriberName, "stovepipe-fixtrack-dlq")},
{
Key: stovepipemq.TopicKeyFixTrack,
Name: "fixtrack",
Queue: q,
Subscription: fixTrackingSubscription,
},
{
Key: stovepipemq.TopicKeyFix,
Name: "fix",
Expand Down
7 changes: 6 additions & 1 deletion stovepipe/controller/fixtrack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["fixtrack.go"],
srcs = [
"dlq.go",
"fixtrack.go",
],
importpath = "github.com/uber/submitqueue/stovepipe/controller/fixtrack",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -12,6 +15,7 @@ go_library(
"//stovepipe/entity:go_default_library",
"//stovepipe/extension/fixer:go_default_library",
"//stovepipe/extension/storage:go_default_library",
"@org_uber_go_zap//:go_default_library",
],
)

Expand All @@ -30,5 +34,6 @@ go_test(
"//stovepipe/extension/storage/mock:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@org_uber_go_mock//gomock:go_default_library",
"@org_uber_go_zap//:go_default_library",
],
)
2 changes: 2 additions & 0 deletions stovepipe/controller/fixtrack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
A fix result schedules one durable task per queue, executor ID, and fix ID. Tracking observes existing work through the executor's optional `ResultTracker` capability. It never submits a repair or depends on the per-issue submission receipt being written. An observed outcome is a complete snapshot, including all known change URLs, and does not imply the original issues were fixed.

While publication is pending, the controller durably saves progress and postpones that delivery with backoff from 30 seconds up to 15 minutes. The next check time survives redelivery. A terminal outcome stops polling; an unavailable tracker or exhausted pending-check budget produces an inconclusive outcome, not a failed fix. Storage and backend errors follow the host's retry classifier. Optimistic locking prevents a stale worker from overwriting progress.

A rejected task or exhausted infrastructure retry goes to the terminal reconciler, which stores `inconclusive` without calling the executor again. Dead-letter recovery preserves discovered links and never overwrites a terminal observation. Its storage retries are unlimited.
67 changes: 67 additions & 0 deletions stovepipe/controller/fixtrack/dlq.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) 2026 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fixtrack

import (
"context"

entityqueue "github.com/uber/submitqueue/platform/base/messagequeue"
"github.com/uber/submitqueue/platform/consumer"
mq "github.com/uber/submitqueue/stovepipe/core/messagequeue"
"github.com/uber/submitqueue/stovepipe/entity"
"github.com/uber/submitqueue/stovepipe/extension/storage"
"go.uber.org/zap"
)

type terminalController struct {
logger *zap.SugaredLogger
stores storage.Factory
topic consumer.TopicKey
group string
}

// NewDLQController retains terminal evidence without re-invoking the executor. The host must retry storage errors.
func NewDLQController(logger *zap.SugaredLogger, stores storage.Factory, topic consumer.TopicKey, group string) consumer.Controller {
return &terminalController{logger: logger, stores: stores, topic: topic, group: group}
}
func (c *terminalController) Name() string { return string(c.topic) }
func (c *terminalController) TopicKey() consumer.TopicKey { return c.topic }
func (c *terminalController) ConsumerGroup() string { return c.group }
func (c *terminalController) Process(ctx context.Context, delivery consumer.Delivery) error {
msg := delivery.Message()
var key mq.FixTrack
if err := mq.Unmarshal(msg.Payload, &key); err != nil || entityqueue.ValidatePayloadQueue(msg, key.QueueName) != nil || key.ExecutorId == "" || key.FixId == "" {
c.logger.Errorw("discarding malformed fix tracking dead letter", "message_id", msg.ID)
return nil
}
scoped, err := c.stores.For(storage.Config{QueueName: key.QueueName})
if err != nil {
return err
}
store := scoped.GetFixResultStore()
progress, err := store.GetTrackingState(ctx, key.ExecutorId, key.FixId)
if storage.IsNotFound(err) {
c.logger.Warnw("no callback for dead letter", "queue", key.QueueName, "executor_id", key.ExecutorId, "fix_id", key.FixId)
return nil
}
if err != nil {
return err
}
if progress.State != "" && progress.State != entity.FixStatePending {
return nil
}
progress.State, progress.Reason, progress.NextCheckAt = entity.FixStateInconclusive, "tracking_abandoned", 0
return store.UpdateTrackingState(ctx, key.ExecutorId, key.FixId, progress, progress.Version, progress.Version+1)
}
39 changes: 39 additions & 0 deletions stovepipe/controller/fixtrack/fixtrack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/uber/submitqueue/stovepipe/extension/storage"
storagemock "github.com/uber/submitqueue/stovepipe/extension/storage/mock"
"go.uber.org/mock/gomock"
"go.uber.org/zap"
)

func TestFixTrack(t *testing.T) {
Expand Down Expand Up @@ -95,3 +96,41 @@ func TestFixTrack(t *testing.T) {
})
}
}

func TestDeadLetterRetainsOutcome(t *testing.T) {
pending := entity.FixTrackingState{FixObservation: entity.FixObservation{State: entity.FixStatePending, ChangeURLs: []string{"https://example.org/pr/3"}}, NextCheckAt: 1000, Version: 3}
terminal := pending
terminal.State, terminal.Reason, terminal.NextCheckAt = entity.FixStateInconclusive, "tracking_abandoned", 0
for _, tt := range []struct {
name string
current entity.FixTrackingState
write bool
err error
}{
{"rejected before first observation", entity.FixTrackingState{}, true, nil},
{"exhausted retries preserve links", pending, true, nil},
{"lost CAS retries instead of acknowledging", pending, true, storage.ErrVersionMismatch},
{"duplicate delivery preserves winner", terminal, false, nil},
} {
t.Run(tt.name, func(t *testing.T) {
m := gomock.NewController(t)
stores := storagemock.NewMockFactory(m)
scoped := storagemock.NewMockStorage(m)
store := storagemock.NewMockFixResultStore(m)
d := consumermock.NewMockDelivery(m)
payload, err := mq.Marshal(&mq.FixTrack{QueueName: "q", ExecutorId: "e", FixId: "f"})
require.NoError(t, err)
d.EXPECT().Message().Return(entityqueue.Message{Tenant: "q", Payload: payload})
stores.EXPECT().For(storage.Config{QueueName: "q"}).Return(scoped, nil)
scoped.EXPECT().GetFixResultStore().Return(store)
store.EXPECT().GetTrackingState(gomock.Any(), "e", "f").Return(tt.current, nil)
if tt.write {
want := tt.current
want.State, want.Reason, want.NextCheckAt = entity.FixStateInconclusive, "tracking_abandoned", 0
store.EXPECT().UpdateTrackingState(gomock.Any(), "e", "f", want, tt.current.Version, tt.current.Version+1).Return(tt.err)
}
c := NewDLQController(zap.NewNop().Sugar(), stores, "fixtrack_dlq", "dlq")
require.ErrorIs(t, c.Process(t.Context(), d), tt.err)
})
}
}
17 changes: 17 additions & 0 deletions test/integration/stovepipe/extension/storage/mysql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_test(
"build_issue_list_test.go",
"build_issue_test.go",
"build_issue_update_test.go",
"fix_tracking_test.go",
"issue_log_test.go",
"issue_state_list_test.go",
"issue_state_test.go",
Expand All @@ -25,18 +26,32 @@ go_test(
],
data = [
"docker-compose.yml",
"//platform/extension/messagequeue/mysql/schema",
"//stovepipe/extension/storage/mysql/schema",
],
tags = [
"integration",
"requires-network",
],
deps = [
"//platform/consumer:go_default_library",
"//platform/consumer/mock:go_default_library",
"//platform/errs:go_default_library",
"//platform/errs/yarpc:go_default_library",
"//platform/extension/consumergate/noop:go_default_library",
"//platform/extension/messagequeue:go_default_library",
"//platform/extension/messagequeue/mysql:go_default_library",
"//stovepipe/controller:go_default_library",
"//stovepipe/controller/dlq:go_default_library",
"//stovepipe/controller/fixtrack:go_default_library",
"//stovepipe/core/issuelog:go_default_library",
"//stovepipe/core/messagequeue:go_default_library",
"//stovepipe/core/queuelog:go_default_library",
"//stovepipe/core/queuestate:go_default_library",
"//stovepipe/core/requestlog:go_default_library",
"//stovepipe/entity:go_default_library",
"//stovepipe/extension/fixer:go_default_library",
"//stovepipe/extension/fixer/mock:go_default_library",
"//stovepipe/extension/sourcecontrol:go_default_library",
"//stovepipe/extension/sourcecontrol/fake:go_default_library",
"//stovepipe/extension/sourcecontrol/mock:go_default_library",
Expand All @@ -51,5 +66,7 @@ go_test(
"@com_github_stretchr_testify//suite:go_default_library",
"@com_github_uber_go_tally//:go_default_library",
"@org_uber_go_mock//gomock:go_default_library",
"@org_uber_go_yarpc//yarpcerrors:go_default_library",
"@org_uber_go_zap//zaptest:go_default_library",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2025 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mysql

import (
"database/sql"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/uber-go/tally"
"github.com/uber/submitqueue/platform/consumer"
consumermock "github.com/uber/submitqueue/platform/consumer/mock"
"github.com/uber/submitqueue/platform/errs"
yarpcclassifier "github.com/uber/submitqueue/platform/errs/yarpc"
"github.com/uber/submitqueue/platform/extension/consumergate/noop"
extqueue "github.com/uber/submitqueue/platform/extension/messagequeue"
sqlqueue "github.com/uber/submitqueue/platform/extension/messagequeue/mysql"
"github.com/uber/submitqueue/stovepipe/controller"
"github.com/uber/submitqueue/stovepipe/controller/dlq"
"github.com/uber/submitqueue/stovepipe/controller/fixtrack"
mq "github.com/uber/submitqueue/stovepipe/core/messagequeue"
"github.com/uber/submitqueue/stovepipe/entity"
"github.com/uber/submitqueue/stovepipe/extension/fixer"
fixermock "github.com/uber/submitqueue/stovepipe/extension/fixer/mock"
"github.com/uber/submitqueue/stovepipe/extension/storage"
"go.uber.org/mock/gomock"
"go.uber.org/yarpc/yarpcerrors"
"go.uber.org/zap/zaptest"
)

func testFixTrackingDeadLetter(t *testing.T, db *sql.DB, stores storage.Factory) {
const tenant = "repairs"
logger := zaptest.NewLogger(t)
q, err := sqlqueue.NewQueue(sqlqueue.Params{DB: db, Logger: logger, MetricsScope: tally.NoopScope, Tenants: []string{tenant}})
require.NoError(t, err)
defer q.Close()
sub := extqueue.SingleMessageSubscriptionConfig("worker", "observe")
sub.Retry.MaxAttempts = 2
sub.Retry.InitialBackoffMs = 1
sub.Retry.MaxBackoffMs = 10
sub.PollIntervalMs = 10
sub.PartitionDiscoveryIntervalMs = 10
dead := extqueue.DLQSubscriptionConfig("worker", "recover")
dead.PartitionDiscoveryIntervalMs = 10
dead.PollIntervalMs = 10
key := mq.TopicKeyFixTrack
topic := "fixtrack"
registry, err := consumer.NewTopicRegistry([]consumer.TopicConfig{{Key: key, Name: topic, Queue: q, Subscription: sub}, {Key: dlq.TopicKey(key), Name: topic + sub.DLQ.TopicSuffix, Queue: q, Subscription: dead}})
require.NoError(t, err)
deliveries, err := q.Subscriber().Subscribe(t.Context(), topic+sub.DLQ.TopicSuffix, dead)
require.NoError(t, err)
mocks := gomock.NewController(t)
factory := fixermock.NewMockFactory(mocks)
observer := fixermock.NewMockResultTracker(mocks)
executor := struct {
fixer.RepairExecutor
fixer.ResultTracker
}{fixermock.NewMockRepairExecutor(mocks), observer}
factory.EXPECT().For(fixer.Config{QueueName: tenant}).Return([]fixer.Registration{{ID: "rep", Executor: executor}}, nil).AnyTimes()
worker := consumer.New(logger.Sugar(), tally.NoopScope, registry, errs.NewClassifierProcessor(yarpcclassifier.Classifier), noop.New())
require.NoError(t, worker.Register(fixtrack.NewController(stores, factory, sub.ConsumerGroup)))
require.NoError(t, worker.Start(t.Context()))
defer func() { require.NoError(t, worker.Stop(time.Minute.Milliseconds())) }()
record := controller.NewRecordFixResultController(stores, []string{tenant}, registry)
recoverer := fixtrack.NewDLQController(logger.Sugar(), stores, dlq.TopicKey(key), dead.ConsumerGroup)
scoped, err := stores.For(storage.Config{QueueName: tenant})
require.NoError(t, err)
for _, tt := range []struct {
id string
err error
calls int
}{{"denied", yarpcerrors.PermissionDeniedErrorf("denied"), 1}, {"exhausted", yarpcerrors.UnavailableErrorf("down"), sub.Retry.MaxAttempts}} {
report := entity.FixResult{Queue: tenant, FixID: tt.id, ExecutorID: "rep", ResultJSON: []byte(`{}`)}
observer.EXPECT().ObserveFix(gomock.Any(), report).Return(entity.FixObservation{}, tt.err).Times(tt.calls)
require.NoError(t, record.RecordFixResult(t.Context(), report))
delivery := <-deliveries
require.NotNil(t, delivery)
d := consumermock.NewMockDelivery(mocks)
d.EXPECT().Message().Return(delivery.Message()).Times(2)
require.NoError(t, recoverer.Process(t.Context(), d))
require.NoError(t, recoverer.Process(t.Context(), d))
require.NoError(t, delivery.Ack(t.Context()))
progress, err := scoped.GetFixResultStore().GetTrackingState(t.Context(), "rep", tt.id)
require.NoError(t, err)
require.Equal(t, entity.FixStateInconclusive, progress.State)
require.EqualValues(t, 1, progress.Version)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func TestMySQLStorage(t *testing.T) {
return backend.For(config.QueueName)
}).AnyTimes()

t.Run("FixTrackingDeadLetter", func(t *testing.T) {
testutil.ApplySchema(t, log, db, testutil.SchemaDir("platform/extension/messagequeue/mysql/schema"))
testFixTrackingDeadLetter(t, db, factory)
})

t.Run("FixResult", func(t *testing.T) {
result := entity.FixResult{Queue: "result/main", ExecutorID: "repair", FixID: "AbC", ResultJSON: json.RawMessage(`{"results":[]}`)}
bound, err := backend.For(result.Queue)
Expand Down