Skip to content

fix(cli): suppress memory prefetch for single-query runs - #44353

Closed
hyper-factor wants to merge 1 commit into
NousResearch:mainfrom
hyper-factor:fix/chat-q-honcho-prefetch-shutdown
Closed

fix(cli): suppress memory prefetch for single-query runs#44353
hyper-factor wants to merge 1 commit into
NousResearch:mainfrom
hyper-factor:fix/chat-q-honcho-prefetch-shutdown

Conversation

@hyper-factor

@hyper-factor hyper-factor commented Jun 11, 2026

Copy link
Copy Markdown

Summary

  • Suppresses post-turn memory prefetch for non-interactive single-query CLI runs (hermes chat -q / quiet one-shot paths).
  • Prevents Honcho/background memory prefetch work from racing Python interpreter shutdown after the response has already printed.
  • Keeps normal interactive/gateway prefetch behavior intact.

Why

We reproduced a legitimate upstream bug: hermes chat -q can print the correct answer, then exit with SIGABRT / rc=134 when Honcho hybrid memory is enabled. The crash happens after successful output, which breaks automation/worker callers that rely on exit code.

This overlaps with existing shutdown-related reports, but the open PRs I checked focus on hermes -z, provider shutdown, or forced one-shot exit. This PR targets the chat -q path by avoiding unnecessary prefetch work when there is no next turn to warm.

Related

Test plan

  • uv run --with pytest --with pytest-asyncio python -m pytest -o addopts='' tests/cli/test_cli_active_agent_ref.py tests/agent/test_memory_post_turn_prefetch.py -q
    • Result: 4 passed
  • Live smoke test from patched branch against Honcho-enabled HERMES_HOME:
    • HERMES_HOME=/tmp/hermes-home PYTHONFAULTHANDLER=1 .venv/bin/hermes chat -Q --toolsets safe -q 'Reply exactly: UPSTREAM_PR_OK'
    • Result: printed UPSTREAM_PR_OK, exit code 0

Avoid spawning post-turn memory prefetch work for non-interactive single-query CLI invocations. These processes exit immediately after printing the response, so prefetch threads can race interpreter shutdown and surface as SIGABRT/exit 134 despite a successful answer.
@liuhao1024

Copy link
Copy Markdown
Contributor

Positive verification: Suppress post-turn memory prefetch in single-query runs

Reviewed: cli.py signal handler, cli_agent_setup_mixin.py atexit cleanup.

The fix is well-scoped: single-query non-interactive runs (-q flag) set _suppress_post_turn_prefetch on both the CLI and agent objects, preventing Honcho background threads from racing interpreter shutdown. The _active_agent_ref fix in the setup mixin correctly assigns to the owning module (cli or __main__) instead of using a bare global that would create a dead reference in the wrong module namespace.

No findings. LGTM.

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/memory Memory tool and memory providers P3 Low — cosmetic, nice to have labels Jun 11, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor

Reviewed this PR — the _active_agent_ref module-owner fix is a real bug. The old code used global _active_agent_ref inside the mixin module (hermes_cli.cli_agent_setup_mixin), creating a shadow variable invisible to the cli module's atexit cleanup. The sys.modules lookup correctly targets the concrete owner module. The _suppress_post_turn_prefetch flag for single-query runs is clean and prevents background thread races at shutdown. Both regressions have dedicated test files. No issues found.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused shutdown investigation. This is now implemented on main through a more general lifecycle fix, so this PR's suppression flag is redundant.

  • cli.py:1230-1236 finalizes every single-query invocation through _run_cleanup() before releasing its session.
  • cli.py:1114-1147 flushes pending memory work and calls shutdown_memory_provider() for the active CLI agent.
  • agent/memory_manager.py:654-662 uses a daemon-backed memory worker so wedged provider work cannot block interpreter exit.
  • Commit 64b21e50fb637a9445cc83ed12cf12a7109b8e34 fixed the same _active_agent_ref publication issue at hermes_cli/cli_agent_setup_mixin.py:404-405; tests/cli/test_cli_active_agent_ref_wiring.py:49-69 covers it. That commit is contained in v2026.7.1.

Automated hermes-sweeper review.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have sweeper:implemented-on-main Sweeper: behavior already present on current main tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intermittent SIGABRT (core dump) on process exit under concurrent fresh hermes chat -q subprocesses

4 participants