Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias evaluation is not deterministic #1237

Closed
smemsh opened this issue Sep 22, 2024 · 4 comments
Closed

alias evaluation is not deterministic #1237

smemsh opened this issue Sep 22, 2024 · 4 comments
Labels
Bug Confirmed to be a bug Easy Good for new contributors
Milestone

Comments

@smemsh
Copy link

smemsh commented Sep 22, 2024

Required information

  • Distribution: Ubuntu
  • Distribution version: 22
  • Kernel version: 6.8.0-40-generic
  • LXC version: 6.0.0
  • Incus version: zabbly 1:6.5-ubuntu22.04-202409162056

Issue description

alias evaluation is not deterministic. reissuing same aliased command has random effect.

Steps to reproduce

 $ incus alias list -f compact | grep prof
  prof        profile                  
  prof ls     profile list -f compact  
  profile ls  profile list -f compact  

 $ incus prof ls
+---------+-----------------------+---------+
|  NAME   |      DESCRIPTION      | USED BY |
+---------+-----------------------+---------+
| default | Default Incus profile | 0       |
+---------+-----------------------+---------+

 $ incus prof ls
   NAME         DESCRIPTION       USED BY  
  default  Default Incus profile  0        

 $ incus prof ls
   NAME         DESCRIPTION       USED BY  
  default  Default Incus profile  0        

 $ incus prof ls
+---------+-----------------------+---------+
|  NAME   |      DESCRIPTION      | USED BY |
+---------+-----------------------+---------+
| default | Default Incus profile | 0       |
+---------+-----------------------+---------+

note how sometimes compact is in effect, other times it is not, although it's the same command. It seems roughly even, with a little bias towards ignoring format:

 $ unset hits; declare -A hits; \
   for ((i = 0; i < 1000; i++))
   do len=$(incus prof ls | wc -l); let "hits[$len]++"; done; \
   for hit in ${!hits[@]}; do echo "$hit:${hits[$hit]}"; done
5:589
2:411
@stgraber stgraber added Bug Confirmed to be a bug Easy Good for new contributors labels Sep 22, 2024
@stgraber stgraber added this to the incus-6.6 milestone Sep 22, 2024
@stgraber
Copy link
Member

In Go, dictionaries are not sorted so the order when accessed is basically random, leading to what we see here.

We can probably get the dict keys, sort them alphabetically and then process the map to have a consistent order.

@smemsh
Copy link
Author

smemsh commented Sep 23, 2024

Why does one of the possibilities it's cycling between, not have the -f compact? For these alias definitions:

prof        profile                  
prof ls     profile list -f compact  
profile ls  profile list -f compact  

both forms with the ls have -f compact. So why is incus prof ls resolving to any possibility without it? Stranger still, it knows enough to expand the list part but drops the -f compact !?

Note, they were defined like:

 $ incus alias add "prof ls" "profile list -f compact"

@stgraber
Copy link
Member

I suspect it's because we don't re-enter alias evaluation.

So when the matching alias is your prof=profile one, then you don't get the argument.

@smemsh
Copy link
Author

smemsh commented Sep 24, 2024

maybe it should match command line against possible alias matches in longest to shortest alias order.

recursive alias evaluation could be useful. loop detected could end recursion.

partial/stem/prefix command word matching would help too. a lot of aliases wouldn't be necessary then.

@tych0 tych0 closed this as completed in 7030add Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed to be a bug Easy Good for new contributors
Development

No branches or pull requests

2 participants