Skip to content

Conversation

@michaellee1019
Copy link
Member

@michaellee1019 michaellee1019 commented Oct 24, 2025

The changes in this PR focus on hot reloading and provide more feedback as to what the process is doing and how long it is taking.

  • I chose the library pterm as it seems like the best golang option for multi-step progress with support to nest some steps inside of others. I did try other dependencies as well and this seems the best and most popular option. I know the CLI generator uses huh but it does not provide the same features such as multiple steps (on different lines) and step nesting. Maybe a separate task could be done to use this new dependency on the generator side.
  • I made a utility to handle progress tracking across the codebase and called it ProgressManager. Without it the code was gross and had too much state progress management throughout the code. Added unit tests as well.
  • I removed some conflicting error messages and for now returned the copy progress indicators in this PR. I would like to do another PR that refactors the printing inside of the shell copy code to universally use progress bars provided by pterm.
  • I also refactored the code so that the build artifact download step actually happens as a post-build step in the code flow.
  • I refactored addShellService to return whether it actually added the service.

Testing

Success case

michaellee@ROBOT-MYHLX2FTJN working-wheel % viam module reload --part-id 92b25c04-2fc3-444f-9062-15d73f228913
 ✓  Preparing for build... (1s)
 ✓     → Module is registered (0s)                                                                                                                                                                                
 ✓     → Source code archive created (0s)                                                                                                                                                                         
 ✓     → Source code uploaded (1s)                                                                                                                                                                                
 ✓  Building... (1m36s)
 ✓     → Build started (ID: 8015580d-b26d-4ba8-816e-a85cfa9736d0) (0s)                                                                                                                                            
 ✓     → Build completed successfully (1m36s)                                                                                                                                                                     
 ✓  Reloading to part... (27s)
 ✓     → Build artifact downloaded (11s)                                                                                                                                                                          
 ✓     → Shell service already exists (0s)                                                                                                                                                                        
 ✓     → Package uploaded (16s)                                                                                                                                                                                   
 ✓     → Module added to part (0s)   

Failed build case

michaellee@ROBOT-MYHLX2FTJN test3 % viam module reload --part-id cfc5404e-e269-425d-b1f9-ad7ce18790e9
Info: Using "app.viam.dev" as base URL value
 ✓  Preparing for build... (1s)
 ✓     → Module is registered (0s)                                                                                                                                                                                
 ✓     → Source code archive created (0s)                                                                                                                                                                         
 ✓     → Source code uploaded (1s)                                                                                                                                                                                
 …  Building...
 ✓     → Build started (ID: 447e7561-9f65-4f8f-bc96-032c26e7645e) (0s)                                                                                                                                            
 ✗     → Build 447e7561-9f65-4f8f-bc96-032c26e7645e failed                                                                                                                                                        
 ✗   Building...
Error: Build "447e7561-9f65-4f8f-bc96-032c26e7645e" failed to complete. Please check the logs below for more information.
Info: viam version
Version ..1-dev.- Git=ff808cb0 API=v0.1.483
Info: echo "::warning::git repository is missing. set 'url' in meta.json to your module's public git repo please"
::warning::git repository is missing. set 'url' in meta.json to your module's public git repo please
Info: curl "https://storage.googleapis.com/viam-packages-e277130c-c24d-428f-a62e-30244ac297bd/e277130c-c24d-428f-a62e-30244ac297bd/packages/test3/5Whuuh5b072iCNG4Pwa2gEYdE49ZyAbm2HfZHxpDmyFbHuYTFe1JrqPSGvSDr8TJ.tar.gz?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=app-service%!s(MISSING)taging-cloud-web-app.iam.gserviceaccount.com%!F(MISSING)20251024%!F(MISSING)auto%!F(MISSING)storage%!F(MISSING)goog4_request&X-Goog-Date=20251024T175643Z&X-Goog-Expires=899&X-Goog-Signature=44bea160e3369434540471cbf5cf25bae004b13e4a518b082547062d9647f45273a1d9501127d35d69edca7834fb9a81a4a1159447d1ce8c6da58345cce2d428f50952ac06bc3811890beb3c9e01f2a3f6e095d9d6e3f953b85f24d6fb0ee4734fd52f61ce7def8bcc94ab7a025258e102ec574ce74b778dcc03d8b33bcd9fa27bf86088708d09b47fff92cd7d08c2ea0a49859a8166d7cc3a638f21a3899a27a0f84eb6a81c65c08a1e472745152c233a8949fabdcebff949609c6eed115ae9be835fb1f4c5b62b81ef4863ee270cb4c7894889cdec94173101e73c549ad6e2e951e50b6817c023e185e094f89ae2fb58859c2b336200ef4f195baa0367994f&X-Goog-SignedHeaders=host" > repo_archive.tar.gz
tar -xzvf repo_archive.tar.gz

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5077  100  5077    0     0  20389      0 --:--:-- --:--:-- --:--:-- 20389
.github/workflows/deploy.yml
.gitignore
.viam-gen-info
README.md
build.sh
build.sh~
meta.json
requirements.txt
run.sh
setup.sh
src/main.py
src/models/test.py
Info: cd .
viam module build local

