Skip to content
Merged
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
6 changes: 3 additions & 3 deletions doc/rfc/stovepipe/fix-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Stovepipe tracks three different facts: **the backend accepted work**, **a chang
| When | What Stovepipe retains | What the user sees |
|---|---|---|
| A registered executor accepts an issue opening | An `issue_repair` receipt with the executor's `fix_id`, and an association between that fix and the request. A fix can cover multiple openings or requests. | **Fix accepted** (`fix_submitted`), once per opening and executor. No link is promised. |
| The executor delivers `RecordFixResult` | An immutable report, then a fix-tracking task identifying that report. Without a callback, acceptance alone does not start polling. | No new history event: a callback is not evidence that a change exists. |
| The executor delivers `RecordFixReport` | An immutable report, then a fix-tracking task identifying that report. Without a callback, acceptance alone does not start polling. | No new history event: a callback is not evidence that a change exists. |
| The executor verifies a published or reused change | The first observation of its canonical URL, shared across all reports for the fix. | **Fix available** (`fix_available`), once per associated request, executor, fix and distinct URL. Other changes can still be pending. |

A callback can arrive before the submission receipt. The worker retains verified URLs even when no request is associated yet. Both sides write first, then read the other side: a new association checks for known URLs, and a new observation checks for associated requests. Replaying either step fills in missing history using the same event ID. It never rewrites **Fix accepted**. Read both events through the [request history API](request-history-api.md); `fix_available` is a history event, not a hook notification.

## Integrating a custom fixer

1. **Register and submit.** In host wiring, have `fixer.Factory.For` return a queue-local `Registration` with a stable ID and your `RepairExecutor`. Do not reuse that ID for another backend. `Submit` receives a batch and returns a `Submission` per accepted or deliberately skipped opening: return the backend run ID as `FixID`, or return a `SkipReason`, not both. Deduplicate backend submissions by issue opening across retries, even when the batch changes. If some items were accepted before an error, return their receipts alongside the error.
2. **Carry the run identity into each job.** A trusted callback producer calls `RecordFixResult` with the same `queue`, `executor_id`, and `fix_id` and an executor-owned JSON object encoded in `result_json` (at most 256 KiB). No request ID is needed. Omit `report_id` for a single report; use a stable occurrence ID for each additional report. Include the backend identifiers needed to resolve that occurrence in the payload. Retry an uncertain delivery with the same identity and serialized payload: whitespace is compacted, but object keys are not reordered. A different payload for the same occurrence returns `ALREADY_EXISTS`; progress is not reported by overwriting it.
3. **Verify, don't resubmit.** Implement the optional `ResultTracker` on the same registered executor. `ObserveFix` must be read-only and safe to repeat concurrently. Resolve the *specific* run or child job named by the report, not the latest change on a branch. Return `pending` while publication is outstanding, not an error. Include all verified canonical HTTP(S) links for that report in `ChangeURLs`, even while pending, and mark reused links in `ExistingChangeURLs`. A dry run has no verified change to return. Return a dependency error when the lookup itself fails.
2. **Carry the run identity into each job.** A trusted callback producer calls `RecordFixReport` with the same `queue`, `executor_id`, and `fix_id` and an executor-owned JSON object encoded in `payload_json` (at most 256 KiB). No request ID is needed. Omit `report_id` for a single report; use a stable occurrence ID for each additional report. Include the backend identifiers needed to resolve that occurrence in the payload. Retry an uncertain delivery with the same identity and serialized payload: whitespace is compacted, but object keys are not reordered. A different payload for the same occurrence returns `ALREADY_EXISTS`; progress is not reported by overwriting it.
3. **Verify, don't resubmit.** Implement the optional `ReportTracker` on the same registered executor. `ObserveFix` must be read-only and safe to repeat concurrently. Resolve the *specific* run or child job named by the report, not the latest change on a branch. Return `pending` while publication is outstanding, not an error. Include all verified canonical HTTP(S) links for that report in `ChangeURLs`, even while pending, and mark reused links in `ExistingChangeURLs`. A dry run has no verified change to return. Return a dependency error when the lookup itself fails.

For example, a formatter accepts two issues from one request under `fix_id=run-42`. Its dispatcher sends an unnamed report; its two workers report `job/17/completed` and `job/18/completed`, **both under `run-42`**. Worker 17 can finish before the dispatcher reports. If its output is not yet published, `ObserveFix` returns `pending`; when the backend links job 17 to PR 81, that request gets a link to PR 81 without waiting for job 18. If job 18 finds the same PR, history still shows one link. A different PR gets its own entry.

Expand Down
1 change: 1 addition & 0 deletions stovepipe/entity/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"build.go",
"build_issue.go",
"fix_report.go",
"get_issues_by_request_id.go",
"ingest.go",
"issue_history.go",
Expand Down
62 changes: 62 additions & 0 deletions stovepipe/entity/fix_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 entity

import "encoding/json"

// FixReport is an immutable callback from a repair executor; it need not describe a terminal outcome.
type FixReport struct {
// Queue scopes the repair submission and its reports.
Queue string
// ExecutorID scopes the opaque FixID within the queue.
ExecutorID string
// FixID is the executor-issued identifier shared by the associated submissions.
FixID string
// Payload is an executor-owned JSON object, at most 256 KiB.
Payload json.RawMessage
}

