Skip to content

fix(dispatch): ignore late thread URL sync after leaving /chat - #9579

Open
an-fleet-bot[bot] wants to merge 2 commits into
mainfrom
job/j-20261120-1248-302
Open

an-fleet-bot[bot] wants to merge 2 commits into
mainfrom
job/j-20261120-1248-302

Conversation

@an-fleet-bot

@an-fleet-bot an-fleet-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

Repro

  1. Open Dispatch at /dispatch/chat (blank new thread) and submit "show my apps".
  2. When the navigate { view: "apps" } command fires before the new thread's initial snapshot save finishes, the router navigates from /dispatch/chat to /dispatch/apps, unmounting ChatRoute.
  3. Seconds later, when the in-flight snapshot save resolves, the browser bounces off /dispatch/apps back to /dispatch/chat/<threadId> (observed live on served SHA b571d5e7a5ceab8e756e1a2ca5222058f873f214: /dispatch/chat -> /dispatch/apps at 37.7s -> bounced back to /dispatch/chat/03e50e34-25fe-4dce-94c2-ad7793510a88 at 43.4s while the reply reported "I opened the Apps page").

Root cause

  • packages/toolkit/src/app/chat/AgentKitAssistantChat.tsx (finish inside saveSnapshot, around line 2518): checked !isUnmountingRef.current on every retry path, but omitted the unmount guard before invoking props.onThreadSnapshotPersisted?.(threadId, snapshot.messageCount). A save that resolves after unmount therefore fires onThreadSnapshotPersisted on an unmounted chat surface, triggering writeThreadUrl(threadId).
  • packages/dispatch/src/routes/pages/chat.tsx (navigateThreadUrl, around line 142): passed navigate(dispatchNavTarget(path), options) directly to threadUrlSync without checking whether ChatRoute is still mounted or whether the active route is still /chat. Any late or mid-transition threadUrlSync.navigate call clobbered the destination route (/apps) and navigated back to /chat/<threadId>.

Test that fails first

  • Added two regression tests in 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").
  • Added a regression test in 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]).
  • After fix:
    • pnpm --filter @agent-native/dispatch exec vitest run src/routes/pages/chat.spec.tsx src/hooks/use-navigation-state.spec.ts -> 28/28 PASS
    • pnpm --filter @agent-native/toolkit exec vitest run src/app/chat/AgentKitAssistantChat.spec.tsx src/app/chat/MultiTabAssistantChat.route-handoff.spec.tsx -> 383/383 PASS
    • pnpm --filter @agent-native/dispatch build & pnpm --filter @agent-native/toolkit build -> PASS
    • oxfmt --check, guard:new-prose-comments, guard:strict-lint, guard:no-new-escape-hatches, guard:chat-send-gate -> PASS

Live proof

  • Verified live on https://labs.agent-native.com/dispatch (QA account qa-fleet@builder.io, workspace bootstrap-db8d1b6d64e4ec90ceb335fc, served SHA b571d5e7a5ceab8e756e1a2ca5222058f873f214):
    • Reproduced the bounce race from /dispatch/chat -> "show my apps" -> /dispatch/apps -> /dispatch/chat/03e50e34-25fe-4dce-94c2-ad7793510a88.
    • Confirmed non-race ordering (/dispatch/chat -> /dispatch/chat/<id> -> /dispatch/apps, and /dispatch/chat/<id> with Design open -> "show my apps" -> /dispatch/apps) stays on /dispatch/apps with 0 reloads.
    • Post-merge live verification against the deployed Labs build will follow once this commit is pinned and published.

Ref: j-20261120-1248-302

Steve 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

No deployments
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.

0 participants