Repository navigation
fix(dispatch): ignore late thread URL sync after leaving /chat - #9579
Open
an-fleet-bot[bot] wants to merge 2 commits into
Open
an-fleet-bot[bot] wants to merge 2 commits into
an-fleet-bot[bot] wants to merge 2 commits into
Conversation
added 2 commits
November 20, 2026 13:39
Prevent an in-flight chat snapshot save or stale threadUrlSync callback
from bouncing the router back to /chat/<threadId> after the user or
agent has already navigated away from /chat (such as navigate {view:
"apps"} moving to /apps).
Ref: j-20261120-1248-302
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repro
/dispatch/chat(blank new thread) and submit"show my apps".navigate { view: "apps" }command fires before the new thread's initial snapshot save finishes, the router navigates from/dispatch/chatto/dispatch/apps, unmountingChatRoute./dispatch/appsback to/dispatch/chat/<threadId>(observed live on served SHAb571d5e7a5ceab8e756e1a2ca5222058f873f214:/dispatch/chat->/dispatch/appsat 37.7s -> bounced back to/dispatch/chat/03e50e34-25fe-4dce-94c2-ad7793510a88at 43.4s while the reply reported "I opened the Apps page").Root cause
packages/toolkit/src/app/chat/AgentKitAssistantChat.tsx(finishinsidesaveSnapshot, around line 2518): checked!isUnmountingRef.currenton every retry path, but omitted the unmount guard before invokingprops.onThreadSnapshotPersisted?.(threadId, snapshot.messageCount). A save that resolves after unmount therefore firesonThreadSnapshotPersistedon an unmounted chat surface, triggeringwriteThreadUrl(threadId).packages/dispatch/src/routes/pages/chat.tsx(navigateThreadUrl, around line 142): passednavigate(dispatchNavTarget(path), options)directly tothreadUrlSyncwithout checking whetherChatRouteis still mounted or whether the active route is still/chat. Any late or mid-transitionthreadUrlSync.navigatecall clobbered the destination route (/apps) and navigated back to/chat/<threadId>.Test that fails first
packages/dispatch/src/routes/pages/chat.spec.tsx:ignores stale threadUrlSync navigations after leaving /chat for /apps(RED before fix:Expected "/apps", Received "/chat/thread-late").ignores threadUrlSync navigations when window.location already left /chat(RED before fix:Expected "/chat", Received "/chat/thread-late").packages/toolkit/src/app/chat/AgentKitAssistantChat.spec.tsx:does not fire onThreadSnapshotPersisted when a snapshot save resolves after unmount(RED before fix: called 1 time with["thread-1", 1]).pnpm --filter @agent-native/dispatch exec vitest run src/routes/pages/chat.spec.tsx src/hooks/use-navigation-state.spec.ts-> 28/28 PASSpnpm --filter @agent-native/toolkit exec vitest run src/app/chat/AgentKitAssistantChat.spec.tsx src/app/chat/MultiTabAssistantChat.route-handoff.spec.tsx-> 383/383 PASSpnpm --filter @agent-native/dispatch build&pnpm --filter @agent-native/toolkit build-> PASSoxfmt --check,guard:new-prose-comments,guard:strict-lint,guard:no-new-escape-hatches,guard:chat-send-gate-> PASSLive proof
https://labs.agent-native.com/dispatch(QA accountqa-fleet@builder.io, workspacebootstrap-db8d1b6d64e4ec90ceb335fc, served SHAb571d5e7a5ceab8e756e1a2ca5222058f873f214):/dispatch/chat->"show my apps"->/dispatch/apps->/dispatch/chat/03e50e34-25fe-4dce-94c2-ad7793510a88./dispatch/chat->/dispatch/chat/<id>->/dispatch/apps, and/dispatch/chat/<id>with Design open ->"show my apps"->/dispatch/apps) stays on/dispatch/appswith 0 reloads.Ref: j-20261120-1248-302