Skip to content

fix: strip leading slash from the remote session wstunnel path prefix - #1257

Merged
SalimKayal merged 1 commit into
mainfrom
salimkayal/fix/trim-leading-slash-on-remote-sessions
Nov 11, 2026
Merged

SalimKayal merged 1 commit into
mainfrom
salimkayal/fix/trim-leading-slash-on-remote-sessions

Conversation

@SalimKayal

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1256: the remote-session wstunnel path prefix kept the leading slash from
RENKU_BASE_URL_PATH, so the HPC client requested //sessions/<id>/__amalthea__/tunnel/events.
nginx tolerates that; a proxy that matches paths literally (agentgateway/Envoy) does not, and
remote sessions 404. This trims both edges of the base path when building -P.

Change

  • internal/remote/firecrest/controller.go — WSTUNNEL_PATH_PREFIX is built by a new
    wstunnelPathPrefix() helper that trims / from both ends of renkuBaseURLPath
    (env["WSTUNNEL_PATH_PREFIX"] = wstunnelPathPrefix(renkuBaseURLPath)).
  • internal/remote/firecrest/controller_test.go — TestWstunnelPathPrefix covers leading slash,
    no leading slash, trailing slash and doubled leading slash; all must yield
    sessions/<id>/__amalthea__/tunnel.

No change in internal/remote/runai: it forwards RENKU_BASE_URL_PATH into the workspace spec and
has no tunnel yet. The remote scratch session path goes through path.Join, which is already
slash-tolerant.

Verification

  • go test ./internal/remote/firecrest/ -run 'TestWstunnelPathPrefix|TestRenderSessionScript|TestStreamsToFetch|TestBranchRegExp'
  • go build ./..., go vet ./internal/remote/firecrest/
  • Not exercised end-to-end against a FirecREST HPC; with the patch the emitted -P is
    sessions/<id>/__amalthea__/tunnel, i.e. the request path becomes
    /sessions/<id>/__amalthea__/tunnel/events — exactly the path amalthea's own Ingress exposes.
    Deployments behind nginx accept both forms, so this is not a behaviour change for them.

@SalimKayal
SalimKayal requested review from a team and olevski as code owners November 10, 2026 15:49
@SalimKayal
SalimKayal requested a review from leafty November 10, 2026 15:50
@SalimKayal SalimKayal added the bug Something isn't working label Nov 11, 2026
@SalimKayal
SalimKayal force-pushed the salimkayal/fix/trim-leading-slash-on-remote-sessions branch from bb994a8 to b94e8e5 Compare November 11, 2026 11:13
sgaist
sgaist previously approved these changes Nov 11, 2026
Comment thread internal/remote/firecrest/controller.go Outdated
// wstunnelPathPrefix returns the -P value for the remote wstunnel client. wstunnel prepends a "/" to
// it when building the upgrade request, so the prefix must not carry one itself.
func wstunnelPathPrefix(renkuBaseURLPath string) string {
return strings.Trim(renkuBaseURLPath, "/") + "/" + v1alpha1.TunnelIngressPathSuffix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use the path library here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

witched to path.Join + TrimPrefix: path.Join builds/cleans the URL path but keeps a leading slash, so the trim has to stay.

WSTUNNEL_PATH_PREFIX was built as RENKU_BASE_URL_PATH + "/__amalthea__/tunnel",
and RENKU_BASE_URL_PATH is "/sessions/<id>", so the prefix kept its leading
slash. wstunnel's client prepends another one when building the upgrade request
(format!("/{}/events")), so the HPC side actually asks for
"//sessions/<id>/__amalthea__/tunnel/events".

That works behind ingress-nginx only because nginx merges repeated slashes when
matching locations and still forwards the raw URI. Behind a proxy that matches
paths literally (agentgateway/Envoy among others) the request matches no session
route, falls through to the UI and returns 404, leaving the remote session
frontend unreachable: "failed to do websocket handshake with the server ...
Invalid status code: 404".

Trim both edges of the base path in a small helper so the emitted -P never
starts (or ends) with a slash, and cover it with a test. The remote scratch path
is unaffected: it goes through path.Join.

Reported against renku/amalthea-sessions 0.31.0 (3ac6997) deployed behind
agentgateway; the same code on a nginx-based deployment emits the same doubled
path and is only masked by nginx.
@SalimKayal
SalimKayal force-pushed the salimkayal/fix/trim-leading-slash-on-remote-sessions branch from b94e8e5 to 7a85f51 Compare November 11, 2026 14:45
@SalimKayal
SalimKayal merged commit 2bbe890 into main Nov 11, 2026
12 checks passed
@SalimKayal
SalimKayal deleted the salimkayal/fix/trim-leading-slash-on-remote-sessions branch November 11, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote sessions: the wstunnel upgrade path gets a doubled leading slash, breaking any proxy that does not merge slashes

3 participants