-
Notifications
You must be signed in to change notification settings - Fork 943
feat: persist AI task state in template imports & workspace builds #18449
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9fa7a93
chore: go.mod
dannykopping d01a050
feat: proto & db changes to persist coder_ai_task state
dannykopping 4383350
feat: store coder_ai_task resource state
dannykopping 957fb08
chore: rename ai_tasks_sidebar_app_id to ai_task_sidebar_app_id
dannykopping 91c8f0c
chore: update to d9b0f892f9c2b3768b9647b089900b0628cb7828, prompt nam…
dannykopping efe5da9
chore: update provisioner API version comments
dannykopping 5e0d28a
chore: move prompt param validation to ConvertState with other valida…
dannykopping 57da39f
chore: unify tf testdata versions & fix tests
dannykopping c6c7b5c
chore: dbauthz
dannykopping 4816ed5
chore: fix TestWorkspaceAgentAppHealth test after agent ID field now …
dannykopping e48df2e
chore: add tests
dannykopping 0b2b732
chore: correct bad rebase
dannykopping 5edee05
chore: undo changes to terraform testdata, so as to not complicate th…
dannykopping 3614a5b
chore: fixing tests
dannykopping d7e47f9
chore: ensure sidebar app ID must be set when has_ai_task is set
dannykopping f4111df
chore: test multiple coder_ai_tasks cannot be configured
dannykopping cc0e290
chore: fix CI
dannykopping 138d865
chore: minor refactor
dannykopping 1aba76b
chore: add clarifying/defensive parentheses
dannykopping 6454ffe
chore: fix conflict
dannykopping bce4a88
chore: review comments
dannykopping 9a453e8
Merge branch 'main' of github.com:/coder/coder into dk/coder-ai-task-res
dannykopping File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: store coder_ai_task resource state
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
- Loading branch information
commit 438335039ab6d62488d90dd4ff06ca44b7507de0
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,13 @@ import ( | |
"errors" | ||
"fmt" | ||
"reflect" | ||
"slices" | ||
"strings" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/coder/terraform-provider-coder/v2/provider" | ||
"github.com/google/uuid" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"go.opentelemetry.io/otel/attribute" | ||
|
@@ -584,8 +586,6 @@ func (r *Runner) runTemplateImport(ctx context.Context) (*proto.CompletedJob, *p | |
externalAuthProviderNames = append(externalAuthProviderNames, it.Id) | ||
} | ||
|
||
// fmt.Println("completed job: template import: graph:", startProvision.Graph) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive-by. |
||
|
||
return &proto.CompletedJob{ | ||
JobId: r.job.JobId, | ||
Type: &proto.CompletedJob_TemplateImport_{ | ||
|
@@ -603,6 +603,7 @@ func (r *Runner) runTemplateImport(ctx context.Context) (*proto.CompletedJob, *p | |
ModuleFiles: startProvision.ModuleFiles, | ||
// ModuleFileHash will be populated if the file is uploaded async | ||
ModuleFilesHash: []byte{}, | ||
HasAiTasks: startProvision.HasAITasks, | ||
}, | ||
}, | ||
}, nil | ||
|
@@ -666,6 +667,7 @@ type templateImportProvision struct { | |
Presets []*sdkproto.Preset | ||
Plan json.RawMessage | ||
ModuleFiles []byte | ||
HasAITasks bool | ||
} | ||
|
||
// Performs a dry-run provision when importing a template. | ||
|
@@ -799,6 +801,15 @@ func (r *Runner) runTemplateImportProvisionWithRichParameters( | |
} | ||
} | ||
|
||
if c.HasAiTasks { | ||
hasPromptParam := slices.ContainsFunc(c.Parameters, func(param *sdkproto.RichParameter) bool { | ||
return param.Name == provider.TaskPromptParameterName | ||
}) | ||
if !hasPromptParam { | ||
return nil, xerrors.Errorf("coder_parameter named '%s' is required when 'coder_ai_task' resource is defined", provider.TaskPromptParameterName) | ||
} | ||
} | ||
|
||
return &templateImportProvision{ | ||
Resources: c.Resources, | ||
Parameters: c.Parameters, | ||
|
@@ -807,6 +818,7 @@ func (r *Runner) runTemplateImportProvisionWithRichParameters( | |
Presets: c.Presets, | ||
Plan: c.Plan, | ||
ModuleFiles: moduleFilesData, | ||
HasAITasks: c.HasAiTasks, | ||
}, nil | ||
default: | ||
return nil, xerrors.Errorf("invalid message type %q received from provisioner", | ||
|
@@ -1047,6 +1059,9 @@ func (r *Runner) runWorkspaceBuild(ctx context.Context) (*proto.CompletedJob, *p | |
}, | ||
} | ||
} | ||
if len(planComplete.AiTasks) > 1 { | ||
return nil, r.failedWorkspaceBuildf("only one 'coder_ai_task' resource can be provisioned per template") | ||
} | ||
|
||
r.logger.Info(context.Background(), "plan request successful", | ||
slog.F("resource_count", len(planComplete.Resources)), | ||
|
@@ -1124,6 +1139,7 @@ func (r *Runner) runWorkspaceBuild(ctx context.Context) (*proto.CompletedJob, *p | |
Modules: planComplete.Modules, | ||
// Resource replacements are discovered at plan time, only. | ||
ResourceReplacements: planComplete.ResourceReplacements, | ||
AiTasks: applyComplete.AiTasks, | ||
}, | ||
}, | ||
}, nil | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.