Skip to content

fix(frontend): keep a first message when the user opens another chat before it is sent - #7838

Merged
mmabrouk merged 1 commit into
release/v0.125.2from
fix/first-send-switch-away
Oct 26, 2026
Merged

mmabrouk merged 1 commit into
release/v0.125.2from
fix/first-send-switch-away

Conversation

@mmabrouk

Copy link
Copy Markdown
Member

Symptom

In /m, a user sends the first message of a new chat from an agent's page and opens another chat in the sidebar within about 1.5 s. On staging (release/v0.125.2, which already has #7834) this lost the message in 3 of 4 runs: no /invoke request, no turn, the chat left the sidebar, and its URL showed "This chat does not exist". No "Message not sent" card appeared.

Cause

The agent page hands the first message to the chat screen as a pending task. The chat screen holds it until the transcript, the vault and the setup step answer, and only then sends it. The sidebar row is also added at that send. A switch during the hold unmounted the chat screen, so nothing was left to send the task and no row was added. The sidebar link carries no ?agent=, so the chat screen could not resolve the agent of a session the server does not know. #7834 covered only a send that had already started.

Fix

  • When the chat screen leaves a session whose task was not on its way, the task is marked failed and the session is listed in the sidebar (useLeaveHeldTask, leaveHeldTaskAtom). The check runs one task later, so a remount in place (strict mode) is not a leave.
  • The chat screen takes the agent from the pending task when the route has none. Coming back shows the existing "Message not sent" card with the text and Retry.
  • Retry also waits while a template's connect step is up.

A full page reload still loses the in-memory task. That is unchanged.

Tests

  • New chatScreenLeaveHeldTask.render.test.tsx renders the real ChatScreen. It switches away at 0.3, 0.6 and 1.5 s. These cases failed before the fix and pass now. It also covers a send already on its way, a task that already failed, a quick switch back, a project switch and strict mode.
  • liveConversationOffScreenFailure.render.test.tsx checks the Retry setup gate.
  • Mobile: 685 unit tests pass, tsc is clean and pnpm lint-fix is clean.

…before it is sent

A message typed on Home or an agent's page waits on the chat screen until the
transcript, the vault and the setup step answer. Opening another chat during
that wait unmounted the only code that sends it, so it never went out, the
session got no rail row, and the rail link carries no agent, so coming back
showed "This chat does not exist".

When the chat screen leaves a session whose task was not on its way, mark the
task failed and list the session in the rail. On return the chat screen takes
the agent from the task and shows the "Message not sent" card with Retry.
Retry also waits for a template's connect step.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 30dff47 and 0c4b755.

Files selected for processing: 6
  • web/mobile/src/features/chat/ChatScreen.tsx
  • web/mobile/src/features/chat/LiveConversation.tsx
  • web/mobile/src/features/chat/useLeaveHeldTask.ts
  • web/mobile/src/features/home/pendingTask.ts
  • web/mobile/tests/unit/chatScreenLeaveHeldTask.render.test.tsx
  • web/mobile/tests/unit/liveConversationOffScreenFailure.render.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Pending chat tasks that are interrupted when leaving a conversation are now marked as failed, and the conversation remains available to return to.
    • Retrying a failed task is disabled while session setup is blocking and becomes available once setup is no longer blocking.

Mobile chat now tracks held tasks as chat screens open and close, preserves eligible tasks in local sessions when the last screen closes, and blocks failed-task retries while session setup is blocking.

Changes: Mobile chat task handling

Layer / File(s) Summary
Held-task lifecycle
web/mobile/src/features/home/pendingTask.ts, web/mobile/src/features/chat/useLeaveHeldTask.ts, web/mobile/src/features/chat/ChatScreen.tsx, web/mobile/tests/unit/chatScreenLeaveHeldTask.render.test.tsx
ChatScreen tracks its session and project. When the last screen for a session closes, eligible held tasks are marked failed and registered as local sessions. The chat screen resolves the agent ID from the route or pending task. Tests cover task state, session retention, and screen lifecycle cases.
Retry setup blocking gate
web/mobile/src/features/chat/LiveConversation.tsx, web/mobile/tests/unit/liveConversationOffScreenFailure.render.test.tsx
Failed-task retries are disabled while setup is blocking. The retry handler returns without sending under that condition. Tests check retry availability while setup blocks and after it stops blocking.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ChatScreen
  participant useLeaveHeldTask
  participant leaveHeldTaskAtom
  participant registerLocalSessionAtom
  ChatScreen->>useLeaveHeldTask: provide sessionId and projectId
  useLeaveHeldTask->>leaveHeldTaskAtom: set after the last screen closes
  leaveHeldTaskAtom->>registerLocalSessionAtom: register eligible task session
Loading
Merge Risk: Minimal · up to 0c4b7

The change appears mergeable after normal checks; no actionable failure is established.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: a first message is kept when the user opens another chat before it is sent. The title is short, specific, and matches the changeset (useLeaveHeldTask, leaveHeldTaskAto…
Description check Passed The description explains the symptom, cause, fix, and tests. It matches the changeset: marking held tasks failed on leave, listing the session in the sidebar, taking the agent from the pending task, g…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a first message is kept when the user opens another chat before it is sent. The title is short, specific, and matches the changeset (useLeaveHeldTask, leaveHeldTaskAtom, ChatScreen changes). It uses the fix(frontend) prefix and states the user-visible effect without file lists or vague terms.

Full details: Description check

Explanation

The description explains the symptom, cause, fix, and tests. It matches the changeset: marking held tasks failed on leave, listing the session in the sidebar, taking the agent from the pending task, gating Retry on the connect step, and the new render tests.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Item Value
Status stopped
Commit 0c4b755eba987c5d57bc945b5443bd0e07724dbc
Manual expiry (UTC) Not granted
CI deadline (UTC) Not granted
Workflow https://github.com/Agenta-AI/agenta/actions/runs/40419501673

Provisioning failed; no manual review time granted. Environment absence verified; retained storage requires separate provider accounting.

Post /preview as a new comment to request a one-hour preview. Repeating it while active does not extend the hour.
Preview data is disposable. Expiry is enforced by the next successful cleanup sweep, not an exact timer.
Environment deletion stops its compute. Provider-retained storage and permanent services may still be billed.

@mmabrouk
mmabrouk merged commit b7eb664 into release/v0.125.2 Oct 26, 2026
59 of 60 checks passed
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: Merged into release/v0.125.2 as b7eb664. Codex (gpt-6-astra, medium) reviewed it. Its points are in this PR: a failed task stays listed in the sidebar, and Retry waits for a template's connect step. CodeRabbit had no actionable items. All non-web checks passed. The web unit test job was still running at merge. The mobile unit tests (685), tsc and pnpm lint-fix pass locally. The fix is not verified on a deployed stage yet.

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