Skip to content

[BUG]: Codespaces backend port 3001 not auto-forwarded #4778

@lohas1107

Description

@lohas1107

How are you running AnythingLLM?

Local development (GitHub Codespaces / Dev Container)

What happened?

When developing in GitHub Codespaces, the backend dev server on port 3001 is not reliably auto-forwarded / discoverable.

This is confusing because the devcontainer configuration already contains portsAttributes for 3001, but in practice the port may not get forwarded, which prevents the frontend from reaching the backend API using the expected Codespaces forwarded domain.

Expected

  • Starting the backend in Codespaces causes port 3001 to appear in the Ports view and be forwarded consistently.
  • The frontend can reach ...-3001.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/api without manual port forwarding.

Actual

  • Port 3001 sometimes does not auto-forward (or doesn’t show up as forwarded), requiring manual intervention.
  • gh codespace ports can remain empty until the port is manually forwarded, which also breaks any automation that waits on gh codespace ports | grep 3001.

Are there known steps to reproduce?

  1. Create a new Codespace for this repo.
  2. Start the backend (e.g. run the VS Code task “Server: run” or cd server && yarn dev).
  3. Check the Ports tab and/or run gh codespace ports -c $CODESPACE_NAME.

Observed: port 3001 is not always forwarded automatically.

Notes on likely root cause (IPv6 / localhost behavior)

There are two related behaviors that appear to contribute to how confusing this is:

  1. portsAttributes doesn’t force forwarding.

portsAttributes controls labels and what to do after a port is forwarded, but does not guarantee that forwarding will happen. In Codespaces, if the port is not auto-forwarded for any reason, it won’t show up as forwarded.

  1. VS Code Remote port forwarding has known IPv6 edge cases.

The VS Code Remote extensions have a long-standing issue where port forwarding can be unreliable when a service is bound to the IPv6 loopback address (::1) or when localhost resolves to IPv6 first. This is documented in microsoft/vscode-remote-release#7029.

Even when an application “works locally”, the tunnel may end up targeting an IPv6 loopback address which can break connectivity from the forwarded address.

Reference:

Proposed fix

Explicitly declare forwarded ports in the devcontainer configuration:

"forwardPorts": [3001, 3000]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions