Repository navigation
修复工作目录选择器「远程路径自动补全」逐字符卡顿 - #42
Conversation
…plete The picker posted /dsh-remote/current before every /ls, and that route re-applied the machine via pool.setTarget which unconditionally closed the live SSH connection and reset the platform cache — every keystroke paid a full reconnect + re-detect + readdir (the slow autocomplete bug). - SshPool.setTarget: an unchanged target is now a no-op (keep connection) - setCurrent: idempotent for the already-current machine (no registry rewrite, no credential re-read) - picker client: POST /current only on machine switch (ensureCurrent), TTL-cached dir listings with in-flight dedup (fetchDirList), stale suggestion responses dropped via a request sequence number - regression tests: test/settarget-noop.test.js, test/current-idempotent.test.js (verified red against pre-fix code, green with the fix)
Self-review of the autocomplete change found the setTarget no-op dead on its primary path: applyMachine mutates the shared config (which IS pool.config) BEFORE setTarget reads it, so machine switches kept the old SSH client (wrong-host hazard). Plus client-side cache/switch defects from the same change. - setTarget gains an explicit 'previous' diff baseline; applyActiveMachine/ clearActiveMachine snapshot the target fields before mutating the shared config (the critical regression) - /connect and rw_connect adopt invalidate() as the forced-reconnect escape hatch so a probe never trusts a half-open cached client - lastAppliedMachine is maintained inside applyActiveMachine so boot restore and rw_connect keep the invariant - ensureCurrent: shared in-flight promise, rejects on failure, nothing cached after a failed switch - /ls echoes its machine identity; the picker validates it and re-switches once on mismatch (external machine switches no longer poison the cache) - picker reopen fully resets fetch state incl. in-flight map and seq; per-key fetch generation fences superseded cache writes; the seq-guarded pipeline is extracted to suggestFrom; continueSuggest fetches fresh - invalidate() now fires onCloseHook like close() (forwards detach on both paths; stale close listeners can't tear down re-attached forwards) - tests: apply-active-machine.test.js (production call shape, red 5/6 -> green 6/6), picker-suggest.test.js (12 extraction-based tests over the shipped client logic), red-green verified per finding
…itch cannot redirect a pick PR #42 removed the per-keystroke POST /current that used to keep the active pool pinned to the picker's machine (that reconnect was the issue #41 bug). With its client cache a cache-hit re-type issues NO host request at all, so nothing re-applied the picker's machine before commitPath -- and /mirror carried no identity, so the mirror was built from whichever machine happened to be active. Verified against a real host: with the picker showing jimmycppliu's tree on 9.134.186.191:36000 and an external 'set as current' to a second machine on the same box, the mirror came out with the second machine's identity (machineId=root). Pre-#42 masked this by accident: the pre-fix commit path always re-posted /current first, so the probe landed on the picker's machine. - /mirror and /home accept an optional machineId naming the machine the caller is showing; the host re-asserts it (setCurrent) BEFORE probing. - An unknown id is REFUSED (404) rather than silently falling back to the active machine -- falling back is exactly the hazard. - An absent id keeps the previous machine-scoped behaviour, so older clients and the settings page's workspace flow are unaffected. - The picker sends machineId on both requests. test/mirror-machine-identity.test.js covers all four orderings at route level plus the client-side call shape; red-green verified (4/5 fail without the fix).
Merged — with one follow-up needed (and now applied)Thanks @GDWhisper, this is a good fix. Reviewed, verified against a real SSH host, and squash-merged as d3175e4. Performance claim independently reproduced (real host, real SFTP, real routes; driving the real
The red-green claim also checks out: on pre-fix One issue your self-review didn't cover: a concurrent machine switch can redirect a pickThe PR removes the per-keystroke The Reproduced on a real host ( Pre-#42 masked this by accident: the old Follow-up committed to
|
…#41, PR #42) + machine identity hardening Measured on a real host (9.134.186.191:36000, real SSH/SFTP with the real DirPicker logic extracted from lib/client.js): warm keystroke -> suggestions 1099ms -> 31ms (35x), host requests per keystroke 2 -> 0. Also ships the follow-up hardening for the wrong-host window PR #42 opened: /mirror and /home accept an optional machineId naming the machine the caller is showing, re-asserted by the host before probing; an unknown id is refused (404) rather than silently falling back to the active machine.
Closes #41
问题。 在工作目录选择器里输入远程路径时补全很慢:每敲一个字符都会断开重连一次 SSH、并重复列一遍同一个目录,真实网络下每个字符要卡 0.5–2 秒。
改了什么
rw_connect)总是重新拨号,不再复用可能已经半死的旧连接/dsh-remote/ls响应新增一个附加小字段machine(host/port/username),让选择器能察觉「当前机器被换掉了」界面无变化;没有删除或改动任何既有接口(
ls只是新增字段)。测试。 新增回归测试覆盖连接生命周期(
test/apply-active-machine.test.js)和补全逻辑(test/picker-suggest.test.js),两组测试都在修复前验证过会红。全套 200/201 通过——唯一失败的test/i18n.test.js在 main 上就已失败,与本次无关。范围。 两个提交:性能修复,然后是自审后的正确性修复,仅此而已。