You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
webfetch text output includes inert HTML template contents #64068
webfetch with format: "text" includes the contents of inert HTML <template> elements. The same response in Markdown correctly omits them. Template boilerplate therefore becomes part of the text returned to the model.
Text currently returns BeforeHiddenNestedAlso hiddenAfter; expected BeforeAfter.
Markdown already returns Before\n\nAfter.
Reproduced through the registered tool in packages/core/test/tool-webfetch.test.ts, with the HTTP test layer returning the HTML above. The new regression fails on dev.
Ordinary template content is not rendered. The text extractor's omitted-element list lacks template; the Markdown converter already includes it. I have a small fix and regression test ready.
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the precise report. I reproduced this on 2.2.7, and it still happens on the latest dev (d432a06) run from source.
I ran the real opencode run against a local mock model that calls webfetch twice, once with format: "text" and once with format: "markdown", on a local page serving your HTML. The tool results sent back to the model were:
text: BeforeHiddenNestedAlso hiddenAfter
markdown: Before\n\nAfter
Only the model was mocked; the webfetch tool and its HTTP fetch were real. The script below reproduces it.
Reproduction script (repro.sh)
#!/usr/bin/env bash# Reproduces #64068: webfetch format "text" keeps <template> contents, "markdown" drops them.# Runs the real `opencode run` against a mock OpenAI-compatible model that calls webfetch twice# (text + markdown) on a local HTML page, then prints the tool results OpenCode sent back.# Usage: ./repro.sh (opencode from PATH)# OC_DEV=/path/to/opencode ./repro.sh (run from a source checkout)set -euo pipefail
WORK=$(mktemp -d);cd"$WORK"
cat > mock.ts <<'TS'const HTML = `<p>Before</p><template id="card"><div>Hidden<template>Nested</template><span>Also hidden</span></div></template><p>After</p>`const sse = (chunks: unknown[]) => new Response(chunks.map((c) => `data: ${JSON.stringify(c)}\n\n`).join("") + "data: [DONE]\n\n", { headers: { "content-type": "text/event-stream" } })const base = { id: "c1", object: "chat.completion.chunk", created: 0, model: "mock" }const s = Bun.serve({ port: 4555, hostname: "127.0.0.1", async fetch(req) { const u = new URL(req.url) if (u.pathname === "/page") return new Response(HTML, { headers: { "content-type": "text/html; charset=utf-8" } }) if (!u.pathname.endsWith("/chat/completions")) return new Response("{}", { status: 404 }) const body: any = await req.json() const tools = body.messages.filter((m: any) => m.role === "tool") if (tools.length === 0) { if (!body.tools?.length) return sse([{ ...base, choices: [{ index: 0, delta: { role: "assistant", content: "title" }, finish_reason: "stop" }] }]) const url = "http://127.0.0.1:4555/page" const call = (i: number, id: string, format: string) => ({ index: i, id, type: "function", function: { name: "webfetch", arguments: JSON.stringify({ url, format }) } }) return sse([{ ...base, choices: [{ index: 0, delta: { role: "assistant", tool_calls: [call(0, "call_text", "text"), call(1, "call_md", "markdown")] }, finish_reason: null }] }, { ...base, choices: [{ index: 0, delta: {}, finish_reason: "tool_calls" }] }]) } for (const t of tools) console.log(`TOOL RESULT ${t.tool_call_id}: ${JSON.stringify(t.content)}`) return sse([{ ...base, choices: [{ index: 0, delta: { role: "assistant", content: "done" }, finish_reason: "stop" }] }])} })TS
mkdir -p .opencode
cat > .opencode/opencode.jsonc <<'JSON'{ "permission": { "webfetch": "allow" }, "providers": { "mock": { "name": "Mock", "env": ["MOCK_API_KEY"], "package": "@opencode/ai/providers/openai-compatible", "settings": { "baseURL": "http://127.0.0.1:4555/v1" }, "models": { "m": { "name": "M" } } } } }JSON
bun mock.ts > mock.log 2>&1& MOCK=$!;trap'kill $MOCK' EXIT; sleep 1
export MOCK_API_KEY=x
if [ -n"${OC_DEV:-}" ];then# the spawned server process reads bunfig.toml from the cwd; give it the Solid JSX preloadecho"preload = [\"$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js\"]"> bunfig.toml
OC=(bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js""$OC_DEV/packages/cli/src/index.ts")
else OC=(opencode);fi"${OC[@]}" --version
timeout 120 "${OC[@]}" run -m mock/m "fetch the page"||true
grep "TOOL RESULT" mock.log
Activity
opencodejr commentedon Nov 15, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the precise report. I reproduced this on 2.2.7, and it still happens on the latest
dev(d432a06) run from source.I ran the real
opencode runagainst a local mock model that callswebfetchtwice, once withformat: "text"and once withformat: "markdown", on a local page serving your HTML. The tool results sent back to the model were:BeforeHiddenNestedAlso hiddenAfterBefore\n\nAfterOnly the model was mocked; the
webfetchtool and its HTTP fetch were real. The script below reproduces it.Reproduction script (repro.sh)
Run it:
bash repro.sh