Expose AI model name as a variable in task automation #3208
Zak Siddiqui opened 7 hours ago

TL;DR

Expose the AI model name configured on the AI user as a new environment variable in the Workspace Spec - e.g. $TASK_MODEL - in the Command to Run Task, alongside the existing $TASK_PROMPT, $TASK_SYSTEM_PROMPT, and $TASK_USER_PROMPT variables. This lets automation commands like opencode run --model "$TASK_MODEL" --auto "$TASK_PROMPT" or claude --model "$TASK_MODEL" ... pick up the configured model without hardcoding it.

Priority: major - this is actively burning through AI credits (see Motivation) and is time-sensitive.

Problem

There is no variable exposing the name of the model to be used, so the run-task command cannot forward it to the coding agent's --model option. Today the model name is configured on the AI user via AiSetting.getModelSetting().getName() (server-core/src/main/java/io/onedev/server/model/support/AiModelSetting.java), but it is not surfaced to the task command.

Request

Expose the AI model name as an environment variable available to the Command to Run Task, e.g. $TASK_MODEL, and document it alongside the existing prompt variables. This would let commands such as:

  • opencode run --model "$TASK_MODEL" --auto "$TASK_PROMPT"
  • claude --dangerously-skip-permissions --model "$TASK_MODEL" --system-prompt "$TASK_SYSTEM_PROMPT" -p --verbose "$TASK_USER_PROMPT"

pick up the model configured on the AI user without hardcoding it.

Motivation

  • Uncontrolled credit burn: Because the run-task command has no access to the model name, it must either hardcode a model or omit the --model flag entirely - in which case the coding agent silently falls back to its own default, which is often a premium-priced model. Every automated task run then consumes more credits than intended, even when a cheaper model would suffice.
  • No single point of control: The model is already configured in one place on the AI user (AiSetting.getModelSetting().getName()), but the task command can't see it. Changing models currently means hand-editing every automation command instead of updating a single setting.
  • Wasted setup effort: Users wiring up agents like opencode or claude are forced to duplicate model configuration outside of OneDev, defeating the purpose of configuring it on the AI user.
  • Urgency: Inability to control the model is directly inflating cost on current workloads; surfacing $TASK_MODEL would have an immediate, measurable impact on credit consumption.

Background

When configuring Task Automation (workspace spec → Command to Run Task), the command currently has access to only the following environment variables, injected by the shell decorators:

  • $TASK_PROMPT – combined system + user prompt
  • $TASK_SYSTEM_PROMPT – system prompt only
  • $TASK_USER_PROMPT – user prompt only

Reference points:

  • server-core/src/main/java/io/onedev/server/model/support/workspace/spec/TaskAutomation.java (field description of runTaskCmd)
  • server-core/src/main/java/io/onedev/server/model/support/workspace/spec/shell/PosixShell.java, PowerShell.java, WindowsBatchShell.java (decorateRunPromptCommand)

Notes

  • Should be implemented consistently across all shells (POSIX, PowerShell, Windows batch), matching the existing prompt-variable handling.
  • Zak Siddiqui changed fields 7 hours ago
    Name Previous Value Current Value
    Priority
    Normal
    Major
  • Zak Siddiqui commented 7 hours ago

    Filing as a major priority because the inability to specify the model is burning through my AI credits.

    Hence, this is time-sensitive.

  • Zak Siddiqui commented 7 hours ago

    @robin if you could please clarify the workflow to change code, I can take a look at this problem.

    It looks like I don't have the ability to create a branch or a fork.

1/1
Type
Enhancement
Priority
Major
Assignee
Labels
No labels
Issue Votes (0)
Watchers (2)
Reference
OD-3208
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover