Skip to content

perf(memory): cap concurrent searches in the memory MCP server (AGT-4875) - #910

Open
unohee wants to merge 1 commit into
mainfrom
heewonoh/agt-4875-memory-search-slots
Open

unohee wants to merge 1 commit into
mainfrom
heewonoh/agt-4875-memory-search-slots

Conversation

@unohee

@unohee unohee commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

무엇

  • search_memory 처리 로직을 src/mcp/memorySearch.ts 의 createMemorySearchHandler 로 분리 (memoryServer.ts 는 import 시 바로 stdio 서버를 띄워 테스트할 수 없었다).
  • 동시 검색 상한 MAX_CONCURRENT_SEARCHES = 2.
  • 상한 초과 정책: 대기하지 않고 즉시 busy 도구 오류 (search_memory busy: 2/2 searches already running — retry shortly). 대기열을 두면 그 대기열에도 상한·타임아웃이 또 필요하고, 기억 검색은 힌트라 CLI 에이전트가 재시도하거나 넘어가는 편이 싸다. 정책은 파일 docstring 에 적었다.
  • 슬롯은 성공·실패·deadline 모두에서 finally 로 반납한다. deadline 뒤에도 실제 검색 promise 는 취소할 수 없어 뒤에서 끝날 수 있지만, 멈춘 embedding 이 서버를 영원히 busy 로 묶지 않도록 슬롯은 돌려준다 (AGT-3495 와 같은 규칙).
  • 인자 검증 실패는 슬롯을 잡지 않는다.

왜

deadline 은 있었지만 동시 실행 수 제한이 없어 요청이 몰리면 검색이 무제한 병렬로 돌았다 (AGT-4875).

검증

  • npx vitest run src/mcp/ src/adapters/memoryMcp.test.ts — 5 files / 61 tests 통과 (신규 3: 상한+3 동시 호출에서 실제 실행 peak=2·초과분 busy, deadline 뒤 슬롯 회수(fake timer), 예외·잘못된 인자).
  • npm run typecheck, npm run build, oxlint src/mcp 0 errors.

…875)

The search_memory handler had a deadline but no concurrency limit, so a
burst of calls ran every search in parallel. The handler moves to
memorySearch.ts with at most two searches at once; an over-limit call
gets an immediate busy tool error instead of waiting. A slot is returned
on success, failure and deadline alike.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant