fix(acp): 对齐 ACP session ID 与全局会话状态#1117
Conversation
在 newSession/resumeSession/loadSession 中调用 switchSession, 确保 transcript 持久化、analytics 与 cost tracking 使用 ACP session ID, 而非内部默认 session ID。 - newSession 生成 sessionId 后立即对齐全局状态 - resumeSession 命中 fingerprint 缓存路径也对齐 - loadSession 在 sessionIdExists() 检查前对齐(lookup 依赖 getSessionId) - 补充 5 个测试覆盖上述路径,以及 prompt 不触发额外 switchSession
📝 WalkthroughWalkthroughAcpAgent now imports ChangesSession State Alignment
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/services/acp/__tests__/agent.test.ts (1)
1184-1194: ⚡ Quick winAssert call order for
loadSessionalignment path, not just argument.This test checks
switchSession(requestedId)but does not prove it runs beforesessionIdExists(), which is the regression-sensitive part of this fix.✅ Suggested test hardening
test('loadSession calls switchSession with the requested sessionId', async () => { const agent = new AcpAgent(makeConn()) const requestedId = 'load-test-session-id' + const callOrder: string[] = [] + mockSwitchSession.mockImplementationOnce(() => { + callOrder.push('switch') + }) + mockSessionIdExists.mockImplementationOnce(() => { + callOrder.push('exists') + return false + }) await agent.loadSession({ sessionId: requestedId, cwd: '/tmp', mcpServers: [], } as any) expect(mockSwitchSession).toHaveBeenCalledWith(requestedId) + expect(callOrder.slice(0, 2)).toEqual(['switch', 'exists']) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/acp/__tests__/agent.test.ts` around lines 1184 - 1194, The test asserts switchSession received the right argument but not that it ran before sessionIdExists; update the test for loadSession to assert call order by comparing the jest mock invocation order of mockSwitchSession and mockSessionIdExists (use mock.fn().mock.invocationCallOrder indexes) so the assertion ensures mockSwitchSession was invoked earlier than mockSessionIdExists, while keeping the existing argument check for requestedId on switchSession.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/services/acp/__tests__/agent.test.ts`:
- Around line 1184-1194: The test asserts switchSession received the right
argument but not that it ran before sessionIdExists; update the test for
loadSession to assert call order by comparing the jest mock invocation order of
mockSwitchSession and mockSessionIdExists (use
mock.fn().mock.invocationCallOrder indexes) so the assertion ensures
mockSwitchSession was invoked earlier than mockSessionIdExists, while keeping
the existing argument check for requestedId on switchSession.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5edac5e2-a79e-4426-b1fc-4fab90bf88d6
📒 Files selected for processing (2)
src/services/acp/__tests__/agent.test.tssrc/services/acp/agent.ts
问题描述:
使用--acp启动后,使用newSession协议返回的sessionId和Claude Code本身的sessionId不一致,导致后续对话通过该返回的sessionId对话都是全新会话,无法继续之前会话。
解决方案:
在 newSession/resumeSession/loadSession 中调用 switchSession, 确保 transcript 持久化、analytics 与 cost tracking 使用 ACP session ID, 而非内部默认 session ID。
Need help on this PR? Tag
@codesmithwith what you need.Summary by CodeRabbit
Tests
Bug Fixes