Skip to content

setup drop-through: drop bash -i to fix Step 6 hang#221

Closed
uzyn wants to merge 1 commit into
mainfrom
worktree-fix-setup
Closed

setup drop-through: drop bash -i to fix Step 6 hang#221
uzyn wants to merge 1 commit into
mainfrom
worktree-fix-setup

Conversation

@uzyn

@uzyn uzyn commented May 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes aimx setup hanging at Step 6 with the terminal frozen after Dropping through to aimx agents setup as <user>.... Regression introduced four days ago by b9c1fa1, which added bash -i to the drop-through. Interactive bash here is several pgrps below the foreground (sudo -> aimx setup -> runuser -> bash); its tcsetpgrp(0, shell_pgrp) raises SIGTTOU and bash either self-stops or spin-retries.
  • Switches the drop-through from bash -ic to bash -lc (no job control) and explicitly prepends $HOME/.npm-global/bin and $HOME/.local/bin to PATH inside the shell command body. That replaces the ~/.bashrc-sourced PATH edits the prior fix was reaching for, without the deadlock.
  • Renames the regression test to drop_through_uses_login_bash_with_path_augmentation and adds positive assertions on the new shape (-lc, PATH=, .npm-global/bin) plus a negative assertion that -ic cannot return.

Test plan

  • cargo test --bin aimx drop_through — 2 passed (renamed regression + companion banner-reprint guard).
  • cargo clippy -- -D warnings — clean.
  • cargo fmt -- --check — clean.
  • Full cargo test — 1144 passed locally; the 3 uds_authz failures are macOS-specific nsswitch flake (UID 4294967294 resolves to nobody on macOS), confirmed to also fail on the unmodified branch. AIMX is Linux-only; CI on Ubuntu is unaffected.
  • Live shape verification on Ubuntu 24.04 (Docker): runuser -l ubuntu -s /bin/bash -- -lc 'PATH=$HOME/.npm-global/bin:... exec ...' exits 0 and resolves claude from the canonical ~/.npm-global/bin/.
  • End-to-end manual: rebuild on the host that previously hung, run sudo aimx setup, walk to Step 6. Expect the agents-setup TUI to render (or No AI agents detected on this user's filesystem. if none installed) instead of a frozen terminal.

The previous fix (b9c1fa1) switched the Step 6 drop-through from
`runuser -l USER -c CMD` to `runuser -l USER -s /bin/bash -- -ic CMD`
so stock Ubuntu's `~/.bashrc` body would actually run and put
`~/.npm-global/bin` (the canonical Claude Code install location) on
PATH for the auto-`mcp add` call.

That fix introduced a worse regression: `bash -i` calls
`initialize_job_control()`, which `tcsetpgrp(0, shell_pgrp)`'s the
controlling terminal. This bash sits at the bottom of
`sudo -> aimx setup -> runuser -> bash`, several pgrps away from the
foreground, so the kernel raises SIGTTOU and bash either self-stops
or spin-retries. Symptom: the wizard prints "Dropping through to
`aimx agents setup` as <user>..." and then the terminal freezes.
No TUI ever renders. Reproducible on stock Ubuntu (no exotic
~/.bashrc content needed).

Fix: switch `-ic` to `-lc` so bash never enables job control, and
explicitly prepend `$HOME/.npm-global/bin` and `$HOME/.local/bin`
to PATH inside the shell command body. That replaces the
`~/.bashrc`-sourced PATH edits the previous commit was reaching for,
without the deadlock-inducing `-i`. `bash -l` still sources
`/etc/profile` and `~/.profile`. `exec` replaces the bash wrapper
with the aimx process so the parent observes aimx's exit status
directly.

The renamed regression test
`drop_through_uses_login_bash_with_path_augmentation` locks in the
new shape and adds a positive guard that the shell command body
contains `PATH=` and `.npm-global/bin`, so a future refactor cannot
silently drop the augmentation and re-introduce the `CliMissing`
fallback.

Verified on Ubuntu 24.04 (Docker): the new
`runuser -l ubuntu -s /bin/bash -- -lc 'PATH=...:$HOME/.npm-global/bin:... exec ...'`
shape exits 0 and resolves `claude` from `~/.npm-global/bin/`.
@uzyn

uzyn commented May 11, 2026

Copy link
Copy Markdown
Owner Author

Too kludgy. Considering dropping direct MCP user setup with a message instructing user to run as regular user instead.

@uzyn uzyn closed this May 11, 2026
@uzyn uzyn deleted the worktree-fix-setup branch May 12, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant