Skip to content

fix(opencode): strip transfer-encoding in UI proxy and allow public manifest assets#25698

Merged
kitlangton merged 2 commits intoanomalyco:devfrom
OpeOginni:fix/serve-ui-proxy-chunked-and-manifest-auth
May 4, 2026
Merged

fix(opencode): strip transfer-encoding in UI proxy and allow public manifest assets#25698
kitlangton merged 2 commits intoanomalyco:devfrom
OpeOginni:fix/serve-ui-proxy-chunked-and-manifest-auth

Conversation

@OpeOginni
Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #25697

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  • Fixes net::ERR_INVALID_CHUNKED_ENCODING 200 (OK) when loading / through opencode serve's UI proxy.
  • Fixes 401 Unauthorized on /site.webmanifest and PWA icons when OPENCODE_SERVER_PASSWORD is set.
  • Fixes terminal websocket startup when the app uses an auth_token-style flow by scoping PTY connect tokens to the same directory the websocket uses.

How did you verify your code works?

  • Reproduced and verified both serve UI issues:

    • / previously failed with ERR_INVALID_CHUNKED_ENCODING; now loads cleanly.
    • /site.webmanifest returned 401 with a server password set; now returns 200.
  • Manually verified PTY terminal startup: token mint and websocket connect now consistently succeed because directory matches across both requests.

  • Ran focused server tests:

    • bun test test/server/httpapi-ui.test.ts
    • bun test test/server/httpapi-authorization.test.ts
    • bun test test/server/httpapi-listen.test.ts
  • Manually verified production proxy and local preview proxy through opencode serve.

Screenshots / recordings

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Hey! Your PR title fix(httpapi/desktop): strip transfer-encoding in UI proxy and allow public manifest assets doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@OpeOginni OpeOginni changed the title fix(httpapi/desktop): strip transfer-encoding in UI proxy and allow public manifest assets fix(opencode/desktop): strip transfer-encoding in UI proxy and allow public manifest assets May 4, 2026
@OpeOginni OpeOginni changed the title fix(opencode/desktop): strip transfer-encoding in UI proxy and allow public manifest assets fix(opencode): strip transfer-encoding in UI proxy and allow public manifest assets May 4, 2026
@OpeOginni
Copy link
Copy Markdown
Contributor Author

OpeOginni commented May 4, 2026

How to reproduce / test locally

  1. Build the app:
bun --cwd packages/app build
  1. Serve the built static output on a fixed port
bun --cwd packages/app serve -- --host 127.0.0.1 --port 4173
  1. Temporarily point the serve UI proxy at the local build instead of desktop.opencode.ai:
    • Edit packages/opencode/src/server/shared/ui.ts.
    • Change:
export const UI_UPSTREAM = new URL("https://app.opencode.ai")

to:

export const UI_UPSTREAM = new URL("http://127.0.0.1:4173")
  1. Run opencode serve, optionally with a server password to reproduce the manifest 401:
    OPENCODE_SERVER_PASSWORD=test bun --cwd packages/opencode run dev serve --port 4099

  2. Open the served URL in a browser:
    http://127.0.0.1:4099/

Issues

  • / fails with net::ERR_INVALID_CHUNKED_ENCODING 200 (OK).
  • GET /site.webmanifest returns 401 Unauthorized when a password is set, and the browser logs manifest fetch failures.
  • Opening the integrated terminal: PTY websocket frequently stalls or errors because the minted ticket scope does not match the websocket directory query.

PR Fixes

  • / loads cleanly through the UI proxy.
  • /site.webmanifest and PWA icon fetches return 200 without app credentials.
  • The integrated terminal connects and produces output immediately because connectToken and the PTY websocket share the same directory scope.

…nked-and-manifest-auth

# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
#
# Conflicts:
#	packages/app/src/components/terminal.tsx
@kitlangton kitlangton merged commit 1251a87 into anomalyco:dev May 4, 2026
8 checks passed
kitlangton added a commit that referenced this pull request May 4, 2026
Adds three regression tests that lock in the contracts behind Ope's
cleanup PR #25698:

1. httpapi-ui.test.ts: 'strips upstream transfer-encoding header from
   proxied assets' — fails on dev today (transfer-encoding leaks through
   the UI proxy and triggers ERR_INVALID_CHUNKED_ENCODING in browsers).

2. httpapi-ui.test.ts: 'serves the PWA manifest without auth even when a
   server password is set' — fails on dev today (auth middleware rejects
   /site.webmanifest and the web-app-manifest icons with 401, breaking
   PWA install).

3. httpapi-listen.test.ts: 'PTY connect token requires matching directory
   across mint and connect' — passes on dev (the server already enforces
   strict directory scope match), but documents the contract Ope's app fix
   relies on. Without a directory query, the server resolves the PTY in
   its own cwd and returns 404 — the symptom the app hit when calling
   client.pty.connectToken({ ptyID }) without directory.

On dev: 2 fail, 1 passes (3rd is contract-only).
With #25698 applied: 3 pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode serve UI proxy for HTTPAPI: invalid chunked encoding on / and 401 on site.webmanifest when password is set

2 participants