NousResearch/hermes-agent

Oneshot mode (-z) silent failures and output bugs

Cluster 30623 · hermes cli. Data as of

Nothing open on GitHub. Fix merged in #35384 on 30 May 2026. Check it covers your case.

The short answer

0open issues
0open PRs
4items grouped
Known?
Yes. 4 related items grouped here, 1 issue already closed.
Fix event
A fix was merged to main in PR #35384. Check it covers your case. No release data is tracked.
Tracker
The maintainers' tracker marks this resolved, deciding PR #35384. That is separate from the fix event.
Still open
Nothing open on GitHub.

Multiple reports and fixes around the oneshot CLI mode (-z) silently exiting with empty output, incorrect exit codes, and non-TTY/pipe environment failures. Work spans detection of empty responses, stdout routing, and fail-closed behavior.

Open issues0

No open issues.

Open PRs0

No open pull requests.

Fixes on record

Merged to main. A stamp counts the issues a fix is linked to.

  • #35384 fix(cli): oneshot (-z) fails closed on empty response or agent crash

    merged to main

    files: hermes_cli/oneshot.py, scripts/release.py, tests/hermes_cli/test_tui_resume_flow.py

    Show the diff
    • hermes_cli/oneshot.py
      @@ -174,28 +174,55 @@ def run_oneshot(
           # Redirect stderr AND stdout to devnull for the entire call tree.
           # We'll print the final response to the real stdout at the end.
           real_stdout = sys.stdout
      +    real_stderr = sys.stderr
           devnull = open(os.devnull, "w", encoding="utf-8")
       
      +    response: Optional[str] = None
      +    failure: BaseException | None = None
           try:
               with redirect_stdout(devnull), redirect_stderr(devnull):
      -            response = _run_agent(
      -                prompt,
      -                model=model,
      -                provider=provider,
      -                toolsets=explicit_toolsets,
      -                use_config_toolsets=use_config_toolsets,
      -            )
      +            try:
      +                response = _run_agent(
      +                    prompt,
      +                    model=model,
      +                    provider=provider,
      +                    toolsets=explicit_toolsets,
      +                    use_config_toolsets=use_config_toolsets,
      +                )
      +            except BaseException as exc:  # noqa: BLE001
      +                # Capture anything that escapes the agent (including OSError
      +                # from prompt_toolkit/Vt100 when stdout is a non-TTY pipe,
      +                # KeyboardInterrupt, SystemExit, etc.) so we can surface it on
      +                # the real stderr instead of crashing past the redirect with a
      +                # traceback that the caller never sees. A silent exit in a
      +                # cron / SSH / subprocess context is the worst failure mode.
      +                # See #30623.
      +                failure = exc
           finally:
               try:
                   devnull.close()
               except Exception:
                   pass
       
      -    if response:
      -        real_stdout.write(response)
      -        if not response.endswith("\n"):
      -            real_stdout.write("\n")
      -        real_stdout.flush()
      +    if failure is not None:
      +        # Re-raise control-flow exceptions so the parent handles them as usual
      +        # (Ctrl-C / explicit sys.exit() inside the agent).
      +        if isinstance(failure, (KeyboardInterrupt, SystemExit)):
      +            raise failure
      +        real_stderr.write(f"hermes -z: agent failed: {failure}\n")
      +        real_stderr.flush()
      +        return 1
      +
      +    if not (response or "").strip():
      +        real_stderr.write("hermes -z: no final response was produced; treating the run as failed.\n")
      +        real_stderr.flush()
      +        return 1
      +
      +    assert response is not None  # narrowed by the empty-response guard above
      +    real_stdout.write(response)
      +    if not response.endswith("\n"):
      +        real_stdout.write("\n")
      +    real_stdout.flush()
           return 0
       
       
    • scripts/release.py
      @@ -656,6 +656,7 @@
           "[redacted:email]": "inchargeautomation-lab",
           "[redacted:email]": "Bartok9",
           "[email protected]": "sweetcornna",
      +    "[redacted:email]": "briancl2",
           "[redacted:email]": "CruxExperts",
           "[email protected]": "LeonSGP43",
           "[email protected]": "Kailigithub",
    • tests/hermes_cli/test_tui_resume_flow.py
      @@ -638,6 +638,60 @@ def test_oneshot_rejects_invalid_only_toolsets(monkeypatch, capsys):
           assert "did not contain any valid toolsets" in err
       
       
      +def test_oneshot_fails_closed_on_empty_final_response(monkeypatch, capsys):
      +    _stub_plugin_discovery(monkeypatch)
      +    import hermes_cli.oneshot as oneshot_mod
      +
      +    monkeypatch.setattr(oneshot_mod, "_run_agent", lambda *_args, **_kwargs: "")
      +
      +    assert oneshot_mod.run_oneshot("hello") == 1
      +    captured = capsys.readouterr()
      +    assert captured.out == ""
      +    assert "no final response" in captured.err
      +
      +
      +def test_oneshot_prints_nonempty_final_response(monkeypatch, capsys):
      +    _stub_plugin_discovery(monkeypatch)
      +    import hermes_cli.oneshot as oneshot_mod
      +
      +    monkeypatch.setattr(oneshot_mod, "_run_agent", lambda *_args, **_kwargs: "done")
      +
      +    assert oneshot_mod.run_oneshot("hello") == 0
      +    captured = capsys.readouterr()
      +    assert captured.out == "done\n"
      +    assert captured.err == ""
      +
      +
      +def test_oneshot_fails_closed_on_agent_exception(monkeypatch, capsys):
      +    _stub_plugin_discovery(monkeypatch)
      +    import hermes_cli.oneshot as oneshot_mod
      +
      +    def _boom(*_args, **_kwargs):
      +        raise OSError("not a TTY")
      +
      +    monkeypatch.setattr(oneshot_mod, "_run_agent", _boom)
      +
      +    assert oneshot_mod.run_oneshot("hello") == 1
      +    captured = capsys.readouterr()
      +    assert captured.out == ""
      +    assert "agent failed" in captured.err
      +    assert "not a TTY" in captured.err
      +
      +
      +def test_oneshot_reraises_keyboard_interrupt(monkeypatch):
      +    _stub_plugin_discovery(monkeypatch)
      +    import hermes_cli.oneshot as oneshot_mod
      +    import pytest as _pytest
      +
      +    def _interrupt(*_args, **_kwargs):
      +        raise KeyboardInterrupt
      +
      +    monkeypatch.setattr(oneshot_mod, "_run_agent", _interrupt)
      +
      +    with _pytest.raises(KeyboardInterrupt):
      +        oneshot_mod.run_oneshot("hello")
      +
      +
       def test_oneshot_filters_invalid_toolsets_before_redirect(monkeypatch, capsys):
           _stub_plugin_discovery(monkeypatch)
           from hermes_cli.oneshot import _validate_explicit_toolsets

2 PRs closed without merging

From the close comments: done elsewhere 1 · superseded by another PR 1

  • #31917 fix(cli): dispatch oneshot before _prepare_agent_startup to prevent non-TTY crash (#30623) · done elsewhere → #30623, #35384, #1, #3
  • #33818 fix(cli): run -z oneshot when stdout is non-TTY (SSH/cron/pipe) · superseded by another PR → #35384, #30623
Closed issues · 1
  • Closed#30623[Bug]: `hermes -z` oneshot exits 0 silently before API call when stdout is non-TTY pipe (SSH/cron/subprocess)
How this cluster was grouped
  • Link evidence (structural links throughout): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
  • Pairwise link density 0.50: the share of item pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. 1.00 means every pair is linked.

Pick up a Lab task

Check whether a fix covers the open issues here, with your own agent. Bring back evidence for maintainers.

Open the Lab

At a glance

Subsystem
hermes cli
Merged PRs
#35384
Closed issues
1
Attempts
2 PRs closed without merging
Fix link checked
30 May 2026

For your agent

The same facts, typed.