Skip to content

fix: only set HERMES_INTERACTIVE when stdin/stdout are real terminals#16529

Open
cxgreat2014 wants to merge 2 commits into
NousResearch:mainfrom
cxgreat2014:fix/non-interactive-hermes-interactive-flag
Open

fix: only set HERMES_INTERACTIVE when stdin/stdout are real terminals#16529
cxgreat2014 wants to merge 2 commits into
NousResearch:mainfrom
cxgreat2014:fix/non-interactive-hermes-interactive-flag

Conversation

@cxgreat2014

@cxgreat2014 cxgreat2014 commented Apr 27, 2026

Copy link
Copy Markdown

What does this PR do?

In containerized/automated contexts (Docker, Paperclip integrations, cron), Hermes Agent is invoked via hermes chat -q with piped stdin/stdout. The CLI unconditionally set HERMES_INTERACTIVE=1, which triggers sudo password prompts and approval prompts even when no user is present. Each prompt waits 45s before timing out, causing slow/failing automated runs. This PR gates HERMES_INTERACTIVE=1 behind sys.stdin.isatty() && sys.stdout.isatty(), and adds PermissionError handling for ~/.hermes/.env reads in non-root container setups.

Related Issue

Fixes #17575

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • cli.pymain():
    • HERMES_INTERACTIVE=1 is now only set when both sys.stdin.isatty() and sys.stdout.isatty() return True
    • Piped/automated callers (e.g., hermes chat -q, Paperclip heartbeats, cron) no longer trigger interactive prompts
  • hermes_cli/env_loader.pyload_hermes_dotenv():
    • Wrapped user_env.exists() in try/except PermissionError to prevent crashes when ~/.hermes/.env is unreadable (common in non-root container setups)
  • tests/hermes_cli/test_env_loader.py — added test_env_loader_permission_error_is_graceful
  • tests/hermes_cli/test_interactive_detection.py — new: 7 test cases covering isatty truth table

How to Test

  1. echo 'hello' | hermes chat -q — no approval/sudo prompts, runs to completion
  2. hermes (interactive TTY) — prompts still work, HERMES_INTERACTIVE=1 is set
  3. Run as non-root user with ~/.hermes/ having permissions 000 — no PermissionError crash
  4. Run via Paperclip adapter heartbeat — no 45s timeout stalls

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Debian 13 (Docker)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

N/A — this is a bug fix, not a new skill.

Screenshots / Logs

N/A — no UI changes

- cli.py: HERMES_INTERACTIVE=1 was set unconditionally at cli_main()
  entry, causing sudo password prompts and approval prompts even in
  non-interactive mode (hermes chat -q, Paperclip heartbeats, cron).
  Now gated behind sys.stdin.isatty() && sys.stdout.isatty().

- env_loader.py: user_env.exists() could crash with PermissionError
  when the .hermes directory is owned by a different user (common in
  Docker/container setups where hermes runs as non-root). Now catches
  PermissionError and gracefully skips .env loading.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles labels Apr 27, 2026
@cxgreat2014

Copy link
Copy Markdown
Author

Hi maintainers 👋 Just following up — tests pass (2014 passed, 6 unrelated env failures), and the PR body has been updated with the full template. Would appreciate a review when you have a moment. Thanks!

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

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard 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.

fix: only set HERMES_INTERACTIVE when stdin/stdout are real terminals

2 participants