ensureWorkspaceLoaded detects the workspace from the client's working directory and loads all configured modules onto the dagql server. Called from serveQuery (not initializeDaggerClient) because it requires the client's session attachables to access the client's filesystem for workspace detection.
(ctx context.Context, client *daggerClient)
| 58 | // (not initializeDaggerClient) because it requires the client's session attachables |
| 59 | // to access the client's filesystem for workspace detection. |
| 60 | func (srv *Server) ensureWorkspaceLoaded(ctx context.Context, client *daggerClient) error { |
| 61 | mode, workspaceRef := workspaceBindingMode(client) |
| 62 | if mode == workspaceBindingInherit { |
| 63 | return srv.inheritWorkspaceBinding(ctx, client) |
| 64 | } |
| 65 | |
| 66 | client.workspaceMu.Lock() |
| 67 | defer client.workspaceMu.Unlock() |
| 68 | |
| 69 | if client.workspaceLoaded { |
| 70 | return client.workspaceErr |
| 71 | } |
| 72 | |
| 73 | // Wait for the client's session attachables to be available. |
| 74 | // Don't mark as loaded on failure — allow retry on next request. |
| 75 | if _, err := client.getClientCaller(ctx, client.clientID); err != nil { |
| 76 | return fmt.Errorf("waiting for client session attachables: %w", err) |
| 77 | } |
| 78 | |
| 79 | var err error |
| 80 | switch mode { |
| 81 | case workspaceBindingDeclared: |
| 82 | err = srv.loadWorkspaceFromDeclaredRef(ctx, client, workspaceRef) |
| 83 | case workspaceBindingDetectHost: |
| 84 | err = srv.loadWorkspaceFromHost(ctx, client) |
| 85 | default: |
| 86 | err = fmt.Errorf("unsupported workspace binding mode %q", mode) |
| 87 | } |
| 88 | if err != nil { |
| 89 | client.workspaceErr = err |
| 90 | } |
| 91 | |
| 92 | client.workspaceLoaded = true |
| 93 | return client.workspaceErr |
| 94 | } |
| 95 | |
| 96 | type workspaceBindingModeType string |
| 97 |