fix(core): backport invalidated location cleanup - #46074
Open
Hona wants to merge 2 commits into
Open
Conversation
Backport Kit Langton's RcMap fix from Effect-TS/effect#7516 (0e4793c87c18c5e26ad7c4f21e38f84c3a6bb128) to Effect 4.0.0-rc.112, including matching runtime JavaScript. Remove this temporary patch when upgrading to a fixed Effect release.
Match the JavaScript postimage hash produced by the patch hunks. Bun patch omitted its prepared file's extra EOF newline from the generated diff; the applied runtime code is unchanged.
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.
Summary
Temporarily backport Kit Langton's fix from Effect-TS/effect#7516, upstream commit
0e4793c87c18c5e26ad7c4f21e38f84c3a6bb128, onto the pinned Effect4.0.0-rc.112.This is a backport of the existing upstream work, not a separate implementation. The patch includes the TypeScript source and matching executable JavaScript. Remove it when upgrading to an Effect release that contains the fix.
Why
OpenCode's Location service map uses infinite idle TTL for existing directories. The server separately invalidates idle Locations after 60 minutes; explicit debug eviction can also invalidate them.
If Location A is invalidated while borrowed, the same key is reacquired as B, and A's last borrower then releases it, the unpatched RcMap checks only whether the key exists. With infinite TTL, it skips A's finalizers. With zero TTL, old cleanup can remove B's mapping. A surviving finite-TTL timer can also remove the replacement.
Kit's fix checks entry identity before removing a mapping, closes detached entries when their last borrower releases, and leaves replacement entries untouched. Ordinary TTL behavior and active borrowers are preserved.
Only the dependency patch and its
package.json/bun.lockregistration are included. No application API, Location eviction policy, test files, profiler, or changeset changes.Before / After
The graph overlays two measured checkpoints per version, using the median of five fresh processes on Windows x64 / Bun 1.4.0. Each cycle acquires A, invalidates it while borrowed, acquires B, releases A, verifies B remains usable, then invalidates and releases B.
This is a synthetic resource workload, not 1,000 full production Location graphs. It uses the real
LayerMap,Layer.fresh, and scope-owned timers. Each timer captures a distinct, filled 1-MiB Buffer; the resource finalizer cancels the timer. There are two resources per cycle. Plain unreachable data can be collected even when finalizers are missed, so the timers explicitly model resources whose callbacks require disposal.Both versions use the same warm-up and eight full-GC rounds with 100-ms event-loop gaps. The map owner remains alive during measurement. Both maps have zero cached keys afterward, and all unrelated weak controls are collected. The patched run collects all payload sentinels; the unfixed run retains 1,000 and still misses those finalizers when the map owner closes.
Metric:
bun:jsc.heapStats().heapSize, including external memory. These are not RSS figures or a prediction of production-server savings. The graph and probes are local validation artifacts, not committed files.Verification
LocationServiceMapprobe constructs the actual Instance graph with isolated paths and ambient discovery disabled. Before: only B finalizes, even after shutdown. After: A finalizes when released, B remains usable, and shutdown finalizes B. No network requests occur; baseline-only emergency teardown is performed after recording results.bun typecheckpassed; the pre-push workspace typecheck also passed all 33 tasks.install --frozen-lockfilepassed with the patch registered.package.jsonformatting andgit diff --checkpassed.The running OpenCode server was not patched or restarted for validation.