Skip to content

Commit 507ff33

Browse files
committed
feat(runway): Classify failed merges and name conflicting files so a request can fail as a merge conflict
1 parent 04a3fa0 commit 507ff33

34 files changed

Lines changed: 941 additions & 225 deletions

‎api/runway/messagequeue/proto/merge.proto‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ enum Outcome {
106106
FAILED = 2;
107107
}
108108

109+
// FailureKind classifies why a FAILED result failed, so a consumer can act on it
110+
// without parsing reason.
111+
enum FailureKind {
112+
// FAILURE_KIND_UNSPECIFIED is the zero value: the failure was not classified,
113+
// or the result did not fail.
114+
FAILURE_KIND_UNSPECIFIED = 0;
115+
// FAILURE_KIND_CONFLICT means the steps did not apply cleanly onto the merge
116+
// target; the author has to rebase before the request can succeed.
117+
FAILURE_KIND_CONFLICT = 1;
118+
// FAILURE_KIND_INVALID_REQUEST means the request itself was malformed or
119+
// unsupported, so retrying it unchanged fails the same way.
120+
FAILURE_KIND_INVALID_REQUEST = 2;
121+
}
122+
109123
// MergeResult is the payload Runway publishes to the corresponding signal queue
110124
// (merge-conflict-check-signal for a check, merge-signal for a merge) once a
111125
// request completes.
@@ -129,4 +143,11 @@ message MergeResult {
129143
// queue_name echoes the caller-provided queue name from the request, so the
130144
// consumer can route the result by queue without loading state first.
131145
string queue_name = 5;
146+
// failure_kind classifies a FAILED outcome. Unspecified on success, and when
147+
// the failure was not classified.
148+
FailureKind failure_kind = 6;
149+
// conflicting_files lists the paths that did not apply cleanly, when
150+
// failure_kind is FAILURE_KIND_CONFLICT and the merger could tell. Paths are
151+
// relative to the repository root.
152+
repeated string conflicting_files = 7;
132153
}

‎api/runway/messagequeue/protopb/merge.pb.go‎

Lines changed: 111 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎doc/rfc/hook-framework.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Delivery promise:
5252
- Partition key = subject id; per-subject order only.
5353
- Replay finding the target state already written → republish (idempotent). Beyond it → superseded; the event may be lost. Named, accepted gap.
5454
- RPC-caused transitions are at-most-once; needing the guarantee means publishing from the first queue-driven stage.
55-
- 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 512 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.
55+
- 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 512 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.
5656
- Opt-in per host via topic-key registration; a registered host never skips, so off and loss are distinguishable.
5757

5858
### Contract

‎runway/controller/merge/merge.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
126126
)
127127
}
128128
failed := &runwaymq.MergeResult{
129-
Id: request.GetId(),
130-
Outcome: runwaypb.Outcome_FAILED,
131-
Reason: err.Error(),
129+
Id: request.GetId(),
130+
Outcome: runwaypb.Outcome_FAILED,
131+
Reason: err.Error(),
132+
FailureKind: merger.FailureKind(err),
133+
ConflictingFiles: merger.ConflictingFiles(err),
132134
}
133135
// A merger that lands step by step reports the steps that landed before
134136
// the failure; they stay landed, so the caller must see them.

‎runway/controller/merge/merge_test.go‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,54 @@ func TestProcess_DeserializeError(t *testing.T) {
398398

399399
require.Error(t, controller.Process(context.Background(), delivery))
400400
}
401+
402+
func TestProcess_FailureKind(t *testing.T) {
403+
tests := []struct {
404+
name string
405+
err error
406+
wantKind runwaypb.FailureKind
407+
wantFiles []string
408+
}{
409+
{
410+
name: "conflict naming its files",
411+
err: &merger.ConflictError{Files: []string{"foo.go"}, Err: fmt.Errorf("conflict in foo.go: %w", merger.ErrConflict)},
412+
wantKind: runwaypb.FailureKind_FAILURE_KIND_CONFLICT,
413+
wantFiles: []string{"foo.go"},
414+
},
415+
{name: "conflict without files", err: fmt.Errorf("conflict: %w", merger.ErrConflict), wantKind: runwaypb.FailureKind_FAILURE_KIND_CONFLICT},
416+
{name: "invalid request", err: fmt.Errorf("bad strategy: %w", merger.ErrInvalidRequest), wantKind: runwaypb.FailureKind_FAILURE_KIND_INVALID_REQUEST},
417+
}
418+
for _, tt := range tests {
419+
t.Run(tt.name, func(t *testing.T) {
420+
ctrl := gomock.NewController(t)
421+
m := mergermock.NewMockMerger(ctrl)
422+
m.EXPECT().Merge(gomock.Any(), gomock.Any()).Return(nil, tt.err)
423+
factory := mergermock.NewMockFactory(ctrl)
424+
factory.EXPECT().For(merger.Config{QueueName: testQueue}).Return(m, nil)
425+
var gotPayload []byte
426+
pub := queuemock.NewMockPublisher(ctrl)
427+
pub.EXPECT().Publish(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
428+
func(_ context.Context, _ string, msg entityqueue.Message) error {
429+
gotPayload = msg.Payload
430+
return nil
431+
},
432+
)
433+
q := queuemock.NewMockQueue(ctrl)
434+
q.EXPECT().Publisher().Return(pub).AnyTimes()
435+
registry, err := consumer.NewTopicRegistry([]consumer.TopicConfig{
436+
{Key: runwaymq.TopicKeyMergeSignal, Name: "merge-signal", Queue: q},
437+
})
438+
require.NoError(t, err)
439+
controller := newController(t, factory, registry)
440+
req := &runwaymq.MergeRequest{Id: testID, QueueName: testQueue, Steps: []*runwaymq.MergeStep{{StepId: "step-1"}}}
441+
442+
require.NoError(t, controller.Process(context.Background(), newDelivery(t, ctrl, requestPayload(t, req))))
443+
444+
result := &runwaymq.MergeResult{}
445+
require.NoError(t, runwaymq.Unmarshal(gotPayload, result))
446+
assert.Equal(t, runwaypb.Outcome_FAILED, result.Outcome)
447+
assert.Equal(t, tt.wantKind, result.FailureKind)
448+
assert.Equal(t, tt.wantFiles, result.ConflictingFiles)
449+
})
450+
}
451+
}

