Skip to content

fix(chat): send a prompt whose chat was switched away during omp startup - #389

Merged
andrebrait merged 1 commit into
ompweb-dev:mainfrom
andrebrait:fix/send-on-session-switch
Nov 3, 2026
Merged

andrebrait merged 1 commit into
ompweb-dev:mainfrom
andrebrait:fix/send-on-session-switch

Conversation

@andrebrait

@andrebrait andrebrait commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Sending a message in a session whose omp process had stopped (idle long enough to be reaped), then switching to another chat right away, dropped the send: the text went back into that session's composer and nothing reached omp.

ChatWindow is keyed by session, so the switch unmounts useAgentSession. The existing-session branch of handleSend awaits get_state (which spawns omp, several seconds) and then ensureEventsConnected, which throws EventStreamConnectionError("closed") once the hook is unmounted. The send returned rejected and the composer restored the draft. Queue/steer were unaffected because omp is already running then.

Fix

Same as the new-chat branch already does for ownerGone: once the chat has unmounted, the prompt is still sent, with no observer opened and no host-tool/roster/entry-snapshot setup, and the send returns accepted. A stream failure while the chat is still mounted (or any other error) still rejects as before.

AGENTS.md documents the exception next to the readiness-wait rule.

Tests

  • unmount during the send connection still delivers the prompt (was: must not dispatch): one prompt, no extra observer, no set_host_tools/set_host_uri_schemes/get_subagents.
  • unmount during prompt RPC startup cannot create an observer after teardown: prompt now sent, still no observer; the btw case is unchanged.
  • New a send connection that fails while the chat is mounted rejects without dispatching the prompt (fails if the alive check is dropped from the catch).

bun test --parallel hooks/: 325 pass.

Known limit

Switching away and back to the same chat within the omp startup window: the remounted chat may load before the wrapper exists and so not attach a stream for the run the earlier instance starts (the sidebar badge shows it; a reload shows it). The same applies today to any run started elsewhere on a chat that loaded idle.

Summary by CodeRabbit

  • Bug Fixes
    • Messages sent as a session starts are no longer returned to the composer when you switch chats during startup. The message is accepted and sent, without setting up further activity for the chat you left.
    • Connection failures while the chat remains open still prevent the message from being sent.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

When an existing chat unmounts during startup, handleSend can still send the prompt. It skips stream and UI-state setup after unmount. Mounted connection failures still reject the send without dispatching the prompt.

Changes: Unmount-safe send flow

Layer / File(s) Summary
Unmount-safe send handling
hooks/useAgentSession.ts, hooks/useAgentSession.rpc.test.mjs, AGENTS.md, CHANGELOG.md
After unmount, handleSend proceeds with the prompt without setting up roster or host-tool state. Tests cover accepted prompt sends, fatal mounted connection failures, and /btw requests. The changelog and agent guidance describe the unmount behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: cloudwindy

Merge Risk: Minimal · up to f124b

No actionable merge-blocking issue is established. The change allows pending prompts to proceed after switching chats while preserving rejection of mounted connection failures.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: preserving prompt delivery when the user switches away from a chat during omp startup.
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: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • 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

A rabbit taps send as the chat slips away
The prompt finds its path, though the view does not stay
No roster is fetched, no host tools appear
A mounted failure still stops the request here
Soft paws applaud as the tests make it clear

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59de34b8-76da-4653-8aea-b184e95300bb
Commits

Reviewing files that changed from the base of the PR and between 2ca0bca and f124b42.

Files selected for processing: 5
  • AGENTS.md
  • CHANGELOG.md
  • graphify-out/graph.json
  • hooks/useAgentSession.rpc.test.mjs
  • hooks/useAgentSession.ts

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

Recent review details
Context from checks skipped due to timeout: 3
  • GitHub Check: CodeRabbit
  • GitHub Check: Verify (windows-latest)
  • GitHub Check: Verify (ubuntu-latest)
Additional context used
Code guidelines: 1
AGENTS.md — auto-discovered
Path-based instructions: 2
Source excerpt: Client code (`components/`, `hooks/`) must not call `AbortSignal.timeout`, `AbortSignal.any` or `Promise.withResolvers` — older mobile browsers throw and the whole tree shows the "unexpected error" screen.

CodeRabbit inference engine (AGENTS.md)

Files:

  • hooks/useAgentSession.rpc.test.mjs
  • hooks/useAgentSession.ts
Source excerpt: `components/ui/` holds the shared primitives (built on `@base-ui/react`): `primitives.tsx` (Dialog/Tooltip/Collapsible), `field.tsx` (form fields + ConfirmDialog), `toast.tsx` (`toast.success/error/info`, mounted in AppShell...

CodeRabbit inference engine (AGENTS.md)

Files:

  • CHANGELOG.md
  • AGENTS.md
  • hooks/useAgentSession.rpc.test.mjs
  • hooks/useAgentSession.ts

@kilo-code-bot

kilo-code-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.

Files Reviewed (5 files)
  • AGENTS.md
  • CHANGELOG.md
  • graphify-out/graph.json
  • hooks/useAgentSession.rpc.test.mjs
  • hooks/useAgentSession.ts

Reviewed by free · Input: 20.6K · Output: 3.1K · Cached: 182.7K

@andrebrait

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T13:43:39.097697Z f124b42 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: f124b4290e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@andrebrait
andrebrait merged commit 3c2a31a into ompweb-dev:main Nov 3, 2026
5 checks passed
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