@@ -121,7 +121,10 @@ func (s *TrainingJobService) CreateJob(req schema.TrainingJobRequest) (schema.Tr
121121
122122// GetJob returns a training job by ID
123123func (s * TrainingJobService ) GetJob (id string ) (schema.TrainingJob , bool ) {
124- return s .jobs .Get (id )
124+ if ! s .jobs .Exists (id ) {
125+ return schema.TrainingJob {}, false
126+ }
127+ return s .jobs .Get (id ), true
125128}
126129
127130// ListJobs returns all training jobs, sorted by creation time (newest first)
@@ -139,17 +142,17 @@ func (s *TrainingJobService) ListJobs() []schema.TrainingJob {
139142
140143// CancelJob cancels a running training job
141144func (s * TrainingJobService ) CancelJob (id string ) error {
142- job , ok := s .jobs .Get (id )
143- if ! ok {
145+ if ! s .jobs .Exists (id ) {
144146 return fmt .Errorf ("job not found: %s" , id )
145147 }
148+ job := s .jobs .Get (id )
146149
147150 if job .Status != schema .TrainingJobStatusPending && job .Status != schema .TrainingJobStatusRunning {
148151 return fmt .Errorf ("job %s is not cancellable (status: %s)" , id , job .Status )
149152 }
150153
151- cancelFn , ok := s .cancellations .Get (id )
152- if ok {
154+ if s .cancellations .Exists (id ) {
155+ cancelFn := s . cancellations . Get ( id )
153156 cancelFn ()
154157 }
155158
@@ -165,15 +168,15 @@ func (s *TrainingJobService) CancelJob(id string) error {
165168
166169// DeleteJob removes a job from the store
167170func (s * TrainingJobService ) DeleteJob (id string ) error {
168- job , ok := s .jobs .Get (id )
169- if ! ok {
171+ if ! s .jobs .Exists (id ) {
170172 return fmt .Errorf ("job not found: %s" , id )
171173 }
174+ job := s .jobs .Get (id )
172175
173176 // Cancel if still running
174177 if job .Status == schema .TrainingJobStatusRunning || job .Status == schema .TrainingJobStatusPending {
175- if cancelFn , ok := s .cancellations .Get (id ); ok {
176- cancelFn ()
178+ if s .cancellations .Exists (id ) {
179+ s . cancellations . Get ( id ) ()
177180 }
178181 }
179182
@@ -185,10 +188,10 @@ func (s *TrainingJobService) DeleteJob(id string) error {
185188
186189// executeJob runs the training job via the backend gRPC call
187190func (s * TrainingJobService ) executeJob (id string ) {
188- job , ok := s .jobs .Get (id )
189- if ! ok {
191+ if ! s .jobs .Exists (id ) {
190192 return
191193 }
194+ job := s .jobs .Get (id )
192195
193196 ctx , cancel := context .WithCancel (s .ctx )
194197 s .cancellations .Set (id , cancel )
@@ -229,29 +232,21 @@ func (s *TrainingJobService) executeJob(id string) {
229232
230233 modelConfig := config.ModelConfig {
231234 Name : job .Model ,
232- Model : job .Model ,
233235 Backend : backendName ,
234236 }
235237
236238 // Attempt to load from existing model configs
237- if cfgs := s .configLoader .ListConfigs (); len (cfgs ) > 0 {
238- for _ , name := range cfgs {
239- if name == job .Model {
240- if cfg , exists := s .configLoader .GetConfig (name ); exists {
241- modelConfig = cfg
242- if backendName != "" {
243- modelConfig .Backend = backendName
244- }
245- }
246- break
247- }
239+ if cfg , exists := s .configLoader .GetModelConfig (job .Model ); exists {
240+ modelConfig = cfg
241+ if backendName != "" {
242+ modelConfig .Backend = backendName
248243 }
249244 }
250245
251246 // Load backend and call TrainStream directly (avoids import cycle with core/backend)
252247 opts := []model.Option {
253248 model .WithBackendString (modelConfig .Backend ),
254- model .WithModel (modelConfig .Model ),
249+ model .WithModel (modelConfig .Name ),
255250 model .WithContext (s .appConfig .Context ),
256251 model .WithModelID (modelConfig .Name ),
257252 }
@@ -267,7 +262,7 @@ func (s *TrainingJobService) executeJob(id string) {
267262 }
268263
269264 // Final status update
270- job , _ = s .jobs .Get (id )
265+ job = s .jobs .Get (id )
271266 completedAt := time .Now ()
272267
273268 if err != nil {
@@ -296,10 +291,10 @@ func (s *TrainingJobService) executeJob(id string) {
296291
297292// updateJobFromResponse updates job state from a streaming TrainResponse
298293func (s * TrainingJobService ) updateJobFromResponse (id string , resp * proto.TrainResponse ) {
299- job , ok := s .jobs .Get (id )
300- if ! ok {
294+ if ! s .jobs .Exists (id ) {
301295 return
302296 }
297+ job := s .jobs .Get (id )
303298
304299 job .Progress = resp .Progress
305300 job .CurrentEpoch = resp .CurrentEpoch
0 commit comments