fix(server): share global memoMap in TCP listener to dedupe singleton services#28152
Open
sjawhar wants to merge 1 commit into
Open
fix(server): share global memoMap in TCP listener to dedupe singleton services#28152sjawhar wants to merge 1 commit into
sjawhar wants to merge 1 commit into
Conversation
f3f4f8e to
bb7bba1
Compare
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.
Issue for this PR
Closes #28037
Type of change
What does this PR do?
#28037 has the full root-cause writeup. The fix is small:
startListenerwas callingLayer.makeMemoMapUnsafe(), so the TCP listener's singleton services lived in a different memoMap fromServer.Default()/ AppRuntime. This PR passes the sharedmemoMapfrom@opencode-ai/core/effect/memo-maptoLayer.buildWithMemoMapinstead.The function-call layers inside
listenerLayer(HttpRouter.serve(...),serverLayer({port, hostname}),ConfigProvider.layer(...)) return fresh Layer references per call, so they stay listener-local — only the Service-tagged singletons get deduplicated.Beyond #28037's permission-reply symptom, the same bug also produces parallel
SessionRunStaterunners for one session under heavy use: pressing Esc cancels one runner while a second keeps streaming, eventually accumulating two trailing assistant messages.How did you verify your code works?
test/effect/run-service.test.tsassert thatLayer.buildWithMemoMap(SessionRunState.defaultLayer, memoMap, scope)resolves to the sameServiceinstance asAppRuntime.runPromise(SessionRunState.Service), and that a freshMemoMapproduces a separate instance.bun typecheckclean.bun test test/effect/passes. The session/server suites show no fix-induced regressions; remaining timeouts are pre-existing flakes ondev, confirmed by running the same tests isolated against the parent commit.Screenshots / recordings
N/A — server-internal layer wiring.
Checklist