Repository navigation
fix(chat): tell a replacement ACP session the conversation it lost - #2476
Conversation
When an ACP agent no longer has the chat's stored session (the -32002 rejoin refusal, or a Restart session), the host silently opens session/new. onRuntimeCreated only recorded the new id, so the next turn landed on an agent that had never seen the kept turns ADE still displays, with no notice and no conversation tail. Claude, Codex, Muse and Copilot all notify and re-orient in that situation; ACP did neither. Now onRuntimeCreated treats a stored id that opened as a new session as the replacement it is: it emits a warning notice naming the provider, re-stages the once-per-thread sections (resetStagedSection, so a prior "none" continuity key cannot count as no change), and rebuilds the turn context so the conversation tail rides that same turn. Brand-new chats and successful resume/load are untouched, as are entry-plan selection, prompt order and the queued-steer path. Proof: the new case in agentChatServiceAcpRuntime.test.ts models a restored chat whose first turn resumed the agent's session (spending the conversation tail), then lost that session on a Restart. Pre-fix it fails twice: the replacement's session/prompt carries no "teal" from the kept turn, and no "started a new one" notice is emitted. With the patch both pass, and removing restageSectionsForNewProviderThread makes it red again, proving the reset is load-bearing. The whole file passes (37 tests), and the ade-desktop typecheck is clean. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 18 minutes. View limit details
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. |
There was a problem hiding this comment.
Devin Review found 1 potential issue.
4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| message: `${dialect.displayName} could not reopen this chat's session, so it started a new one. Earlier turns are summarized for it.`, | ||
| }); | ||
| restageSectionsForNewProviderThread(managed); | ||
| refreshReconstructionContext(managed); |
There was a problem hiding this comment.
🟡 Replacement chat repeats the current message
On a replacement send, refreshReconstructionContext treats the current message as history because showTurnBeforeRuntime already recorded it. runAcpTurn sends it again as the live prompt, crowding out one older message when the history is full.
Learn more
runAcpTurn records the outgoing user message before opening the provider session so the user can see startup progress. Recording writes the message into the in-memory history immediately via commitChatEvent. collectConversationEntries reads that history along with the transcript. buildRecentConversationContext keeps the newest 20 entries for ordinary chats. The outgoing message takes one of those slots before the prompt builder appends it as the live request.
Example: A Qwen chat has ten completed exchanges with one user entry and one assistant entry each. After Restart agent session, the provider rejects the old ID. The replacement sees 19 earlier entries plus “What did I say first?” in its history, then receives the same question as the live prompt. The first user entry is missing.
Recommended fix: Pass the opening turn ID from runAcpTurn to the reconstruction path and exclude that turn before selecting the history tail. Filter both the transcript and live-ring fallback by turn ID, not by message text, so an identical request from an earlier turn remains in history.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d2cc38f. Configure here.
| }); | ||
| restageSectionsForNewProviderThread(managed); | ||
| refreshReconstructionContext(managed); | ||
| } |
There was a problem hiding this comment.
Replacement tail restages current turn
Medium Severity
Rebuilding reconstruction in onRuntimeCreated runs after showTurnBeforeRuntime has already written this send's user_message. refreshReconstructionContext then folds that current turn into the replacement session's conversation tail, and consumePendingTurnContextPrefix prepends it again as the prompt. On the idle rejoin-fallback path this PR targets, the new thread sees the latest user turn twice — once as prior history and once as the live message.
Reviewed by Cursor Bugbot for commit d2cc38f. Configure here.
Review findings on PR #2476: - A model switch that changes provider kept the previous provider's seeded ACP session id. Handed to the new provider it opened as a new session, so the lost-session guard warned about a conversation loss and staged the conversation tail on top of the full transcript replay the switch had already staged. The seed is now dropped on a provider switch (the persisted copy is already dropped by runtimeInvalidated), and the notice/re-stage only fire for an id ADE itself opened (seed or persisted) rather than a Devin Cloud chat's derived id, which a brand-new chat has never opened. - The proof test pinned the warning's sentence. It now asserts the event shape the contract actually promises: a system_notice warning that names the provider. Proof: agentChatServiceAcpRuntime.test.ts (37 tests) and the ade-desktop typecheck pass. Co-Authored-By: Claude Code <noreply@anthropic.com>


Why
When a stored ACP session cannot be resumed — the provider answers
-32002and ADE opens a replacement session — the chat silently lost its conversation. The transcript kept rendering as if the context were still there, and the next turn started from nothing.Same defect class as pingdotgg/t3code#30188, verified against ADE's ACP runtime setup.
What changed
Evidence
agentChatServiceAcpRuntime.test.ts37/37 pass, including config, resume/rejoin and login-change restart.Not checked
Not exercised against a live provider that drops a session; the test uses the mock ACP agent's
-32002path. Full CI matrix not run locally.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issues were found.Summary
The PR restores earlier conversation context when an ACP provider opens a replacement session.
No new actionable issues were found. Tests were inspected, not run.
Reviews (2) · Last reviewed commit: "fix(chat): only a session ADE opened can..." · Reviewed by Greptile