diff --git a/internal/contracts/state/v1/state.pb.go b/internal/contracts/state/v1/state.pb.go index e30733539..aaf0f4835 100644 --- a/internal/contracts/state/v1/state.pb.go +++ b/internal/contracts/state/v1/state.pb.go @@ -1087,8 +1087,15 @@ type Task struct { // review_payload is the JSON-encoded review unit the remediate workflow's // current run must address (docs/prds/pr-review-remediation.md decision 4). ReviewPayload string `protobuf:"bytes,27,opt,name=review_payload,json=reviewPayload,proto3" json:"review_payload,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // The workflow pin: the exact definition version this run started with. + // It has to cross the wire for the daemon's digest guard to hold, because + // a retry reads the task back over this contract before deciding whether + // to reuse the pinned YAML (docs/prds/runtime-control-plane.md:95). + WorkflowDefinitionVersion int64 `protobuf:"varint,28,opt,name=workflow_definition_version,json=workflowDefinitionVersion,proto3" json:"workflow_definition_version,omitempty"` + WorkflowDefinitionDigest string `protobuf:"bytes,29,opt,name=workflow_definition_digest,json=workflowDefinitionDigest,proto3" json:"workflow_definition_digest,omitempty"` + WorkflowDefinitionYaml string `protobuf:"bytes,30,opt,name=workflow_definition_yaml,json=workflowDefinitionYaml,proto3" json:"workflow_definition_yaml,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Task) Reset() { @@ -1310,6 +1317,27 @@ func (x *Task) GetReviewPayload() string { return "" } +func (x *Task) GetWorkflowDefinitionVersion() int64 { + if x != nil { + return x.WorkflowDefinitionVersion + } + return 0 +} + +func (x *Task) GetWorkflowDefinitionDigest() string { + if x != nil { + return x.WorkflowDefinitionDigest + } + return "" +} + +func (x *Task) GetWorkflowDefinitionYaml() string { + if x != nil { + return x.WorkflowDefinitionYaml + } + return "" +} + // Event mirrors internal/events.Event. Data is carried as a JSON object // string (matching the store's own on-disk representation) rather than // google.protobuf.Struct, to stay a direct mirror of the existing column. @@ -6983,7 +7011,7 @@ const file_state_v1_state_proto_rawDesc = "" + "\x1aReactivateIdentityResponse\x12.\n" + "\bidentity\x18\x01 \x01(\v2\x12.state.v1.IdentityR\bidentity\"H\n" + "\x16RetireIdentityResponse\x12.\n" + - "\bidentity\x18\x01 \x01(\v2\x12.state.v1.IdentityR\bidentity\"\xae\x06\n" + + "\bidentity\x18\x01 \x01(\v2\x12.state.v1.IdentityR\bidentity\"\xe6\a\n" + "\x04Task\x12\x0e\n" + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" + "\x05owner\x18\x02 \x01(\tR\x05owner\x12\x12\n" + @@ -7020,7 +7048,10 @@ const file_state_v1_state_proto_rawDesc = "" + "created_at\x18\x19 \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x129\n" + "\n" + "updated_at\x18\x1a \x01(\v2\x1a.google.protobuf.TimestampR\tupdatedAt\x12%\n" + - "\x0ereview_payload\x18\x1b \x01(\tR\rreviewPayload\"\x9b\x02\n" + + "\x0ereview_payload\x18\x1b \x01(\tR\rreviewPayload\x12>\n" + + "\x1bworkflow_definition_version\x18\x1c \x01(\x03R\x19workflowDefinitionVersion\x12<\n" + + "\x1aworkflow_definition_digest\x18\x1d \x01(\tR\x18workflowDefinitionDigest\x128\n" + + "\x18workflow_definition_yaml\x18\x1e \x01(\tR\x16workflowDefinitionYaml\"\x9b\x02\n" + "\x05Event\x12\x0e\n" + "\x02id\x18\x01 \x01(\x03R\x02id\x12*\n" + "\x02at\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\x02at\x12\x12\n" + diff --git a/internal/infrastructure/staterpc/conformance_test.go b/internal/infrastructure/staterpc/conformance_test.go index 3a9bcf644..986c1d1b2 100644 --- a/internal/infrastructure/staterpc/conformance_test.go +++ b/internal/infrastructure/staterpc/conformance_test.go @@ -95,6 +95,13 @@ func TestStateStoreConformance(t *testing.T) { task.Plan = "the plan" task.Status = "running" task.PRNumber = 401 + // The workflow pin is what a retry re-reads instead of resolving the + // active control-plane resource again (docs/prds/runtime-control-plane.md:95). + // A wire hop that drops it leaves the daemon's digest guard dead, so + // the battery carries it through Update and back out of TaskByID. + task.WorkflowDefinitionVersion = 7 + task.WorkflowDefinitionDigest = "sha256:beef" + task.WorkflowDefinitionYAML = "name: implement\nsteps: []\n" if err := c.Update(ctx, task); err != nil { t.Fatalf("Update: %v", err) } @@ -134,6 +141,11 @@ func TestStateStoreConformance(t *testing.T) { if err != nil || got == nil || got.Plan != "the plan" { t.Fatalf("TaskByID: %+v %v", got, err) } + if got.WorkflowDefinitionVersion != 7 || got.WorkflowDefinitionDigest != "sha256:beef" || + got.WorkflowDefinitionYAML != "name: implement\nsteps: []\n" { + t.Errorf("workflow pin after round trip = (%d, %q, %q), want (7, \"sha256:beef\", the YAML); a dropped pin makes each retry re-resolve the active definition", + got.WorkflowDefinitionVersion, got.WorkflowDefinitionDigest, got.WorkflowDefinitionYAML) + } byIssue, err := c.TaskByIssue(ctx, task.Owner, task.Repo, task.IssueNumber) if err != nil || byIssue == nil || byIssue.ID != task.ID { t.Fatalf("TaskByIssue: %+v %v", byIssue, err) diff --git a/internal/infrastructure/staterpc/values.go b/internal/infrastructure/staterpc/values.go index d299ac49a..126293661 100644 --- a/internal/infrastructure/staterpc/values.go +++ b/internal/infrastructure/staterpc/values.go @@ -67,7 +67,10 @@ func taskProto(t *task.Task) *pb.Task { //nolint:dupl // mirror-image field-by-f WatchCommentId: t.WatchCommentID, Source: t.Source, Identity: t.Identity, BindingId: t.BindingID, BindingVersion: int64(t.BindingVersion), CreatedAt: timestamp(t.CreatedAt), UpdatedAt: timestamp(t.UpdatedAt), - ReviewPayload: t.ReviewPayload, + ReviewPayload: t.ReviewPayload, + WorkflowDefinitionVersion: t.WorkflowDefinitionVersion, + WorkflowDefinitionDigest: t.WorkflowDefinitionDigest, + WorkflowDefinitionYaml: t.WorkflowDefinitionYAML, } } @@ -84,7 +87,10 @@ func taskValue(t *pb.Task) *task.Task { //nolint:dupl // see taskProto above WatchCommentID: t.WatchCommentId, Source: t.Source, Identity: t.Identity, BindingID: t.BindingId, BindingVersion: int(t.BindingVersion), CreatedAt: timeValue(t.CreatedAt), UpdatedAt: timeValue(t.UpdatedAt), - ReviewPayload: t.ReviewPayload, + ReviewPayload: t.ReviewPayload, + WorkflowDefinitionVersion: t.WorkflowDefinitionVersion, + WorkflowDefinitionDigest: t.WorkflowDefinitionDigest, + WorkflowDefinitionYAML: t.WorkflowDefinitionYaml, } } diff --git a/internal/infrastructure/staterpc/values_parity_test.go b/internal/infrastructure/staterpc/values_parity_test.go new file mode 100644 index 000000000..c2e9e56f8 --- /dev/null +++ b/internal/infrastructure/staterpc/values_parity_test.go @@ -0,0 +1,49 @@ +package staterpc + +import ( + "reflect" + "testing" + "time" + + "github.com/samcharles93/archie-core/internal/domain/workflow/task" +) + +// TestTaskProtoCarriesEveryDomainField fills every field of task.Task with a +// distinct non-zero value and requires the proto round trip to return it +// unchanged. taskProto/taskValue assign field by field, so a field added to +// the domain type and forgotten on the wire is otherwise invisible: the task +// still crosses, just with that field silently zeroed. This test fails for the +// forgotten field by name rather than leaving it to a caller to discover in +// production (archie-core-zf8h). +func TestTaskProtoCarriesEveryDomainField(t *testing.T) { + stamp := time.Date(2026, 9, 21, 10, 30, 0, 0, time.UTC) + + want := &task.Task{} + v := reflect.ValueOf(want).Elem() + for i := range v.NumField() { + field := v.Field(i) + switch { + case field.Type() == reflect.TypeFor[time.Time](): + field.Set(reflect.ValueOf(stamp.Add(time.Duration(i) * time.Hour))) + case field.Kind() == reflect.String: + field.SetString(v.Type().Field(i).Name + "-value") + case field.CanInt(): + field.SetInt(int64(i) + 1) + default: + t.Fatalf("field %s has kind %s, which this test does not know how to fill; extend it alongside the field", v.Type().Field(i).Name, field.Kind()) + } + } + + got := taskValue(taskProto(want)) + if reflect.DeepEqual(got, want) { + return + } + for i := range v.NumField() { + name := v.Type().Field(i).Name + gotField := reflect.ValueOf(got).Elem().Field(i).Interface() + wantField := v.Field(i).Interface() + if !reflect.DeepEqual(gotField, wantField) { + t.Errorf("Task.%s did not survive the proto round trip: got %v, want %v", name, gotField, wantField) + } + } +} diff --git a/proto/state/v1/state.proto b/proto/state/v1/state.proto index 81946fefe..7a3762bf0 100644 --- a/proto/state/v1/state.proto +++ b/proto/state/v1/state.proto @@ -206,6 +206,13 @@ message Task { // review_payload is the JSON-encoded review unit the remediate workflow's // current run must address (docs/prds/pr-review-remediation.md decision 4). string review_payload = 27; + // The workflow pin: the exact definition version this run started with. + // It has to cross the wire for the daemon's digest guard to hold, because + // a retry reads the task back over this contract before deciding whether + // to reuse the pinned YAML (docs/prds/runtime-control-plane.md:95). + int64 workflow_definition_version = 28; + string workflow_definition_digest = 29; + string workflow_definition_yaml = 30; } // Event mirrors internal/events.Event. Data is carried as a JSON object