Skip to content
Open
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
21 changes: 21 additions & 0 deletions api/runway/messagequeue/proto/merge.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ enum Outcome {
FAILED = 2;
}

// FailureKind classifies why a FAILED result failed, so a consumer can act on it
// without parsing reason.
enum FailureKind {
// FAILURE_KIND_UNSPECIFIED is the zero value: the failure was not classified,
// or the result did not fail.
FAILURE_KIND_UNSPECIFIED = 0;
// FAILURE_KIND_CONFLICT means the steps did not apply cleanly onto the merge
// target; the author has to rebase before the request can succeed.
FAILURE_KIND_CONFLICT = 1;
// FAILURE_KIND_INVALID_REQUEST means the request itself was malformed or
// unsupported, so retrying it unchanged fails the same way.
FAILURE_KIND_INVALID_REQUEST = 2;
}

// MergeResult is the payload Runway publishes to the corresponding signal queue
// (merge-conflict-check-signal for a check, merge-signal for a merge) once a
// request completes.
Expand All @@ -129,4 +143,11 @@ message MergeResult {
// queue_name echoes the caller-provided queue name from the request, so the
// consumer can route the result by queue without loading state first.
string queue_name = 5;
// failure_kind classifies a FAILED outcome. Unspecified on success, and when
// the failure was not classified.
FailureKind failure_kind = 6;
// conflicting_files lists the paths that did not apply cleanly, when
// failure_kind is FAILURE_KIND_CONFLICT and the merger could tell. Paths are
// relative to the repository root.
repeated string conflicting_files = 7;
}
136 changes: 111 additions & 25 deletions api/runway/messagequeue/protopb/merge.pb.go

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

2 changes: 1 addition & 1 deletion doc/rfc/hook-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Delivery promise:
- Partition key = subject id; per-subject order only.
- Replay finding the target state already written → republish (idempotent). Beyond it → superseded; the event may be lost. Named, accepted gap.
- RPC-caused transitions are at-most-once; needing the guarantee means publishing from the first queue-driven stage.
- SubmitQueue request events follow the gateway's request summary, the status users see, rather than pipeline transitions, so a hook agrees with the UI even for a request whose start failed before the orchestrator saved it. Each status announces one event per change, so a hook retrying one change's failure never repeats another's. A finish is announced on every delivery of a log that restates it, which keeps the replay rule above: a failed publish fails the delivery and its redelivery republishes. `request.received` is published by the update that takes the request out of `accepting`, normally inside `Land`, which makes it RPC-caused and at-most-once: a failed publish is only counted. A later status announces it only when `Land` failed to record `accepted` at all. The events cross from the gateway to the orchestrator's hook stage, so their payload carries the change's URI, which never changes, and `request.failed` adds the failure's category and reason, cut to 8192 characters, and a duplicate's in-flight request id. The summary keeps the details a finish was first recorded with, so a restated finish republishes the same payload. The rest of the summary's metadata, which can hold internal diagnostics, stays out of the payload.
- SubmitQueue request events follow the gateway's request summary, the status users see, rather than pipeline transitions, so a hook agrees with the UI even for a request whose start failed before the orchestrator saved it. Each status announces one event per change, so a hook retrying one change's failure never repeats another's. A finish is announced on every delivery of a log that restates it, which keeps the replay rule above: a failed publish fails the delivery and its redelivery republishes. `request.received` is published by the update that takes the request out of `accepting`, normally inside `Land`, which makes it RPC-caused and at-most-once: a failed publish is only counted. A later status announces it only when `Land` failed to record `accepted` at all. The events cross from the gateway to the orchestrator's hook stage, so their payload carries the change's URI, which never changes, and `request.failed` adds the failure's category and reason, cut to 8192 characters, a duplicate's in-flight request id, and a merge conflict's paths. The summary keeps the details a finish was first recorded with, so a restated finish republishes the same payload. The rest of the summary's metadata, which can hold internal diagnostics, stays out of the payload.
- Opt-in per host via topic-key registration; a registered host never skips, so off and loss are distinguishable.

### Contract
Expand Down
2 changes: 1 addition & 1 deletion doc/rfc/runway/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Runway is stateless and the sole responder on the client's correlation id: Submi

Failures split into two classes:

- **Named terminal outcomes** — a merge conflict or an invalid request (an unknown/unsupported strategy, a malformed change URI, or an invalid `PROMOTE` composition). These can never succeed on retry, so the controller publishes a `FAILED` `MergeResult` (with a reason) and acks, rather than nacking. The merger surfaces them as the `ErrConflict` / `ErrInvalidRequest` sentinels; `IsTerminal` is the single classification point.
- **Named terminal outcomes** — a merge conflict, an invalid request (an unknown/unsupported strategy, a malformed change URI, or an invalid `PROMOTE` composition), or a merge the backend rejected without calling it a conflict (a `PROMOTE` target the branch moved past, a merge GitHub reports as failed). These can never succeed on retry, so the controller publishes a `FAILED` `MergeResult` (with a reason) and acks, rather than nacking. The merger surfaces them as the `ErrConflict` / `ErrInvalidRequest` / `ErrRejected` sentinels; `IsTerminal` is the single classification point. Only `ErrConflict` is classified as `FAILURE_KIND_CONFLICT`.