‎runway/controller/mergeconflictcheck/mergeconflictcheck.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
126126
)
127127
}
128128
result = &runwaymq.MergeResult{
129-
Id: request.GetId(),
130-
Outcome: runwaypb.Outcome_FAILED,
131-
Reason: err.Error(),
129+
Id: request.GetId(),
130+
Outcome: runwaypb.Outcome_FAILED,
131+
Reason: err.Error(),
132+
FailureKind: merger.FailureKind(err),
133+
ConflictingFiles: merger.ConflictingFiles(err),
132134
}
133135
}
134136

‎runway/controller/mergeconflictcheck/mergeconflictcheck_test.go‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,54 @@ func TestProcess_DeserializeError(t *testing.T) {
340340

341341
require.Error(t, controller.Process(context.Background(), delivery))
342342
}
343+
344+
func TestProcess_FailureKind(t *testing.T) {
345+
tests := []struct {
346+
name string
347+
err error
348+
wantKind runwaypb.FailureKind
349+
wantFiles []string
350+
}{
351+
{
352+
name: "conflict naming its files",
353+
err: &merger.ConflictError{Files: []string{"foo.go"}, Err: fmt.Errorf("conflict in foo.go: %w", merger.ErrConflict)},
354+
wantKind: runwaypb.FailureKind_FAILURE_KIND_CONFLICT,
355+
wantFiles: []string{"foo.go"},
356+
},
357+
{name: "conflict without files", err: fmt.Errorf("conflict: %w", merger.ErrConflict), wantKind: runwaypb.FailureKind_FAILURE_KIND_CONFLICT},
358+
{name: "invalid request", err: fmt.Errorf("bad strategy: %w", merger.ErrInvalidRequest), wantKind: runwaypb.FailureKind_FAILURE_KIND_INVALID_REQUEST},
359+
}
360+
for _, tt := range tests {
361+
t.Run(tt.name, func(t *testing.T) {
362+
ctrl := gomock.NewController(t)
363+
m := mergermock.NewMockMerger(ctrl)
364+
m.EXPECT().CheckMergeability(gomock.Any(), gomock.Any()).Return(nil, tt.err)
365+
factory := mergermock.NewMockFactory(ctrl)
366+
factory.EXPECT().For(merger.Config{QueueName: testQueue}).Return(m, nil)
367+
var gotPayload []byte
368+
pub := queuemock.NewMockPublisher(ctrl)
369+
pub.EXPECT().Publish(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
370+
func(_ context.Context, _ string, msg entityqueue.Message) error {
371+
gotPayload = msg.Payload
372+
return nil
373+
},
374+
)
375+
q := queuemock.NewMockQueue(ctrl)
376+
q.EXPECT().Publisher().Return(pub).AnyTimes()
377+
registry, err := consumer.NewTopicRegistry([]consumer.TopicConfig{
378+
{Key: runwaymq.TopicKeyMergeConflictCheckSignal, Name: "merge-conflict-check-signal", Queue: q},
379+
})
380+
require.NoError(t, err)
381+
controller := newController(t, factory, registry)
382+
req := &runwaymq.MergeRequest{Id: testID, QueueName: testQueue, Steps: []*runwaymq.MergeStep{{StepId: "step-1"}}}
383+
384+
require.NoError(t, controller.Process(context.Background(), newDelivery(t, ctrl, requestPayload(t, req))))
385+
386+
result := &runwaymq.MergeResult{}
387+
require.NoError(t, runwaymq.Unmarshal(gotPayload, result))
388+
assert.Equal(t, runwaypb.Outcome_FAILED, result.Outcome)
389+
assert.Equal(t, tt.wantKind, result.FailureKind)
390+
assert.Equal(t, tt.wantFiles, result.ConflictingFiles)
391+
})
392+
}
393+
}

0 commit comments

Comments
 (0)