Skip to content

fix(environments): insert -- between setsid and bash to fix Termux (closes #37124)#37240

Closed
alaamohanad169-ship-it wants to merge 1 commit into
NousResearch:mainfrom
alaamohanad169-ship-it:fix/37124-termux-setsid-separator
Closed

fix(environments): insert -- between setsid and bash to fix Termux (closes #37124)#37240
alaamohanad169-ship-it wants to merge 1 commit into
NousResearch:mainfrom
alaamohanad169-ship-it:fix/37124-termux-setsid-separator

Conversation

@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor

Closes #37124

Root cause

GatewayRunner builds an argv list for the detached restart and update
subprocesses as [setsid_bin, "bash", "-lc"|"-c", <command>]. POSIX
requires -- to terminate option parsing for the parent so that the
flags destined for the child are not interpreted by the parent.

On Termux (util-linux setsid 2.41.3) the setsid binary advertises
-c, --ctty and several other single-letter options. When invoked as
setsid bash -lc <cmd> those flags can be swallowed by setsid
itself rather than forwarded to bash, causing the spawned shell
command to fail silently (no error message, just no execution).

The same hazard exists for the /update path, which uses
setsid bash -c <update_cmd>.

Fix

Insert -- between the setsid path and bash in both call sites
in gateway/run.py:

  • gateway/run.py:3985 — detached restart command (setsid bash -lc ...)
  • gateway/run.py:14845 — detached update command (setsid bash -c ...)

After the change the argv is [setsid_bin, "--", "bash", "-lc", <cmd>],
which is POSIX-conformant and prevents the parent from consuming the
child's option flags on any conforming setsid implementation.

Tests

  • Updated tests/gateway/test_restart_drain.py::test_launch_detached_restart_command_uses_setsid
    to assert cmd[:3] == ["/usr/bin/setsid", "--", "bash"].
  • Updated tests/gateway/test_update_command.py::TestHandleUpdateCommand::test_spawns_setsid
    to assert that index 1 of the argv is "--" and index 2 is "bash".
  • Added test_launch_detached_restart_command_inserts_double_dash_separator
    — a dedicated regression test that locates the setsid path in the
    argv and asserts that --, bash, and -lc follow it in order.
  • Added TestHandleUpdateCommand::test_spawns_setsid_with_double_dash_separator
    — same dedicated regression test for the /update path (asserts
    --, bash, and -c follow the setsid path).

Test run (relevant file scope only):

tests/gateway/test_restart_drain.py tests/gateway/test_update_command.py
47 passed in 2.37s

Targeted regression tests (new and modified):

tests/gateway/test_restart_drain.py::test_launch_detached_restart_command_inserts_double_dash_separator PASSED
tests/gateway/test_update_command.py::TestHandleUpdateCommand::test_spawns_setsid_with_double_dash_separator PASSED
tests/gateway/test_restart_drain.py::test_launch_detached_restart_command_uses_setsid PASSED
tests/gateway/test_update_command.py::TestHandleUpdateCommand::test_spawns_setsid PASSED
4 passed in 0.53s

Manual verification (on Termux)

Ran a side-by-side subprocess test against this host's
/data/data/com.termux/files/usr/bin/setsid (util-linux 2.41.3).
On this particular util-linux build getopt_long stops at the first
non-option (bash) so the simple echo cases worked without -- too,
but the -- form is still required by POSIX and prevents the silent
failure mode on stricter / future setsid implementations. The new
tests pin the correct argv shape so any regression will be caught.

Notes

  • Minimal diff: 2 source-line changes + 2 test updates + 2 new tests.
  • Branched from upstream/main (merge-base verified == upstream/main HEAD).
  • Pushed to fork (alaamohanad169-ship-it/hermes-agent); PR opened
    against NousResearch/hermes-agent:main.
  • Part of the Auto Money Agency fix-flow pipeline (fix agent).

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels Jun 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #37137 (fix(gateway): add -- separator between setsid and bash for Termux) — identical fix inserting -- between the setsid path and bash in the detached restart/update argv. Both close #37124. Suggest consolidating on whichever is further along.

@alaamohanad169-ship-it alaamohanad169-ship-it force-pushed the fix/37124-termux-setsid-separator branch from f11c829 to 9ed97af Compare June 3, 2026 00:50
@alaamohanad169-ship-it alaamohanad169-ship-it deleted the fix/37124-termux-setsid-separator branch June 6, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Termux] setsid bash -lc fails on Termux (-- separator missing)

2 participants