{"record":{"id":"2c3fcc2a4f459872","repo":"paperclipai/paperclip","slug":"interrupt-the-active-turn-before-deleting-the-remo","errorCode":null,"errorMessage":"interrupt the active turn before deleting the remote session","messagePattern":"interrupt the active turn before deleting the remote session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/paperclip-runner/src/live/live-session.ts","lineNumber":2109,"sourceCode":"    return this.snapshot();\n  }\n\n  async deleteManagedRemoteSession(): Promise<CapabilityLiveSessionSnapshot> {\n    if (\n      (this.#config.provider !== \"claude_managed\" &&\n        this.#config.provider !== \"aws_agentcore\") ||\n      this.#transport === null\n    ) {\n      throw new Error(\n        \"remote session deletion requires a connected remote provider session\",\n      );\n    }\n    if (\n      this.#activeTurnId !== null ||\n      this.#turnWaiter !== null ||\n      this.#pendingTurnAdmission !== null\n    ) {\n      throw new Error(\n        \"interrupt the active turn before deleting the remote session\",\n      );\n    }\n    await this.#transport.request(\"session/destroy\", {});\n    this.#providerSessionId = null;\n    this.#authority.active = false;\n    this.#status = \"closed\";\n    this.#appendEvidence(\"cleanup\", null, {\n      reason: \"remote session explicitly deleted\",\n      remoteDeleted: true,\n      resumable: false,\n    });\n    await this.#persist();\n    return this.snapshot();\n  }\n\n  async resolveInteraction(input: CapabilityInteractionResolution): Promise<CapabilityLiveTurnResult> {\n    const interaction = pendingInteractions(this.#port).find(","sourceCodeStart":2091,"sourceCodeEnd":2127,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/paperclip-runner/src/live/live-session.ts#L2091-L2127","documentation":"deleteManagedRemoteSession refuses to destroy the remote session while a turn is still active (#activeTurnId !== null). The provider cannot safely delete an in-flight session, so the caller must interrupt the current turn first.","triggerScenarios":"Calling deleteManagedRemoteSession while a model turn is executing (e.g. user hits delete during a streaming response, or shutdown code fires mid-turn).","commonSituations":"Deleting a session from the UI while the agent is mid-answer; watchdog cleanup racing an active turn; forgetting to await turn completion before teardown.","solutions":["Interrupt/abort the active turn (e.g. session.interrupt()) and await it before deleting","Await turn completion before triggering deletion","Serialize operations so delete is only issued when the session is idle","Catch this error in UI code and prompt the user to stop the turn first"],"exampleFix":"// before\nawait session.deleteManagedRemoteSession(); // throws if a turn is active\n// after\nif (session.snapshot().activeTurnId !== null) {\n  await session.interrupt();\n}\nawait session.deleteManagedRemoteSession();","handlingStrategy":"validation","validationCode":"if (session.snapshot().activeTurnId !== null) await session.interrupt();","typeGuard":null,"tryCatchPattern":"try {\n  await session.deleteManagedRemoteSession();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('interrupt the active turn')) {\n    await session.interrupt();\n    await session.deleteManagedRemoteSession();\n  } else throw err;\n}","preventionTips":["Disable delete UI while a turn is streaming","Always check active turn state before teardown","Await turn completion in shutdown paths before deleting remote sessions"],"tags":["live-session","deletion","turn-state"],"backgroundTag":"session-delete-while-turn-active","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}