From b15ccd82a8e43e5074190e836a028e0a8b17ee07 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Mon, 16 Nov 2026 14:05:30 -0800 Subject: [PATCH] feat(sessions): pass relaygate's group label through the dashboard catalog route relaygate (groupLabels) annotates readable sessions with `relaygate: {gid, label}`. The list route already spreads upstream items, so the field reaches the dashboard; the catalog route rebuilds its body, so it now passes `relaygate` through, keeping only a non-negative integer gid and a label in relaygate's charset. Documented in openapi (RelaygateGroupLabel). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ openapi.yaml | 17 +++++++++++++++++ src/sessions/routes.ts | 16 ++++++++++++++++ test/sessions.test.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cecb1b2..032d2d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ assigned at release. ## Unreleased +- Added: the dashboard session catalog route passes relaygate's owning-group + label (`relaygate: {gid, label}`, from relaygate's `groupLabels` policy) + through when the session read API is relaygate; only those two validated + fields pass. Session list items already carried it unchanged. - Added: Replicas failure paths (migration 0070). The environment MCP create intent is persisted on the policy and, while it is set, every sync or enable (startup run, periodic sync, the sync and enable routes, a plain diff --git a/openapi.yaml b/openapi.yaml index 9c14434d..fb56ba5d 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -9766,6 +9766,23 @@ components: type: object truncated: type: boolean + relaygate: + $ref: "#/components/schemas/RelaygateGroupLabel" + RelaygateGroupLabel: + type: object + description: | + Present only when the session read API is relaygate and its policy + labels the session's owning group (relaygate `groupLabels`). Display + only; passed through from the read API with just these two fields. + Session list items carry the same field unchanged. + required: [gid, label] + properties: + gid: + type: integer + minimum: 0 + label: + type: string + maxLength: 24 RunStatus: enum: [pending, running, completed, failed, cancelled] EnrollmentTokenSummary: diff --git a/src/sessions/routes.ts b/src/sessions/routes.ts index 2e6de0f5..6c65ee77 100644 --- a/src/sessions/routes.ts +++ b/src/sessions/routes.ts @@ -214,6 +214,21 @@ function sessionItem(value: unknown): Record { }; } +/** + * relaygate's owning-group label for one session (`relaygate: {gid, label}`, + * relaygate docs/contract.md "Group labels"), when the read API is relaygate + * and the session's group has one. Only the two known fields pass; anything + * else is dropped. + */ +function groupLabelOf(body: Record): { relaygate?: { gid: number; label: string } } { + const value = body.relaygate; + if (!isRecord(value)) return {}; + const { gid, label } = value; + if (!Number.isSafeInteger(gid) || (gid as number) < 0) return {}; + if (typeof label !== "string" || !/^[A-Za-z0-9](?:[A-Za-z0-9 ._-]{0,22}[A-Za-z0-9._-])?$/.test(label)) return {}; + return { relaygate: { gid: gid as number, label } }; +} + function eventItem(value: unknown): Record { if ( !isRecord(value) || @@ -609,6 +624,7 @@ async function routeSessions(ctx: SessionRouteContext): Promise { children: list(body.children), commitLinks: list(body.commitLinks), truncated: body.truncated === true, + ...groupLabelOf(body), }); return true; } diff --git a/test/sessions.test.ts b/test/sessions.test.ts index afe39143..cb641b1c 100644 --- a/test/sessions.test.ts +++ b/test/sessions.test.ts @@ -512,6 +512,39 @@ test("members: names for the dashboard without a History read", async (t) => { assert.equal(anonymous.status, 401); }); +test("relaygate group labels reach the dashboard on the list and the catalog, and nothing else of it", async (t) => { + const env = await setup(t); + const token = await env.login(env.ownerId, env.alpha); + const base = `/cloud/api/v1/workspaces/${env.alpha}`; + env.history.overrides.set("/v1/sessions", () => ({ + body: { + sessions: [ + { sessionId: "alpha-1", source: "codex", relaygate: { gid: 22, label: "pit" } }, + { sessionId: "alpha-2", source: "codex" }, + ], + nextCursor: null, + }, + })); + const list = await call(env.origin, `${base}/sessions?metadata=deferred`, { token }); + assert.equal(list.status, 200); + assert.deepEqual(list.body.items[0].relaygate, { gid: 22, label: "pit" }); + assert(!("relaygate" in list.body.items[1])); + + const catalogBody = (relaygate: unknown) => ({ + body: { sessionId: "alpha-1", workspaceId: env.alpha, catalog: { title: "t" }, parents: [], children: [], relaygate }, + }); + env.history.overrides.set("/v1/sessions/alpha-1/catalog", () => catalogBody({ gid: 22, label: "pit", owner: "someone" })); + const labeled = await call(env.origin, `${base}/sessions/alpha-1/catalog?source=codex`, { token }); + assert.equal(labeled.status, 200); + assert.deepEqual(labeled.body.relaygate, { gid: 22, label: "pit" }); + for (const bad of [{ gid: "22", label: "pit" }, { gid: 22, label: "pit" }, { gid: -1, label: "pit" }, "pit"]) { + env.history.overrides.set("/v1/sessions/alpha-1/catalog", () => catalogBody(bad)); + const refused = await call(env.origin, `${base}/sessions/alpha-1/catalog?source=codex`, { token }); + assert.equal(refused.status, 200); + assert(!("relaygate" in refused.body), JSON.stringify(bad)); + } +}); + test("list, search, transcript, timing, and subagent catalog for the dashboard", async (t) => { const env = await setup(t); const token = await env.login(env.ownerId, env.alpha);