Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(coderd)!: only show task status for current build#19966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 3 commits intomainfromcj/exp-tasks-last-status
Sep 26, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletionscli/exp_task_status_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -96,9 +96,9 @@ func Test_TaskStatus(t *testing.T) {
STATE CHANGED STATUS STATE MESSAGE
4s ago running
3s ago running working Reticulating splines...
2s ago runningcompleted Splines reticulated successfully!
2s ago stoppingcompleted Splines reticulated successfully!
2s ago stoppedcompleted Splines reticulated successfully!`,
2s ago runningcomplete Splines reticulated successfully!
2s ago stoppingcomplete Splines reticulated successfully!
2s ago stoppedcomplete Splines reticulated successfully!`,
hf: func(ctx context.Context, now time.Time) func(http.ResponseWriter, *http.Request) {
var calls atomic.Int64
return func(w http.ResponseWriter, r *http.Request) {
Expand DownExpand Up@@ -143,7 +143,7 @@ STATE CHANGED STATUS STATE MESSAGE
CreatedAt: now.Add(-5 * time.Second),
UpdatedAt: now.Add(-4 * time.Second),
CurrentState: &codersdk.TaskStateEntry{
State: codersdk.TaskStateCompleted,
State: codersdk.TaskStateComplete,
Timestamp: now.Add(-2 * time.Second),
Message: "Splines reticulated successfully!",
},
Expand All@@ -155,7 +155,7 @@ STATE CHANGED STATUS STATE MESSAGE
CreatedAt: now.Add(-5 * time.Second),
UpdatedAt: now.Add(-1 * time.Second),
CurrentState: &codersdk.TaskStateEntry{
State: codersdk.TaskStateCompleted,
State: codersdk.TaskStateComplete,
Timestamp: now.Add(-2 * time.Second),
Message: "Splines reticulated successfully!",
},
Expand All@@ -167,7 +167,7 @@ STATE CHANGED STATUS STATE MESSAGE
CreatedAt: now.Add(-5 * time.Second),
UpdatedAt: now,
CurrentState: &codersdk.TaskStateEntry{
State: codersdk.TaskStateCompleted,
State: codersdk.TaskStateComplete,
Timestamp: now.Add(-2 * time.Second),
Message: "Splines reticulated successfully!",
},
Expand Down
15 changes: 10 additions & 5 deletionscoderd/aitasks.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,13 +245,18 @@ func taskFromWorkspace(ws codersdk.Workspace, initialPrompt string) codersdk.Tas
}
}

// Ignore 'latest app status' if it is older than the latest build and the latest build is a 'start' transition.
// This ensures that you don't show a stale app status from a previous build.
// For stop transitions, there is still value in showing the latest app status.
var currentState *codersdk.TaskStateEntry
if ws.LatestAppStatus != nil {
currentState = &codersdk.TaskStateEntry{
Timestamp: ws.LatestAppStatus.CreatedAt,
State: codersdk.TaskState(ws.LatestAppStatus.State),
Message: ws.LatestAppStatus.Message,
URI: ws.LatestAppStatus.URI,
if ws.LatestBuild.Transition != codersdk.WorkspaceTransitionStart || ws.LatestAppStatus.CreatedAt.After(ws.LatestBuild.CreatedAt) {
currentState = &codersdk.TaskStateEntry{
Timestamp: ws.LatestAppStatus.CreatedAt,
State: codersdk.TaskState(ws.LatestAppStatus.State),
Message: ws.LatestAppStatus.Message,
URI: ws.LatestAppStatus.URI,
}
}
}

Expand Down
61 changes: 50 additions & 11 deletionscoderd/aitasks_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,6 +18,7 @@ import (
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/coderd/util/slice"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
Expand DownExpand Up@@ -269,19 +270,39 @@ func TestTasks(t *testing.T) {
t.Run("Get", func(t *testing.T) {
t.Parallel()

client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)
ctx := testutil.Context(t, testutil.WaitLong)

template := createAITemplate(t, client, user)
var (
client, db = coderdtest.NewWithDatabase(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
ctx = testutil.Context(t, testutil.WaitLong)
user = coderdtest.CreateFirstUser(t, client)
template = createAITemplate(t, client, user)
// Create a workspace (task) with a specific prompt.
wantPrompt = "review my code"
workspace = coderdtest.CreateWorkspace(t, client, template.ID, func(req *codersdk.CreateWorkspaceRequest) {
req.RichParameterValues = []codersdk.WorkspaceBuildParameter{
{Name: codersdk.AITaskPromptParameterName, Value: wantPrompt},
}
})
)

// Create a workspace (task) with a specific prompt.
wantPrompt := "review my code"
workspace := coderdtest.CreateWorkspace(t, client, template.ID, func(req *codersdk.CreateWorkspaceRequest) {
req.RichParameterValues = []codersdk.WorkspaceBuildParameter{
{Name: codersdk.AITaskPromptParameterName, Value: wantPrompt},
}
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
ws := coderdtest.MustWorkspace(t, client, workspace.ID)
// Assert invariant: the workspace has exactly one resource with one agent with one app.
require.Len(t, ws.LatestBuild.Resources, 1)
require.Len(t, ws.LatestBuild.Resources[0].Agents, 1)
agentID := ws.LatestBuild.Resources[0].Agents[0].ID
taskAppID := ws.LatestBuild.Resources[0].Agents[0].Apps[0].ID

// Insert an app status for the workspace
_, err := db.InsertWorkspaceAppStatus(dbauthz.AsSystemRestricted(ctx), database.InsertWorkspaceAppStatusParams{
ID: uuid.New(),
WorkspaceID: workspace.ID,
CreatedAt: dbtime.Now(),
AgentID: agentID,
AppID: taskAppID,
State: database.WorkspaceAppStatusStateComplete,
Message: "all done",
})
require.NoError(t, err)

// Fetch the task by ID via experimental API and verify fields.
exp := codersdk.NewExperimentalClient(client)
Expand All@@ -293,6 +314,24 @@ func TestTasks(t *testing.T) {
assert.Equal(t, wantPrompt, task.InitialPrompt, "task prompt should match the AI Prompt parameter")
assert.Equal(t, workspace.ID, task.WorkspaceID.UUID, "workspace id should match")
assert.NotEmpty(t, task.Status, "task status should not be empty")

// Stop the workspace
coderdtest.MustTransitionWorkspace(t, client, workspace.ID, codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop)

// Verify that the previous status still remains
updated, err := exp.TaskByID(ctx, workspace.ID)
require.NoError(t, err)
assert.NotNil(t, updated.CurrentState, "current state should not be nil")
assert.Equal(t, "all done", updated.CurrentState.Message)
assert.Equal(t, codersdk.TaskStateComplete, updated.CurrentState.State)

// Start the workspace again
coderdtest.MustTransitionWorkspace(t, client, workspace.ID, codersdk.WorkspaceTransitionStop, codersdk.WorkspaceTransitionStart)

// Verify that the status from the previous build is no longer present
updated, err = exp.TaskByID(ctx, workspace.ID)
require.NoError(t, err)
assert.Nil(t, updated.CurrentState, "current state should be nil")
})

t.Run("Delete", func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletionscodersdk/aitasks.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,10 +79,10 @@ func (c *ExperimentalClient) CreateTask(ctx context.Context, user string, reques
type TaskState string

const (
TaskStateWorkingTaskState = "working"
TaskStateIdleTaskState = "idle"
TaskStateCompleted TaskState = "completed"
TaskStateFailedTaskState = "failed"
TaskStateWorking TaskState = "working"
TaskStateIdle TaskState = "idle"
TaskStateComplete TaskState = "complete"
TaskStateFailed TaskState = "failed"
)

// Task represents a task.
Expand Down
4 changes: 2 additions & 2 deletionssite/src/api/typesGenerated.ts
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp