Fix #1927: fix: initialize() spawns new headless bridge without closing old one — process l#1928
Open
Memtensor-AI wants to merge 1 commit into
Open
Fix #1927: fix: initialize() spawns new headless bridge without closing old one — process l#1928Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
…p process leak Hermes calls `MemTensorProvider.initialize()` on every reconnect / new session. Each call spawned a fresh `MemosBridgeClient` (and therefore a new `--no-viewer` Node subprocess) but never closed the previous one referenced by `self._bridge`. The orphaned bridges accumulated at ~93 MB each, indefinitely — the headless-bridge reaper does not catch them because their parent (Hermes dashboard / gateway) stays alive. Close any pre-existing `self._bridge` at the top of `initialize()`, mirroring the safe pattern already used by `_reconnect_bridge()` (swallowing exceptions so a stuck Node subprocess never blocks re-init). Added 3 regression tests covering: the leak scenario, the no-previous-bridge happy path, and isolation when the old bridge's close() raises. Fixes #1927
5 tasks
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (35/35 executed, 35 skipped). memos_local_plugin/smoke: 0/0, memos_local_plugin/contract: 35 passed, 35 skipped. Duration: 4s AI-generated tests: 0/17 passed. Branch: |
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.
Description
Fixes #1927:
MemTensorProvider.initialize()was spawning a freshMemosBridgeClient(and therefore a new--no-viewerNode bridge subprocess) on every call without closing the previously-referencedself._bridge, leaking ~93 MB per re-initialization. Hermes re-callsinitialize()on each reconnect / new session, so orphaned bridges accumulated indefinitely — the headless-bridge reaper never collected them because their parent (Hermes dashboard / gateway) stays alive.The fix mirrors the safe pattern already used by
_reconnect_bridge()(line ~1727 of the same file): at the very top ofinitialize(), capture the currentself._bridge, log its PID, call.close()insidecontextlib.suppress(Exception)so a stuck Node subprocess never blocks re-init, and clearself._bridgebefore the existing creation flow runs. The fix is +19 lines inapps/memos-local-plugin/adapters/hermes/memos_provider/__init__.py, scoped entirely to the plugin sub-project; mainsrc/memos/is untouched andmake openapiis not required.Verification (TDD): added 3 regression tests in
tests/python/test_hermes_provider_pipeline.py—test_initialize_closes_previous_bridge_before_spawning_new_one(the actual leak scenario, two queued FakeBridge instances),test_initialize_when_no_previous_bridge_does_not_call_close(first-init happy path), andtest_initialize_swallows_exception_from_old_bridge_close(isolation when the previous bridge's close() raises). Tests #1 and #3 fail before the fix and pass after; full plugin Python suite is 45/45 passing.ruff checkandruff format --checkboth clean on the touched files.Branch
bugfix/autodev-1927pushed to origin at commit5a0a3fc3. Spec archive synced to memos-autodev-specs.Related Issue (Required): Fixes #1927
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist