Repository navigation
feat: install CLI updates without a prompt from the upgrade command with the auto-update experiment - #818
feat: install CLI updates without a prompt from the upgrade command with the auto-update experiment#818zimeg wants to merge 18 commits into
Conversation
…ith the auto-update experiment Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…alling alongside it Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #818 +/- ##
==========================================
+ Coverage 81.35% 81.40% +0.05%
==========================================
Files 247 247
Lines 18881 18911 +30
==========================================
+ Hits 15360 15394 +34
+ Misses 3521 3517 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cchensh
left a comment
There was a problem hiding this comment.
Thanks! The experiment gate defaults off when the config can't be read, the foreground wait can be cancelled, and the re-check under the lock closes the earlier gap where upgrade didn't take the lock. One race worth fixing here, or ticketing before background spawns turn on, checked at 823fbb9:
On Linux, the lock path follows a renamed binary (background.go:89-90, used by InstallUpdate at cli_autoupdate.go:57). newUpdateLock derives the lock from Os.Executable() plus EvalSymlinks. On Linux that's /proc/self/exe, which follows the inode after a rename.
- When it happens: process B (the prompt path, or
upgradewith the experiment) starts while process A is installing. A renames B's binary intobackups/vX/before B reachesnewUpdateLock, and theConfirmPromptwait (isInstallScriptruns atcli.go:96, before the prompt) gives that plenty of time. - What B does then:
- B locks
backups/vX/autoupdate.lock, so it doesn't wait for A. isInstalledruns the old backup and returns false.- B re-extracts
bin/<new>/slackwithO_TRUNC(archiveutil.go:113). That's the same file the live~/.slack/bin/slackhard-links to, so it hits ETXTBSY or briefly truncates the running binary, and thenos.Linkfails with EEXIST.
- B locks
#817 already avoids this for the spawn by using installScriptPath. Using that same install path for the lock and for the binary isInstalled checks, in both AutoUpdate and InstallUpdate, would close it.
Smaller:
- With the experiment on,
slack upgradenow installs without a prompt in CI and non-TTY shells too (upgrade.go:70), while the help text at:44says the prompt is skipped in non-interactive shells. A committed project.slack/config.jsoncan also turn the experiment on for every contributor and CI job. On your open question, I'd keep non-TTY runs notice-only until GA. TryLockContext(cli_autoupdate.go:69) has no overall timeout, so a hung holder (e.g.verifyUpgrade's--versioncall has no context) makesupgradewait until Ctrl-C. A cap with a clear error would help.InstallUpdates(update.go:106) copies thePrintAndPromptUpdatesloop; a parameter would keep them from drifting.
…d binary can't race another update Co-authored-by: Cheng Chen <35309699+cchensh@users.noreply.github.com> Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
|
🔒 Thanks for catching the rename race @cchensh! Fixed in 0d0006d:
On the smaller points:
|
WilliamBergamin
left a comment
There was a problem hiding this comment.
🧠 Thanks @zimeg! Taking the lock from the install-script path closes the Linux case where a moved binary could race a finished update, and the moved-binary tests pin it.
Left a few comments, nothing blocking 🙏
| // the running binary resolves outside of those folders, as it does on Linux after another update | ||
| // moved the running binary to the backups folder. | ||
| func newUpdateLock(ctx context.Context, clients *shared.ClientFactory) (*flock.Flock, string, error) { | ||
| binaryPath, ok := installScriptPath(ctx, clients) |
There was a problem hiding this comment.
💯 praise: Deriving the lock from installScriptPath means a binary another update moved into backups/ can never pick a different lock, which was the one real race left here.
| if err != nil { | ||
| return slackerror.Wrap(err, slackerror.ErrCLIAutoUpdate) | ||
| } | ||
| locked, err := lock.TryLock() |
There was a problem hiding this comment.
🤔 question (non-blocking): When TryLock errors, the install still runs without the lock. Is that worth keeping now that a moved binary returns an error? A lock file another user owns, say after a sudo slack upgrade, would let two installs overlap.
| } | ||
| if !locked { | ||
| c.clients.IO.PrintInfo(ctx, false, "%s", style.Indent(style.Secondary("Waiting for another update to finish..."))) | ||
| if _, err := lock.TryLockContext(ctx, lockRetryDelay); err != nil { |
There was a problem hiding this comment.
💯 praise: TryLockContext on a kernel flock means Ctrl-C cancels the wait cleanly, and a crashed holder never leaves a stale lock.
|
|
||
| if err := updateNotification.PrintAndPromptUpdates(cmd); err != nil { | ||
| var err error | ||
| if clients.Config.WithExperimentOn(experiment.AutoUpdate) { |
There was a problem hiding this comment.
🤔 question (non-blocking): With the experiment on, slack upgrade installs without asking in CI or a pipe, but the help above still says the prompt is skipped there. Installing seems right for an explicit -e auto-update; could we add a line to the help or the experiments doc so they agree?
| if !tc.lockUnavailable { | ||
| locked, err := flock.New(lockPath).TryLock() | ||
| require.NoError(t, err) | ||
| assert.False(t, locked, "the lock is held while installing") |
There was a problem hiding this comment.
💯 praise: Asserting the lock is held from inside the stubbed install tests the real guarantee, not just the install count.
…mmand Co-authored-by: William Bergamin <25348381+WilliamBergamin@users.noreply.github.com> Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
mwbrooks
left a comment
There was a problem hiding this comment.
✅ Thanks @zimeg! Checking the version under the lock means a second terminal waits, then skips instead of installing over a finished update. On the non-TTY question, installing without a prompt feels right for an explicit -e auto-update, so updating the help when the experiment ships works for me.
| c.clients.IO.PrintInfo(ctx, false, "%s You are using the latest Slack CLI version", style.Green("✔")) | ||
| return nil | ||
| } | ||
| return installUpdateFunc(ctx, c) |
There was a problem hiding this comment.
suggestion (non-blocking): Since InstallUpdate already locked and checked binaryPath, could installUpdate take it instead of calling os.Executable() again? On Linux a waiting process whose binary was moved into backups/ could otherwise install there. Fine as the follow-up you mentioned too.
WilliamBergamin
left a comment
There was a problem hiding this comment.
🧩 Thanks @zimeg! The shared installUpdates loop means the prompt and no-prompt paths can't drift apart now.
One small optional idea on its shape; the TryLock and help-text questions from before are still open whenever you get to them 🙏
|
|
||
| // installUpdates installs each update that installsWithoutPrompt allows, and prints the update | ||
| // notice for the others, installing those that the notice prompts for and the user accepts. | ||
| func (u *UpdateNotification) installUpdates(cmd *cobra.Command, installsWithoutPrompt func(context.Context, Dependency) bool) error { |
There was a problem hiding this comment.
🧩 suggestion (non-blocking): PrintAndPromptUpdates only ever passes a func that returns false, so could this take a bool instead? Then the check reads installCLIWithoutPrompt && u.installsWithoutPrompt(ctx, dependency).
| func (u *UpdateNotification) installUpdates(cmd *cobra.Command, installsWithoutPrompt func(context.Context, Dependency) bool) error { | |
| func (u *UpdateNotification) installUpdates(cmd *cobra.Command, installCLIWithoutPrompt bool) error { |
WilliamBergamin
left a comment
There was a problem hiding this comment.
🙏 @zimeg thanks, the main merge keeps the change itself the same and everything still passes locally on this head. Left one optional test comment, nothing blocking. 💯
| expectedOutput: "A new version of the Slack CLI is available", | ||
| expectedPrompt: true, | ||
| }, | ||
| "skips the prompt with the auto-update experiment": { |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): The fake binary here already reports 99.0.0, so this case takes the already-installed skip and never installs. Could we name it for that ("skips the install when the binary is already current"), or add a case on an older binary that checks the install script runs?
WilliamBergamin
left a comment
There was a problem hiding this comment.
📝 @zimeg thanks, re-checked after the latest main merge: the PR's own changes are unchanged and the tracer flush from main doesn't touch the lock wait or install paths. The earlier non-blocking threads still stand, nothing new 💯
|
📌 leaving this open too while i'm out next week (11-23 to 11-27). no rush before the next release, so here's the current state for anyone who wants to help land it:
this stays behind the |
WilliamBergamin
left a comment
There was a problem hiding this comment.
📝 @zimeg re-checked after the latest main merge: the PR's own changes are unchanged, and the gofrs/flock 0.13.2 bump only makes TryLockContext notice a cancel between retries, which tightens the Ctrl-C path here. Tests still pass on it. The earlier non-blocking threads still stand, nothing new 💯
WilliamBergamin
left a comment
There was a problem hiding this comment.
🔁 Thanks @zimeg! The latest main merge keeps the PR's own diff unchanged, and the update, upgrade, and experiment tests pass again with the OpenTelemetry changes from main.
Nothing new from me, the open threads are all optional 🙏
WilliamBergamin
left a comment
There was a problem hiding this comment.
🔁 Thanks @zimeg! These main merges (the OpenTracing bridge removal, the api --app fix, and new tests) leave the PR's own diff unchanged, and the update, upgrade, experiment, tracer, and cmd tests pass again on the new head. Nothing new from me; the open threads above still stand as optional.
WilliamBergamin
left a comment
There was a problem hiding this comment.
Re-checked on 2481eb4: this merge brings in #879 (test-only edits in cmd/datastore), and the PR's own diff is unchanged. Tests, the Windows build, and vet all pass locally, and CI is green. Nothing new from me; the two open suggestions still stand, and both are optional.
Changelog
The
auto-updateexperiment hasslack upgradeinstall Slack CLI updates without asking first.Summary
This pull request has
slack upgradeinstall a Slack CLI update without a prompt when theauto-updateexperiment is on, and has every foreground install take the same lock asAutoUpdatefrom #807.auto-updateexperiment, with a line indocs/reference/experiments.md.UpdateNotification.InstallUpdatesinstalls a CLI update placed by the installation scripts straight away, with the existing progress output. Other CLI installs, such as Homebrew, still show the update notice, and SDK updates prompt as before.slack upgradecalls it with the experiment on and callsPrintAndPromptUpdatesotherwise, and a failed check still returnscli_update_check_error.CLIDependency.InstallUpdatenow takes the lock next to the binary in the installation folder before installing. That coversslack upgradewith the experiment and the interactive self-update after the prompt without it:--version, and if that already reports the target, it prints the up-to-date message and doesn't install again.backups/, it returns an error instead of locking and checking the moved binary.AutoUpdateskips in that case too.--versioncheck are shared withAutoUpdatethroughnewUpdateLockandisInstalled, not copied.newUpdateLockresolves the binary withinstallScriptPath, the same change toinstall_script.goas feat: start CLI updates in a detached background process #817. The existing install moves to an unexportedinstallUpdate, whichinstallUpdateFunccalls with the lock already held.Preview
With the experiment, while another update holds the lock:
Testing
In a sandboxed
HOMEwith a binary built to reportv4.10.0in~/.slack/bin:slack upgrade --experiment auto-updateinstalls v4.14.0 with the progress output above and no prompt.--experiment, the notice and the "Do you want to auto-update to the latest version now?" prompt show as before.~/.slack/bin/autoupdate.lockfor 8 seconds,slack upgrade --experiment auto-updateprints the waiting line, then installs once the lock is released.A dev build from
mainreportsv4.14.0-<n>-g<sha>, which counts as 4.14.0, so withSLACK_TEST_VERSION=v4.10.0the check under the lock prints "You are using the latest Slack CLI version" and doesn't install. That's the intended behavior.The unit tests cover:
InstallUpdates: installs a CLI from the installation scripts without a prompt, prints the notice for other installs, and still prompts for SDK updates.slack upgrade: prompts without the experiment, and skips the prompt with it.InstallUpdate: holds the lock while installing, waits for another holder and then skips once the binary reports the target, skips when the binary already reports the target, still installs when the lock can't be created, and returns without installing when cancelled while waiting.Removing the experiment gate, the lock, the check under the lock, or the fallback when the lock can't be created each fails at least one of these tests.
GOOS=windows go build ./...andgo vetpass.Notes
AutoUpdate, which skips when the lock is held. Foreground installs wait instead, since a developer asked for that update.docs/reference/experiments.mddescribes onlyslack upgradefor now. It grows when background updates turn on.autoupdate.lockis now created in the install folder, and a second terminal that accepts while another install runs waits for it to finish.slack upgradein a non-interactive shell installs without a prompt too, since nothing asks first. The command's help still says the prompt is skipped in non-interactive environments. Should that case keep showing only the notice, or should the help change once the experiment ships?Requirements
🤖 Generated with Claude Code