Repository navigation
fix(chat): tell a replacement ACP session the conversation it lost #2476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38185,8 +38185,13 @@ export function createAgentChatService(args: { | |
| const invocationKey = acpInvocationKey(spawnPlan); | ||
|
|
||
| const persisted = readPersistedState(managed.session.id); | ||
| const existingSessionId = managed.seededAcpSessionId?.trim() | ||
| // The id of a session ADE itself opened for this chat. A Devin Cloud | ||
| // chat's derived id (below) only guesses at a session nothing has opened | ||
| // yet, so it cannot be evidence that a session was lost. | ||
| const storedAcpSessionId = managed.seededAcpSessionId?.trim() | ||
| || persisted?.acpSessionId?.trim() | ||
| || null; | ||
| const existingSessionId = storedAcpSessionId | ||
| // A Devin Cloud chat opened from the panel knows its session by the web | ||
| // id before it has ever spoken ACP. | ||
| || (devinCloud && managed.session.devinSessionId?.trim() | ||
|
|
@@ -38319,6 +38324,21 @@ export function createAgentChatService(args: { | |
| managed.runtimeInvalidated = false; | ||
| managed.acpReasoningEffortInvalidated = false; | ||
| managed.seededAcpSessionId = runtime.session.sessionId; | ||
| // A stored session the agent no longer had: this new session holds | ||
| // none of the conversation ADE keeps. Re-stage the once-per-thread | ||
| // sections and say so, as Muse's replacement session does. Only a | ||
| // session ADE opened can be lost; a provider switch clears the seed | ||
| // and replays the whole transcript instead. | ||
| if (storedAcpSessionId && runtime.session.entryPlan.mode === "new") { | ||
| emitChatEvent(managed, { | ||
| type: "system_notice", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replacement tail restages current turnMedium Severity Rebuilding reconstruction in Reviewed by Cursor Bugbot for commit d2cc38f. Configure here. |
||
| noticeKind: "warning", | ||
| severity: "warning", | ||
| 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); | ||
| } | ||
| managed.session.acpPermissionMode = permissionMode; | ||
| if (runtime.session.systemPromptAppended) { | ||
| markLaneGuidanceDelivered(managed, runtime.session.sessionId, runtime.session.systemPromptAppended); | ||
|
|
@@ -79621,6 +79641,12 @@ export function createAgentChatService(args: { | |
| } | ||
| if (previousProvider !== nextProvider || freshThreadForRoute) { | ||
| delete managed.session.threadId; | ||
| // An ACP session id belongs to the provider that minted it. Carried | ||
| // onto the next provider, a deliberate switch looks like a session | ||
| // the agent no longer has (a `new` entry under a stored id), which | ||
| // warns about a lost conversation and stacks the tail on the full | ||
| // replay staged below. `runtimeInvalidated` drops the persisted copy. | ||
| delete managed.seededAcpSessionId; | ||
| managed.runtimeInvalidated = true; | ||
| managed.acpReasoningEffortInvalidated = false; | ||
| clearDeliveredDirectiveEpoch(managed); | ||
|
|
||


There was a problem hiding this comment.
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,
refreshReconstructionContexttreats 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
runAcpTurnto 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.