Skip to content

Keep a Bot's answer when a conversation is reloaded a moment after it answered - #2614

Closed
davidmckayv wants to merge 1 commit into
mainfrom
fix/reload-keeps-answer
Closed

davidmckayv wants to merge 1 commit into
mainfrom
fix/reload-keeps-answer

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

What a person saw

A person allowed a Bot's change, the Bot answered (the order number), and the page was reloaded a moment later. The answer was on screen for half a second, then gone: the conversation showed the person's message and the approved step, nothing else, until it was opened again. Found by the backend's stock AG-UI approval journey (stock-agui-langgraph-langchain), in about two runs of seven after #2567.

Why

Read from the page's own log in that journey (instrumented, looped on four runners):

  1. The opening join ran twice. The app is drawn under StrictMode (main.tsx), so in development React runs the effect twice on mount, and since Keep each conversation's agent, so going back replays only what is new #2567 the conversation's agent is kept and ready at once (useKeptAgent), so both runs joined the thread. Anything else that runs the join again (the agent changing, OpenBot answering again) does the same.
  2. The gate every read of the store waits on (joinedPromise) was one per mount, opened by whichever join ended first. The first join, given up for the second, ended at once and opened it.
  3. The sidebar's list then arrived, its line for this conversation the Bot's answer, and its read merged the whole stored history onto the agent, before the second join had replayed anything.
  4. The second join's replay rebuilt the agent from the thread's first run (the person's message and the step waiting for approval) and was cut at its 1.5 s deadline before the second run, which held the answer.
  5. The opening's own read after that join was skipped as no longer current: the list's read had taken the newer read version. Nothing read the store again.

The fix

One gate per join. Each join the opening effect makes gets its own gate, and every read that waits for the join (pull, the rejoin of a run started elsewhere, following a turn the server carries) waits for the newest one to settle (joinSettled). A read can no longer land before the join that is replaying the thread, so the store's copy goes on after the replay, as it was meant to.

Tests

  • app/tests/reload-keeps-answer.test.tsx: the real provider, ChannelChat, its history reader and the AG-UI reducer, under StrictMode, through a stand-in for the gateway's realtime protocol, with a thread shaped like the journey's (a run stopped for approval, then the run after Allow once). Fails on main (the page ends on "Place seed order · Fernhill Seed Shop" with no answer, as in the journey), passes with the fix: red 3 of 3, green 5 of 5.
  • app/tests/reload-keeps-answer-browser.test.tsx: the same, opened and reloaded in a real browser, Chromium and WebKit (added to CI's real-browser list). Fails on main in both, passes with the fix in both.
  • The conversation tests around it pass (channel-join-replay, kept-agents, kept-transcripts, approval-answered-*, approval-carry-on-running).

The looped journey with the fix, and #2567 put back on top of its revert (#2606), follow before this leaves draft.

…it answered

The opening join can run more than once: in development React runs it twice on mount (StrictMode), and a kept agent is ready at once, so both runs join the thread. The gate every read of the store waits on was one per mount, opened by whichever join ended first. The first join, given up for the second, ended at once, so the sidebar list's read merged the stored history onto the agent before the second join replayed anything. That replay rebuilt the agent from the thread's first run and was cut at its deadline before the run that held the answer, and the opening's own read had been taken over by the list's, so nothing read the store again: the answer showed for half a second, then was gone.

Each join now has a gate of its own, and every read waits for the newest join to settle (joinSettled). reload-keeps-answer.test.tsx (under StrictMode, real provider and gateway protocol) and reload-keeps-answer-browser.test.tsx (Chromium and WebKit) fail before and pass after.
@davidmckayv

Copy link
Copy Markdown
Contributor Author

Superseded by #2916, which re-lands #2567 (reverted in #2606) with this fix on top. #2567 was wanted; it was reverted only for this bug, and main without it doesn't have the bug (this PR's test passes on main). With #2567 back and without this fix, the reload test fails 12 of 12; with it, it passes 20 of 20, and the browser version passes in Chromium and WebKit.

@davidmckayv davidmckayv closed this Dec 4, 2026
@davidmckayv
davidmckayv deleted the fix/reload-keeps-answer branch December 4, 2026 02:17
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