fix(service): inject WORK_DIR and map file_ids before param validation

Previously ValidateParams ran before WORK_DIR injection and file_ids mapping,
causing required parameter missing errors for auto-handled params. Now the
execution order is: inject WORK_DIR, map file_ids to file params, validate, resolve.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-20 13:41:28 +08:00
parent a7c48dae84
commit 08ca4da691

View File

@@ -284,16 +284,43 @@ func (s *TaskService) ProcessTask(ctx context.Context, taskID int64) error {
}
}
// 16a. Auto-inject WORK_DIR if the app defines it as a parameter.
// The work directory is created by the server, not provided by the user.
for _, p := range params {
if p.Name == "WORK_DIR" {
values["WORK_DIR"] = workDir
break
}
}
// 16b. Map input_file_ids to file-type parameters by order.
// User selects files via FilePicker; we assign their IDs to file/directory
// params sequentially so the backend can resolve them to filenames later.
var inputFileIDs []int64
if len(task.InputFileIDs) > 0 {
if err := json.Unmarshal(task.InputFileIDs, &inputFileIDs); err != nil {
return fail(model.TaskStepSubmitting, fmt.Sprintf("parse input file ids: %v", err))
}
}
if len(inputFileIDs) > 0 {
fileParamIdx := 0
for _, p := range params {
if p.Type != model.ParamTypeFile && p.Type != model.ParamTypeDirectory {
continue
}
if fileParamIdx < len(inputFileIDs) {
values[p.Name] = strconv.FormatInt(inputFileIDs[fileParamIdx], 10)
fileParamIdx++
}
}
}
// 16c. Validate all params (WORK_DIR and file params now have values).
if err := ValidateParams(params, values); err != nil {
return fail(model.TaskStepSubmitting, err.Error())
}
if strings.Contains(app.ScriptTemplate, "$WORK_DIR") {
values["WORK_DIR"] = workDir
}
// Resolve file-type parameters: user sends file_id, we replace with filename.
// Only query the database if there are file/directory-type parameters with values.
// 16d. Resolve file-type parameter values: file_id → filename.
var fileLookupIDs []int64
for _, p := range params {
if p.Type != model.ParamTypeFile && p.Type != model.ParamTypeDirectory {