Repository navigation
Fix #1747: bridge.cts 启动竞态: startStdioServer 应在 core.init 之前启动 - #1999
Merged
Merged
Conversation
…1747) Issue #1747 reported that the Hermes Python adapter's first `session.open` RPC times out (30s default) when MemOS bridge starts with dirty orphan episodes from a previous chat — `core.init()` was running orphan-episode recovery (LLM-driven reward grading, 10-60+ seconds) while the stdio JSON-RPC read loop was not yet attached, so the parent process's RPC frames sat unread in the pipe buffer until asyncio.TimeoutError fired. The structural fix (start stdio before `await core.init()`) already landed in commit 7c6bd25 (May 2026, "fix(memos-local-plugin): start stdio before host LLM fallback"), motivated by a different concern but structurally identical to what #1747 asks for. This change locks the fix in place so a future refactor cannot silently undo it. Three small additions, no runtime behavior change: - bridge.cts: expand the rationale comment at the ordering site (now documents BOTH host LLM fallback AND #1747's Python adapter timeout scenarios side-by-side, with an explicit link to the new test). - bridge/methods.ts: mark RPC_METHODS.CORE_INIT as deprecated in its docblock — no in-tree adapter sends it (#1747 correctly flagged this as dead code). Dispatch branch retained for wire-contract backward compatibility. - tests/unit/bridge/bridge-startup-ordering.test.ts: new source-level regression test (2 cases) asserting `stdio = startStdioServer({ core })` appears before `await core.init();` and stays inside the `if (!args.daemon)` guard. Verified red-on-bug / green-on-fix by programmatically swapping the call sites. All bridge unit tests pass (17/17). Environment-independent suites pass (82/82). The 2 pre-existing storage-layer failures on the base branch are unrelated (confirmed via `git stash`). `tsc --noEmit` clean. Refs: #1747
Memtensor-AI
requested review from
CarltonXiang,
MatthewZhuang,
World-controller and
syzsunshine219
June 30, 2026 15:49
Collaborator
Author
❌ Automated Test Results: FAILED
Failed tests:
Error detailsBranch: |
Collaborator
Author
|
Automated Test Results: PASSED Cloud test-engine rerun against
This replaces the earlier failed signal for this PR. Manual code review is still required before merge. |
steven-stack-s
pushed a commit
to steven-stack-s/dsh-memos-local
that referenced
this pull request
Sep 18, 2026
…启动 (MemTensor#1999) test(memos-local-plugin): pin bridge.cts startup ordering invariant (MemTensor#1747) Issue MemTensor#1747 reported that the Hermes Python adapter's first `session.open` RPC times out (30s default) when MemOS bridge starts with dirty orphan episodes from a previous chat — `core.init()` was running orphan-episode recovery (LLM-driven reward grading, 10-60+ seconds) while the stdio JSON-RPC read loop was not yet attached, so the parent process's RPC frames sat unread in the pipe buffer until asyncio.TimeoutError fired. The structural fix (start stdio before `await core.init()`) already landed in commit 7c6bd25 (May 2026, "fix(memos-local-plugin): start stdio before host LLM fallback"), motivated by a different concern but structurally identical to what MemTensor#1747 asks for. This change locks the fix in place so a future refactor cannot silently undo it. Three small additions, no runtime behavior change: - bridge.cts: expand the rationale comment at the ordering site (now documents BOTH host LLM fallback AND MemTensor#1747's Python adapter timeout scenarios side-by-side, with an explicit link to the new test). - bridge/methods.ts: mark RPC_METHODS.CORE_INIT as deprecated in its docblock — no in-tree adapter sends it (MemTensor#1747 correctly flagged this as dead code). Dispatch branch retained for wire-contract backward compatibility. - tests/unit/bridge/bridge-startup-ordering.test.ts: new source-level regression test (2 cases) asserting `stdio = startStdioServer({ core })` appears before `await core.init();` and stays inside the `if (!args.daemon)` guard. Verified red-on-bug / green-on-fix by programmatically swapping the call sites. All bridge unit tests pass (17/17). Environment-independent suites pass (82/82). The 2 pre-existing storage-layer failures on the base branch are unrelated (confirmed via `git stash`). `tsc --noEmit` clean. Refs: MemTensor#1747 Co-authored-by: autodev-bot <autodev@memtensor.local>
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
Issue #1747 reported that the Hermes Python adapter's first
session.openRPC times out (30 s default) when the MemOS bridge restarts with orphan episodes from a previous chat —core.init()was running LLM-driven orphan-episode recovery (10-60+ s) while the stdio JSON-RPC read loop was not yet attached, so the parent process's RPC frames sat unread in the pipe buffer untilasyncio.TimeoutErrorfired.Investigation showed that the exact structural fix the issue asks for (start
startStdioServer({ core })beforeawait core.init()) is already in place inapps/memos-local-plugin/bridge.cts:352vs:362, landed in commit7c6bd250(May 2026, "fix(memos-local-plugin): start stdio before host LLM fallback") — motivated by a different concern but structurally identical to what #1747 asks for. The work scope therefore converged on a complex-fix that locks the existing fix in place so a future refactor cannot silently undo it, without changing runtime behaviour.Three small additions: (1) a new source-level regression test
apps/memos-local-plugin/tests/unit/bridge/bridge-startup-ordering.test.ts(2 cases) assertsstdio = startStdioServer({ core })appears textually beforeawait core.init();and stays inside theif (!args.daemon)guard — verified red-on-bug / green-on-fix by programmatically swapping the call sites; (2) the rationale comment block inbridge.ctsis expanded from 5 to 27 lines and now documents both motivations side-by-side (host LLM fallback AND the issue #1747 Python adapter 30 s timeout / orphan recovery scenario), with an explicit pointer to the new test; (3)bridge/methods.tsRPC_METHODS.CORE_INITdispatch branch gets a deprecation docblock — the issue correctly flagged this RPC as dead code (no in-tree adapter sends it), but the branch is retained for wire-contract backward compatibility.Verification: all 17 bridge unit tests pass; all 82 environment-independent unit tests pass; full unit suite reports 1042 passed / 2 pre-existing failures on the unchanged base branch (verified via
git stash, both intests/unit/storage/, unrelated to this change);tsc --noEmitclean. Working branchbugfix/autodev-1747pushed to origin at commit0a33001e3e62857b20c95214e1e37bfcddcf0586; opsp artifacts (.ai-tasks/<id>.md+openspec/changes/<id>/{proposal,spec,design,verification-report}.md) archived to the siblingmemos-autodev-specsrepo. Skipped on YAGNI grounds: adding aserver.readystdio notification (would need a symmetric Python-adapter change; the original symptom is already gone) and removing theCORE_INITRPC outright (breaking wire change with no caller-visible benefit).Related Issue (Required): Fixes #1747
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