Skip to content

fix(chat): tell a replacement ACP session the conversation it lost - #2476

Merged
arul28 merged 2 commits into
mainfrom
fix/acp-rollback-capability
Nov 23, 2026
Merged

arul28 merged 2 commits into
mainfrom
fix/acp-rollback-capability

Conversation

@arul28

@arul28 arul28 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Why

When a stored ACP session cannot be resumed — the provider answers -32002 and 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

  • When a stored session id opens as a fresh session (the rejoin fallback), ADE now emits a warning system notice naming the provider, restages the transcript sections for the new provider thread, and refreshes the reconstruction context.
  • Brand-new chats and successful resume/load are untouched.

Evidence

  • New proof: on unmodified code, "tells a replacement ACP session the conversation it lost" fails; after the patch it passes.
  • agentChatServiceAcpRuntime.test.ts 37/37 pass, including config, resume/rejoin and login-change restart.
  • Desktop typecheck passes.

Not checked

Not exercised against a live provider that drops a session; the test uses the mock ACP agent's -32002 path. Full CI matrix not run locally.

🤖 Generated with Claude Code

ADE   Open in ADE  ·  fix/acp-rollback-capability branch  ·  PR #2476


Devin Review

RetriggerView in GreptileConfidence 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.

  • ACP chats warn and carry earlier turns when a session is replaced.

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

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>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f263fed and 12b57f1.

Files selected for processing: 2

  • apps/desktop/src/main/services/chat/agentChatService.ts
  • apps/desktop/src/main/services/chat/agentChatServiceAcpRuntime.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

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>
@arul28
arul28 merged commit 1abcac5 into main Nov 23, 2026
28 checks passed
@arul28
arul28 deleted the fix/acp-rollback-capability branch November 23, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant