Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(openai-codex): reject a promise passed as a nested tool's input

Jack Rudenko0e5548f888e9
diff --git a/packages/cli/src/code-mode/sandbox/script-runtime.ts b/packages/cli/src/code-mode/sandbox/script-runtime.ts
index 95702128..2cfa7e46 100644
--- a/packages/cli/src/code-mode/sandbox/script-runtime.ts
+++ b/packages/cli/src/code-mode/sandbox/script-runtime.ts
@@ -428,6 +428,13 @@ class QuickJSScriptRuntime implements ScriptRuntime, LeasedRuntime {
`claudish: tools.${ident} takes an object as its argument; this call was not run`
);
}
+ // `ctx.dump` renders a promise as `{type:"pending"}` / `{type:"fulfilled",
+ // value}`, an object, which would be relayed as the tool's input.
+ if (this.isPromise(argsH)) {
+ return this.rejected(
+ `claudish: tools.${ident} was given a promise; await it and pass the object. This call was not run`
+ );
+ }
const input = ctx.dump(argsH) as unknown;
if (!input || typeof input !== "object" || Array.isArray(input)) {
return this.rejected(
@@ -683,6 +690,19 @@ class QuickJSScriptRuntime implements ScriptRuntime, LeasedRuntime {
deferred.dispose();
}
+ /** True when `handle` is a QuickJS promise (any state); disposes the settled value it reads. */
+ private isPromise(handle: QuickJSHandle): boolean {
+ const state = this.requireCtx().getPromiseState(handle);
+ if (state.type === "fulfilled") {
+ // `notAPromise`: `value` IS `handle`, which the caller still owns.
+ if (state.notAPromise) return false;
+ state.value.dispose();
+ } else if (state.type === "rejected") {
+ state.error.dispose();
+ }
+ return true;
+ }
+
/** A promise handle already rejected with `message` (consumed by the library on return). */
private rejected(message: string): QuickJSHandle {
const ctx = this.requireCtx();