Unable to rebuild due to themes:update failing on unchanged theme

I’m trying to update to the latest stable (from 2.8.10 to 2.8.11) and it’s aborting while calling themes:update. I tried to run the themes:update task manually and the error is the same:

# rake themes:update
Checking 'xyz (darker)' for 'default'... Failed to update 'xyz (darker)': undefined method `scheme' for nil:NilClass
rake aborted!
NoMethodError: undefined method `scheme' for nil:NilClass
/var/www/discourse/lib/theme_store/git_importer.rb:129:in `clone_http!'
/var/www/discourse/lib/theme_store/git_importer.rb:94:in `clone!'
/var/www/discourse/lib/theme_store/git_importer.rb:19:in `import!'
/var/www/discourse/app/models/remote_theme.rb:126:in `update_remote_version'
/var/www/discourse/lib/tasks/themes.rake:62:in `block in update_themes'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:71:in `block (2 levels) in find_each'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:71:in `each'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:71:in `block in find_each'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:138:in `block in find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:245:in `block in in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:229:in `loop'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:229:in `in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:137:in `find_in_batches'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/relation/batches.rb:70:in `find_each'
/var/www/discourse/lib/tasks/themes.rake:56:in `update_themes'
/var/www/discourse/lib/tasks/themes.rake:87:in `block (2 levels) in <main>'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rails_multisite-4.0.0/lib/rails_multisite/connection_management.rb:80:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rails_multisite-4.0.0/lib/rails_multisite/connection_management.rb:90:in `each_connection'
/var/www/discourse/lib/tasks/themes.rake:86:in `block in <main>'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/cli/exec.rb:58:in `load'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/cli/exec.rb:58:in `kernel_load'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/cli/exec.rb:23:in `run'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/cli.rb:486:in `exec'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/cli.rb:31:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/cli.rb:25:in `start'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/exe/bundle:48:in `block in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/lib/bundler/friendly_errors.rb:120:in `with_friendly_errors'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.22/exe/bundle:36:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Tasks: TOP => themes:update
(See full trace by running task with --trace)

The theme in question has not been changed (for over a year) and is in fact pretty basic — only changes some colors and adds a single css rule, so something seems to have changed in discourse. Not sure if relevant, but the theme is remote (github private repos).

After this I noticed that if I try to update the theme from the web interface, I get a 500 error with similar error:

Started PUT "/admin/themes/48" for x.x.x.x at 2022-11-14 17:44:14 +0000
Processing by Admin::ThemesController#update as */*
  Parameters: {"theme"=>{"remote_check"=>true}, "id"=>"48"}
Completed 500 Internal Server Error in 1904ms (ActiveRecord: 0.0ms | Allocations: 24475)
NoMethodError (undefined method `scheme' for nil:NilClass)
lib/theme_store/git_importer.rb:129:in `clone_http!'
lib/theme_store/git_importer.rb:94:in `clone!'
lib/theme_store/git_importer.rb:19:in `import!'
app/models/remote_theme.rb:126:in `update_remote_version'
app/controllers/admin/themes_controller.rb:207:in `update'
app/controllers/application_controller.rb:387:in `block in with_resolved_locale'
app/controllers/application_controller.rb:387:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:361:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:198:in `call'

Any idea what I should be looking into? Can share the theme files if it helps.

EDIT TO ADD: Changing the repo to public stopped the error, so something seems to have changed with the handling of private repos using auth tokens. However, oddly, changing the repo back to private didn’t bring the error back on rebuild… Plus, there’s two remote themes with the same setup (in private repo) and only one of them failed.