Skip to content

Conversation

@DanielleMaywood
Copy link
Contributor

@DanielleMaywood DanielleMaywood commented Nov 18, 2025

This PR adds the backend implementation for modifying task prompts. Part of coder/internal#1084

Changes

  • New UpdateTaskPrompt database query to update task prompts
  • New PATCH /api/v2/tasks/{task}/prompt endpoint

Notes

This is part 1 of a 2-part PR stack. The frontend UI will be added in a follow-up PR based on this branch (#20812).


🤖 PR was written by Claude Sonnet 4.5 Thinking using Coder Mux and reviewed by a human 👩

This adds a new PATCH endpoint to modify the prompt of an existing task
and restart its build. This is the backend implementation including:

- New UpdateTaskPrompt database query
- New PATCH /api/v2/tasks/{task}/prompt endpoint
- Authorization checks for task modification
- Database changes to support prompt updates
- Generated API documentation and TypeScript types
@DanielleMaywood DanielleMaywood marked this pull request as draft November 18, 2025 00:02
@DanielleMaywood DanielleMaywood changed the title feat(tasks): add task prompt modification endpoint feat(coderd): add task prompt modification endpoint Nov 18, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@DanielleMaywood DanielleMaywood marked this pull request as ready for review November 18, 2025 10:33
return
}

if req.Prompt == "" {
Copy link
Member

Choose a reason for hiding this comment

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

I could see this as a use-case, set the prompt to empty for e.g. next start.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can remove this then

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate that use-case? 🤔 I'm not clear on what the agent would do with an empty prompt on next start

Copy link
Member

@mafredri mafredri Nov 18, 2025

Choose a reason for hiding this comment

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

It looks like you need to fill something into the prompt in the UI too, so I’m fine with leaving the check. @ssncferreira my thought was that you might want to start up the task in idle state so that you can interact with agentapi directly, e.g. upload attachments, etc. But you can just as well type ”do nothing” as prompt to achieve that so aligning with UI is fine.

// @Tags Experimental
// @Param user path string true "Username, user ID, or 'me' for the authenticated user"
// @Param task path string true "Task ID" format(uuid)
// @Param request body codersdk.UpdateTaskPromptRequest true "Update task prompt request"
Copy link
Member

Choose a reason for hiding this comment

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

Our terminology is becoming a bit inconsistent here, first you create a task with input, but then update prompt which replaces the input/prompt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer renaming prompt to input here? Happy to do so

Copy link
Member

Choose a reason for hiding this comment

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

Let's go with input to stay consistent 👍🏻

return
}

if req.Prompt == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate that use-case? 🤔 I'm not clear on what the agent would do with an empty prompt on next start

// Block updates if:
// 1. Job is actively running (pending, running, canceling)
// 2. Workspace is running (job succeeded with start transition)
if job.JobStatus == database.ProvisionerJobStatusPending ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we disallowing prompt update on job pending? In this state, the provisioner hasn't even picked up the workspace build job yet, so it should be safe to update the prompt, correct?

Copy link
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

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

LGTM ✅
Just some nits, but nothing blocking 🙂

})
}

if task.Status == database.TaskStatusInitializing || task.Status == database.TaskStatusActive {
Copy link
Contributor

Choose a reason for hiding this comment

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

So this leaves us with: "pending,paused,unknown,error"...should we allow changes on unknown and error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still happy with removing this entirely but this allows us to change on Unknown and Error. The task status is considered Error when you cancel the workspace build, which is what needs to be done to stop it before it starts executing.

As for unknown, I'm on the fence and can be convinced either way on that.

Copy link
Member

Choose a reason for hiding this comment

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

Error could also mean the app is unhealthy. I guess a bigger question is. If a workspace is initializing or active, how is this API intended to be used? Do we cancel the current transition, run a stop transition on the workspace, update the prompt, then start it again?

In this scenario, one could see paused as the only acceptable state where prompt can be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh should I also run a stop transition after the cancel? 👀 My plan was to just cancel the transition (hence why I allow changing on error), update the prompt, and run a start transition again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mafredri I've updated the PR and it only allows updating the input when the task is paused.

Copy link
Member

Choose a reason for hiding this comment

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

@DanielleMaywood it's safest to run a stop transition because otherwise there isn't a guarantee the workspace will be in a valid state afterwards.

I think there's another issue related to this that I can't find right now, but the discussion here should give at least some context: #8266



-- name: UpdateTaskPrompt :one
UPDATE
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I understand that the task status is computed from the view tasks_with_status, so this might not be trivial, but should we change the query to only update the task's prompt if the task is in an allowed status? Otherwise, maybe just adding a comment that we should only update a task's prompt if it is in status 'pending', 'paused', 'unknown', or 'error' (i.e., NOT 'initializing' or 'active').

@ssncferreira
Copy link
Contributor

Also, just a note on the Chromatic CI failed test: OrganizationSidebarView. This was already fixed by #20808

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

The main blocker is still the task.Status check IMO, it's feels like somewhat arbitrary enforcement due to some states having multiple potential causes. Like error could be failed build or unhealthy app (potentially running task, just agentapi failing health check).

Some minor additional feedback inline.

})
}

if task.Status == database.TaskStatusInitializing || task.Status == database.TaskStatusActive {
Copy link
Member

Choose a reason for hiding this comment

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

Error could also mean the app is unhealthy. I guess a bigger question is. If a workspace is initializing or active, how is this API intended to be used? Do we cancel the current transition, run a stop transition on the workspace, update the prompt, then start it again?

In this scenario, one could see paused as the only acceptable state where prompt can be updated?

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

:shipit:

@DanielleMaywood DanielleMaywood merged commit 82f525b into main Nov 25, 2025
35 checks passed
@DanielleMaywood DanielleMaywood deleted the danielle-change-task-prompt-backend branch November 25, 2025 11:13
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants