can1357/oh-my-pi · error · ToolError

Computer session is closed

Error message

Computer session is closed

What it means

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.

Source

Thrown at packages/coding-agent/src/tools/computer.ts:135

	get parameters(): ComputerSchema {
		return getComputerSchema();
	}

	get description(): string {
		this.#description ??= prompt.render(computerDescription);
		return this.#description;
	}

	async execute(
		_toolCallId: string,
		params: ComputerToolInput,
		signal?: AbortSignal,
		_onUpdate?: AgentToolUpdateCallback<ComputerToolDetails>,
		_context?: AgentToolContext,
	): Promise<AgentToolResult<ComputerToolDetails>> {
		throwIfAborted(signal);
		if (this.#closed) throw new ToolError("Computer session is closed");

		const timeoutSeconds = clampTimeout("computer", params.timeout, this.session.settings.get("tools.maxTimeout"));
		const coordinateSafe = usesCoordinateSafeImageSizing(this.session.getActiveModel?.());
		const configuredMaxWidth = this.session.settings.get("computer.maxWidth");
		const configuredMaxHeight = this.session.settings.get("computer.maxHeight");
		const snapshot: ComputerSessionSnapshot = {
			cwd: this.session.cwd,
			sessionId: this.session.getEvalSessionId?.() ?? this.session.getSessionId?.() ?? "computer",
			captureMaxWidth: coordinateSafe
				? Math.min(configuredMaxWidth, COORDINATE_SAFE_MAX_CAPTURE_WIDTH)
				: configuredMaxWidth,
			captureMaxHeight: coordinateSafe
				? Math.min(configuredMaxHeight, COORDINATE_SAFE_MAX_CAPTURE_HEIGHT)
				: configuredMaxHeight,
			display: this.session.settings.get("computer.display") ?? "all",
			readOnly: !!params.read_only,
		};
		const run = await this.#controller.run(params.code, timeoutSeconds * 1000, snapshot, signal);

View on GitHub (pinned to 9690622007)

Solutions

  1. Re-open/start a new computer session and use the fresh tool instance instead of the closed one.
  2. Check session lifecycle: don't invoke the computer tool after close() or after the owning agent session has ended.
  3. Restructure the workflow so all computer actions happen within a single live session.
  4. If this happens unexpectedly, verify nothing in your code path calls close() early (error handlers, finally blocks).

Example fix

// before
await computerTool.execute(params, signal); // tool already closed
// after
if (!computerTool.isClosed()) {
  await computerTool.execute(params, signal);
} else {
  computerTool = await openComputerSession(...);
  await computerTool.execute(params, signal);
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await computerTool.execute(params, signal);
} catch (err) {
  if (err instanceof ToolError && err.message === 'Computer session is closed') {
    // recreate the session/tool and retry once
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/a63e4e128e80db19. Report an issue: GitHub.