Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,24 @@ describe('useAgentCrdtFollower', () => {
unmount()
})

it('FE-1969: naming the rebound workflow keeps its confirmed subscription', async () => {
const setup = mountFollower('wf-1')
dispatchFrame('doc_subscribed', { ok: true })
setup.unmount()
bridgeState.current = null
const { unmount, workflowId, status } = mountFollower(null)
dispatchFrame('doc_subscribed', { ok: true })

workflowId.value = 'wf-1'
await nextTick()

expect(status().connected).toBe(true)
expect(bridge().subscribe).toHaveBeenCalledOnce()
vi.advanceTimersByTime(SUBSCRIBE_CATCHUP_GRACE_MS)
expect(bridge().resubscribe).toHaveBeenCalledOnce()
unmount()
})

it('FE-1902: a real detach clears the persisted binding and unsubscribes', async () => {
const { unmount, workflowId } = mountFollower('wf-1')
dispatchFrame('doc_subscribed', { ok: true })
Expand Down
23 changes: 18 additions & 5 deletions src/workbench/extensions/agent/crdt/useAgentCrdtFollower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,21 @@ function startAgentCrdtFollower(
if (justActivated) applyCollected(persisted)
}

type TargetSnapshot = [string | null | undefined, boolean | undefined]
const isActivationEdge = (
active: boolean,
previous: TargetSnapshot | undefined
): boolean => active && previous?.[1] === false
const acknowledgesFollowedDoc = (
next: string | null,
active: boolean,
justActivated: boolean
): boolean =>
active &&
!justActivated &&
next !== null &&
next === subscribedWorkflowId.value

const activateTarget = (next: string, justActivated: boolean): void => {
initialBind = false
rebindProjection(next)
Expand All @@ -853,14 +868,12 @@ function startAgentCrdtFollower(

watch(
[workflowId, isTargetActive],
(
[next, active],
previous: [string | null | undefined, boolean | undefined] | undefined
) => {
([next, active], previous: TargetSnapshot | undefined) => {
// Only the inactive->active edge, and never the `immediate` first run
// (`previous` is undefined there): a plain mount or retarget has no
// collected changes to apply, the graph watcher covers readiness.
const justActivated = active && previous?.[1] === false
const justActivated = isActivationEdge(active, previous)
if (acknowledgesFollowedDoc(next, active, justActivated)) return
lifecycle.clearForRetarget()
connected.value = false
pendingLiveNodeIds.clear()
Expand Down
Loading