earendil-works/pi · error · Error

Cannot while session is

Error message

Cannot ${description} while session is ${this.phase ?? "unavailable"}

What it means

Guard in RemoteSession.#runIdleOperation: setModel/setThinking were requested while the session phase is not 'idle' (a turn or other operation is active); these settings may only change between turns.

Solutions

  1. Retry after the current turn completes
  2. Subscribe to phase notifications and apply settings when idle
  3. Abort the active turn first if the change is urgent
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/coding-agent/src/client/remote-session.ts:303 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/7edf5652c6479211. Report an issue: GitHub.

Appendix: source

Thrown at packages/coding-agent/src/client/remote-session.ts:303

				} catch (cleanupError) {
					throw new AggregateError([error, cleanupError], "Failed to replace remote session attachment");
				}
				throw error;
			}
		}
		await this.#assertNotDisposedAfterAwait(next);
		this.#bind(next, snapshot);
	}

	async #runIdleOperation(
		operation: "setModel" | "setThinking",
		description: string,
		run: () => Promise<void>,
	): Promise<void> {
		this.#assertAvailable();
		this.#requireHandle();
		if (this.phase !== "idle") {
			throw new Error(`Cannot ${description} while session is ${this.phase ?? "unavailable"}`);
		}
		await this.#runOperation(operation, run);
	}

	async #runOperation(operation: RemoteSessionOperation, run: () => Promise<void>, preempt = false): Promise<void> {
		if (preempt) this.#assertNotDisposed();
		else this.#assertAvailable();
		const previous = this.#lifecycle;
		const busy: RemoteSessionLifecycle = { status: "busy", operation };
		this.#lifecycle = busy;
		this.#activeOperationStates.add(busy);
		this.#notify();
		const running = run();
		try {
			await Promise.race([
				running,
				this.#disposeSignal.then(() => {
					throw new Error("Remote session is disposed");

View on GitHub (pinned to 4af9d21d3b)