fix(desktop): route a shared-id unpin to the row the pull adopted

With every slice feeding the pin sync, two profiles can legitimately hold
the same session id. The pull already tie-breaks toward the active gateway's
row (rowsByPinId), but the push resolved the profile by first match — so an
unpin PATCHed the other profile and the next page re-adopted the pin.
Resolve the write's row with the same active-gateway preference.

Case and test from #92609.

Co-authored-by: Jake Vincent <45184202+jakewvincent@users.noreply.github.com>
This commit is contained in:
Teknium
2026-09-02 04:10:39 -07:00
parent d417aee387
commit 7b951e46ab
2 changed files with 34 additions and 2 deletions
@@ -133,6 +133,25 @@ describe('watchSessionPins remote pull', () => {
expect(patch).toHaveBeenCalledWith('cron-pin', false, 'jobs')
})
it('routes a cross-slice unpin to the active profile', async () => {
$activeGatewayProfile.set('work')
try {
$sessions.set([row('shared', { pinned: true, profile: 'default' })])
$messagingSessions.set([row('shared', { pinned: true, profile: 'work', source: 'photon' })])
await flush()
expect($pinnedSessionIds.get()).toEqual(['shared'])
patch.mockClear()
$pinnedSessionIds.set([])
await flush()
expect(patch).toHaveBeenCalledWith('shared', false, 'work')
} finally {
$activeGatewayProfile.set('default')
}
})
it('adopts a pin another app made', async () => {
$sessions.set([row('remote', { pinned: true })])
await flush()
+15 -2
View File
@@ -77,13 +77,26 @@ function publishUnconfirmed(): void {
}
function profileFor(pinId: string): null | string | undefined {
return loadedSessionRows().find(row => sessionMatchesStoredId(row, pinId))?.profile
return loadedRowFor(pinId)?.profile
}
function loadedSessionRows(): SessionInfo[] {
return [...$sessions.get(), ...$cronSessions.get(), ...$messagingSessions.get()]
}
/**
* The row a stored pin id resolves to, across every slice. Same tie-break as
* `rowsByPinId`: when two profiles share the id, the write must target the
* row the pull adopted — the active gateway's — or an unpin PATCHes the other
* profile and the next page re-adopts the pin.
*/
function loadedRowFor(pinId: string): SessionInfo | undefined {
const rows = loadedSessionRows().filter(row => sessionMatchesStoredId(row, pinId))
const gateway = normalizeProfileKey($activeGatewayProfile.get())
return rows.find(row => normalizeProfileKey(row.profile) === gateway) ?? rows[0]
}
/**
* One authoritative row per durable pin id. Session ids are only unique inside
* a profile, so the cross-profile list can legitimately hold two rows with the
@@ -259,7 +272,7 @@ function reconcileInner(): void {
// Flush whatever we can resolve now; unresolved ids (row not loaded yet)
// retry on the next loaded-session slice change.
for (const id of [...pending]) {
const row = loadedSessionRows().find(entry => sessionMatchesStoredId(entry, id))
const row = loadedRowFor(id)
if (!row) {
continue