evals: codex harness across all code tool surfaces - #2609
Conversation
|
697f2c2 to
f60761e
Compare
There was a problem hiding this comment.
Review completed against the latest diff
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Architecture diagram
sequenceDiagram
participant CodexAgent as Codex Agent
participant CodexHarness as Eval Harness
participant ToolAdapter as Codex Tool Adapter
participant CodeBridge as Codex Code Bridge
participant Surface as Tool Surface
participant Trajectory as Trajectory Adapter
Note over CodexAgent,Trajectory: NEW: Codex Code Surface Flow (stagehand_code/playwright_code/cdp_code)
CodexHarness->>ToolAdapter: prepareCodexToolAdapter(surface, plan)
ToolAdapter->>ToolAdapter: Determine code surface variant
alt browse_cli
ToolAdapter->>ToolAdapter: Use existing browse CLI adapter
else code surface (stagehand_code, playwright_code, cdp_code)
ToolAdapter->>Surface: prepareLLMExposure(plan, environment)
Surface-->>ToolAdapter: exposure with code_handles
ToolAdapter->>CodeBridge: startCodeBridge(exposure, plan)
CodeBridge->>CodeBridge: Create HTTP server on random port
CodeBridge-->>ToolAdapter: bridge instance with port
ToolAdapter->>ToolAdapter: Create temp directory
ToolAdapter->>ToolAdapter: Write browser_run.mjs client script
ToolAdapter-->>CodexHarness: adapter with cwd, env, promptInstructions, cleanup
end
Note over CodexAgent,CodexHarness: Agent Tool Invocation
CodexHarness->>ToolAdapter: Get prompt instructions
ToolAdapter-->>CodexHarness: Rewritten instructions (run-tool → browser_run.mjs)
CodexAgent->>CodexAgent: Write snippet.js file
CodexAgent->>CodexAgent: Execute: node browser_run.mjs snippet.js
CodexAgent->>CodeBridge: POST /run with snippet code
CodeBridge->>CodeBridge: Execute snippet with handles, startUrl, task, console
alt Execution succeeds
CodeBridge-->>CodexAgent: HTTP 200 { ok: true, result: "..." }
else Execution fails
CodeBridge-->>CodexAgent: HTTP 200 { ok: false, error: "..." }
else Timeout (EVAL_CODEX_RUN_TOOL_TIMEOUT_MS)
CodeBridge-->>CodexAgent: HTTP 200 { ok: false, error: "timed out" }
end
Note over CodexHarness,Trajectory: Final Artifact Capture
CodexHarness->>ToolAdapter: captureFinalState()
ToolAdapter->>Surface: captureFinalState()
Surface-->>ToolAdapter: TerminalArtifact { screenshot, url }
ToolAdapter-->>CodexHarness: terminal state
CodexHarness->>Trajectory: gradeExternalTrajectory(with terminalArtifact)
Trajectory->>Trajectory: Build finalObservation from terminal state
Trajectory-->>CodexHarness: Graded trajectory
Note over CodexHarness,ToolAdapter: Cleanup
CodexHarness->>ToolAdapter: cleanup()
ToolAdapter->>CodeBridge: close bridge server
ToolAdapter->>Surface: cleanup exposure
ToolAdapter->>ToolAdapter: Remove temp directory
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
b66b040 to
1cfc2d8
Compare
6df6202 to
e63992a
Compare
e63992a to
7a9aa3e
Compare
7a9aa3e to
a710ed6
Compare
The agent-facing half of the stagehand_code code-mode surface: prepareLLMExposure initializes a v4 Stagehand client via initStagehand and declares a code_handles agent mount — stagehand/page/z in the snippet scope, surface-owned prompt instructions and run-tool copy, final-state evidence capture (screenshot + URL + aria tree), and cleanup that closes the browser as well as the client (stagehand.close() alone leaves the browser running). Nothing consumes the mount here; the claude_code adapter does in #2596 and codex in #2609. Bottom of the nondeterministic-evals stack (#2591 → #2611, with the merge-readiness fixes in #2649 and the MCP tool surfaces in #2650 stacked on top).⚠️ **Base housekeeping before merge**: this PR still targets `evals-v4-root`, which has since merged (via #2570 → #2494) into `v4-spike`. Rebase onto current `v4-spike` and retarget. One known reconciliation: v4-spike removed the `EVAL_VERIFIER_MODEL` override from `verifierAdapter` (2af557b) as redundant with V3Evaluator's own constructor options; this stack's later PRs still carry it — drop it during the rebase rather than reintroducing it. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds the `stagehand_code` code-mode tool and registers it in the core tool registry, wiring a v4 `@browserbasehq/stagehand` client with scoped handles, run-tool execution, artifact capture, and full teardown. Enables the v4 code-mode surface for STG-2671 with a fixed SDK model and local/Browserbase startup profiles. - New Features - New `StagehandCodeTool` (`id: stagehand_code`) with session, navigation, evaluation, screenshot, viewport, wait, click, hover, scroll, type, press, tabs, and representation. - Targets: `selector`, `coords`, `focused`. - Agent mount via handles: `stagehand`, `page`, and `z`; scoped prompt instructions; run-tool description, code param description, and deny message. Snippets also get `startUrl`, `task`, and `console` in scope. - Captures screenshot, URL, and ARIA tree; cleanup closes both the Stagehand client and the browser. - Profiles: `tool_launch_local` and `tool_create_browserbase`; connection mode derived; model fixed to `openai/gpt-4.1-mini`. - Registered in `listCoreTools`/`getCoreTool`; tests assert `stagehand_code` is retrievable and that prompt guidance includes awaited locator actions. <sup>Written for commit e579140. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/browserbase/stagehand/pull/2591?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Summary
Codex joins claude_code as an external harness across all three code tool surfaces (
stagehand_code,playwright_code,cdp_code) — recreating #2397 on the LLMExposure architecture.codex-sdk has no in-process MCP mounting (unlike claude-agent-sdk), and an external MCP process could not share this process's live surface handles. So the codex mount for a
code_handlesexposure is a loopback HTTP bridge: this process executes snippets against the in-memory handles; the codex workspace gets a tinybrowser_run.mjsclient that posts a snippet file to the bridge and prints the result. Scope semantics are identical to the claude_code run tool.codexCodeBridge.ts(new): the bridge server + generated workspace clientcodexToolAdapter.ts: code-surface mounting (exposure selection, bridge lifecycle, tmpdir cwd, prompt rewrite from run-tool tobrowser_run.mjsinvocation)codexRunner.ts/harnesses/codexAdapter.ts: harness-observed terminal artifact anchors the verifier's final observation, mirroring the claude_code runnerPart of the nondeterministic-evals stack; stacks on the exposure-adapter PR.
Follow-up on top of the stack: #2650 adds the MCP tool surfaces (playwright_mcp / chrome_devtools_mcp) to both external harnesses; MCP tool calls there count against the codex tool-step budget introduced in #2649.
Summary by cubic
Enable Codex on
stagehand_code,playwright_code, andcdp_codevia a loopback HTTP bridge that runs snippets against in-memory handles, with terminal artifact capture in the runner for grounded grading.browse_cliremains supported with sane startup defaults, and code surfaces now have clearbrowser_run.mjsguidance.New Features
codexCodeBridge.ts:browser_run.mjsposts snippet code to/run; executes withhandles,startUrl,task, andconsole; timeout viaEVAL_CODEX_RUN_TOOL_TIMEOUT_MS; non-zero exit on failure.codexToolAdapter.tsmountsbrowse_cli,stagehand_code,playwright_code,cdp_code; defaults to tool-owned browsers forbrowse_cli/stagehand_codeand runner-provided CDP forplaywright_code/cdp_code; writesbrowser_run.mjsand rewritesAGENT_RUN_TOOL_NAME; captures evidence viacaptureEvidenceand passes it tocodexAdapter.ts; robust cleanup.Bug Fixes
signingKey,sk-*) from snippet error messages before crossing the bridge or hitting logs.Written for commit a710ed6. Summary will update on new commits.