Skip to content

fix(opencode): block unmatched /api/* paths from Web UI proxy - #374

Merged
Million-mo merged 1 commit into
wolf1069b:mainfrom
Million-mo:fix/opencode-block-api-proxy
Aug 17, 2026
Merged

fix(opencode): block unmatched /api/* paths from Web UI proxy#374
Million-mo merged 1 commit into
wolf1069b:mainfrom
Million-mo:fix/opencode-block-api-proxy

Conversation

@Million-mo

Copy link
Copy Markdown
Collaborator

Summary

The OpenCode TUI calls GET /api/fs/find when completing @-mentions. wolfharness has no route for it, so the request fell through to the Web UI proxy catch-all and was forwarded to https://app.opencode.ai/api/fs/find. The cloud responds 200 with text/html (the SPA index.html), which the SDK parses as a text string (Content-Type: text/html;charset=UTF-8parseAs: "text"). The TUI then receives result.data as a string and crashes on result.data.data.map(...):

TypeError: undefined is not an object (evaluating 'e.data.data.map')

Root cause

server.py's Web UI proxy catch-all blocks a fixed list of API path prefixes before forwarding to the cloud. The list was missing api/, so every unmatched /api/* route (including /api/fs/find) was proxied to the hosted Web UI and returned a text/html SPA page with 200.

Fix

  • Add "api/" to the proxy block prefixes
  • Extract the decision into is_proxy_path_blocked(path) (module-level constant PROXY_BLOCKED_PREFIXES)

After the fix, unmatched /api/* routes return 404 JSON. The SDK then produces { error, request, response }, and the TUI's if (!result.error && result.data) guard safely skips the crashing code path.

Verification

  • New unit tests: tests/servers/opencode_server/test_proxy_path_blocking.py (29 parametrized cases)
  • uv run ruff check passes
  • End-to-end repro confirmed before/after: previously result.data was a string; now it's a 404 { error } → TUI guard blocks the crash

The OpenCode TUI calls GET /api/fs/find when completing @-mentions.
wolfharness had no route for it, so the request fell through to the
Web UI proxy catch-all and was forwarded to app.opencode.ai. The cloud
responds 200 with text/html (the SPA index.html), which the SDK parses
as a text string (Content-Type text/html;charset=UTF-8 -> parseAs text),
so the TUI receives result.data as a string and crashes on
result.data.data.map(...).

Add 'api/' to the proxy block prefixes and extract the decision into
is_proxy_path_blocked() so unmatched /api/* routes now return 404 JSON.
The SDK then produces { error }, and the TUI's guard (!result.error)
safely skips the crashy code path.
@Million-mo
Million-mo merged commit db99b49 into wolf1069b:main Aug 17, 2026
12 of 13 checks passed
@Million-mo
Million-mo deleted the fix/opencode-block-api-proxy branch August 17, 2026 02:37
coderlihong pushed a commit to coderlihong/wolfharness that referenced this pull request Aug 18, 2026
…l-worker-tools

Integrate upstream wolf1069b#364/wolf1069b#356/wolf1069b#368/wolf1069b#372/wolf1069b#374/wolf1069b#375/wolf1069b#367 changes. Resolved:
- pyproject/uv.lock: openviking-sdk 0.1.8 (keep local; image download_bytes comment)
- mcp_server_cap.py: keep fork's self._tool_prefix logic
- viking/tools.py: combine imports (PurePosixPath + json/Path/shutil/tempfile)
- test_viking*.py: accept upload_tree (local wiki feature), 4→5 / 12→13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant