# NousResearch/hermes-agent · Oneshot mode (-z) silent failures and output bugs

## Open now

- 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.

## TL;DR

- 4 member(s): 0 open issue(s), 1 closed issue(s), 0 open PR(s), 1 merged PR(s), 2 PR(s) closed without merging.
- A fix was merged to main in PR #35384. Verify it addresses your case.
- **Recommended:** read PR #35384 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `resolved` · deciding PR(s): `pr-35384`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_SPANNING`): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
- Pairwise link density `0.50`: the share of member 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.

## Closed / duplicate issues

- #30623: \[Bug\]: \`hermes -z\` oneshot exits 0 silently before API call when stdout is non-TTY pipe (SSH/cron/subprocess)

## Prior & competing PRs

- **#35384: fix(cli): oneshot (-z) fails closed on empty response or agent crash**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`
  - files: `hermes_cli/oneshot.py`, `scripts/release.py`, `tests/hermes_cli/test_tui_resume_flow.py`
  - fix hunks:
  - `hermes_cli/oneshot.py`

    ```diff
    @@ -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`

    ```diff
    @@ -656,6 +656,7 @@
         "[redacted:email]": "inchargeautomation-lab",
         "[redacted:email]": "Bartok9",
         "96944678+ymylive@users.noreply.github.com": "sweetcornna",
    +    "[redacted:email]": "briancl2",
         "[redacted:email]": "CruxExperts",
         "154585401+LeonSGP43@users.noreply.github.com": "LeonSGP43",
         "12250313+Kailigithub@users.noreply.github.com": "Kailigithub",
    ```
  - `tests/hermes_cli/test_tui_resume_flow.py`

    ```diff
    @@ -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
    ```
- **#31917: fix(cli): dispatch oneshot before _prepare_agent_startup to prevent non-TTY crash (#30623)**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `#30623`, `#35384`, `#1`, `#3`
- **#33818: fix(cli): run -z oneshot when stdout is non-TTY (SSH/cron/pipe)**. closed without merge
  - maintainer direction: category `superseded_by_pr`; implication `superseded`; refs `#35384`, `#30623`

## Fix status

- Merged to main in PR #35384 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-05-30`.
- Subsystem: `hermes_cli`
