Skip to content

feat: install CLI updates without a prompt from the upgrade command with the auto-update experiment - #818

Open
zimeg wants to merge 18 commits into
mainfrom
zimeg-feat-auto-update-upgrade
Open

zimeg wants to merge 18 commits into
mainfrom
zimeg-feat-auto-update-upgrade

Conversation

@zimeg

@zimeg zimeg commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Changelog

The auto-update experiment has slack upgrade install Slack CLI updates without asking first.

Summary

This pull request has slack upgrade install a Slack CLI update without a prompt when the auto-update experiment is on, and has every foreground install take the same lock as AutoUpdate from #807.

  • Adds the auto-update experiment, with a line in docs/reference/experiments.md.
  • UpdateNotification.InstallUpdates installs 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 upgrade calls it with the experiment on and calls PrintAndPromptUpdates otherwise, and a failed check still returns cli_update_check_error.
  • CLIDependency.InstallUpdate now takes the lock next to the binary in the installation folder before installing. That covers slack upgrade with the experiment and the interactive self-update after the prompt without it:
    • While another update holds the lock, it prints "Waiting for another update to finish..." and waits rather than skipping. Ctrl-C cancels the wait without installing.
    • With the lock held, it runs the binary with --version, and if that already reports the target, it prints the up-to-date message and doesn't install again.
    • When the lock can't be created or taken for any reason other than another holder, it logs that to the debug log and installs anyway, so a lock problem never blocks a manual upgrade. An error after another holder was seen, Ctrl-C included, returns the error instead, so it never installs alongside a running update.
    • When the running binary resolves outside the installation folders, as it does on Linux after another update moved it into backups/, it returns an error instead of locking and checking the moved binary. AutoUpdate skips in that case too.
  • The lock path and the --version check are shared with AutoUpdate through newUpdateLock and isInstalled, not copied. newUpdateLock resolves the binary with installScriptPath, the same change to install_script.go as feat: start CLI updates in a detached background process #817. The existing install moves to an unexported installUpdate, which installUpdateFunc calls with the lock already held.

Preview

With the experiment, while another update holds the lock:

$ slack upgrade --experiment auto-update

   Waiting for another update to finish...
   Starting the auto-update...
   Downloading version 4.14.0...
   Found current install path: ~/.slack/bin/slack
   Extracting the download: ~/.slack/bin/4.14.0
   Backing up current install: ~/.slack/bin/backups/v4.10.0
   Updating to version 4.14.0: ~/.slack/bin/slack
   Successfully updated to version 4.14.0
   Verifying the update...

Testing

In a sandboxed HOME with a binary built to report v4.10.0 in ~/.slack/bin:

  1. slack upgrade --experiment auto-update installs v4.14.0 with the progress output above and no prompt.
  2. Without --experiment, the notice and the "Do you want to auto-update to the latest version now?" prompt show as before.
  3. With a second process holding ~/.slack/bin/autoupdate.lock for 8 seconds, slack upgrade --experiment auto-update prints the waiting line, then installs once the lock is released.

A dev build from main reports v4.14.0-<n>-g<sha>, which counts as 4.14.0, so with SLACK_TEST_VERSION=v4.10.0 the 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 ./... and go vet pass.

Notes

  • The background spawn in the next PR runs AutoUpdate, which skips when the lock is held. Foreground installs wait instead, since a developer asked for that update.
  • The experiment line in docs/reference/experiments.md describes only slack upgrade for now. It grows when background updates turn on.
  • Without the experiment, two changes reach anyone who accepts the self-update prompt: autoupdate.lock is now created in the install folder, and a second terminal that accepts while another install runs waits for it to finish.
  • With the experiment on, slack upgrade in 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

zimeg and others added 2 commits November 20, 2026 02:14
…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>
@zimeg
zimeg requested review from a team as code owners November 20, 2026 10:18
@zimeg zimeg added this to the Next Release milestone Nov 20, 2026
@zimeg zimeg added enhancement M-T: A feature request for new functionality changelog Use on updates to be included in the release notes experiment Experimental feature accessed behind the --experiment flag or toggle semver:patch Use on pull requests to describe the release version increment labels Nov 20, 2026
@zimeg zimeg self-assigned this Nov 20, 2026
@zimeg
zimeg requested a review from mwbrooks November 20, 2026 10:19
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.40%. Comparing base (1829e0a) to head (2481eb4).

Files with missing lines Patch % Lines
internal/update/install_script.go 71.42% 2 Missing ⚠️
internal/update/background.go 83.33% 1 Missing ⚠️
internal/update/cli_autoupdate.go 94.44% 1 Missing ⚠️
internal/update/update.go 88.88% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cchensh cchensh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 upgrade with the experiment) starts while process A is installing. A renames B's binary into backups/vX/ before B reaches newUpdateLock, and the ConfirmPrompt wait (isInstallScript runs at cli.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.
    • isInstalled runs the old backup and returns false.
    • B re-extracts bin/<new>/slack with O_TRUNC (archiveutil.go:113). That's the same file the live ~/.slack/bin/slack hard-links to, so it hits ETXTBSY or briefly truncates the running binary, and then os.Link fails with EEXIST.

#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 upgrade now installs without a prompt in CI and non-TTY shells too (upgrade.go:70), while the help text at :44 says the prompt is skipped in non-interactive shells. A committed project .slack/config.json can 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 --version call has no context) makes upgrade wait until Ctrl-C. A cap with a clear error would help.
  • InstallUpdates (update.go:106) copies the PrintAndPromptUpdates loop; 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>
@zimeg

zimeg commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

🔒 Thanks for catching the rename race @cchensh! Fixed in 0d0006d:

  • newUpdateLock now resolves the binary with installScriptPath, which is the same change to install_script.go as feat: start CLI updates in a detached background process #817, so the two merge cleanly. The lock and the --version check both use the binary in the installation folder, in AutoUpdate and InstallUpdate.
  • When the running binary resolves outside those folders, as it does on Linux after another update moved it into backups/, InstallUpdate returns cli_auto_update instead of installing anyway, and AutoUpdate skips. A lock that can't be created still falls back to installing.
  • New cases cover a moved binary while another update holds the lock, in both Test_AutoUpdate and Test_CLIDependency_InstallUpdate. Going back to Executable plus EvalSymlinks fails both.

On the smaller points:

  • Non-TTY with the experiment: thanks for weighing in on the open question in the Notes. I'm leaving it open for now so Michael can weigh in too before it changes.
  • No cap on the lock wait: saved for a follow-up, along with a related edge I found here. If the holder fails and restores the old binary while this process waits, installUpdate still resolves os.Executable() on its own instead of using the path that took the lock.
  • The duplicated loop: saved for a follow-up as well. I kept PrintAndPromptUpdates untouched in this PR so the default prompt path only changes by the lock.

@zimeg
zimeg requested a review from cchensh November 20, 2026 14:45

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧠 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯 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.

Comment thread internal/update/cli_autoupdate.go Resolved
if err != nil {
return slackerror.Wrap(err, slackerror.ErrCLIAutoUpdate)
}
locked, err := lock.TryLock()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤔 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯 praise: TryLockContext on a kernel flock means Ctrl-C cancels the wait cleanly, and a crashed holder never leaves a stale lock.

Comment thread internal/update/update.go Resolved
Comment thread internal/update/update.go Resolved
Comment thread internal/update/update.go Resolved
Comment thread cmd/upgrade/upgrade.go

if err := updateNotification.PrintAndPromptUpdates(cmd); err != nil {
var err error
if clients.Config.WithExperimentOn(experiment.AutoUpdate) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤔 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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯 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 mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧩 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 🙏

Comment thread internal/update/update.go

// 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧩 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).

Suggested change
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 WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🙏 @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": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧪 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 WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 @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 💯

@zimeg

zimeg commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

📌 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:

  • reviews: approved by Michael at 8c4b89e, and CI is green. Cheng's review is still requested.
  • open questions:
    1. when TryLock errors, the install still runs without the lock. William asked whether that's worth keeping, since a lock file another user owns (say after a sudo slack upgrade) would let two installs overlap. the other option is an error that says to remove the lock file.
    2. with the experiment on, should slack upgrade install without asking in CI or a pipe? Michael and William lean toward installing for an explicit -e auto-update, with the help or the experiments doc updated to agree. Cheng suggested keeping non-TTY runs notice-only until GA, since a committed .slack/config.json can turn the experiment on for every contributor and CI job.
  • non-blocking suggestions still open: passing binaryPath into installUpdate (Michael), a bool instead of a func for installUpdates (William), and a test case in upgrade_test.go on an older binary that checks the install script runs (William).

this stays behind the auto-update experiment 🧪

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 @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 WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔁 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 WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔁 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 WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔁 Thanks @zimeg! This main merge (the create directory access fix from #877) leaves the PR's own diff unchanged, and the update, upgrade, experiment, and create tests pass locally on this head. The earlier open threads still stand as-is, nothing new from me.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔁 Thanks @zimeg! This main merge (the golangci-lint bump from #878) leaves the PR's own diff unchanged, and the update, upgrade, experiment, platform, and cmd tests pass locally on this head. The earlier open threads still stand as optional, nothing new from me.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog Use on updates to be included in the release notes enhancement M-T: A feature request for new functionality experiment Experimental feature accessed behind the --experiment flag or toggle semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants