Skip to content

feat(coderd): add tasks list and get endpoints - #19468

Merged
mafredri merged 10 commits into
mainfrom
mafredri/feat-coderd-add-tasks-list-and-get
Aug 22, 2025
Merged

mafredri merged 10 commits into
mainfrom
mafredri/feat-coderd-add-tasks-list-and-get

Conversation

@mafredri

@mafredri mafredri commented Aug 21, 2025 •

Copy link
Copy Markdown
Member

Fixes coder/internal#899

Example API response:

{
  "tasks": [
    {
      "id": "a7a27450-ca16-4553-a6c5-9d6f04808569",
      "organization_id": "241e869f-1a61-42c9-ae1e-9d46df874058",
      "owner_id": "9e9b9475-0fc0-47b2-9170-a5b7b9a075ee",
      "name": "task-hardcore-herschel-bd08",
      "template_id": "accab607-bbda-4794-89ac-da3926a8b71c",
      "workspace_id": "a7a27450-ca16-4553-a6c5-9d6f04808569",
      "initial_prompt": "What directory are you in?",
      "status": "running",
      "current_state": {
        "timestamp": "2025-08-22T10:03:27.837842Z",
        "state": "working",
        "message": "Listed root directory contents, working directory reset",
        "uri": ""
      },
      "created_at": "2025-08-22T09:21:39.697094Z",
      "updated_at": "2025-08-22T09:21:39.697094Z"
    },
    {
      "id": "50f92138-f463-4f2b-abad-1816264b065f",
      "organization_id": "241e869f-1a61-42c9-ae1e-9d46df874058",
      "owner_id": "9e9b9475-0fc0-47b2-9170-a5b7b9a075ee",
      "name": "task-musing-dewdney-f058",
      "template_id": "accab607-bbda-4794-89ac-da3926a8b71c",
      "workspace_id": "50f92138-f463-4f2b-abad-1816264b065f",
      "initial_prompt": "What is 1 + 1?",
      "status": "running",
      "current_state": {
        "timestamp": "2025-08-22T09:22:33.810707Z",
        "state": "idle",
        "message": "Completed arithmetic calculation",
        "uri": ""
      },
      "created_at": "2025-08-22T09:18:28.027378Z",
      "updated_at": "2025-08-22T09:18:28.027378Z"
    }
  ],
  "count": 2
}

NOTE: For now I've opted not to implement task "state" filter. Will require joining workspace apps to the workspaces query which is already complex enough. Regular workspace filters (status = running) will work, though.

@mafredri
mafredri force-pushed the mafredri/feat-coderd-add-tasks-list-and-get branch from f8660ff to bd14ddd Compare August 21, 2025 13:02
@mafredri
mafredri force-pushed the mafredri/feat-coderd-add-tasks-list-and-get branch from ff91ceb to 66fbc02 Compare August 22, 2025 10:06
@mafredri
mafredri marked this pull request as ready for review August 22, 2025 10:12
Comment thread coderd/aitasks.go

// tasksFromWorkspaces converts a slice of API workspaces into tasks, fetching
// prompts and mapping status/state.
func (api *API) tasksFromWorkspaces(ctx context.Context, apiWorkspaces []codersdk.Workspace) ([]codersdk.Task, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we fine with this not validating that the passed in workspaces are tasks? I understand that where it is currently called from we only pass tasks in, I'm just curious.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably no harm to filter out workspaces that are not "tasks", wdyt?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It would be an error if passed to this function. Handling exists in both list and get endpoints currently, before calling this, but I can add a guard here as well or try to consolidate some more of the code into this method.

Comment thread coderd/aitasks_test.go Resolved
Comment thread coderd/aitasks_test.go Resolved
Comment thread coderd/aitasks.go

// tasksFromWorkspaces converts a slice of API workspaces into tasks, fetching
// prompts and mapping status/state.
func (api *API) tasksFromWorkspaces(ctx context.Context, apiWorkspaces []codersdk.Workspace) ([]codersdk.Task, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably no harm to filter out workspaces that are not "tasks", wdyt?

Comment thread coderd/aitasks.go Resolved

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

@mafredri
mafredri merged commit 427b23f into main Aug 22, 2025
@mafredri
mafredri deleted the mafredri/feat-coderd-add-tasks-list-and-get branch August 22, 2025 14:11
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 22, 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.

Tasks API: Implement GET /tasks and GET /tasks/{id}

3 participants