{"record":{"id":"1cbf33bb4377570e","repo":"can1357/oh-my-pi","slug":"collab-replica-activation-was-cancelled","errorCode":null,"errorMessage":"Collab replica activation was cancelled","messagePattern":"Collab replica activation was cancelled","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/coding-agent/src/collab/guest.ts","lineNumber":444,"sourceCode":"\t\t\tthis.#armSnapshotProgressTimer();\n\t\t}\n\t\treturn complete;\n\t}\n\n\t/** Write the accumulated welcome snapshot to the replica file and (re)load it through the resume machinery. */\n\tasync #finalizeSnapshot(): Promise<void> {\n\t\tconst pending = this.#pendingSnapshot;\n\t\tthis.#pendingSnapshot = null;\n\t\tthis.#clearSnapshotProgressTimer();\n\t\tif (!pending || this.#left) return;\n\t\tconst replicaPath = path.join(getConfigRootDir(), \"collab\", `${this.#roomId}.jsonl`);\n\t\tconst lines = [pending.header, ...pending.entries].map(entry => JSON.stringify(entry)).join(\"\\n\");\n\t\tawait Bun.write(replicaPath, `${lines}\\n`);\n\n\t\t// Resume through AgentSession without adopting the host's cwd.\n\t\tconst switched = await this.#ctx.session.switchSession(replicaPath, { preserveLocalCwd: true });\n\t\tif (switched === false) {\n\t\t\tthrow new Error(\"Collab replica activation was cancelled\");\n\t\t}\n\t\tthis.#clearTransientUi();\n\t\tthis.#clearAgentMirror();\n\t\tthis.state = pending.state;\n\t\treconcileGuestSnapshotHostState(this.#ctx, pending.state.isStreaming);\n\t\tthis.#applyHostState(pending.state);\n\t\tthis.#ctx.resetObserverRegistry();\n\t\tthis.#applyAgentSnapshots(pending.agents);\n\t\tthis.#ctx.syncRunningSubagentBadge();\n\t\tthis.#assistantStreamSynced = false;\n\t\tsetSessionTerminalTitle(pending.state.sessionName ?? pending.header.title, pending.state.cwd);\n\t\tthis.#ctx.chatContainer.disposeChildren();\n\t\tawait this.#ctx.renderInitialMessages({ clearTerminalHistory: true });\n\t\tawait this.#ctx.reloadTodos();\n\t\tthis.#updateStatusSegment();\n\t\tthis.#readOnly = pending.readOnly;\n\t\tthis.#welcomed = true;\n\t\tconst suffix = this.#readOnly ? \" (read-only)\" : \"\";","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/collab/guest.ts#L426-L462","documentation":"After downloading the host's snapshot and writing it to a replica session file, the guest resumes it via ctx.session.switchSession(replicaPath, { preserveLocalCwd: true }). switchSession returned false, meaning the interactive session refused/aborted the switch (typically the user cancelled a confirmation prompt). The guest throws so the join is not half-applied: no snapshot state, UI, or agent mirror is adopted.","triggerScenarios":"A guest joining a room when the interactive session prompts to switch away from the current session and the user dismisses/cancels it; switchSession failing internally and reporting false (e.g. replica file rejected by the session loader).","commonSituations":"Guest already has an active session with unsaved context and cancels the 'switch session?' dialog during join; a corrupted replica file causes the session manager to bail; joining from a context (RPC mode, script) where interactive switching is not possible.","solutions":["Retry the join and accept the session-switch prompt when it appears.","Finish or abandon the current session first, then re-join the room so no confirmation is needed.","Inspect the replica session file written to the temp/replica path if the switch keeps failing despite accepting the prompt.","If embedding the guest non-interactively, provide a switchSession implementation that does not require user confirmation, or handle the cancelled case by keeping the local session."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await guest.join(link);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"cancelled\")) {\n    ui.info(\"Join aborted — the session switch was cancelled; current session unchanged.\");\n    return;\n  }\n  throw err;\n}","preventionTips":["Accept the session-switch confirmation prompt when joining.","Join from a quiet session state (not mid-stream) to minimize prompting.","Communicate to users that joining replaces the current session view."],"tags":["collaboration","user-cancelled","session-management"],"backgroundTag":"operation-cancelled","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}