Skip to content

Conversation

@yuhuan130
Copy link

@yuhuan130 yuhuan130 commented Jan 10, 2026

Tracking issue

Closes part 1 of #6824

Why are the changes needed?

Currently, CreateRun passes protobuf requests directly to the repository layer, violating separation of concerns. This creates tight coupling between the API and data layers, making testing harder and inconsistent with the pattern in task_service.go (PR #6813).

What changes were proposed in this pull request?

Refactored CreateRun to use the transformer pattern:

Before:  Service → Repository (protobuf) → Database
After:   Service → Transformer → Repository (domain model) → Database

New Files:

  • runs/repository/transformers/run.go - Converts protobuf → domain model
    • CreateRunRequestToModel: Transforms incoming request to domain model
    • RunModelToCreateRunResponse: Builds complete API response with Action hierarchy (ID, Status, Metadata)

Modified Files:

  • runs/service/create_run.go - Uses transformers instead of passing protobuf directly
  • runs/repository/interfaces/action.go - Changed signature to accept *models.Run
  • runs/repository/impl/action_repo.go - Accepts domain models, removed protobuf logic
  • runs/service/run_service_test.go - Updated mocks and tests
  • runs/repository/mocks/mock_ActionRepo.go - Regenerated mocks to match new interface signature

Key improvements:

  • Repository layer no longer depends on protobuf definitions
  • Clean separation between API and data layers
  • Follows closely as pattern for task_service.go
  • Completed RunModelToCreateRunResponse transformer to build full API response hierarchy (includes Action ID, Status with phase/timestamps, and Metadata with source)

How was this patch tested?

  • Added unit tests for transformer functions
  • Updated service and repository tests to use domain models
  • Verified response structure matches expected hierarchy
  • All tests pass locally: go test ./runs/... -v

Screenshots

Screenshot 2026-01-11 at 18 14 09 Screenshot 2026-01-12 at 18 13 30 Screenshot 2026-01-12 at 18 13 42

Signed-off-by: “Alex <alexchien130@gmail.com>
Signed-off-by: “Alex <alexchien130@gmail.com>
Signed-off-by: “Alex <alexchien130@gmail.com>
@welcome
Copy link

welcome bot commented Jan 10, 2026

Thank you for opening this pull request! 🙌

These tips will help get your PR across the finish line:

  • Most of the repos have a PR template; if not, fill it out to the best of your knowledge.
  • Sign off your commits (Reference: DCO Guide).

yuhuan130 and others added 4 commits January 11, 2026 17:48
Signed-off-by: “Alex <alexchien130@gmail.com>
Signed-off-by: “Alex <alexchien130@gmail.com>
Signed-off-by: Alex Chien <115371007+yuhuan130@users.noreply.github.com>
Signed-off-by: “Alex <alexchien130@gmail.com>
@yuhuan130 yuhuan130 changed the title [WIP]: CreateRun add initial service and response structure [Refactor]: CreateRun add initial service and response structure Jan 11, 2026
@yuhuan130 yuhuan130 marked this pull request as ready for review January 11, 2026 13:53
@machichima
Copy link
Member

Could you please add a script for testing under https://github.com/flyteorg/flyte/tree/v2/runs/test/scripts and test this API manually to ensure the runs are created successfully?

Signed-off-by: “Alex <alexchien130@gmail.com>
@machichima
Copy link
Member

Hi @yuhuan130 ,
We update the mockery format in #6829. Could you please merge v2 and generate the mockery again?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep one buf request only and commented out others, so that when we execute this script, there's only one run being created.

We can do things like below. I keep creating run with run_id as default as this is something that we will use the most

# Create run by run ID
# buf curl --schema . "$ENDPOINT/flyteidl2.workflow.RunService/CreateRun" --data @- <<EOF
# {
#   "run_id": {
#     "org": "$ORG",
#     "project": "$PROJECT",
#     "domain": "$DOMAIN",
#     "name": "my-custom-run-123"
#   },
#   "task_id": {
#     "org": "$ORG",
#     "project": "$PROJECT",
#     "domain": "$DOMAIN",
#     "name": "$TASK_NAME",
#     "version": "$VERSION"
#   },
#   "source": "RUN_SOURCE_WEB"
# }
# EOF

# Create run by project ID
buf curl --schema . "$ENDPOINT/flyteidl2.workflow.RunService/CreateRun" --data @- <<EOF
{
  "project_id": {
    "organization": "$ORG",
    "name": "$PROJECT",
    "domain": "$DOMAIN"
  },
  "task_spec": {
    "short_name": "test"
  },
  "source": "RUN_SOURCE_CLI"
}
EOF

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, super quick confirm, you mentioned run_id as the default since it's most commonly used. But I think your example showed it the other way around, so I wanted to double-check before making the change. Thanks!

const InitialPhase = "PHASE_QUEUED"

// CreateRunRequestToModel converts CreateRunRequest protobuf to Run domain model
func CreateRunRequestToModel(ctx context.Context, req *workflow.CreateRunRequest) (*models.Run, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer isolate service layer and repository layer to prevent the transformer function depends on service request. That is, let's not pass the CreateRunRequest and transform here. Instead, do things in service layer, and just pass runID and actionSpec into here. Like what we did in:

taskId := request.GetTaskId()
taskModel, err := transformers.NewTaskModel(ctx, taskId, taskSpec)

In this case, we can reuse the run proto to run model transform function in other places rather than only for create run function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh~ I see. No problem

@machichima
Copy link
Member

machichima commented Jan 13, 2026

For the check generate CI failure, we removed Cargo.lock in gen in #6844. Please merge v2 and run git rm --cached gen/rust/Cargo.lock to prevent git tracking the Cargo.lock.
Thank you!!

Signed-off-by: “Alex <alexchien130@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants