can1357/oh-my-pi · error · ToolError

Missing required parameter 'code' for action 'run'.

Error message

Missing required parameter 'code' for action 'run'.

What it means

Action 'run' executes user-supplied JavaScript in the tab; params.code is mandatory. When code is missing, empty, or whitespace-only, this ToolError is thrown before any tab lookup. It is a required-parameter validation error.

Source

Thrown at packages/coding-agent/src/tools/browser.ts:388

		if (params.all) {
			const count = await untilAborted(signal, () => releaseAllTabs({ kill, timeoutMs }));
			details.result = `Released ${count} managed tab${count === 1 ? "" : "s"}`;
			return toolResult(details).text(details.result).done();
		}
		const closed = await untilAborted(signal, () => releaseTab(name, { kill, timeoutMs }));
		details.result = closed ? `Released managed tab ${JSON.stringify(name)}` : `No tab named ${JSON.stringify(name)}`;
		return toolResult(details).text(details.result).done();
	}

	async #run(
		name: string,
		params: BrowserParams,
		details: BrowserToolDetails,
		timeoutMs: number,
		signal?: AbortSignal,
	): Promise<AgentToolResult<BrowserToolDetails>> {
		if (!params.code?.trim()) {
			throw new ToolError("Missing required parameter 'code' for action 'run'.");
		}
		const tab = getTab(name);
		if (tab) {
			details.browser = tab.browser.kind.kind;
			details.url = tab.info.url;
		}

		const { displays, returnValue, screenshots } = await runInTab(name, {
			code: params.code,
			timeoutMs,
			signal,
			session: this.session,
		});

		if (screenshots.length) details.screenshots = screenshots;

		const content = [...displays];
		if (returnValue !== undefined) {

View on GitHub (pinned to 9690622007)

Solutions

  1. Provide a non-empty code string with the run action
  2. Check the caller/template that builds the params object to ensure code is included
  3. Validate params before sending (action==='run' requires trimmed-nonempty code)
  4. Use the correct action if you did not intend to execute code

Example fix

// before
await browser.run({ action: 'run' })
// after
await browser.run({ action: 'run', code: 'document.title' })
Defensive patterns

Strategy: validation

Validate before calling

if (params.action === 'run' && typeof params.code !== 'string') {
	throw new Error("action 'run' requires a non-empty 'code' string");
}

Type guard

function hasRunCode(p: { action: string; code?: string }): p is { action: 'run'; code: string } {
	return p.action !== 'run' || (typeof p.code === 'string' && p.code.trim().length > 0);
}

Try / catch

try {
	await browser.run({ action: 'run', code });
} catch (err) {
	if (err instanceof ToolError && /Missing required parameter 'code'/.test(err.message)) {
		// fix params generation, then retry with code supplied
	} else throw err;
}

Prevention

When it happens

Trigger: Calling browser run with action:'run' but no code field; code set to '' or only whitespace after a templating mistake; model-generated args omitting code while emitting other fields.

Common situations: Prompt/template bug dropping the code argument; copying an 'open'/'close' payload and switching action to 'run' without adding code; SDK wrapper not forwarding the code field.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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