{"record":{"id":"a63e4e128e80db19","repo":"can1357/oh-my-pi","slug":"computer-session-is-closed-a63e4e","errorCode":null,"errorMessage":"Computer session is closed","messagePattern":"Computer session is closed","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/computer.ts","lineNumber":135,"sourceCode":"\n\tget parameters(): ComputerSchema {\n\t\treturn getComputerSchema();\n\t}\n\n\tget description(): string {\n\t\tthis.#description ??= prompt.render(computerDescription);\n\t\treturn this.#description;\n\t}\n\n\tasync execute(\n\t\t_toolCallId: string,\n\t\tparams: ComputerToolInput,\n\t\tsignal?: AbortSignal,\n\t\t_onUpdate?: AgentToolUpdateCallback<ComputerToolDetails>,\n\t\t_context?: AgentToolContext,\n\t): Promise<AgentToolResult<ComputerToolDetails>> {\n\t\tthrowIfAborted(signal);\n\t\tif (this.#closed) throw new ToolError(\"Computer session is closed\");\n\n\t\tconst timeoutSeconds = clampTimeout(\"computer\", params.timeout, this.session.settings.get(\"tools.maxTimeout\"));\n\t\tconst coordinateSafe = usesCoordinateSafeImageSizing(this.session.getActiveModel?.());\n\t\tconst configuredMaxWidth = this.session.settings.get(\"computer.maxWidth\");\n\t\tconst configuredMaxHeight = this.session.settings.get(\"computer.maxHeight\");\n\t\tconst snapshot: ComputerSessionSnapshot = {\n\t\t\tcwd: this.session.cwd,\n\t\t\tsessionId: this.session.getEvalSessionId?.() ?? this.session.getSessionId?.() ?? \"computer\",\n\t\t\tcaptureMaxWidth: coordinateSafe\n\t\t\t\t? Math.min(configuredMaxWidth, COORDINATE_SAFE_MAX_CAPTURE_WIDTH)\n\t\t\t\t: configuredMaxWidth,\n\t\t\tcaptureMaxHeight: coordinateSafe\n\t\t\t\t? Math.min(configuredMaxHeight, COORDINATE_SAFE_MAX_CAPTURE_HEIGHT)\n\t\t\t\t: configuredMaxHeight,\n\t\t\tdisplay: this.session.settings.get(\"computer.display\") ?? \"all\",\n\t\t\treadOnly: !!params.read_only,\n\t\t};\n\t\tconst run = await this.#controller.run(params.code, timeoutSeconds * 1000, snapshot, signal);","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/computer.ts#L117-L153","documentation":"Thrown at the start of the computer tool's execute() when the tool's underlying computer session has already been closed (the #closed flag is set). Once closed, the tool can no longer drive the desktop — screenshots, clicks, and window operations all fail fast with this error instead of hitting a dead native session.","triggerScenarios":"Invoking the computer tool after its session was shut down (explicit close, agent session teardown, or resource cleanup); reusing a stored tool/handle reference past the lifetime of its owning session.","commonSituations":"Long-running agent workflows that keep a computer-tool reference across session restarts; retry logic re-invoking the tool after the run finished and cleaned up; scripts holding the tool instance after an abort.","solutions":["Re-open/start a new computer session and use the fresh tool instance instead of the closed one.","Check session lifecycle: don't invoke the computer tool after close() or after the owning agent session has ended.","Restructure the workflow so all computer actions happen within a single live session.","If this happens unexpectedly, verify nothing in your code path calls close() early (error handlers, finally blocks)."],"exampleFix":"// before\nawait computerTool.execute(params, signal); // tool already closed\n// after\nif (!computerTool.isClosed()) {\n  await computerTool.execute(params, signal);\n} else {\n  computerTool = await openComputerSession(...);\n  await computerTool.execute(params, signal);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await computerTool.execute(params, signal);\n} catch (err) {\n  if (err instanceof ToolError && err.message === 'Computer session is closed') {\n    // recreate the session/tool and retry once\n  } else throw err;\n}","preventionTips":["Scope all computer actions to the lifetime of the owning session; close cleanly at the end.","Don't store computer tool references across session restarts or aborts.","Track session state explicitly and skip computer calls after shutdown.","Treat this error as 'restart required', not retryable in place."],"tags":["computer-tool","session-lifecycle","closed-resource"],"backgroundTag":"session-already-closed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}