fix(routes): preserve same remote handoffs
- commit
- 08343ae96c593d8dd6005399d3f1c090e46e326f
- author
- brice · · 2026-08-11 08:37 UTC
- parent
- 11bc196
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +37 -0
M internal/usecase/client/routes.go +4 -0
| @@ -549,6 +549,10 @@ func (l *routeLedger) samePeerHandoff(active AttachRequest, target ports.AttachT | |||
| 549 | 549 | } | |
| 550 | 550 | request := cloneAttachRequest(entry.request) | |
| 551 | 551 | request.Intent = target.Intent | |
| 552 | + | // The active dialer already reaches this daemon. Retaining the route's | |
| 553 | + | // original discovery target would make its Hello request a second, | |
| 554 | + | // incorrect remote handoff instead of a same-peer session switch. | |
| 555 | + | request.RemoteTarget = nil | |
| 552 | 556 | request.EnvironmentPolicy = target.EnvironmentPolicy | |
| 553 | 557 | request.ExactTarget = target.ExactTarget | |
| 554 | 558 | if target.ExactTarget == nil { | |
| @@ -549,6 +549,10 @@ func (l *routeLedger) samePeerHandoff(active AttachRequest, target ports.AttachT | |||||
| 549 | } | 549 | } | ||
| 550 | request := cloneAttachRequest(entry.request) | 550 | request := cloneAttachRequest(entry.request) | ||
| 551 | request.Intent = target.Intent | 551 | request.Intent = target.Intent | ||
| 552 | + | // The active dialer already reaches this daemon. Retaining the route's | |||
| 553 | + | // original discovery target would make its Hello request a second, | |||
| 554 | + | // incorrect remote handoff instead of a same-peer session switch. | |||
| 555 | + | request.RemoteTarget = nil | |||
| 552 | request.EnvironmentPolicy = target.EnvironmentPolicy | 556 | request.EnvironmentPolicy = target.EnvironmentPolicy | ||
| 553 | request.ExactTarget = target.ExactTarget | 557 | request.ExactTarget = target.ExactTarget | ||
| 554 | if target.ExactTarget == nil { | 558 | if target.ExactTarget == nil { | ||
M internal/usecase/client/routes_test.go +33 -0
| @@ -148,6 +148,39 @@ func TestRouteLedgerSamePeerHandoffRestoresRouteTab(t *testing.T) { | |||
| 148 | 148 | } | |
| 149 | 149 | } | |
| 150 | 150 | ||
| 151 | + | func TestRouteLedgerSamePeerHandoffDropsOriginalRemoteTarget(t *testing.T) { | |
| 152 | + | ledger := newRouteLedger() | |
| 153 | + | work := routeTestCandidate(1, ports.RouteOriginRemote) | |
| 154 | + | work.originKey = "remote" | |
| 155 | + | work.request.Remote = true | |
| 156 | + | work.request.OriginKey = "remote" | |
| 157 | + | work.request.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |
| 158 | + | work.request.RemoteTarget = &domain.RemoteSessionTarget{ | |
| 159 | + | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: work.target.LifecycleID, | |
| 160 | + | SessionName: work.target.SessionName, LiveTabID: "tab-work", | |
| 161 | + | } | |
| 162 | + | _, err := ledger.commit(work) | |
| 163 | + | require.NoError(t, err) | |
| 164 | + | ||
| 165 | + | agents := routeTestCandidate(2, ports.RouteOriginRemote) | |
| 166 | + | agents.originKey = "remote" | |
| 167 | + | agents.request.Remote = true | |
| 168 | + | agents.request.OriginKey = "remote" | |
| 169 | + | agents.request.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |
| 170 | + | ||
| 171 | + | request := ledger.samePeerHandoff(agents.request, ports.AttachTarget{ | |
| 172 | + | Session: work.target.SessionName, | |
| 173 | + | Intent: ports.IntentAttach, | |
| 174 | + | ExactTarget: &work.target, | |
| 175 | + | EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 176 | + | }) | |
| 177 | + | ||
| 178 | + | require.True(t, request.Remote) | |
| 179 | + | require.Equal(t, ports.RouteOriginRemote, request.Origin) | |
| 180 | + | require.Equal(t, "remote", request.OriginKey) | |
| 181 | + | require.Nil(t, request.RemoteTarget) | |
| 182 | + | } | |
| 183 | + | ||
| 151 | 184 | func TestRouteAttentionSubscriptionIncludesOnlyActiveOriginRoutes(t *testing.T) { | |
| 152 | 185 | ledger := newRouteLedger() | |
| 153 | 186 | first := routeTestCandidate(0, ports.RouteOriginRemote) | |
| @@ -148,6 +148,39 @@ func TestRouteLedgerSamePeerHandoffRestoresRouteTab(t *testing.T) { | |||||
| 148 | } | 148 | } | ||
| 149 | } | 149 | } | ||
| 150 | 150 | ||||
| 151 | + | func TestRouteLedgerSamePeerHandoffDropsOriginalRemoteTarget(t *testing.T) { | |||
| 152 | + | ledger := newRouteLedger() | |||
| 153 | + | work := routeTestCandidate(1, ports.RouteOriginRemote) | |||
| 154 | + | work.originKey = "remote" | |||
| 155 | + | work.request.Remote = true | |||
| 156 | + | work.request.OriginKey = "remote" | |||
| 157 | + | work.request.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |||
| 158 | + | work.request.RemoteTarget = &domain.RemoteSessionTarget{ | |||
| 159 | + | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: work.target.LifecycleID, | |||
| 160 | + | SessionName: work.target.SessionName, LiveTabID: "tab-work", | |||
| 161 | + | } | |||
| 162 | + | _, err := ledger.commit(work) | |||
| 163 | + | require.NoError(t, err) | |||
| 164 | + | ||||
| 165 | + | agents := routeTestCandidate(2, ports.RouteOriginRemote) | |||
| 166 | + | agents.originKey = "remote" | |||
| 167 | + | agents.request.Remote = true | |||
| 168 | + | agents.request.OriginKey = "remote" | |||
| 169 | + | agents.request.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |||
| 170 | + | ||||
| 171 | + | request := ledger.samePeerHandoff(agents.request, ports.AttachTarget{ | |||
| 172 | + | Session: work.target.SessionName, | |||
| 173 | + | Intent: ports.IntentAttach, | |||
| 174 | + | ExactTarget: &work.target, | |||
| 175 | + | EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |||
| 176 | + | }) | |||
| 177 | + | ||||
| 178 | + | require.True(t, request.Remote) | |||
| 179 | + | require.Equal(t, ports.RouteOriginRemote, request.Origin) | |||
| 180 | + | require.Equal(t, "remote", request.OriginKey) | |||
| 181 | + | require.Nil(t, request.RemoteTarget) | |||
| 182 | + | } | |||
| 183 | + | ||||
| 151 | func TestRouteAttentionSubscriptionIncludesOnlyActiveOriginRoutes(t *testing.T) { | 184 | func TestRouteAttentionSubscriptionIncludesOnlyActiveOriginRoutes(t *testing.T) { | ||
| 152 | ledger := newRouteLedger() | 185 | ledger := newRouteLedger() | ||
| 153 | first := routeTestCandidate(0, ports.RouteOriginRemote) | 186 | first := routeTestCandidate(0, ports.RouteOriginRemote) | ||