-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: set codersdk.Task current_state during task initialization #20692
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: set codersdk.Task current_state during task initialization #20692
Conversation
…-initializing-state-message
…-initializing-state-message
…-initializing-state-message
coderd/aitasks_test.go
Outdated
| assert.NotEqual(t, "all done", updated.CurrentState.Message) | ||
| }) | ||
|
|
||
| t.Run("InitializingAgentState", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracting the function will mean we can test it on its own and only need to test a couple cases here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial idea was to unit test taskFromDBTaskAndWorkspace, however, the packages are different (coderd and coderd_test). The only way to unit test the extracted function would be to either make it public or create a separate test file with package coderd, but that goes against the current approach for other test files in this directory 😕 Unless I'm missing something really basic 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to test an unexported function, you can create aitasks_internal_test.go with package coderd and test it there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to test an unexported function, you can create
aitasks_internal_test.gowithpackage coderdand test it there.
Completely forgot about the pattern with _internal_ files 🤦♀️ Addressed in: b1cb7fe
mafredri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be pretty cool if we could add these messages to the app status at the time they happen (attached with a timestamp), that way they could be viewed in history/timeline of the task as well. That's a much larger refactor though and this is fine for now, nice clean implementation. 👍🏻
| message = "Agent is starting" | ||
| default: | ||
| message = "Initializing workspace agent" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we take into account the coder app status as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean LatestAppStatus? I thought about adding different messages based on the app status state, for example, if LatestAppStatus.State == idle, the message could be "Agent is idle", or for completed/failed states, we could provide more detailed information to users. Or were you thinking of something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about WorkspaceAppHealth, specifically WorkspaceAppHealthInitializing. If disabled we can ignore it.
I'm not sure if we need to enrich LatestAppStatus if there already exists an entry 🤔. I imagine users could want to tweak that via having the agent give some context via the mcp report tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about WorkspaceAppHealth, specifically WorkspaceAppHealthInitializing. If disabled we can ignore it.
Ah, I see. So this would be the case where the agent is ready but the app is still initializing, correct? Do you think it makes sense to get into that level of detail? We have different possible AppHealth statuses:
WorkspaceAppHealthDisabled WorkspaceAppHealth = "disabled"
WorkspaceAppHealthInitializing WorkspaceAppHealth = "initializing"
WorkspaceAppHealthHealthy WorkspaceAppHealth = "healthy"
WorkspaceAppHealthUnhealthy WorkspaceAppHealth = "unhealthy"
I'm guessing only the initializing here would make sense, because the others would probably affect the overall task status, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this would be the case where the agent is ready but the app is still initializing, correct?
Yep! 👍🏻
Do you think it makes sense to get into that level of detail?
It would better reflect how we determine the tasks status in the tasks_with_status view.
I'm guessing only the
initializinghere would make sense, because the others would probably affect the overall task status, correct?
Correct. 👍🏻
We could consider unhealthy as well, but that would open a can of worms I'd prefer to avoid for now (messages for agent health, workspace build failure, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in b1cb7fe
That would be nice, but it would require more changes. The way I see it, we have 2 stages of initialization here:
For phase 1, we cannot insert a For phase 2, we could insert workspace app statuses by having the agent call The implementation in this PR is simpler and works for both phases, but now that I think about it, I'm not sure if it's hackier compared to properly reporting statuses...We could report statuses for phase 2 (agent initialization) and keep the current implementation for phase 1 (provisioning). |
|
@ssncferreira let's keep it like this for now, it's trivial enough of a change to redo later 👍🏻. Perhaps we can open up a new ticket to track the improvement. Good point about phase 1, although I think it applies strictly to the pending phase and perhaps slightly past it. Once the workspace is starting the agent and apps should be created meaning we could update the status in the same place in the provisionerdserver where we perform update on the I could see two ways for phase 2, first is as you propose, have the agent do it explicitly. The second is to do it behind the scenes inside coderd on agent lifecycle change (but perhaps that's too much spooky action at a distance?). |
…-initializing-state-message
Created issue #20749 to track this for future improvements 👍 |
…-initializing-state-message
…-initializing-state-message
DanielleMaywood
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me with one minor nit
| message = "Initializing workspace applications" | ||
| } | ||
| default: | ||
| message = "Initializing workspace agent" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should never happen, but the fallback is fine, should we log something if this happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this should never happen, similarly to the "Initializing workspace applications" path. I think adding a comment here is enough for now. Addressed in 677339d
…-initializing-state-message
Problem
With the new tasks data model, a task starts with an
initializingstatus. However, the API returnscurrent_state: nullto represent the agent state, causing the frontend to display "No message available". This PR updatescodersdk.Taskto return acurrent_statewhen the task is initializing with meaningful messages about what's happening during task initialization.Previous message
New message
Changes
current_statewith descriptive initialization messages when task status isinitializingand no valid app status exists for the current buildWorkspaceBuildbuilder to properly handle pending/running jobs by linking tasks without requiring agent/app resourcesNote: UI Storybook changes to reflect these new messages will be addressed in a follow-up PR.
Closes: coder/internal#1063