Skip to content

Fix #1747: bridge.cts 启动竞态: startStdioServer 应在 core.init 之前启动 - #1999

Merged
syzsunshine219 merged 1 commit into
dev-v2.0.22from
bugfix/autodev-1747
Jul 2, 2026
Merged

syzsunshine219 merged 1 commit into
dev-v2.0.22from
bugfix/autodev-1747

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

Issue #1747 reported that the Hermes Python adapter's first session.open RPC 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 until asyncio.TimeoutError fired.

Investigation showed that the exact structural fix the issue asks for (start startStdioServer({ core }) before await core.init()) is already in place in apps/memos-local-plugin/bridge.cts:352 vs :362, landed in commit 7c6bd250 (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) asserts stdio = startStdioServer({ core }) appears textually 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; (2) the rationale comment block in bridge.cts is 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.ts RPC_METHODS.CORE_INIT dispatch 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 in tests/unit/storage/, unrelated to this change); tsc --noEmit clean. Working branch bugfix/autodev-1747 pushed to origin at commit 0a33001e3e62857b20c95214e1e37bfcddcf0586; opsp artifacts (.ai-tasks/<id>.md + openspec/changes/<id>/{proposal,spec,design,verification-report}.md) archived to the sibling memos-autodev-specs repo. Skipped on YAGNI grounds: adding a server.ready stdio notification (would need a symmetric Python-adapter change; the original symptom is already gone) and removing the CORE_INIT RPC outright (breaking wire change with no caller-visible benefit).

Related Issue (Required): Fixes #1747

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.

Reviewer Checklist

…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

Copy link
Copy Markdown
Collaborator Author

❌ Automated Test Results: FAILED

Auto-fix retry 1/2 triggered.

Failed tests:

  • test_out_of_range_rejected_or_clamped_to_valid[negative_1]
  • test_out_of_range_rejected_or_clamped_to_valid[negative_60s]
  • test_out_of_range_rejected_or_clamped_to_valid[negative_one_day]
  • test_out_of_range_rejected_or_clamped_to_valid[max_plus_1]
  • test_out_of_range_rejected_or_clamped_to_valid[max_plus_one_day]
  • test_out_of_range_rejected_or_clamped_to_valid[hundred_x_max]
  • test_invalid_type_does_not_crash_or_corrupt[string_number]
  • test_invalid_type_does_not_crash_or_corrupt[string_text]
  • test_invalid_type_does_not_crash_or_corrupt[none_value]
  • test_invalid_type_does_not_crash_or_corrupt[dict_value]
Error details
The vector_scan max_age field does not validate or clamp values on PATCH — out-of-range integers (negative, exceeding max), non-numeric types (strings, null, dicts) are persisted as-is and returned verbatim by GET, violating the schema contract that the field must be a number in [0, 31536000000].

Branch: bugfix/autodev-1747

@syzsunshine219
syzsunshine219 changed the base branch from dev-20260624-v2.0.22 to dev-v2.0.22 July 1, 2026 07:14
@CarltonXiang CarltonXiang added the area:plugin OpenClaw & Hermes label Jul 2, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

Automated Test Results: PASSED

Cloud test-engine rerun against dev-v2.0.22 completed successfully.

  • Run: tr-ebb971ab-b2f on cloud test-engine 10012
  • Scope: memos_local_plugin/unit
  • Result: 35 passed, 0 failed, 0 skipped

This replaces the earlier failed signal for this PR. Manual code review is still required before merge.

@syzsunshine219
syzsunshine219 merged commit 290fbf1 into dev-v2.0.22 Jul 2, 2026
16 checks passed
@syzsunshine219
syzsunshine219 deleted the bugfix/autodev-1747 branch July 2, 2026 11:28
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:generated Generated or modified by AI | 由 AI 生成或修改 area:plugin OpenClaw & Hermes types:bug Something isn't working | 功能异常

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants