Skip to content

aitools: stop the calling script when auto-install is interrupted - #7874

Open
anton-107 wants to merge 2 commits into
mainfrom
aitools-auto-install-raise-signal
Open

anton-107 wants to merge 2 commits into
mainfrom
aitools-auto-install-raise-signal

Conversation

@anton-107

Copy link
Copy Markdown
Contributor

Changes

When auto-install catches a signal, the CLI now records its state and then ends by that signal. Before, it swallowed the signal and exited 0.

 autoInstall (after a command succeeded)
   gate lookup        catches SIGINT, SIGTERM, +SIGHUP
     record the version as a failed lookup
+    raise(sig)
   ask "Install Databricks AI tools ...? [Y/n]"   catches SIGINT
     settle the version as unanswered
+    raise(sig)
  • cmd/aitools/autoinstall_run.go: notifyInterrupt now takes the signals to catch, and its stop function returns the signal it caught, or nil. The gate lookup and the install question both use it. After the state is saved, they call raise(sig). A signal that arrives right after an answer, or after an interrupted lookup still answered from a cached manifest, also counts as a stop. The gate lookup now catches SIGHUP as well.
  • libs/process: new Raise(sig). On Unix it sends sig to the current process and waits up to a second for it to take effect. It returns only if the signal does not end the process, for example SIGHUP under nohup. On other platforms it does nothing. BackgroundInGroup now uses Raise, and it also forwards SIGHUP, so closing the terminal stops a coding agent's CLI while it installs its plugin.
  • Changelog fragment under .nextchanges/cli/.

Why

A shell stops a script, a loop or an && list only when the command ends by the signal. A command that catches Ctrl-C and exits 0 lets the script carry on. Auto-install runs after a command has already succeeded. So Ctrl-C at the install question, or while the gate is being looked up, let the rest of the script run, even though Ctrl-C at any other point in the command would have stopped it. The CLI still saves the answer, or the failed lookup, before it ends, so the next command neither asks again nor repeats the lookup.

Tests

  • TestAutoInstallEndsByTheSignal (Unix): runs the hook in a helper process and signals it at the question (SIGINT) and during the gate lookup (SIGINT, SIGTERM, SIGHUP). It checks that the helper ends by that exact signal and that the state on disk is already recorded.
  • TestAutoInstallStopsWhenTheGateLookupIsInterrupted: checks which signals are caught and that raise runs only after the version is recorded.
  • TestNotifyInterruptWithoutASignal: stopping with no signal returns nil.
  • TestRaiseEndsTheProcessBySignal and TestRaiseReturnsWhenTheSignalIsIgnored in libs/process.
  • TestBackgroundInGroupForwardsInterrupt now covers SIGHUP as well as SIGINT.

## Changes

When auto-install catches a signal, the CLI now records its state and then ends by that signal. Before, it swallowed the signal and exited 0.

```diff
 autoInstall (after a command succeeded)
   gate lookup        catches SIGINT, SIGTERM, +SIGHUP
     record the version as a failed lookup
+    raise(sig)
   ask "Install Databricks AI tools ...? [Y/n]"   catches SIGINT
     settle the version as unanswered
+    raise(sig)
```

- `cmd/aitools/autoinstall_run.go`: `notifyInterrupt` now takes the signals to catch, and its stop function returns the signal it caught, or nil. The gate lookup and the install question both use it. After the state is saved, they call `raise(sig)`. A signal that arrives right after an answer, or after an interrupted lookup still answered from a cached manifest, also counts as a stop. The gate lookup now catches SIGHUP as well.
- `libs/process`: new `Raise(sig)`. On Unix it sends `sig` to the current process and waits up to a second for it to take effect. It returns only if the signal does not end the process, for example SIGHUP under `nohup`. On other platforms it does nothing. `BackgroundInGroup` now uses `Raise`, and it also forwards SIGHUP, so closing the terminal stops a coding agent's CLI while it installs its plugin.
- Changelog fragment under `.nextchanges/cli/`.

## Why

A shell stops a script, a loop or an `&&` list only when the command ends by the signal. A command that catches Ctrl-C and exits 0 lets the script carry on. Auto-install runs after a command has already succeeded. So Ctrl-C at the install question, or while the gate is being looked up, let the rest of the script run, even though Ctrl-C at any other point in the command would have stopped it. The CLI still saves the answer, or the failed lookup, before it ends, so the next command neither asks again nor repeats the lookup.

## Tests

- `TestAutoInstallEndsByTheSignal` (Unix): runs the hook in a helper process and signals it at the question (SIGINT) and during the gate lookup (SIGINT, SIGTERM, SIGHUP). It checks that the helper ends by that exact signal and that the state on disk is already recorded.
- `TestAutoInstallStopsWhenTheGateLookupIsInterrupted`: checks which signals are caught and that `raise` runs only after the version is recorded.
- `TestNotifyInterruptWithoutASignal`: stopping with no signal returns nil.
- `TestRaiseEndsTheProcessBySignal` and `TestRaiseReturnsWhenTheSignalIsIgnored` in `libs/process`.
- `TestBackgroundInGroupForwardsInterrupt` now covers SIGHUP as well as SIGINT.

Co-authored-by: Isaac <no-reply@databricks.com>
@anton-107
anton-107 requested review from a team and lennartkats-db as code owners November 21, 2026 11:50
@github-actions github-actions Bot added the aitools AI tools (databricks aitools) related changes label Nov 21, 2026
Co-authored-by: Isaac <no-reply@databricks.com>

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review at 724c961. Each finding was verified against the code.

No blocking issues found.

The PR makes auto-install end by the caught signal (via Raise) instead of exiting 0, so that Unix shells stop the enclosing script. It also adds SIGHUP handling to BackgroundInGroup. The implementation is correct: notifyInterrupt synchronizes properly through the done channel, Raise produces a true signal death that shells distinguish from a normal exit, and the non-Unix no-op is documented and matches the unchanged base behavior on those platforms. Tests cover the key scenarios. No defects found.

@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: c5e1c6c

Run: 44901678120

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 272 19 3:55
💚​ aws-windows-latest-4core-16gb 1 274 17 3:22
💚​ azure linux-2core-8gb 1 271 19 3:42
💚​ azure-windows-latest-4core-16gb 1 273 17 4:34
💚​ gcp linux-2core-8gb 1 272 19 3:54
💚​ gcp-windows-latest-4core-16gb 1 274 17 4:13
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 4 slowest tests (at least 2 minutes):
duration env testname
4:31 azure-windows-latest-4core-16gb TestAccept
4:11 gcp-windows-latest-4core-16gb TestAccept
3:21 aws-windows-latest-4core-16gb TestAccept
2:01 gcp linux-2core-8gb TestAccept

This branch has not been deployed

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

Labels

aitools AI tools (databricks aitools) related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants