Repository navigation
fix(workspace): 远程会话结束时释放它建立的搜索索引 (1lck/Lithe-IDEA#2277) - #165
Merged
Merged
Conversation
workspace 新增会话结束钩子(on_session_end / is_registered),remote.disconnect、 断线后遗忘会话和 remote.closeAll 都会运行;project 的搜索索引键带上会话, 缓存初始化时登记钩子,会话结束即删掉该会话的全部索引。仍持有旧会话的请求 先插入槽位再检查会话是否还在,不会在会话结束后留下新条目。
…-cache-release # Conflicts: # rust/crates/workspace/src/sessions.rs
xiaoyumuxi
marked this pull request as ready for review
November 22, 2026 01:56
This was referenced Nov 22, 2026
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
Fixes 1lck/Lithe-IDEA#2277。Refs 1lck/Lithe-IDEA#2231(远程开发完整设计)。
类型
改动说明
问题
crates/project/src/search_index.rs的INDEX_CACHE用“会话 id + 主机路径”作为远程索引的键。会话 id 每次连接都是新的,但会话结束时没有代码删掉这些条目。Scope::begin就以connection_closed失败,所以没法替 Core 清理。crates/workspace:会话结束钩子sessions.rs:on_session_end(hook):会话离开登记表时运行钩子,钩子按函数地址去重。is_registered(id)。ended(id):remote.disconnect(end和keep都算)、断线后forget、remote.closeAll的close_registry。scope.rs:Host::identity()(crate 内可见)改为公开的Host::session_id(),让其他 crate 能拿到会话 id 作为键。identity_key的结果不变。test_support.rs:unregister也运行钩子,和remote.disconnect一致。forget_keeping_link:把会话移出登记表并运行钩子,但不关闭连接,用来模拟“请求还拿着主机时会话被断开”。返回的KeptLink在释放时关闭连接。crates/project:索引按会话释放IndexKey新增session: Option<String>,本机为None。用单独的字段,不靠路径前缀匹配,不会误删本机或其他会话的索引。cache()第一次初始化时登记release_session钩子,所以只要缓存里有条目,钩子就已经登记了。release_session(id)删掉该会话的所有槽位,包括正在建立的索引。已有的槽位机制保证被删的槽位不会再发布回缓存。get_index先插入槽位,再用is_registered检查会话是否还在;会话已经不在,就释放它的槽位。这个顺序封住了竞态:要么检查时已经看到会话结束,要么钩子在插入之后才运行并把槽位删掉。这样,请求在会话结束前拿到主机、结束后才建索引,也不会留下条目。cached_indexes_for_session,只在test-support特性下编译,供lithe-core的测试统计。contracts/rust-core-api.mdremote.disconnect、remote.closeAll或断线(connection_closed)离开 Core 时,Core 同时删掉经它建立的搜索索引,包括还持有该会话的请求正在建立的索引;客户端不用、也无法再为它们调用workspace.searchIndex.invalidate。测试夹具
crates/core/src/tests/remote_sessions.rs的HostFixture::drop原来先用旧会话调workspace.searchIndex.invalidate手动清理,现在删掉这一步,由unregister运行钩子释放。所有远程端到端测试都因此经过新的释放路径。桌面端
releaseProjectSearch引用本 Issue 的注释,等固定版本升级到包含本 PR 的 Core 后再更新。验证
cargo fmt -p lithe-workspace -p lithe-project -p lithe-corecargo clippy -p lithe-workspace -p lithe-project -p lithe-core --all-targets --all-features -- -D warnings:无警告cargo test -p lithe-workspace -p lithe-project -p lithe-core:全部通过(lithe-core892 个、lithe-workspace61 个、lithe-project102 个,加上各个集成测试)ending_a_remote_session_releases_its_search_indexes,使用进程内的真实主机服务:remote.disconnect之后数量为 0。forget_keeping_link让会话离开登记表,此时数量为 0。随后拿着这个主机直接调用lithe_project::search,仍能在主机上搜到内容;搜索之后数量还是 0。