Repository navigation
Conversation
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #817 +/- ##
==========================================
+ Coverage 80.46% 80.53% +0.06%
==========================================
Files 246 249 +3
Lines 18882 18931 +49
==========================================
+ Hits 15194 15246 +52
+ Misses 3688 3685 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cchensh
left a comment
There was a problem hiding this comment.
LGTM. The detach is right: Setsid on Unix and CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP on Windows, stdin is /dev/null with output to the log, and Release without Wait leaves no zombie. Starting in the install folder can't pick up a project's .slack. The tests would fail without the change. Some nits and follow-ups, none blocking:
spawn_windows.go:31: withoutCREATE_BREAKAWAY_FROM_JOB, a kill-on-close job (OpenSSH sessions, CI runners, some IDE terminals) kills the update when the parent's session ends, possibly mid-install. You could try breakaway first and fall back onERROR_ACCESS_DENIED.- Pre-existing, but it matters more now that installs run unattended (
cli_autoupdate.go:251then:176): the install renames the binary to the backup, then hard-links the new one. A SIGTERM in that gap (logout or shutdown) leaves no~/.slack/bin/slack. Linking to a temp file and renaming over the old binary would make the swap atomic on Unix. spawn.go:55:O_TRUNCruns on every spawn before the child checks the lock, so a second spawn wipes the log of the update that's actually running. Truncating after the lock is taken (or skipping the spawn whenTryLockfails) would keep it.spawn_test.go:121,129: the copied helper binaries have no.exe, andos.Symlinkneeds Developer Mode, so these would fail on Windows. They don't today only because unit tests run on macOS alone. A//go:build !windowsor the.exesuffix would fix it.autoupdate.go:34:_autoupdate <version>takes any string into the download URL and thebin/<version>path. A semver check is cheap.
WilliamBergamin
left a comment
There was a problem hiding this comment.
🧪 Thanks @zimeg! The re-exec test that checks the child's session, working directory and arguments makes the detach easy to trust.
One blocking comment on SLACK_CONFIG_DIR reaching the child, the rest are optional 🙏
| // isn't read or changed. Output goes to the autoupdate log in the logs folder, which is opened | ||
| // with os because the process writes to a file descriptor. | ||
| func startBackgroundUpdate(ctx context.Context, clients *shared.ClientFactory, targetVersion string) error { | ||
| binaryPath, ok := installScriptPath(ctx, clients) |
There was a problem hiding this comment.
💯 praise: Resolving through installScriptPath means a binary moved into backups/ never starts an update, and the test pins that case.
| } | ||
| defer logFile.Close() | ||
| command := exec.Command(binaryPath, args...) | ||
| command.Dir = filepath.Dir(binaryPath) |
There was a problem hiding this comment.
💯 praise: Running from the binary's folder keeps the child's InitConfig away from any project in the developer's directory.
…lid version - Set SLACK_CONFIG_DIR to the absolute config directory, since it overrides --config-dir - Return an invalid_semver error for a target that isn't a semantic version - Let LogsDir create the logs folder - Run the re-exec spawn test on Unix only and drop a duplicate isEnabled case Co-authored-by: William Bergamin <25348381+WilliamBergamin@users.noreply.github.com> Co-authored-by: Cheng Chen <35309699+cchensh@users.noreply.github.com> Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
|
🌟 Thanks for the review @cchensh!
|
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 @zimeg thanks for the quick turnaround! The child now gets the absolute config dir in both the env and the flag, and the test pins the relative SLACK_CONFIG_DIR case.
Left two small comments, nothing blocking 🙏
| command := exec.Command(binaryPath, backgroundUpdateArgs(targetVersion, configDir)...) | ||
| command.Dir = filepath.Dir(binaryPath) | ||
| if configDir != "" { | ||
| command.Env = append(os.Environ(), slackConfigDirEnv+"="+configDir) |
There was a problem hiding this comment.
💯 praise: Setting SLACK_CONFIG_DIR to the same absolute path means an inherited relative value can't override --config-dir anymore, and the spawn test checks exactly that.
The blocking concerns are resolved; see the latest review.
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 Thanks @zimeg! The main merge leaves this change exactly as reviewed, and the suite plus a Windows vet stay green on top of the tracer refactor.
Nothing new here, the earlier version-check suggestion is still optional 🚀
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 Thanks @zimeg! This merge only brings in the setup-go bump, so the change is exactly as reviewed, and the tests plus a Windows vet are still green.
Nothing new from me, the version-check suggestion is still optional 🚀
WilliamBergamin
left a comment
There was a problem hiding this comment.
🙏 @zimeg thanks for keeping this current with main; the new tracer flush doesn't change anything for the background process, and the tests still pass.
The open version-check suggestion from earlier is the only thing left, nothing blocking 💯
Co-authored-by: William Bergamin <25348381+WilliamBergamin@users.noreply.github.com> Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…config directory variable Co-authored-by: William Bergamin <25348381+WilliamBergamin@users.noreply.github.com> Co-authored-by: Michael Brooks <21328+mwbrooks@users.noreply.github.com> Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
|
📌 leaving this open while i'm out next week (11-23 to 11-27). no rush to land it before the next release, so here's where it stands for anyone who wants to help:
nothing calls |
WilliamBergamin
left a comment
There was a problem hiding this comment.
🪞 @zimeg thanks, IsReleaseVersion puts the check beside the other semver helpers and now turns away 4.12 and v4.12.0 before any download. One optional cleanup below, nothing blocking 💯
Co-authored-by: William Bergamin <25348381+WilliamBergamin@users.noreply.github.com> Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
WilliamBergamin
left a comment
There was a problem hiding this comment.
🪓 Thanks @zimeg! With that last restating comment gone, the background update reads cleanly end to end, and the release check and config dir each have one home.
Nothing left from me, this looks good to land 🚀
Changelog
N/A, groundwork for the
auto-updateexperiment.Summary
This pull request adds the hidden
_autoupdate <version>command andstartBackgroundUpdate, which starts that command in a detached process so a CLI update can install after a command without the developer waiting for it.startBackgroundUpdateruns the binary at<install-script folder>/<binary name>, the folder the install script check matched, instead ofos.Executable(). On Linuxos.Executablereads/proc/self/exe, which follows a binary that an update moved intobackups/<old>/. A running binary that resolves outside the install script folders, backups included, starts nothing._autoupdate <version>plus--config-dir <absolute path>when the parent had one, so the result is recorded where the next command reads it.Setsidon Unix, andCREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUPon Windows. Stdin is empty, and stdout and stderr go to<logs>/autoupdate.log, truncated each time and opened in append mode. The parent callsStartthenReleaseand doesn't wait.project_id, and run the.slackfolder cleanup after the developer's command has finished._autoupdatecallsupdate.AutoUpdatewith the running version and the target, and turns off telemetry before it runs._autoupdateby the parsed command, as it does forupgrade, so the background process never starts its own check or prints a notice.isInstallScriptnow wrapsinstallScriptPath, which also returns the resolved path it matched. Its callers don't change.startBackgroundUpdateyet; the next PR starts it after commands with theauto-updateexperiment.Preview
N/A, nothing changes for developers yet.
Testing
The unit tests cover the review focus for this step:
Test_UpdateNotification_isEnabled"skips the background update" and "… with a custom config directory" (--config-dirafter the command) are false.--config-dir:Test_backgroundUpdateArgskeeps a custom config directory and makes a relative one absolute.Test_startBackgroundUpdate"starts the binary with a custom config directory" checks the arguments the started process got.Test_startBackgroundUpdate"skips a running binary that moved to the backups folder" mocksos.Executable()tohome/.slack/bin/backups/v4.11.0/slackand starts nothing. "… from a symbolic link" starts the install script binary, not the link.Test_startBackgroundUpdatere-runs the test binary as the started process. It waits for a file the test writes only afterstartBackgroundUpdatereturns, then reports its arguments, working directory, and whether it leads its own session. The log holds only its output.Test_detachchecks theSysProcAttron each platform.Test_NewAutoUpdateCommandchecks telemetry is off beforeAutoUpdateruns. The usage event is sent after the command returns and reads that flag then.Manual steps, in a sandboxed
HOME(a dev build counts as newer than the latest release, so build it with an older version):v4.14.0, the old one is backed up to/tmp/c3home/config/bin/backups/v4.13.0, and/tmp/c3home/config/autoupdate.jsonis{"from":"v4.13.0","to":"v4.14.0"}.FlushToLogstashline is printed. The same flags onauth listprint one.v4.14.0in that folder,_autoupdate 4.14.0prints "Skipping the update since 4.14.0 is already installed", with no backup and no record.Notes
osrather thanclients.Fs, since the process needs a file descriptor, as with the lock in feat: install CLI updates with a lock and record the result #807.CREATE_NO_WINDOWrather thanDETACHED_PROCESSfrom the plan. A process with no console gives each console program it starts a new console window, and the background process runsslack --versiontwice (the already-installed check and the verify step), so each would flash a window. With a hidden console of its own, it still doesn't share the terminal's console or receive its interrupts. Windows wasn't run by hand;GOOS=windowsbuilds and vets.backgroundUpdateArgsreturns an error too, from making the config directory absolute. It trims the flag first, like the parent does.startBackgroundUpdateFunccomes with its caller in the next PR, since an unused variable fails lint.Release, so it stays a zombie until the parent exits, right after the command in the next PR.main.gobefore flags are read and doesn't honorSLACK_DISABLE_TELEMETRYfor any command, so the background process sends spans too. That's unchanged here.Requirements
🤖 Generated with Claude Code