Skip to content

fix(ui): a message sent right after opening a session reaches it - #6733

Open
dam-application[bot] wants to merge 2 commits into
mainfrom
fix/6732-chat-first-message-conversation-changed
Open

dam-application[bot] wants to merge 2 commits into
mainfrom
fix/6732-chat-first-message-conversation-changed

Conversation

@dam-application

Copy link
Copy Markdown
Contributor

What and why

In the web chat, a message sent right after a person opened a session could fail with "Couldn't send — the conversation changed while the message was on its way". Retry failed in the same way until the person switched sessions and came back.

The cause: a session/resume that answered after the chat moved to another session bound the chat's connection to the old session. Every later send then got the old session back, and the send path refused it. This change stops the late bind, repairs a stale binding at the next send, and makes the send path deliver instead of refusing.

Reviewer guide

What changes in substance

  • A reset voids an engagement in flight. clear() now bumps a counter. engage() binds only when no clear() ran while its resume was in flight; otherwise it returns null. Before, the late answer bound the old session.
  • The engagement follows the session on screen. When the binding names another session than the shown one, engage() resumes the shown session on the same connection and binds it. This is what makes Retry work without a session switch. The chat's update handler already drops frames for sessions that are not on screen, so the old engagement shows nothing.
  • The send path no longer refuses. When the chat's connection answers for another session, the message goes over the one-off connection to its own session (engageAside, from fix(sessions): a message sent before leaving the chat runs, and says it is sending until the agent has it #6239). The error text "the conversation changed while the message was on its way" is gone.

Where to look closely

  • use-acp-session-engagement.ts: when no session is on screen (the new-chat page), engage() still returns the existing binding, as before. That path only starts sessions through beginSession.
  • use-acp-prompt.ts (open): with the engagement fix, the chat's connection should not answer for another session while that session is on screen. If it does, the message reaches the right session over the one-off connection, but its reply does not stream into the chat until the chat engages that session again. I chose delivery over an error here.

Ruled out

  • Rebinding through a new call from the send path into the connection hook. engage() already runs on every send and Retry, so the repair belongs there.
  • Making two concurrent connection opens share one socket. When a send and a load start together, openConnection opens two sockets. That leaves a second socket that a reset does not close, and is one way a resume answers late. The guard above makes the late answer harmless. Sharing the open is a separate change.

Scope

  • packages/ui/src/modules/sessions/hooks/use-acp-session-engagement.ts: the reset guard and the shown-session check.
  • packages/ui/src/modules/sessions/hooks/use-acp-prompt.ts: the send-path branch.
  • Tests: new session-engagement-after-reset.test.ts, one new case in send-after-switch.test.ts.
  • docs/architecture/sessions.md: one sentence on the chat's engagement, and the Last verified date.

Testing

  • The new engagement tests (reset during resume, stale binding) and the new send case fail on main and pass with this change.
  • mise run check passes.
  • mise run test stops in vm-runner on boot::tests::an_entry_holding_a_locked_file_is_kept_whole. That test fails in this sandbox on main too, and this change does not touch vm-runner.
  • The ui suite alone: 342 files, 2274 tests pass.
  • No demo: the race depends on timing that an installed Environment cannot show on request.

Fixes #6732

Written by this agent — https://dam-dev.apps.dam-cl.fmaas.res.ibm.com/a/agent-677ca492fbca62dd?s=b3ac5afb-7836-4ba7-9257-b423d940a2e9

🤖 Generated with Claude Code

dam-application Bot and others added 2 commits November 19, 2026 12:14
A session/resume that answered after the chat moved to another session
bound the chat's connection to the old one, and every later send, Retry
included, failed with "the conversation changed" until the person
switched sessions. A reset now voids an engagement in flight, a binding
to another session than the shown one engages the shown one again, and a
send whose connection still answers for another session goes over a
connection of its own instead of failing.

Fixes #6732

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dam-application dam-application Bot added agent/karel Claims and pull requests of software-developer agent Karel (agent-677ca492fbca62dd) code-guardian:review Add this label to trigger an automatic review by code-guardian. labels Nov 19, 2026

@dam-code-protector dam-code-protector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Code Guardian 🛡️ — ✅ Code Review @ 2cc394a

PR #6733: fix(ui): a message sent right after opening a session reaches it

Author: dam-application[bot] | Branch: fix/6732-chat-first-message-conversation-changed → main | Changes: +156 −11 (5 files)

Summary

This PR stops a late session/resume from binding the chat's connection to a session the person left. A stale binding now follows the shown session, and a mismatched send goes over a one-off connection.

Limits: 1 skill(s) did not run: react-ui-engineering.

Findings

  • 🟢 Suggestion: Page promises that a move never fails a send (docs/architecture/sessions.md:200).
  • ✅ Looks good: The new engagement and send tests fail with the base hooks and pass at HEAD (packages/ui/src/modules/sessions/hooks/use-acp-session-engagement.ts:30).

Documentation Check (doc-drift)

✅ No findings.

Issue Fit

✅ No findings.

TypeScript Engineering Review

✅ No findings.

Verdict

APPROVE — No blocking finding remains, and the new tests prove the reset guard and the send fallback.


Review by Code Guardian 🛡️ · automated code guardian · ibm/aws/claude-opus-5-5 on pi

Unacknowledged this long means it never arrived, and the failure carries the socket's stated cause when it gave one.
Until the acceptance arrives the person's own message says it is **sending**, or that the agent is **waking** when the send woke it, after a second so a fast send shows nothing; the reply, the working indicator and the session's row in the sidebar wait for the acceptance, so none says the agent is working on a message it does not have.
A send whose chat moves to another session before it went out goes over a connection of its own, engaged to its session, so the move cannot strand it.
The chat's own connection is engaged to the session on screen alone: a resume that answers after the person moved on never engages it, and one left engaged to another session engages the shown one again at the next send, so a send or its retry never fails for the move.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Suggestion: The new sentence says that a send or its retry never fails for the move. This is not true when the person moves away and back while the send sets up its connection. Each move resets the connection, so the send's ensureLive returns null. The send then fails with "Failed to establish connection" (use-acp-prompt.ts:337), as it does on main. Reported by Documentation Check (doc-drift).

Suggested change
The chat's own connection is engaged to the session on screen alone: a resume that answers after the person moved on never engages it, and one left engaged to another session engages the shown one again at the next send, so a send or its retry never fails for the move.
The chat's own connection is engaged to the session on screen alone: a resume that answers after the person moved on never engages it, and one left engaged to another session engages the shown one again at the next send, so a stale engagement never fails a send or its retry.

@dam-code-protector dam-code-protector Bot removed the code-guardian:review Add this label to trigger an automatic review by code-guardian. label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/karel Claims and pull requests of software-developer agent Karel (agent-677ca492fbca62dd) qa:design

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web chat: a message sent right after opening a session fails with "the conversation changed", and retry keeps failing

0 participants