Info: Starting build
Info: Starting setup step: "./setup.sh"
Virtualenv found/created. Installing/upgrading Python packages...
Info: Starting build step: "./build.sh"
Error: Error running process "bash": exit status 1

Exited with code exit status 1
Info: Uploading artifacts
Uploading /tmp/module.tar.gz to tmp/module.tar.gz
  No artifact files found at /tmp/module.tar.gz
Total size uploaded: 0 B
Error: Reloading module failed

Prompt to create registry item case

michaellee@ROBOT-MYHLX2FTJN test3 % viam module reload --part-id cfc5404e-e269-425d-b1f9-ad7ce18790e9
Info: Using "app.viam.dev" as base URL value
 …  Preparing for build...
 ⠋     → Ensuring module is registered... (0s)
Error: module not registered in cloud or you lack permissions to edit it.
Info: The reloading process requires the module to first be registered in the cloud. Do you want to proceed with module registration?
Continue: y/n: 
 ✓  Preparing for build... (4s)
 ✓     → Module is registered (0s)                                                                                                                                                                                
 ✓     → Source code archive created (0s)                                                                                                                                                                         
 ✓     → Source code uploaded (1s)                                                                                                                                                                                
 ✓  Building... (1m32s)
 ✓     → Build started (ID: 30f47da2-3542-4487-9cb5-72cc7282ed2c) (0s)                                                                                                                                            
 ✓     → Build completed successfully (1m32s)   

Failed to copy to part case

michaellee@ROBOT-MYHLX2FTJN test3 % viam module reload --part-id cfc5404e-e269-425d-b1f9-ad7ce18790e9
Info: Using "app.viam.dev" as base URL value
 ✓  Preparing for build... (2s)
 ✓     → Module is registered (0s)                                                                                                                                                                                
 ✓     → Source code archive created (0s)                                                                                                                                                                         
 ✓     → Source code uploaded (2s)                                                                                                                                                                                
 ✓  Building... (1m18s)
 ✓     → Build started (ID: 570d4966-21a8-4f7d-9bef-4d7e4d16ad04) (0s)                                                                                                                                            
 ✓     → Build completed successfully (1m18s)                                                                                                                                                                     
 …  Reloading to part...
 ✓     → Build artifact downloaded (7s)                                                                                                                                                                           
 ✓     → Shell service already exists (0s)                                                                                                                                                                        
 ⠏     → Uploading package... (30s)2025-10-24T15:31:42.027-0400	DEBUG	shell/copy_local.go:328	unchecked error	{"error": "io: read/write on closed pipe"}
 ✗     → Uploading package...: io: read/write on closed pipe                                                                                                                                                      
 ✗   Reloading to part...
Error: Failed copying to part (~/.viam/packages-local/viam_test3_from_reload-dist-archive.tar.gz): io: read/write on closed pipe

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Oct 24, 2025
@michaellee1019 michaellee1019 changed the title Provide better progress messaging for hot reloading RSDK-12022 + RSDK-12276 Provide better progress messaging for hot reloading Oct 24, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 24, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 24, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 24, 2025
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks great. thanks for putting this together! I have a couple comments (mostly minor and optional) though I would like to continue respecting NoProgress or else not advertise it as a thing we do.

}

// Fail marks a step as failed with an error message.
func (pm *ProgressManager) Fail(stepID string, err error) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor, opt) this and FailWithMessage are largely duplicative, might be nice to factor out the shared bits. But also I think this will be touched infrequently enough that it's probably fine to just leave as is.

}

elapsed := time.Since(step.startTime)
if elapsed < 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(q) would it be useful to instead check that elapsed is greater than 10milis (the sleep time)?

Comment on lines 398 to 399
// We can't easily verify the text was updated since pterm doesn't expose it,
// but we can verify no error occurred
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we should be doing some sort of check after this comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this doesn't return an error. I think I will omit the test here since we cant assert anything.

}
err = vc.copyFilesToFqdn(
part.Part.Fqdn, globalArgs.Debug, false, false, []string{buildPath},
dest, logging.NewLogger(reloadVersionPrefix), args.NoProgress)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the only location where we used NoProgress for module reloading. I think ideally we should not create the progress manager if NoProgress is true, and have all PM methods return be no-ops if the pm pointer is nil. Barring that, we should probably remove NoProgress from the args type so we don't try to parse it, and make it hidden (though still existent for backwards compatibility) in the viam module reload args list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I was too focused on the goal of adding a spinner and forgot about this. Let me reincorporate NoProgress to not make there be a progress spinner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok --no-progress is now respected with the progress manager. I encapsulated it within the progress manager to avoid some gross if/else logic throughout everywhere a status is being set/updated.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 28, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 28, 2025
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice lgtm!

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 29, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 29, 2025
@michaellee1019 michaellee1019 merged commit b2a3b6c into viamrobotics:main Oct 29, 2025
18 checks passed
@michaellee1019 michaellee1019 deleted the ml/progress-spinner-2 branch October 29, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test This pull request is marked safe to test from a trusted zone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants