Repository navigation
fix(sagemaker-ai): remove ssm-exec.sh temp file after each call - #292
Open
TheSaiEaranti wants to merge 1 commit into
Open
TheSaiEaranti wants to merge 1 commit into
TheSaiEaranti wants to merge 1 commit into
Conversation
BSD/macOS mktemp only randomizes trailing X's, so the ssm-cmd-XXXXXXXXXX.json template created a file with that literal name. Both aws ssm start-session calls ran through exec, so the EXIT trap that removes the file never ran. On macOS every call after the first then failed with "mkstemp failed ... File exists", and on Linux every call left its payload file in /tmp. Use a template without a suffix and run aws as a child process again so the trap removes the file. Bump sagemaker-ai to 1.3.1 and add a pytest with a stub aws command.
TheSaiEaranti
requested review from
a team,
arnewouters,
krokoko and
laithalsaadoon
October 27, 2026 10:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On macOS,
ssm-exec.shworks once per$TMPDIR. Every call after that fails before it reaches AWS:The other HyperPod skills send their ad hoc node commands through hyperpod-ssm (for example the
ssm-exec.shcalls in hyperpod-node-debugger's references), so those fail after the first call too. Their bundled diagnostic scripts make their own SSM calls and aren't affected.Related
No existing issue. I found this while reading the hyperpod-ssm skill.
Changes
Two things combine here:
mktemponly replaces trailing X's, so thessm-cmd-XXXXXXXXXX.jsontemplate creates a file with that literal name. The template is nowssm-cmd.XXXXXXXXXX. The AWS CLI readsfile://parameters without needing a.jsonextension.aws ssm start-sessioncalls ran throughexec, which replaces the shell, so thetrap 'rm -f "$TMPFILE"' EXITcleanup never ran and the payload file stayed behind. On Linux GNU mktemp randomizes the name, but every call still left a file in/tmpholding the remote command or the base64 of an uploaded file.execcame in with theunbufferchange in feat(sagemaker-ai): add HyperPod debugging skills #169, andunbufferattaches its PTY either way, so both calls now run as child processes, the way the script invokedawsbefore feat(sagemaker-ai): add HyperPod debugging skills #169, and the trap fires. Withset -e, a failingawscall still exits the script with the same status.One behavior change from dropping
exec: a signal sent only to the script's own PID (a plainkill <pid>, or a SIGKILL from a caller's timeout) now stops bash and leavesawsrunning until the remote command ends. Before, that signal went straight tounbufferoraws. Ctrl-C and GNUtimeoutsignal the whole process group, so they behave as before, and the trap now removes the file.I also bumped sagemaker-ai to 1.3.1 in the marketplace and both plugin manifests, following the patch-bump rule in the maintainers guide.
Added
tools/test_ssm_exec_sh.py. It runs the script with a stubawsthat records each--parameterspayload. PATH holds only the stubs plus links to the tools the script needs, so a realawsorunbufferon the machine is never picked up, and each case checks which branch ran:unbuffer, three calls in a row each exit 0, send{"command": ["hostname"]}, and leave$TMPDIRemptyunbuffer, anawsexit status of 254 is returned, and the temp file is still removedunbuffer, a call still works next to a leftoverssm-cmd-XXXXXXXXXX.jsonfrom an older versionAll 5 cases fail on main. With only the template changed they still fail (the file leaks). With only
execremoved, the leftover-file case fails on macOS.Verification:
uv run --with pytest pytest tools plugins: 137 passedbandit -r . -x ./.tmp,./node_modules: no issuessemgrep scan --oss-only --config=tools/semgrep/rules-vendored.yaml: no new findings. The test'ssubprocessimport pairsnosec B404withnosemgrep: gitlab.bandit.B404, ashyperpod_issue_report.pyin this plugin does.ruff checkandruff format --check(v0.15.0, as in pre-commit) on the new test,dprint check, thelint:manifestsajv checks on the three manifests, andnode tools/validate-cross-refs.cjs: clean (the one cross-refs warning, about migration-to-aws, is on main too)nccl-diagnose.shuses the same kind of suffixed template (kubectl-check-XXXXXX.err,nccl-ssm-XXXXXX.json). A normal run removes those files, but_ssm_runis called inside$(...), so a run interrupted during an SSM call can leavenccl-ssm-XXXXXX.jsonbehind, and on macOS later runs would then fail atmktemp. I left it alone to keep this PR to one script, and can send a follow-up.Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.