From e30451fbcb8bc5ff12104358a5ec61ef90293e33 Mon Sep 17 00:00:00 2001 From: Yasith Jayawardana Date: Wed, 11 Nov 2026 17:47:43 -0500 Subject: [PATCH 1/6] Proxy Linkspan through the link --- api/process/controller/link.go | 31 ++++++++++++++++++++----------- api/process/service/link.go | 25 +++++++++++++++++++------ dashboard/README.md | 2 +- docs/notebooks.md | 8 ++++---- internal/app/app.go | 2 +- internal/server/link_test.go | 13 ++++++++++--- 6 files changed, 55 insertions(+), 26 deletions(-) diff --git a/api/process/controller/link.go b/api/process/controller/link.go index b198f7e54c..b2c97080f3 100644 --- a/api/process/controller/link.go +++ b/api/process/controller/link.go @@ -54,7 +54,7 @@ func NewLinkController(svc *service.LinkService) *LinkController { svc: svc, proxy: &httputil.ReverseProxy{ Transport: svc.Registry().Transport(), - // The target was set on the request by jupyter; Rewrite only keeps the + // The target was set on the request by the linkspan handler; Rewrite only keeps the // client's forwarding headers out. Rewrite: func(out *httputil.ProxyRequest) { out.Out.URL.Scheme = "http" @@ -62,10 +62,10 @@ func NewLinkController(svc *service.LinkService) *LinkController { out.Out.Host = out.In.Host }, ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) { - slog.Warn("Jupyter proxy could not reach the process's server", "path", r.URL.Path, "error", err) + slog.Warn("Linkspan proxy could not reach the process's job", "path", r.URL.Path, "error", err) httpx.WriteJSON(w, http.StatusBadGateway, map[string]string{ "error": "Bad Gateway", - "message": "The process's Jupyter Server could not be reached: its job is not linked to Airavata, or its server has not started", + "message": "The process's Linkspan could not be reached: its job is not linked to Airavata, or the server has not started", }) }, }, @@ -76,7 +76,7 @@ func NewLinkController(svc *service.LinkService) *LinkController { func (h *LinkController) Register(mux *http.ServeMux) { mux.HandleFunc("GET /api/v1/processes/{processId}/link", h.link) mux.HandleFunc("GET /api/v1/processes/{processId}/jupyter-server", h.jupyterServer) - mux.HandleFunc("/api/v1/processes/{processId}/jupyter/", h.jupyter) + mux.HandleFunc("/api/v1/processes/{processId}/linkspan/", h.linkspan) } // link admits the WebSocket a process's Linkspan dials and holds it as the process's @@ -87,6 +87,9 @@ func (h *LinkController) link(w http.ResponseWriter, r *http.Request) { httpx.WriteError(w, r, httpx.Unauthorized("The link token is not the one issued to process %s", processID)) return } + if err := h.svc.Begun(r.Context(), processID); err != nil { + slog.Warn("Failed to record a linking process as running", "processId", processID, "error", err) + } conn, err := websocket.Accept(w, r, &websocket.AcceptOptions{Subprotocols: []string{link.Protocol}}) if err != nil { return @@ -112,30 +115,36 @@ func (h *LinkController) jupyterServer(w http.ResponseWriter, r *http.Request) { httpx.WriteJSON(w, http.StatusOK, resp) } -// jupyter proxies the Jupyter Server API, kernel WebSockets included, to the server -// the process's job runs, over its link. The token is left on the request: the -// Jupyter Server checks it again. -func (h *LinkController) jupyter(w http.ResponseWriter, r *http.Request) { +// linkspan proxies a request over the process's link: to Linkspan's API, or to the port +// itself for a path under forward/{port}/, as Linkspan's forward carries TCP only. +// The token stays on the request because the Jupyter Server checks it again. +func (h *LinkController) linkspan(w http.ResponseWriter, r *http.Request) { processID := r.PathValue("processId") token := r.URL.Query().Get("token") if scheme, value, found := strings.Cut(r.Header.Get("Authorization"), " "); found && strings.EqualFold(scheme, "token") { token = strings.TrimSpace(value) } - port, ok := h.svc.JupyterPort(r.Context(), processID, token) + port, ok := h.svc.ControlPort(r.Context(), processID, token) if !ok { httpx.WriteError(w, r, httpx.Unauthorized("The Jupyter token is not the one issued to process %s", processID)) return } - prefix := "/api/v1/processes/" + processID + "/jupyter" + prefix := "/api/v1/processes/" + processID + "/linkspan" out := r.Clone(r.Context()) out.URL.Path = strings.TrimPrefix(r.URL.Path, prefix) out.URL.RawPath = "" if out.URL.Path == "" { out.URL.Path = "/" } + // A bare forward/{port} has no slash to cut on and stays Linkspan's own TCP stream. + if rawPort, path, ok := strings.Cut(strings.TrimPrefix(out.URL.Path, "/api/v1/forward/"), "/"); ok { + if forwarded, err := strconv.ParseUint(rawPort, 10, 16); err == nil { + port, out.URL.Path = uint16(forwarded), "/"+path + } + } out.URL.Host = link.Host(processID, port) - // The Jupyter Server sees itself addressed on its own loopback port. + // The server sees itself addressed on its own loopback port. out.Host = "127.0.0.1:" + strconv.Itoa(int(port)) h.proxy.ServeHTTP(w, out) } diff --git a/api/process/service/link.go b/api/process/service/link.go index 2a3457b4aa..ff77b2b282 100644 --- a/api/process/service/link.go +++ b/api/process/service/link.go @@ -29,12 +29,14 @@ import ( "encoding/hex" "fmt" "net/url" + "strconv" "strings" "time" "github.com/apache/airavata/internal/auth" "github.com/apache/airavata/internal/httpx" "github.com/apache/airavata/internal/link" + "github.com/apache/airavata/internal/ptr" dto "github.com/apache/airavata/api/process/dto" model "github.com/apache/airavata/api/process/model" @@ -48,14 +50,25 @@ import ( type LinkService struct { links *repository.LinkRepository processes *repository.ProcessRepository + statuses *StatusService registry *link.Registry publicURL string } // NewLinkService returns a link service. publicURL is where jobs reach this server, // http(s)://host[:port]; the link URL is its ws(s) form. -func NewLinkService(links *repository.LinkRepository, processes *repository.ProcessRepository, registry *link.Registry, publicURL string) *LinkService { - return &LinkService{links: links, processes: processes, registry: registry, publicURL: strings.TrimRight(publicURL, "/")} +func NewLinkService(links *repository.LinkRepository, processes *repository.ProcessRepository, statuses *StatusService, registry *link.Registry, publicURL string) *LinkService { + return &LinkService{links: links, processes: processes, statuses: statuses, registry: registry, publicURL: strings.TrimRight(publicURL, "/")} +} + +// Begun records a SUBMITTED process as RUNNING, without waiting on Slurm's begin mail. +func (s *LinkService) Begun(ctx context.Context, processID string) error { + statuses, err := s.statuses.ListForProcess(ctx, processID) + if err != nil || len(statuses) == 0 || ptr.From(statuses[len(statuses)-1].Status) != model.ProcessStatusTypeSubmitted { + return err + } + _, err = s.statuses.Record(ctx, processID, model.ProcessStatusTypeRunning, nil) + return err } // Registry is the live links this service admits. @@ -140,14 +153,14 @@ func (s *LinkService) JupyterServer(ctx context.Context, processID string) (*dto return &dto.JupyterServerResponse{ ProcessID: processID, Linked: s.registry.Linked(processID), - BaseURL: "/api/v1/processes/" + url.PathEscape(processID) + "/jupyter/", + BaseURL: "/api/v1/processes/" + url.PathEscape(processID) + "/linkspan/api/v1/forward/" + strconv.Itoa(int(found.JupyterPort)) + "/", Token: found.JupyterToken, }, nil } -// JupyterPort returns the port of the process's Jupyter Server when token is its +// ControlPort returns the port of the process's Linkspan API when token is its // Jupyter token, and false otherwise. -func (s *LinkService) JupyterPort(ctx context.Context, processID, token string) (uint16, bool) { +func (s *LinkService) ControlPort(ctx context.Context, processID, token string) (uint16, bool) { if token == "" { return 0, false } @@ -155,7 +168,7 @@ func (s *LinkService) JupyterPort(ctx context.Context, processID, token string) if err != nil || subtle.ConstantTimeCompare([]byte(token), []byte(found.JupyterToken)) != 1 { return 0, false } - return uint16(found.JupyterPort), true + return uint16(found.ControlPort), true } func newSecret() (string, error) { diff --git a/dashboard/README.md b/dashboard/README.md index 34b3bcf3b6..b7f384e634 100644 --- a/dashboard/README.md +++ b/dashboard/README.md @@ -35,7 +35,7 @@ src/components/NotebookView.tsx, NotebookFiles.tsx the Notebooks page: a file browser and a @datalayer/jupyter-react notebook, either on an in-browser Pyodide kernel with files in the browser's IndexedDB, or on the Jupyter Server of a process's - Linkspan job, through the API's /processes/{id}/jupyter/ proxy + Linkspan job, through the API's /processes/{id}/linkspan/ proxy ``` The build uses webpack (`next build --webpack`), not Turbopack: the JupyterLab packages diff --git a/docs/notebooks.md b/docs/notebooks.md index 5f3d906ab2..d97efccfe6 100644 --- a/docs/notebooks.md +++ b/docs/notebooks.md @@ -6,7 +6,7 @@ The job reaches Airavata the way a [CyberShuttle](https://github.com/cyber-shutt ``` browser ──HTTPS──▶ Airavata ──link (WebSocket, yamux)──▶ Linkspan ──loopback──▶ Jupyter Server - /api/v1/processes/{id}/jupyter/ dialled from the job on the compute node + /api/v1/processes/{id}/linkspan/ dialled from the job on the compute node ``` ## What every batch job is given @@ -54,7 +54,7 @@ This needs Linkspan 0.22.0 or newer, the first release with the link transport, On the Notebooks page, **Run notebooks** lists the signed-in user's processes that are submitted or running. Choosing one waits for its Linkspan to link, then opens the job's Jupyter Server: the file browser shows the job's files, and notebooks run on a `python3` kernel on the compute node. The kernel is shut down when the page is left or another source is chosen. Choosing **In this browser** goes back to Pyodide and the notebooks kept in the browser. -If Airavata restarts, or the link drops, Linkspan redials on its own and the page picks the server up again. +If Airavata restarts, or the link drops, Linkspan redials on its own and the page picks the server up again. A `SUBMITTED` process is recorded `RUNNING` when its Linkspan dials, without waiting for Slurm's begin mail. ## API @@ -62,9 +62,9 @@ If Airavata restarts, or the link drops, Linkspan redials on its own and the pag |---|---|---| | `GET /api/v1/processes/{processId}/link` | The link token, as the WebSocket subprotocol `link.` | Linkspan's link. Airavata selects the subprotocol `cybershuttle.v1`. | | `GET /api/v1/processes/{processId}/jupyter-server` | Bearer token of the process owner | `{processId, linked, baseUrl, token}`: where to reach the Jupyter Server and its token | -| `/api/v1/processes/{processId}/jupyter/…` | The Jupyter token, as `Authorization: token ` or `?token=` | Proxy to the job's Jupyter Server, including kernel WebSockets. `502` while the job is not linked. | +| `/api/v1/processes/{processId}/linkspan/…` | The Jupyter token, as `Authorization: token ` or `?token=` | Proxy to [Linkspan's API](https://github.com/cyber-shuttle/linkspan#http-api) in the job, including WebSockets. Linkspan's `api/v1/forward/{port}` carries TCP only, so Airavata sends a request for `api/v1/forward/{port}/…` to that port itself, over the link: the `baseUrl` above reaches the Jupyter Server this way. `502` while the job is not linked. | -Only the owner of a process can read its Jupyter token, because the token runs code as the owner's cluster account. The proxy compares the token before forwarding, and the Jupyter Server checks it again. Airavata's bearer tokens are never sent to the job. Other users on a shared node can reach the job's loopback ports, but they still need the Jupyter token to use the server ([Linkspan's security model](https://github.com/cyber-shuttle/linkspan/blob/main/SECURITY.md#security-model)). +Only the owner of a process can read its Jupyter token, because the token runs code as the owner's cluster account. The proxy compares the token before forwarding. The Jupyter Server checks it again; Linkspan's own API does not. Airavata's bearer tokens are never sent to the job. Other users on a shared node can reach the job's loopback ports, but they still need the Jupyter token to use the Jupyter Server ([Linkspan's security model](https://github.com/cyber-shuttle/linkspan/blob/main/SECURITY.md#security-model)). The link protocol is Linkspan's, as frozen in its [compatibility document](https://github.com/cyber-shuttle/linkspan/blob/main/docs/COMPATIBILITY.md): yamux runs over binary WebSocket frames, with Airavata as the yamux client. For each stream Airavata writes the target port as two big-endian bytes, and Linkspan answers `1` and carries the stream if one of its own servers listens there, or answers `0`. diff --git a/internal/app/app.go b/internal/app/app.go index 01ea558207..218c864af7 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -243,7 +243,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos *Repositories, workflowBa virtualDataDirectorySharingSvc := datasvc.NewVirtualDataDirectorySharingService(db, virtualDirs, shares, groups, users, groupMembers) sshCredentialSvc := credentialssvc.NewSSHCredentialService(sshCredentials, users, clusterConfigs, storages) - linkSvc := processsvc.NewLinkService(repos.Links, processes, link.NewRegistry(), cfg.PublicURL) + linkSvc := processsvc.NewLinkService(repos.Links, processes, statusSvc, link.NewRegistry(), cfg.PublicURL) executionEngine := orchestration.NewExecutionEngine(stagingTasks, submissionTasks, monitoringTasks, products, storages, clusterConfigs, processes, deployments, templates, batchStatus, statuses, repos.TaskStatuses, processWorkflows, workflowBackend, sshContext, linkSvc) diff --git a/internal/server/link_test.go b/internal/server/link_test.go index 0dfcc50a49..ce00eb6b4b 100644 --- a/internal/server/link_test.go +++ b/internal/server/link_test.go @@ -140,7 +140,7 @@ func TestLinkCarriesTheJupyterServerToItsOwner(t *testing.T) { wsBase := "ws" + strings.TrimPrefix(api.URL, "http") linkURL := wsBase + "/api/v1/processes/" + processID + "/link" jupyter := fakeJupyter(t) - proxy := api.URL + "/api/v1/processes/" + processID + "/jupyter" + proxy := api.URL + "/api/v1/processes/" + processID + "/linkspan/api/v1/forward/" + itoa(jupyterPort) get := func(path, authorization string) (*http.Response, map[string]string) { req, _ := http.NewRequest(http.MethodGet, proxy+path, nil) @@ -157,6 +157,10 @@ func TestLinkCarriesTheJupyterServerToItsOwner(t *testing.T) { return resp, body } + if _, err := h.svcs.ProcessStatus.Record(ctx, processID, "SUBMITTED", nil); err != nil { + t.Fatal(err) + } + // Before Linkspan links, the proxy has nowhere to go. if resp, _ := get("/api/status", "token "+issued.JupyterToken); resp.StatusCode != http.StatusBadGateway { t.Errorf("unlinked proxy: status = %d, want 502", resp.StatusCode) @@ -184,9 +188,12 @@ func TestLinkCarriesTheJupyterServerToItsOwner(t *testing.T) { time.Sleep(20 * time.Millisecond) } if access["linked"] != true || access["token"] != issued.JupyterToken || - access["baseUrl"] != "/api/v1/processes/"+processID+"/jupyter/" { + access["baseUrl"] != "/api/v1/processes/"+processID+"/linkspan/api/v1/forward/"+itoa(jupyterPort)+"/" { t.Fatalf("jupyter-server = %v", access) } + if statuses := h.list("/api/v1/processes/"+processID+"/statuses", tokenAlice); statuses[len(statuses)-1]["status"] != "RUNNING" { + t.Errorf("statuses after link = %v, want the submitted process recorded RUNNING", statuses) + } // The proxy wants the Jupyter token, not a bearer token. if resp, _ := get("/api/status", ""); resp.StatusCode != http.StatusUnauthorized { @@ -205,7 +212,7 @@ func TestLinkCarriesTheJupyterServerToItsOwner(t *testing.T) { } // Kernel channels are WebSockets with the token in the query. - wsURL := wsBase + "/api/v1/processes/" + processID + "/jupyter/api/kernels/k1/channels?token=" + issued.JupyterToken + wsURL := "ws" + strings.TrimPrefix(proxy, "http") + "/api/kernels/k1/channels?token=" + issued.JupyterToken kernel, wsResp, err := websocket.Dial(ctx, wsURL, nil) if wsResp != nil && wsResp.Body != nil { wsResp.Body.Close() From f90540730307824acd41542b93f012cc088ddb57 Mon Sep 17 00:00:00 2001 From: Yasith Jayawardana Date: Thu, 12 Nov 2026 23:53:48 -0500 Subject: [PATCH 2/6] Tighten the Linkspan proxy row --- docs/notebooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/notebooks.md b/docs/notebooks.md index d97efccfe6..48d69af26e 100644 --- a/docs/notebooks.md +++ b/docs/notebooks.md @@ -62,7 +62,7 @@ If Airavata restarts, or the link drops, Linkspan redials on its own and the pag |---|---|---| | `GET /api/v1/processes/{processId}/link` | The link token, as the WebSocket subprotocol `link.` | Linkspan's link. Airavata selects the subprotocol `cybershuttle.v1`. | | `GET /api/v1/processes/{processId}/jupyter-server` | Bearer token of the process owner | `{processId, linked, baseUrl, token}`: where to reach the Jupyter Server and its token | -| `/api/v1/processes/{processId}/linkspan/…` | The Jupyter token, as `Authorization: token ` or `?token=` | Proxy to [Linkspan's API](https://github.com/cyber-shuttle/linkspan#http-api) in the job, including WebSockets. Linkspan's `api/v1/forward/{port}` carries TCP only, so Airavata sends a request for `api/v1/forward/{port}/…` to that port itself, over the link: the `baseUrl` above reaches the Jupyter Server this way. `502` while the job is not linked. | +| `/api/v1/processes/{processId}/linkspan/…` | The Jupyter token, as `Authorization: token ` or `?token=` | Proxy to [Linkspan's API](https://github.com/cyber-shuttle/linkspan#http-api) in the job, including WebSockets. A request for `api/v1/forward/{port}/…` goes to that port itself; the `baseUrl` above uses it. `502` while the job is not linked. | Only the owner of a process can read its Jupyter token, because the token runs code as the owner's cluster account. The proxy compares the token before forwarding. The Jupyter Server checks it again; Linkspan's own API does not. Airavata's bearer tokens are never sent to the job. Other users on a shared node can reach the job's loopback ports, but they still need the Jupyter token to use the Jupyter Server ([Linkspan's security model](https://github.com/cyber-shuttle/linkspan/blob/main/SECURITY.md#security-model)). From 8a95173a6ff4db59b2822a9dde4c85a9f5ab4ddd Mon Sep 17 00:00:00 2001 From: Yasith Jayawardana Date: Sat, 14 Nov 2026 22:13:59 -0500 Subject: [PATCH 3/6] Trim Linkspan proxy comments --- api/process/controller/link.go | 9 ++++----- docs/notebooks.md | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/api/process/controller/link.go b/api/process/controller/link.go index b2c97080f3..41485db963 100644 --- a/api/process/controller/link.go +++ b/api/process/controller/link.go @@ -54,7 +54,7 @@ func NewLinkController(svc *service.LinkService) *LinkController { svc: svc, proxy: &httputil.ReverseProxy{ Transport: svc.Registry().Transport(), - // The target was set on the request by the linkspan handler; Rewrite only keeps the + // The target was set on the request by linkspan; Rewrite only keeps the // client's forwarding headers out. Rewrite: func(out *httputil.ProxyRequest) { out.Out.URL.Scheme = "http" @@ -115,9 +115,8 @@ func (h *LinkController) jupyterServer(w http.ResponseWriter, r *http.Request) { httpx.WriteJSON(w, http.StatusOK, resp) } -// linkspan proxies a request over the process's link: to Linkspan's API, or to the port -// itself for a path under forward/{port}/, as Linkspan's forward carries TCP only. -// The token stays on the request because the Jupyter Server checks it again. +// linkspan proxies over the process's link to Linkspan's API, or to the port itself under +// forward/{port}/. The token stays on the request: the Jupyter Server checks it again. func (h *LinkController) linkspan(w http.ResponseWriter, r *http.Request) { processID := r.PathValue("processId") token := r.URL.Query().Get("token") @@ -137,7 +136,7 @@ func (h *LinkController) linkspan(w http.ResponseWriter, r *http.Request) { if out.URL.Path == "" { out.URL.Path = "/" } - // A bare forward/{port} has no slash to cut on and stays Linkspan's own TCP stream. + // A bare forward/{port} is Linkspan's own TCP stream; leave it. if rawPort, path, ok := strings.Cut(strings.TrimPrefix(out.URL.Path, "/api/v1/forward/"), "/"); ok { if forwarded, err := strconv.ParseUint(rawPort, 10, 16); err == nil { port, out.URL.Path = uint16(forwarded), "/"+path diff --git a/docs/notebooks.md b/docs/notebooks.md index 48d69af26e..0823b73ade 100644 --- a/docs/notebooks.md +++ b/docs/notebooks.md @@ -62,7 +62,7 @@ If Airavata restarts, or the link drops, Linkspan redials on its own and the pag |---|---|---| | `GET /api/v1/processes/{processId}/link` | The link token, as the WebSocket subprotocol `link.` | Linkspan's link. Airavata selects the subprotocol `cybershuttle.v1`. | | `GET /api/v1/processes/{processId}/jupyter-server` | Bearer token of the process owner | `{processId, linked, baseUrl, token}`: where to reach the Jupyter Server and its token | -| `/api/v1/processes/{processId}/linkspan/…` | The Jupyter token, as `Authorization: token ` or `?token=` | Proxy to [Linkspan's API](https://github.com/cyber-shuttle/linkspan#http-api) in the job, including WebSockets. A request for `api/v1/forward/{port}/…` goes to that port itself; the `baseUrl` above uses it. `502` while the job is not linked. | +| `/api/v1/processes/{processId}/linkspan/…` | The Jupyter token, as `Authorization: token ` or `?token=` | Proxy to [Linkspan's API](https://github.com/cyber-shuttle/linkspan#http-api) in the job, WebSockets included. `api/v1/forward/{port}/…` goes to that port; `baseUrl` uses it. `502` while unlinked. | Only the owner of a process can read its Jupyter token, because the token runs code as the owner's cluster account. The proxy compares the token before forwarding. The Jupyter Server checks it again; Linkspan's own API does not. Airavata's bearer tokens are never sent to the job. Other users on a shared node can reach the job's loopback ports, but they still need the Jupyter token to use the Jupyter Server ([Linkspan's security model](https://github.com/cyber-shuttle/linkspan/blob/main/SECURITY.md#security-model)). From 36f051ea33e1ef01e6d1f3552ba42584fa557d9b Mon Sep 17 00:00:00 2001 From: Yasith Jayawardana Date: Sun, 15 Nov 2026 03:05:13 -0500 Subject: [PATCH 4/6] Fold the running record into link authentication --- api/process/controller/link.go | 3 --- api/process/service/link.go | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/api/process/controller/link.go b/api/process/controller/link.go index 41485db963..41f556577c 100644 --- a/api/process/controller/link.go +++ b/api/process/controller/link.go @@ -87,9 +87,6 @@ func (h *LinkController) link(w http.ResponseWriter, r *http.Request) { httpx.WriteError(w, r, httpx.Unauthorized("The link token is not the one issued to process %s", processID)) return } - if err := h.svc.Begun(r.Context(), processID); err != nil { - slog.Warn("Failed to record a linking process as running", "processId", processID, "error", err) - } conn, err := websocket.Accept(w, r, &websocket.AcceptOptions{Subprotocols: []string{link.Protocol}}) if err != nil { return diff --git a/api/process/service/link.go b/api/process/service/link.go index ff77b2b282..bdf6e6246e 100644 --- a/api/process/service/link.go +++ b/api/process/service/link.go @@ -28,6 +28,7 @@ import ( "encoding/base64" "encoding/hex" "fmt" + "log/slog" "net/url" "strconv" "strings" @@ -61,16 +62,6 @@ func NewLinkService(links *repository.LinkRepository, processes *repository.Proc return &LinkService{links: links, processes: processes, statuses: statuses, registry: registry, publicURL: strings.TrimRight(publicURL, "/")} } -// Begun records a SUBMITTED process as RUNNING, without waiting on Slurm's begin mail. -func (s *LinkService) Begun(ctx context.Context, processID string) error { - statuses, err := s.statuses.ListForProcess(ctx, processID) - if err != nil || len(statuses) == 0 || ptr.From(statuses[len(statuses)-1].Status) != model.ProcessStatusTypeSubmitted { - return err - } - _, err = s.statuses.Record(ctx, processID, model.ProcessStatusTypeRunning, nil) - return err -} - // Registry is the live links this service admits. func (s *LinkService) Registry() *link.Registry { return s.registry } @@ -121,15 +112,22 @@ func (s *LinkService) Issue(ctx context.Context, processID string) (*link.Issued } // Authenticate reports whether token is the link token last issued to the process. +// A match records a SUBMITTED process as RUNNING, without waiting on Slurm's begin mail. func (s *LinkService) Authenticate(ctx context.Context, processID, token string) bool { if token == "" { return false } found, err := s.links.FindByProcessID(ctx, processID) - if err != nil { + if err != nil || subtle.ConstantTimeCompare([]byte(digest(token)), []byte(found.LinkTokenHash)) != 1 { return false } - return subtle.ConstantTimeCompare([]byte(digest(token)), []byte(found.LinkTokenHash)) == 1 + if statuses, err := s.statuses.ListForProcess(ctx, processID); err == nil && len(statuses) > 0 && + ptr.From(statuses[len(statuses)-1].Status) == model.ProcessStatusTypeSubmitted { + if _, err := s.statuses.Record(ctx, processID, model.ProcessStatusTypeRunning, nil); err != nil { + slog.Warn("Failed to record a linking process as running", "processId", processID, "error", err) + } + } + return true } // JupyterServer returns the caller's access to their process's Jupyter Server. Only From a199cf2e68fbb2ad5534fd260deab7a2546ba568 Mon Sep 17 00:00:00 2001 From: Yasith Jayawardana Date: Sun, 15 Nov 2026 17:42:25 -0500 Subject: [PATCH 5/6] Name link functions after what they do --- api/process/controller/link.go | 10 +++++----- api/process/service/link.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/process/controller/link.go b/api/process/controller/link.go index 41f556577c..b180b8ef31 100644 --- a/api/process/controller/link.go +++ b/api/process/controller/link.go @@ -76,14 +76,14 @@ func NewLinkController(svc *service.LinkService) *LinkController { func (h *LinkController) Register(mux *http.ServeMux) { mux.HandleFunc("GET /api/v1/processes/{processId}/link", h.link) mux.HandleFunc("GET /api/v1/processes/{processId}/jupyter-server", h.jupyterServer) - mux.HandleFunc("/api/v1/processes/{processId}/linkspan/", h.linkspan) + mux.HandleFunc("/api/v1/processes/{processId}/linkspan/", h.proxyToLinkspan) } // link admits the WebSocket a process's Linkspan dials and holds it as the process's // link until it closes. func (h *LinkController) link(w http.ResponseWriter, r *http.Request) { processID := r.PathValue("processId") - if !h.svc.Authenticate(r.Context(), processID, link.OfferedToken(r)) { + if !h.svc.AuthenticateAndMarkRunning(r.Context(), processID, link.OfferedToken(r)) { httpx.WriteError(w, r, httpx.Unauthorized("The link token is not the one issued to process %s", processID)) return } @@ -112,15 +112,15 @@ func (h *LinkController) jupyterServer(w http.ResponseWriter, r *http.Request) { httpx.WriteJSON(w, http.StatusOK, resp) } -// linkspan proxies over the process's link to Linkspan's API, or to the port itself under +// proxyToLinkspan proxies over the process's link to Linkspan's API, or to the port itself under // forward/{port}/. The token stays on the request: the Jupyter Server checks it again. -func (h *LinkController) linkspan(w http.ResponseWriter, r *http.Request) { +func (h *LinkController) proxyToLinkspan(w http.ResponseWriter, r *http.Request) { processID := r.PathValue("processId") token := r.URL.Query().Get("token") if scheme, value, found := strings.Cut(r.Header.Get("Authorization"), " "); found && strings.EqualFold(scheme, "token") { token = strings.TrimSpace(value) } - port, ok := h.svc.ControlPort(r.Context(), processID, token) + port, ok := h.svc.LinkspanPort(r.Context(), processID, token) if !ok { httpx.WriteError(w, r, httpx.Unauthorized("The Jupyter token is not the one issued to process %s", processID)) return diff --git a/api/process/service/link.go b/api/process/service/link.go index bdf6e6246e..960035d6d4 100644 --- a/api/process/service/link.go +++ b/api/process/service/link.go @@ -111,9 +111,9 @@ func (s *LinkService) Issue(ctx context.Context, processID string) (*link.Issued return &link.Issued{URL: linkURL, LinkToken: linkToken, JupyterToken: jupyterToken, ControlPort: control, JupyterPort: jupyter}, nil } -// Authenticate reports whether token is the link token last issued to the process. +// AuthenticateAndMarkRunning reports whether token is the link token last issued to the process. // A match records a SUBMITTED process as RUNNING, without waiting on Slurm's begin mail. -func (s *LinkService) Authenticate(ctx context.Context, processID, token string) bool { +func (s *LinkService) AuthenticateAndMarkRunning(ctx context.Context, processID, token string) bool { if token == "" { return false } @@ -156,9 +156,9 @@ func (s *LinkService) JupyterServer(ctx context.Context, processID string) (*dto }, nil } -// ControlPort returns the port of the process's Linkspan API when token is its +// LinkspanPort returns the port of the process's Linkspan API when token is its // Jupyter token, and false otherwise. -func (s *LinkService) ControlPort(ctx context.Context, processID, token string) (uint16, bool) { +func (s *LinkService) LinkspanPort(ctx context.Context, processID, token string) (uint16, bool) { if token == "" { return 0, false } From 125dd4ceb3410a9c676569bf99e922281d85872b Mon Sep 17 00:00:00 2001 From: Yasith Jayawardana Date: Mon, 16 Nov 2026 13:43:42 -0500 Subject: [PATCH 6/6] Regenerate the MCP client --- internal/mcp/client/client.gen.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/mcp/client/client.gen.go b/internal/mcp/client/client.gen.go index 2dc60f1602..780139755b 100644 --- a/internal/mcp/client/client.gen.go +++ b/internal/mcp/client/client.gen.go @@ -1311,6 +1311,9 @@ type SlurmClusterConfigRequest struct { // machine it logs in to. The key is inlined as its safe summary. type SlurmClusterConfigResponse struct { Description *string `json:"description,omitempty"` + + // Disabled True while the config accepts no new processes: none can be created or + // launched under it. Disabled *bool `json:"disabled,omitempty"` LoginUser string `json:"loginUser"` Name *string `json:"name,omitempty"`