E2E web lane: VITE_BACKEND_URL is baked at build time, so a session on different ports silently calls a mock that is not listening
Summary
app/scripts/e2e-web-build.sh bakes the mock-backend and core ports into the web bundle at build time, while app/scripts/e2e-web-session.sh reads the same variables at session time. Set them for the session but not the build — the obvious thing to do, since the ports are a session concern — and you get a bundle that points at a different core than the one the session starts.
Nothing errors. The app loads, renders, and then behaves as though the product is broken.
Audited on main at 0f1ecc9d28d85289ee3f87ade13156be02ffbd28.
Where
app/scripts/e2e-web-build.sh:18,22:
export VITE_BACKEND_URL="http://127.0.0.1:${E2E_MOCK_PORT:-18473}"
export VITE_OPENHUMAN_CORE_RPC_URL="http://127.0.0.1:${OPENHUMAN_CORE_PORT:-17788}/rpc"
Those are VITE_*, so Vite inlines them into the bundle as literals. The values are fixed at build time and cannot be changed afterwards.
app/scripts/e2e-web-session.sh:12-14 reads the same two variables (plus E2E_WEB_PORT) to decide what to actually start:
E2E_MOCK_PORT="${E2E_MOCK_PORT:-18473}"
OPENHUMAN_CORE_PORT="${OPENHUMAN_CORE_PORT:-17788}"
E2E_WEB_PORT="${E2E_WEB_PORT:-4173}"
Same defaults on both sides, which is exactly why the coupling is invisible until someone overrides them.
Reproduce
pnpm --filter openhuman-app test:e2e:web:buildwith no port variables set — bundle is built against17788/18473.E2E_MOCK_PORT=18573 OPENHUMAN_CORE_PORT=17888 E2E_WEB_PORT=4273 bash app/scripts/e2e-web-session.sh …— a core starts on17888, a mock on18573.- Load the app. The bundle calls
127.0.0.1:17788/rpc, which this session never started.
If nothing is listening on 17788, every RPC fails and the UI renders empty surfaces. If another session is already running on the defaults, it is worse: the bundle connects to that session's core, reads its threads and writes into its workspace. Both sessions appear to work. Neither is testing what it thinks it is.
Why this matters more than a stale config
The failure presents as a product bug, not a configuration error. A surface that renders empty because its RPC went to the wrong core is indistinguishable, from the browser, from a surface that is genuinely broken — and this lane is the only app-level e2e lane, so it is where people go specifically to decide whether a change works. A wrong answer here is expensive.
It also compounds with the fixed defaults: the lane is not concurrency-safe, and overriding the ports is the natural mitigation for that. So the person most likely to hit this is the person doing the right thing about the other problem.
Suggested fix
Any of these would close it; the first is the smallest:
- Have
e2e-web-session.shverify the bundle it is about to serve was built for the ports it is about to use, and fail loudly if not.e2e-web-build.sh:30already echoesBuilding web E2E bundle with backend ${VITE_BACKEND_URL}— writing that value to a file besidedist-webwould make the check trivial. - Or resolve the core RPC URL at runtime rather than baking it, e.g. from the served origin or a small runtime config fetched at boot, so the bundle is port-agnostic.
- Or make the two scripts share one source of truth for the ports so they cannot diverge.
Acceptance
- [ ] Building on default ports and serving on custom ones fails with a clear message instead of silently pointing at the wrong core
- [ ] Or the bundle no longer encodes the core port at all
- [ ] A note in the lane's docs that the port variables must be set for both build and session
Notes for anyone running this lane
Two adjacent things found at the same time, both worth knowing:
- Verify teardown by process tree, not by port. Freeing the three ports is necessary but not sufficient — a session can leave a detached
bashat ppid 1 and a playwright tree beneath it that hold no listeners at all, solsofreports clean while they keep running.ps -eo pid=,command= | grep -F <worktree-path>returning nothing is the real check. - A fresh worktree needs
pnpm installbefore the session script will get pastwait_for_http .../__admin/health; the mock backend needs thewspackage.
Related
- #6476 —
setsid/teardown on macOS in the same two scripts; the port coupling here is independent of that fix but lands on the same person.
E2E web lane: build-time baked core/mock ports cause silent mismatch when session ports differ, leading to wrong core communication and false test results.
Labelled priority: p1.
Correction from the filer: half of this issue is wrong, and I am retitling it to the half that holds.
I filed this saying a session on custom ports "silently talks to the wrong core". That part is false. I inferred it after exporting ports before a build and never tested the consequence. Correcting it here rather than in a PR body, because an issue that overstates a defect is what someone acts on later without re-deriving it.
The core RPC URL is NOT affected
A runtime source already exists and already wins. app/src/services/coreRpcClient.ts:435-442, web path:
const storedUrl = peekStoredRpcUrl();
resolvedCoreRpcUrl = normalizeRpcUrl(storedUrl ?? CORE_RPC_URL);
localStorage beats the baked CORE_RPC_URL, and the Playwright helper seedBrowserCoreMode (app/test/playwright/helpers/core-rpc.ts) always seeds openhuman_core_rpc_url from PW_CORE_RPC_URL, which e2e-web-session.sh exports from the runtime OPENHUMAN_CORE_PORT. So for any Playwright run the baked core port is never consulted.
The repo says so plainly and I did not read it — gitbooks/developing/architecture/frontend.md:135 calls VITE_OPENHUMAN_CORE_RPC_URL a "build-time fallback for development".
Please do not re-open that half. "Ports are baked into the bundle" is true of both variables and misleading about one of them.
What is actually broken: VITE_BACKEND_URL
This one has no runtime override in web mode.
app/src/utils/config.ts:162—(import.meta.env.VITE_BACKEND_URL)?.trim() || DEFAULT_BACKEND_URLapp/src/services/backendUrl.ts:31-39—getBackendUrl()in web returnswebFallbackBackendUrl(): the baked value, thenwindow.location.origin, then a hardcoded default.
The window.location.origin fallback cannot rescue a mismatch: the origin is the web host port (E2E_WEB_PORT, e.g. 4273), not the mock backend's (E2E_MOCK_PORT, e.g. 18573). They are different services.
It is baked at app/scripts/e2e-web-build.sh:18:
export VITE_BACKEND_URL="http://127.0.0.1:${E2E_MOCK_PORT:-18473}"
while app/scripts/e2e-web-session.sh:12 independently resolves E2E_MOCK_PORT at session time. Set the ports for the session but not the build — the obvious thing to do, since ports are a session concern — and the two disagree with nothing to reconcile them.
Why it is worth fixing despite the narrower scope
The frontend's own API calls route through getBackendUrl() — app/src/services/apiClient.ts, services/session/sessionOwner.ts:78, services/mascotService.ts:35. So a mismatch sends those to a mock that is not listening.
The failure is partial, which is what makes it expensive. The core reads its own api_url from the config.toml that e2e-web-session.sh generates at runtime, so the core talks to the right mock. Chat-through-the-core keeps working while auth/session-dependent specs fail. A lane where some specs pass and some fail for an invisible configuration reason reads as a product bug, not a setup error.
Suggested fix (unchanged, and narrower than it sounds)
Have e2e-web-build.sh record the ports it baked into a marker beside dist-web, and have e2e-web-session.sh refuse to serve a bundle built for different ports. Silent wrong-backend becomes a loud startup failure, and it needs no application changes.
The alternative — making the app learn its backend URL at runtime, e.g. from a small config document fetched at boot — is real plumbing in application code to fix a test-lane configuration problem, and is deliberately not proposed here.
Acceptance
- [ ] Building on one set of ports and running a session on another fails loudly at startup, naming both
- [ ] Matching ports are unaffected
- [ ] No application code changes
Still true from the original report
pnpm installis required in a fresh worktree before the session script gets pastwait_for_http .../__admin/health— the mock backend needsws.- Verify teardown by process tree, not by port: a session can leave a detached
bashat ppid 1 and a playwright tree beneath it holding no listeners, solsofon the three ports reports clean while they keep running.ps -eo pid=,command= | grep -F <worktree-path>returning nothing is the real check.
Related
- #6470 / #6476 — a different defect in the same two scripts (
setsidon macOS). No overlap with this one, and neither supersedes the other.
This looks done. Re-checked on 6c8c7ad93f today, against the acceptance list in the correction above rather than the title.
Building on one set of ports and running a session on another fails loudly at startup, naming both. Built with E2E_PORT_BASE=19000, which recorded {"e2e_mock_port":"19000","openhuman_core_port":"19001","vite_backend_url":"http://127.0.0.1:19000"}, then ran the session with E2E_PORT_BASE=19100:
ERROR: dist-web was built for E2E_MOCK_PORT=19000 but this session uses 19100.
The backend URL is baked into the bundle and cannot be changed at run time,
so the app would call a mock that is not listening while the core called the right one.
Rebuild with the ports this session uses: E2E_MOCK_PORT=19100 pnpm --filter openhuman-app test:e2e:web:build
It fires before the mock, the core or the web host start, so nothing is left running. OPENHUMAN_CORE_PORT has its own message a few lines down.
Matching ports are unaffected. The same bundle with E2E_PORT_BASE=19000 clears the gate and proceeds.
No application code changed. The check is in e2e-web-session.sh (the .e2e-build-ports.json block); app/src/utils/config.ts and app/src/services/backendUrl.ts are untouched, and the runtime-config alternative you ruled out was not built.
That came from #6503, and #6719 later widened it from the two ports to the whole block (E2E_PORT_BASE), so a session on a derived block is covered too. scripts/__tests__/e2e-web-ports.test.mjs pins both halves by running the real scripts: a session on a different base than the build is refused and a session with a different core port than the build is refused.
Two notes before this is closed:
- The title still carries the retracted half — "so a session on different ports silently calls a mock that is not listening". The correction says it was being retitled, but it reads the same, so anyone skimming the list gets the overstated version. Worth fixing even on a closed issue.
- The two items under "Still true from the original report" are not addressed by this and are not about the defect: a fresh worktree still needs
pnpm installbefore the session gets past the mock health wait (hit this today), and teardown still has to be verified by process tree rather than by port. If either should outlive the issue, they probably want their own.
Not closing it myself since I am not the filer — flagging that the acceptance criteria are met.
Triage: patched — Fixed by PR #6503. Closing as completed.