Removed needs-initial-file-selection logic changes behavior
Location
ai-code-backends-infra.el:532-538
Severity
Low (behavior change)
Problem
The logic that detected when a file needed initial selection was removed:
;; Removed:
(needs-initial-file-selection (and (null buffer-name)
file-key
(null attached-buffer)
(not attached-missing)))
Impact
This affects the effective-force-prompt calculation. The old code would force a prompt in this scenario; the new code will not. This could change the initial file selection behavior in edge cases.
Scenario
When:
- No buffer name is set
- A file key exists
- No attached buffer
- The attached buffer is not marked as missing
Previously, this would trigger initial file selection. Now it does not.
Suggested Fix
Either restore this logic or document why it was intentionally removed.
Hmm this part of code will need to be well tested to apply the suggestion above. Cause it will affect around 10 backends using it.
Feedback from codex (gpt-5.4 xhigh)
• 这是一个真实问题,应该修,但触发条件比 issue #254 的文字更窄。问题不是“所有新 文件首次绑定都会错”,而是“同一 repo 里有多个活跃 AI session,且目录级 remembered session 已存在时”,当前实现会静默复用 remembered session,把新文件 直接绑定到它,而不是让用户选择。
依据
- 当前 ai-code-backends-infra.el:600 里的 effective-force-prompt 只看 force- prompt 和 attached-missing,之前的 needs-initial-file-selection 已被移除。
- 同文件 ai-code-backends-infra.el:726 的 ai-code-backends-infra--select- session-buffer 在“多 session”场景下,只要 force-prompt 为 nil 且 remembered buffer 还在,就直接返回 remembered buffer,不会弹选择器。
- 现有测试 test/test_ai-code-backends-infra.el:576 把“新文件复用 remembered session”写成了预期,但这个测试本身模拟的是两个活跃 session,因此把歧义场景也 当成了“应该静默复用”。
- 另一个测试 test/test_ai-code-backends-infra.el:693 只覆盖了“多个活跃 session 但没有 remembered session”的情况,所以漏掉了真正有问题的分支。
- 我用 batch Emacs 复现了当前行为:多活跃 session + remembered session + 新文 件首次绑定 时结果是 prompted=nil,说明不会提示选择;而“无 remembered session 的多活跃 session”会提示,“只有一个活跃 session”不会提示。这说明问题真实存 在,而且边界很清楚。
根因 #244 把“有 remembered session”视为“可以安全跳过首次绑定选择”,但这在多活跃 session 时并不成立。对新文件来说,remembered session 最多只能作为默认候选,不 应该变成静默自动绑定。
怎么修
- 优先改 ai-code-backends-infra.el:600 这一段,把旧的“首次文件绑定”判定恢复回 来,或等价地恢复成 first-file-association 语义。
- 直接恢复旧逻辑其实是安全的,因为 ai-code-backends-infra.el:726 在“只有一个 session”时本来就不会 prompt,所以不会破坏“单 session 自动复用”的好处;它只会 在“多个 session”时重新触发选择器。
- 测试上应调整 test/test_ai-code-backends-infra.el:576 和 test/test_ai-code-
backends-infra.el:693:
- 新文件 + 单活跃 session + remembered session => 不提示,直接复用。
- 新文件 + 多活跃 session + remembered session => 必须提示,但 remembered session 可作为默认项。
- 保留现有的 missing attachment / force rebind 场景。
我认为这个 issue 应该修。它是共享基础设施里的行为回归,会影响所有走 ai-code- backends-infra 的 CLI backend,不只是某一个后端。
来源:
- Issue #254: https://github.com/tninja/ai-code-interface.el/issues/254
- PR #244: https://github.com/tninja/ai-code-interface.el/pull/244
- PR review discussion:
https://github.com/tninja/ai-code-interface.el/pull/244#discussion_r2968553013