fix(honcho): drain context prefetch threads during shutdown - #69070
Open
bigstar0920 wants to merge 1 commit into
Open
fix(honcho): drain context prefetch threads during shutdown#69070bigstar0920 wants to merge 1 commit into
bigstar0920 wants to merge 1 commit into
Conversation
teknium1
reviewed
Jul 30, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for tracing the provider-to-manager shutdown gap; current main still starts honcho-context-prefetch as an untracked daemon in plugins/memory/honcho/session.py:689-702, while provider shutdown only calls flush_all() at plugins/memory/honcho/__init__.py:1539-1547.
Problems
tests/test_honcho_shutdown.py:35assumes async-manager construction starts_async_thread. Current main commitbd1a850fa2intentionally starts it lazily via_ensure_async_writer()inplugins/memory/honcho/session.py:548-567, so this regression test needs updating during salvage.- The new tracking covers only
prefetch_context(). The first-turn path independently creates daemonhoncho-base-firstand calls the sameget_prefetch_context()atplugins/memory/honcho/__init__.py:729-746; provider shutdown does not retain or join that thread at:1539-1547. This leaves the same finalization class reachable on first-turn context fetches.
Suggested changes
- Preserve the lazy-writer behavior and make the test enqueue work before asserting writer state.
- Bring
honcho-base-firstunder the same shutdown ownership, with coverage for that path.
Automated hermes-sweeper review.
| provider._manager = manager | ||
|
|
||
| assert manager._async_thread is not None | ||
| assert manager._async_thread.is_alive() |
Contributor
There was a problem hiding this comment.
Current main starts the async writer lazily in _ensure_async_writer() after save() enqueues work (bd1a850fa2), so a newly constructed manager has _async_thread is None. Enqueue a save before asserting writer lifecycle, otherwise this regression test fails when salvaged.
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.
Summary
HonchoMemoryProvider.shutdown()throughHonchoSessionManager.shutdown()so manager-owned workers are stopped, not only flushedhoncho-context-prefetchregistrations while shutdown snapshots and joins in-flight requestsReproduction and root cause
On current
main(d8bf3df255) with Honcho enabled, a supported single-query CLI invocation printed the complete answer and then exited via SIGABRT (134/ signal 6):The coredump showed the main thread in
Py_FinalizeExwhile another thread was still in socket receive / Pydantic response handling. A cleanup-time thread snapshot identified that worker as:The provider already received the CLI shutdown hook, but it called
manager.flush_all()rather thanmanager.shutdown(). Also,prefetch_context()created a fire-and-forget daemon thread without retaining a handle, so no shutdown path could join it.Changing only
flush_all()toshutdown()was insufficient until the context-prefetch thread itself was tracked. With this patch, the same live Honcho-backed CLI smoke test prints the expected marker and exits0. A post-cleanup thread snapshot no longer containshoncho-context-prefetch.Existing reports and PRs
Py_FinalizeEx/ Honcho daemon-thread signature)mainhermes -zcleanup gap, while this reproduction usedhermes chat -q, whose cleanup hook already ran; the remaining bug was inside the provider/session-manager shutdown chainhoncho-context-prefetchlifecycle fix and atomic registration/shutdown boundaryVerification
Focused test set:
Scope and behavior
No configuration or public API changes. Long-running interactive/gateway behavior remains asynchronous. During provider shutdown, new context-prefetch work is rejected and existing work receives a bounded 10-second join. If a network request outlives that bound, the non-daemon worker prevents unsafe interpreter finalization and completes according to the existing HTTP timeout instead of being force-unwound through native frames.