- **Infrastructure faults** — fetch/network/auth failures, a push rejected for a reason other than a moved tip, and so on. These are nacked for retry.

Expand Down
2 changes: 1 addition & 1 deletion runway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Each controller deserializes the `MergeRequest`, obtains a `Merger` for the requ

## Failure handling

A merge outcome the controller can name is published as a `FAILED` result and acked, not retried: a merge conflict (`merger.ErrConflict`) or an invalid request (`merger.ErrInvalidRequest` — unknown strategy, malformed change URI, invalid PROMOTE composition). The `merger.IsTerminal` helper draws that line. Any other error is an infrastructure fault and is nacked for retry.
A merge outcome the controller can name is published as a `FAILED` result and acked, not retried: a merge conflict (`merger.ErrConflict`), an invalid request (`merger.ErrInvalidRequest` — unknown strategy, malformed change URI, invalid PROMOTE composition), or a merge the backend rejected without calling it a conflict (`merger.ErrRejected`). The `merger.IsTerminal` helper draws that line. Any other error is an infrastructure fault and is nacked for retry.

Because Runway is stateless and the sole responder on the client's correlation id, a request that exhausts retries (or hits an unexpected fault) must still resolve the client. The inbound topics dead-letter by default; the [`dlq`](controller/dlq) reconciler drains those `_dlq` topics and republishes a `FAILED` `MergeResult` to the signal topic so the correlation id never hangs.
8 changes: 5 additions & 3 deletions runway/controller/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
)
}
failed := &runwaymq.MergeResult{
Id: request.GetId(),
Outcome: runwaypb.Outcome_FAILED,
Reason: err.Error(),
Id: request.GetId(),
Outcome: runwaypb.Outcome_FAILED,
Reason: err.Error(),
FailureKind: merger.FailureKind(err),
ConflictingFiles: merger.ConflictingFiles(err),
}
// A merger that lands step by step reports the steps that landed before
// the failure; they stay landed, so the caller must see them.
Expand Down
51 changes: 51 additions & 0 deletions runway/controller/merge/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,54 @@ func TestProcess_DeserializeError(t *testing.T) {

require.Error(t, controller.Process(context.Background(), delivery))
}

func TestProcess_FailureKind(t *testing.T) {
tests := []struct {
name string
err error
wantKind runwaypb.FailureKind
wantFiles []string
}{
{
name: "conflict naming its files",
err: &merger.ConflictError{Files: []string{"foo.go"}, Err: fmt.Errorf("conflict in foo.go: %w", merger.ErrConflict)},
wantKind: runwaypb.FailureKind_FAILURE_KIND_CONFLICT,
wantFiles: []string{"foo.go"},
},
{name: "conflict without files", err: fmt.Errorf("conflict: %w", merger.ErrConflict), wantKind: runwaypb.FailureKind_FAILURE_KIND_CONFLICT},
{name: "invalid request", err: fmt.Errorf("bad strategy: %w", merger.ErrInvalidRequest), wantKind: runwaypb.FailureKind_FAILURE_KIND_INVALID_REQUEST},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
m := mergermock.NewMockMerger(ctrl)
m.EXPECT().Merge(gomock.Any(), gomock.Any()).Return(nil, tt.err)
factory := mergermock.NewMockFactory(ctrl)
factory.EXPECT().For(merger.Config{QueueName: testQueue}).Return(m, nil)
var gotPayload []byte
pub := queuemock.NewMockPublisher(ctrl)
pub.EXPECT().Publish(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
func(_ context.Context, _ string, msg entityqueue.Message) error {
gotPayload = msg.Payload
return nil
},
)
q := queuemock.NewMockQueue(ctrl)
q.EXPECT().Publisher().Return(pub).AnyTimes()
registry, err := consumer.NewTopicRegistry([]consumer.TopicConfig{
{Key: runwaymq.TopicKeyMergeSignal, Name: "merge-signal", Queue: q},
})
require.NoError(t, err)
controller := newController(t, factory, registry)
req := &runwaymq.MergeRequest{Id: testID, QueueName: testQueue, Steps: []*runwaymq.MergeStep{{StepId: "step-1"}}}

require.NoError(t, controller.Process(context.Background(), newDelivery(t, ctrl, requestPayload(t, req))))

result := &runwaymq.MergeResult{}
require.NoError(t, runwaymq.Unmarshal(gotPayload, result))
assert.Equal(t, runwaypb.Outcome_FAILED, result.Outcome)
assert.Equal(t, tt.wantKind, result.FailureKind)
assert.Equal(t, tt.wantFiles, result.ConflictingFiles)
})
}
}
8 changes: 5 additions & 3 deletions runway/controller/mergeconflictcheck/mergeconflictcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
)
}
result = &runwaymq.MergeResult{
Id: request.GetId(),
Outcome: runwaypb.Outcome_FAILED,
Reason: err.Error(),
Id: request.GetId(),
Outcome: runwaypb.Outcome_FAILED,
Reason: err.Error(),
FailureKind: merger.FailureKind(err),
ConflictingFiles: merger.ConflictingFiles(err),
}
}

Expand Down
Loading
Loading