fix(session): fail when multiple persisted sessions lack sessionId - #407
fix(session): fail when multiple persisted sessions lack sessionId#407Mochxd wants to merge 3 commits into
Conversation
|
Could you give me more concrete example with appium-mcp logs? I assume your reported case is const candidates = sessionId
? persisted.filter((p) => p.sessionId === sessionId)
: persisted;Then, if the first candidate is valid, it will be returned. While not, the next one will be tried out (by end of the for (const entry of candidates) {
try {
const client = await attachToRemoteSession({
remoteServerUrl: entry.remoteServerUrl,
sessionId: entry.sessionId,
capabilities: entry.capabilities,
});
// attachToSession does not verify liveness on the remote server. Issue
// a cheap call to confirm the session is still valid before adopting it.
try {
await (client as Client).getTimeouts();
} catch (verifyErr) {
log.warn(
`Persisted session ${entry.sessionId} failed liveness check (${
(verifyErr as Error).message
}); pruning.`
);
await removePersistedSession(entry.sessionId);
continue;
}
const seedCaps: SessionCapabilities = { ...(entry.capabilities ?? {}) };
if (entry.platform) {
seedCaps.platformName = entry.platform;
}
if (entry.automationName) {
seedCaps['appium:automationName'] = entry.automationName;
}
if (entry.deviceName) {
seedCaps['appium:deviceName'] = entry.deviceName;
}
await setSession(
client,
entry.sessionId,
seedCaps,
entry.ownership,
entry.remoteServerUrl
);
log.info(
`Rehydrated attached session ${entry.sessionId} from persisted store.`
);
return { sessionId: entry.sessionId };
} catch (err) { |
|
@KazuCocoa the case I'm targeting is when multiple persisted sessions are still alive, not the prune-and-continue path. Example:
Logs (old behavior): |
|
I see. Actually that condition occurs. One missing case is that even if the persistent dir had multiple files, only one session is "alive". Then, this logic might not work expectedly. This lets me think the |
Summary
resolveDriver()no longer picks the first persisted session when several exist and nosessionIdis passedMultiple persisted sessions: id1, id2. Pass sessionId.(sorted ids)sessionIdunchanged