// FixState is the observed lifecycle of one accepted fix.
type FixState string

const (
FixStateSkipped FixState = "skipped"
FixStatePending FixState = "pending"
FixStateSucceeded FixState = "succeeded"
FixStateFailed FixState = "failed"
FixStateInconclusive FixState = "inconclusive"
)

// FixObservation is a complete snapshot of an executor's known outcome.
type FixObservation struct {
// State is pending until the executor has a terminal outcome.
State FixState `json:"state"`
// ChangeURLs contains all known published or existing changes for this fix.
ChangeURLs []string `json:"change_urls,omitempty"`
// ExistingChangeURLs is the subset identified as pre-existing rather than newly published.
ExistingChangeURLs []string `json:"existing_change_urls,omitempty"`
// Reason is a stable outcome detail, empty when none is available.
Reason string `json:"reason,omitempty"`
}

// FixTrackingState is the versioned progress for an immutable fix report.
type FixTrackingState struct {
// FixObservation is the most recently recorded outcome.
FixObservation
// NextCheckAt is the earliest time for another check, in Unix milliseconds. Zero for terminal outcomes.
NextCheckAt int64 `json:"next_check_at,omitempty"`
// Version is the number of recorded observations. Zero means no observation has been recorded.
Version int32 `json:"-"`
}
1 change: 1 addition & 0 deletions stovepipe/extension/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"build_issue_store.go",
"build_store.go",
"fix_report_store.go",
"issue_log_store.go",
"issue_repair_store.go",
"issue_state_store.go",
Expand Down
2 changes: 2 additions & 0 deletions stovepipe/extension/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ The MySQL primary key contains the queue, build ID, task ID, and unit ID directl

`BuildIssue.FixID` is the legacy single-executor repair association. An empty ID means no association is recorded. `Update` uses the existing entity CAS convention: it guards `oldVersion` and writes `newVersion`, returning `ErrVersionMismatch` for a stale or missing record. The caller owns version arithmetic and repair policy; storage does not enforce a per-build submission limit. Observation identity and membership survive recovery.

`FixReportStore` retains one immutable result per `(queue, executor ID, fix ID)`. It is independent of `issue_repair` so a callback can arrive before the submission is committed. A queue-scoped `Get` joins the two by executor and fix ID without an index over issue memberships. A separate, versioned tracking snapshot is updated without rewriting the callback.

`IssueRepairStore` retains versioned submission state keyed by the complete opening identity and executor ID. Pending rows have empty fix IDs and skip reasons. Create never overwrites existing state; Update replaces a snapshot guarded by its version. The controller creates pending rows and owns submission outcomes; executors own metadata and must preserve other fields when updating. Both writers reload on version conflicts before reapplying their edits. Fix IDs are not unique: an executor can accept multiple issues in one external request. Executor-owned metadata remains a `map[string]string` in Go and is serialized to the non-null JSON `metadata` column. Nil and empty maps are equivalent; empty metadata is stored as `{}`. String values may contain serialized JSON without interpretation by the store. Apply `mysql/schema/issue_repair.sql` before deploying the new readers and writers. Host adapters own backend-specific dispatch limits. The schema's `CREATE TABLE IF NOT EXISTS` does not alter existing tables.

## Request metadata
Expand Down
35 changes: 35 additions & 0 deletions stovepipe/extension/storage/fix_report_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 storage

//go:generate mockgen -source=fix_report_store.go -destination=mock/fix_report_store_mock.go -package=mock

import (
"context"

"github.com/uber/submitqueue/stovepipe/entity"
)

// FixReportStore retains immutable executor reports within one queue.
type FixReportStore interface {
// Create returns ErrAlreadyExists if the executor and fix ID already have a report.
Create(context.Context, entity.FixReport) error
// Get returns ErrNotFound when the key has no recorded report.
Get(ctx context.Context, executorID, fixID string) (entity.FixReport, error)
// GetTrackingState yields a zero snapshot for an existing report not yet checked.
GetTrackingState(ctx context.Context, executorID, fixID string) (entity.FixTrackingState, error)
// UpdateTrackingState replaces progress without changing the callback payload.
UpdateTrackingState(ctx context.Context, executorID, fixID string, snapshot entity.FixTrackingState, oldVersion, newVersion int32) error
}
1 change: 1 addition & 0 deletions stovepipe/extension/storage/mock/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"build_issue_store_mock.go",
"build_store_mock.go",
"fix_report_store_mock.go",
"issue_log_store_mock.go",
"issue_repair_store_mock.go",
"issue_state_store_mock.go",
Expand Down
100 changes: 100 additions & 0 deletions stovepipe/extension/storage/mock/fix_report_store_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions stovepipe/extension/storage/mock/storage_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions stovepipe/extension/storage/mysql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"build_issue_store.go",
"build_store.go",
"fix_report_store.go",
"issue_log_store.go",
"issue_repair_store.go",
"issue_state_store.go",
Expand Down Expand Up @@ -45,6 +46,7 @@ go_test(
"build_issue_store_test.go",
"build_issue_update_test.go",
"build_store_test.go",
"fix_report_store_test.go",
"issue_log_store_test.go",
"issue_repair_store_test.go",
"issue_state_list_test.go",
Expand Down
Loading
Loading