Skip to content

[AI-assisted] docs(browser): teach the code-mode global call, not the removed tools.call API - #128456

Merged
steipete merged 3 commits into
openclaw:mainfrom
santhiprakash:fix/browser-skill-code-mode-loop
Aug 25, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
santhiprakash:fix/browser-skill-code-mode-loop

Conversation

@santhiprakash

@santhiprakash santhiprakash commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The browser-automation skill's Code Mode Loop still taught the guest to call the Browser tool via tools.call("openclaw:browser:browser", input) and read the .result.details / .result.content envelope. That API was removed by #126262 (merged 2026-08-20, "improve(code-mode): call tools as global functions"); an agent following the skill verbatim in code mode fails on the first cell.

The first revision of this fix still had two dead ends, caught in review: it told readers to take a "normal snapshot turn" to read the page (no such turn exists while code mode is active — the Browser tool is cataloged behind exec/wait and the bridge strips snapshot content), and it hard-coded the callable name browser (the catalog can suffix colliding globals and lets a client tool win an identical name, so the run's quick index is the only authority).

Root cause

The skill predates #126262. Code mode now exposes enabled tools as async global functions (src/agents/code-mode.ts: "Enabled tools are async global functions listed in the quick index"), and the bridge returns the tool's structured details directly — src/agents/code-mode-bridge.ts callValue:

value =
  isRecord(called.result) && "details" in called.result
    ? called.result.details
    : called.result;

So result.content (rendered page text) never reaches a code cell; only details does. Callable names are run-scoped: createCodeModeCatalogProjection (src/agents/code-mode-catalog.ts) suffixes colliding/reserved names (suffixedCallableName) and selectEffectiveEntries lets a client tool win an exact-name collision, which is why the exec quick index (and catalog.search fallback) is the documented way to resolve a callable.

Fix

Rewrite the loop for the current contract:

  • call the Browser tool through the async global the exec quick index advertises (normally browser), falling back to catalog.search("browser") when the index omits or renames it,
  • read the structured details (targetId, url, newElements, stats, blockedByDialog — all present in safeDetails from extensions/browser/src/browser-tool.snapshot.ts),
  • diff url / newElements between cells instead of filtering snapshot text,
  • read page text inside code mode via a targeted act evaluate ({ action: "act", kind: "evaluate", fn, targetId }; the fn's value comes back in details.result, and browser.evaluateEnabled can disable it), keeping the returned value bounded — or stay on structured state only when evaluate is unavailable.

Docs only; no code paths touched.

Evidence

Real Code Mode + Browser execution transcript (after-fix, head 4ef2e571)

Ran on this branch with a harness that boots the real gateway with the real browser plugin (headless Chromium), resolves the real gateway-scoped tool surface, applies the real code-mode catalog compaction (applyCodeModeCatalog, force-enabled like an engaged code-mode turn), and drives the real exec tool with the three cells the revised skill teaches. The page is a loopback-only fixture (http://127.0.0.1:<port>/) — nothing to redact: no external URLs, keys, or credentials are involved. Transcript ends with PROOF-TRANSCRIPT-END; each cell's exec result came back status: "completed" with real catalog telemetry (callCount 0 → 2 → 3 across cells).

Cell 1 — callable discovery (quick-index global + catalog.search fallback):

const found = await catalog.search("browser");
const entry = found.find((candidate) => candidate?.toolName === "browser");
return {
  matches: found.map((candidate) => candidate?.toolName ?? candidate?.name),
  callable: typeof entry,
  globalName: typeof browser === "function" ? "browser" : undefined,
};
{
  "status": "completed",
  "value": { "matches": ["browser"], "callable": "function", "globalName": "browser" },
  "telemetry": { "catalogSize": 31, "searchCount": 1, "callCount": 0, "visibleTools": ["exec", "wait"] }
}

Cell 2 — open + structured snapshot loop (reading details, not snapshot text):

let previous = { url: undefined, newElements: undefined };
const opened = await browser({ action: "open", url: "http://127.0.0.1:<port>/" });
const details = await browser({
  action: "snapshot",
  snapshotFormat: "ai",
  targetId: opened?.suggestedTargetId ?? opened?.targetId ?? "task",
  refs: "aria",
  interactive: true,
});
const changed =
  details?.url !== previous.url ||
  (details?.newElements ?? 0) > 0 ||
  details?.blockedByDialog === true;
previous = { url: details?.url, newElements: details?.newElements };
return {
  targetId: details?.targetId,
  url: details?.url,
  newElements: details?.newElements,
  stats: details?.stats,
  changed,
};
{
  "status": "completed",
  "value": {
    "targetId": "8EBD0393F324C2788760085803C7C99E",
    "url": "http://127.0.0.1:<port>/",
    "stats": { "lines": 2, "chars": 82, "refs": 2, "interactive": 2 },
    "changed": true
  },
  "telemetry": { "callCount": 2, "visibleTools": ["exec", "wait"] }
}

Cell 3 — bounded evaluate read (act/kind: "evaluate", value in result):

const read = await browser({
  action: "act",
  kind: "evaluate",
  fn: "() => document.body.innerText.slice(0, 2000)",
  targetId: "8EBD0393F324C2788760085803C7C99E",
});
return { url: read?.url, text: read?.result };
{
  "status": "completed",
  "value": {
    "url": "http://127.0.0.1:<port>/",
    "text": "Browser skill code-mode proof\n\nPROOF-PAGE-READY\n\nQuery  Submit"
  },
  "telemetry": { "callCount": 3, "visibleTools": ["exec", "wait"] }
}

This shows exactly what the fix teaches: the Browser callable resolves as the run-scoped browser global (and via catalog.search("browser")), the snapshot loop consumes structured details (targetId, url, stats — rendered page text never reaches the cell), and page text is read through a targeted bounded evaluate whose value returns in details.result.

After-fix verification on this branch (node 22.23.2, fresh pnpm install):

  • Real guest runtime, node --import tsx scripts/test-projects.mts -- src/agents/code-mode.guest.test.ts — 21/21 passed, including "exposes catalog tools as bare globals and removes the legacy guest surface", "keeps normalized, reserved, and colliding prompt names aligned with runtime", "uses the client tool as the single winner for a shadowed exact name", and "returns structured values from globals and callable catalog handles" (globals return structured details to code cells; callable names come from the runtime projection).
  • Real act formatter (formatBrowserExternalToolResult, extensions/browser/src/browser-tool.actions.ts) with an evaluate act payload { ok: true, targetId: "task", url: "https://example.com/after-submit", result: "Submitted\nConfirmation #42" } returns details = { ok, targetId, url, result } — the evaluate value reaches code cells via details.result — while content[0].text is wrapped as EXTERNAL_UNTRUSTED_CONTENT and never returned to code cells.
  • On current main, git grep "tools.call" extensions/browser matches only this skill's stale example — every other reference in docs is a different surface (mcp.tools.call.v1 node command, the Tool Search openclaw.tools.call bridge, cron migration history).
  • Each taught field was checked against main source: global name resolution (code-mode-catalog.ts), details shape (browser-tool.snapshot.ts safeDetails), act response contract ({ ok, targetId, url?, result? } from client-actions-core.ts / routes/agent.act.ts), evaluate gating (browser.evaluateEnabled, browser-tool.schema.ts).
  • npx --yes [email protected] --check extensions/browser/skills/browser-automation/SKILL.md passes (repo-pinned version).

Risks

Low — docs-only change to a skill file. The evaluate example assumes the evaluate capability is enabled (default); the doc says to fall back to structured state when it is not.

….call API

The browser-automation skill's Code Mode Loop still taught the guest
`tools.call(browserTool, input)` API that openclaw#126262 removed, together with
the `.result.details`/`.result.content` envelope reads. Rewrite the loop
for the current contract: call the `browser(...)` async global directly,
receive the tool's structured details (targetId, url, newElements, stats,
blockedByDialog), and diff url/new-element counts between cells instead of
filtering snapshot text, since rendered page text is no longer
guest-visible in code mode.
@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added extensions: browser size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 24, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 25, 2026, 5:40 AM ET / 09:40 UTC.

ClawSweeper review

What this changes

Updates the Browser automation skill to use Code Mode’s callable catalog handles and structured Browser results instead of the removed tools.call API.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking findings. This remains a useful, contract-aligned documentation repair for Browser use in OpenClaw Code Mode; the supplied PR proof is stronger than required for a docs-only change.

Priority: P1
Reviewed head: a5f446d613f9a5880d867d6e5bb3a56715e98e94

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused documentation repair with source-backed contract alignment and unusually strong supplemental runtime evidence.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a docs-only PR; its supplied real Gateway and Browser-plugin terminal transcript is useful supplemental evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a docs-only PR; its supplied real Gateway and Browser-plugin terminal transcript is useful supplemental evidence.
Evidence reviewed 7 items Documented path matches Code Mode guidance: The updated skill resolves a Browser handle with catalog.search and calls it; Code Mode’s model-visible guidance states that enabled tools are async globals and that catalog-search results are callable.
Collision-safe callable resolution: The catalog selects the effective client-tool winner for same-name entries and suffixes reserved or colliding callable names, supporting the documentation’s instruction not to hard-code browser.
Structured Browser result contract: The bridge projects result.details to Code Mode callers, and Browser snapshots place targetId, url, newElements, stats, and dialog state in those details.
Findings None None.
Security None None.

How this fits together

Code Mode compacts enabled tools behind exec and exposes them as run-scoped JavaScript globals or callable catalog handles. The Browser extension returns structured state for those calls, while page-controlled text remains separately wrapped as untrusted content.

flowchart LR
  A[Browser automation skill] --> B[Code Mode exec cell]
  B --> C[Run-scoped catalog]
  C --> D[Resolved Browser handle]
  D --> E[Browser extension]
  E --> F[Structured details]
  F --> B
Loading

Before merge

  • Add real behavior proof - Not applicable: This is a docs-only PR; its supplied real Gateway and Browser-plugin terminal transcript is useful supplemental evidence.
  • Resolve merge risk (P1) - The local partial checkout could not compare the PR directly with the supplied current-main revision because required historical objects could not be fetched; GitHub context nevertheless reports a clean, mergeable PR.
Agent review details

Security

None.

PR surface

Docs +16. Total +16 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 38 22 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 38 22 +16

Review metrics

None.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/browser/skills/browser-automation/SKILL.md. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the handle-based Browser Code Mode guidance so agents follow the canonical catalog and structured-result contracts without reviving the removed API.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the handle-based Browser Code Mode guidance so agents follow the canonical catalog and structured-result contracts without reviving the removed API.

Do we have a high-confidence way to reproduce the issue?

Yes—source shows the current guest contract uses callable globals or catalog handles and directly projects structured details, while the supplied pre-change documentation used the removed legacy envelope.

Is this the best way to solve the issue?

Yes—the update follows the canonical Code Mode prompt contract and avoids hard-coding a callable name that catalog collision handling may change.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8e040714b305.

Labels

Label justifications:

  • P1: The stale instruction can make an agent’s Browser Code Mode workflow fail before it can inspect or act on a page.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a docs-only PR; its supplied real Gateway and Browser-plugin terminal transcript is useful supplemental evidence.

Evidence

What I checked:

  • Documented path matches Code Mode guidance: The updated skill resolves a Browser handle with catalog.search and calls it; Code Mode’s model-visible guidance states that enabled tools are async globals and that catalog-search results are callable. (extensions/browser/skills/browser-automation/SKILL.md:51, a5f446d613f9)
  • Collision-safe callable resolution: The catalog selects the effective client-tool winner for same-name entries and suffixes reserved or colliding callable names, supporting the documentation’s instruction not to hard-code browser. (src/agents/code-mode-catalog.ts:58, a5f446d613f9)
  • Structured Browser result contract: The bridge projects result.details to Code Mode callers, and Browser snapshots place targetId, url, newElements, stats, and dialog state in those details. (src/agents/code-mode-bridge.ts:438, a5f446d613f9)
  • Existing contract coverage: Current tests exercise catalog-search handles, bare globals, and their equivalent structured return values; the exec-schema test explicitly rejects legacy tools.call guidance. (src/agents/code-mode.guest.test.ts:360, a5f446d613f9)
  • API-change provenance: The linked merged Code Mode change records the hard cut to global callable tools and removal of legacy guest API guidance. (src/agents/code-mode.ts:181, 4249df34b42a)
  • Implementation boundary: The reviewed contract is implemented by OpenClaw’s own Code Mode and Browser-extension source; no patch import, protocol, or proof claim depends on the sibling OpenAI Codex runtime. (src/agents/code-mode.ts:181, a5f446d613f9)

Likely related people:

  • steipete: Authored the merged Code Mode API change that established catalog-search callable handles and removed the legacy guest surface. (role: introduced the current Code Mode callable contract; confidence: high; commits: 4249df34b42a; files: src/agents/code-mode.ts, src/agents/code-mode-catalog.ts, src/agents/code-mode-bridge.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-24T02:12:58.179Z sha 760c1f2 :: needs real behavior proof before merge. :: [P1] Use an available Code Mode text-reading path | [P2] Resolve the Browser callable from the quick index
  • reviewed 2026-08-24T02:29:01.585Z sha 760c1f2 :: needs real behavior proof before merge. :: [P1] Provide a reachable Code Mode text-reading path | [P2] Resolve the Browser callable from the quick index
  • reviewed 2026-08-24T02:53:29.136Z sha 4ef2e57 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T07:50:59.505Z sha 4ef2e57 :: needs changes before merge. :: [P1] Use the discovered Browser callable in the example | [P1] Do not promise previous survives completed cells
  • reviewed 2026-08-24T08:37:19.408Z sha a5f446d :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Aug 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Aug 24, 2026
@steipete

Copy link
Copy Markdown
Contributor

Independent landing verification for contributor head a5f446d613f9a5880d867d6e5bb3a56715e98e94:

  • Current main's model-facing browser skill references the removed tools.call API and an unavailable .result.details / .result.content envelope.
  • Exact contributor fix matches the actual Code Mode controller and guest runtime: collision-safe catalog.search("browser", { limit: 1 }) callable handles, direct structured browser details, isolated completed-cell state, and resumable waiting cells.
  • Page evaluation is bounded to 2,000 characters, treated as untrusted, and falls back to structured-only behavior when evaluation is disabled.
  • node scripts/run-vitest.mjs src/agents/code-mode.guest.test.ts src/agents/code-mode.bridge.test.ts src/agents/code-mode.skills.test.ts: 3 files / 47 tests passing. An independent sibling run passed 6 files / 94 tests.
  • Exact changed skill formatting and git diff --check: clean.
  • Fresh independent Codex autoreview: clean, zero actionable findings.
  • Skill-only change: zero production/runtime lines, no configuration, browser authority, storage, or security changes.
  • Refreshed exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32706466956.

@steipete
steipete merged commit 4f18aea into openclaw:main Aug 25, 2026
103 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
… removed tools.call API (openclaw#128456)

* docs(browser): teach the code-mode global call, not the removed tools.call API

The browser-automation skill's Code Mode Loop still taught the guest
`tools.call(browserTool, input)` API that openclaw#126262 removed, together with
the `.result.details`/`.result.content` envelope reads. Rewrite the loop
for the current contract: call the `browser(...)` async global directly,
receive the tool's structured details (targetId, url, newElements, stats,
blockedByDialog), and diff url/new-element counts between cells instead of
filtering snapshot text, since rendered page text is no longer
guest-visible in code mode.

* docs(browser): resolve callable from quick index and read via targeted evaluate

* docs(browser): call the search-resolved handle and carry cell state explicitly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: browser P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants