Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a08b92f
fix(mcp): return filtered summaries and synced sessions
khaliqgant Nov 19, 2026
9369233
fix(mcp): match gated synced session ids
khaliqgant Nov 19, 2026
3f82543
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
3952b4a
fix(mcp): document and test repo pushdown
khaliqgant Nov 19, 2026
c3ecc0a
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
2f3633e
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
37ce05e
fix(mcp): retain session timing failure causes
khaliqgant Nov 19, 2026
2053cf5
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
79fb327
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
4ac5a07
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
559e54d
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
c659902
fix(mcp): make session enrichment failure-safe
khaliqgant Nov 19, 2026
0e5f1d8
Merge remote-tracking branch 'origin/main' into fix/roma-session-summ…
khaliqgant Nov 19, 2026
d2a8a1d
fix(mcp): explain unavailable relay sessions
khaliqgant Nov 19, 2026
3246ff4
fix(mcp): clear unavailable session metadata
khaliqgant Nov 19, 2026
49eb62d
fix(mcp): preserve roster session kind
khaliqgant Nov 19, 2026
9ae0315
test(mcp): preserve declared session on lookup failure
khaliqgant Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ assigned at release.

## Unreleased

- Fixed: MCP repository-filtered session summaries apply the first 200 characters of a repo-only filter in the session directory before pagination, while still accepting a 512-character repo value and verifying the full returned repository URL. This requires a sessions read API whose session directory list applies `projectContains` as a case-insensitive substring of project ID, catalog project key or recorded repository URL (directory migration `20261105034000` or later). Exact verification can still produce a short or empty page with a cursor. Relay agent listings now link an exact roster agent ID to its already-synced Desktop native session when the agent has no validated Relaycast session declaration. No migration.
- Fixed: MCP repository-filtered session summaries apply the first 200 characters of a repo-only filter in the session directory before pagination, while still accepting a 512-character repo value and verifying the full returned repository URL. This requires a sessions read API whose session directory list applies `projectContains` as a case-insensitive substring of project ID, catalog project key or recorded repository URL (directory migration `20261105034000` or later). Exact verification can still produce a short or empty page with a cursor. Relay agent listings now link an exact roster agent ID to its already-synced Desktop native session when the agent has no validated Relaycast session declaration. The optional session join is failure-open: the roster still returns a null session ID and attribution with `session_unavailable_reason` set to `enrichment_failed` or `ambiguous_sync`; an independently recorded metadata session kind is preserved. No migration.
- Changed: MCP `list_amp_threads` now returns `{ threads, truncated }` instead of a bare thread array. Clients that parse the old array must read the `threads` field; `truncated` reports whether Amp returned more than the first 100 threads.
- Changed: MCP `list_relay_agents` now returns the first at most 100 matching agents in relay order and adds `total_matching` and `truncated`; it previously returned the whole matching roster.
- Changed: MCP `get_session_summary` now returns `summary: { status: "unsupported" }` as a normal result when the selected backend records that status; it previously returned a tool error.
Expand Down
2 changes: 1 addition & 1 deletion src/mcp/relay-messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function registerRelayMessaging(server: McpServer, context: McpContext):
};

server.registerTool("list_relay_agents", {
description: "List the first matching agents in relay order across every teammate in your current workspace's relay, with exact machine addresses, presence, descriptions and owners. The page defaults to 100 agents and cannot exceed 100; total_matching and truncated disclose omitted matches, so narrow the filters when truncated. Ownership metadata describes the roster; it does not grant permission to act as an agent.",
description: "List the first matching agents in relay order across every teammate in your current workspace's relay, with exact machine addresses, presence, descriptions and owners. The page defaults to 100 agents and cannot exceed 100; total_matching and truncated disclose omitted matches, so narrow the filters when truncated. A null session with session_unavailable_reason means optional Desktop session enrichment failed or was ambiguous; the roster remains available. Ownership metadata describes the roster; it does not grant permission to act as an agent.",
inputSchema: { person: z.string().trim().min(1).max(200).optional().describe("me, a teammate's user ID, or display name"),
status: z.enum(["live", "offline", "all"]).default("live"), query: z.string().trim().max(200).optional(),
limit: z.number().int().min(1).max(100).default(100).describe("Maximum matching agents returned from the start of relay order. Use person/query/status filters to narrow a truncated result."),
Expand Down
21 changes: 16 additions & 5 deletions src/mcp/relay-participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,15 @@ function createRelayService(context: McpContext) {

const syncedSessionKinds = new Set(["codex", "grok", "pi", "opencode", "claude", "copilot", "cursor"]);
const syncedSessionId = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/;
type SyncedDesktopSessions = {
sessions: Map<string, { sessionId: string; sessionKind: string }>;
ambiguous: Set<string>;
};
async function syncedDesktopSessions(agents: readonly RosterAgent[]) {
const targets = agents.map(agent => relayAgentOwnerTarget(agent, Boolean(gate)));
const candidates = new Map(targets.map((target, index) => [`${target.lookupId}\0${target.name}`, agents[index]!]));
const ids = [...new Set(targets.map(target => target.lookupId))];
if (!ids.length) return new Map<string, { sessionId: string; sessionKind: string }>();
if (!ids.length) return { sessions: new Map(), ambiguous: new Set() } satisfies SyncedDesktopSessions;
const rows = await executor.query<{ agent_name: string; agent_remote_id: string; native_session_kind: string; native_session_id: string }>(
`SELECT agent_name, agent_remote_id, native_session_kind, native_session_id
FROM desktop_relay_identities
Expand All @@ -753,11 +757,13 @@ function createRelayService(context: McpContext) {
);
const sessions = new Map<string, { sessionId: string; sessionKind: string }>();
const matched = new Set<string>();
const ambiguous = new Set<string>();
for (const row of rows.rows) {
const agent = candidates.get(`${row.agent_remote_id}\0${row.agent_name}`);
if (!agent) continue;
if (matched.has(agent.id)) {
sessions.delete(agent.id);
ambiguous.add(agent.id);
continue;
}
matched.add(agent.id);
Expand All @@ -766,25 +772,30 @@ function createRelayService(context: McpContext) {
sessions.set(agent.id, { sessionId: row.native_session_id, sessionKind: kind });
}
}
return sessions;
return { sessions, ambiguous };
}

async function roster(status: "live" | "all" | "offline", people: readonly McpMember[], includeStale = false, dir: Directory = directory()) {
const listed = await listedAgents(status === "live" ? "active" : "all", includeStale, dir);
const [owners, synced] = await Promise.all([
loadRelayAgentOwners(database, workspaceId, relayWorkspaceId, listed, people, Boolean(gate))
.catch(error => { ownerEnrichmentFailed("list_relay_agents", error); return undefined; }),
syncedDesktopSessions(listed).catch(error => {
syncedDesktopSessions(listed).then(result => ({ ...result, failed: false as const })).catch(error => {
sessionEnrichmentFailed(error);
return new Map<string, { sessionId: string; sessionKind: string }>();
return { sessions: new Map<string, { sessionId: string; sessionKind: string }>(),
ambiguous: new Set<string>(), failed: true as const };
}),
]);
return listed
.map(agent => {
const row = rosterAgent(agent, people, userId, workspaceId, owners?.get(agent.id));
const session = row.session_attribution ? null : synced.get(agent.id);
const session = row.session_attribution ? null : synced.sessions.get(agent.id);
const unavailableReason = row.session_attribution || session ? null
: synced.failed ? "enrichment_failed" as const
: synced.ambiguous.has(agent.id) ? "ambiguous_sync" as const : null;
return { ...row,
...(session ? { session_id: session.sessionId, session_kind: session.sessionKind, session_attribution: "synced" as const } : {}),
session_unavailable_reason: unavailableReason,
...cardSummary(agent.metadata, agent) };
})
.filter(agent => status === "all" || (status === "live" ? agent.online : !agent.online));
Expand Down
22 changes: 15 additions & 7 deletions test/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,16 +900,19 @@ test("list_relay_agents links synced Desktop sessions and keeps validated declar
const client = await relayClient(t, env);
const agents = structured(await client.callTool({ name: "list_relay_agents", arguments: { status: "all" } })).agents;
const syncedRow = agents.find((agent: any) => agent.name === synced.name);
assert.deepEqual([syncedRow.session_id, syncedRow.session_kind, syncedRow.session_attribution],
["ses_ABCD1234", "opencode", "synced"]);
assert.deepEqual([syncedRow.session_id, syncedRow.session_kind, syncedRow.session_attribution,
syncedRow.session_unavailable_reason], ["ses_ABCD1234", "opencode", "synced", null]);
const declaredRow = agents.find((agent: any) => agent.name === declared.name);
assert.deepEqual([declaredRow.session_id, declaredRow.session_kind, declaredRow.session_attribution],
["declared-session-id", "claude", "declared"]);
assert.deepEqual([declaredRow.session_id, declaredRow.session_kind, declaredRow.session_attribution,
declaredRow.session_unavailable_reason], ["declared-session-id", "claude", "declared", null]);
});

test("list_relay_agents session enrichment fails open and refuses ambiguous Desktop rows", async (t) => {
const env = await setup(t);
const peer = env.relay.world.addAgent("session-fallback", { source: "relay-desktop" });
const peer = env.relay.world.addAgent("session-fallback", { source: "relay-desktop", session_kind: "claude" });
const declared = env.relay.world.addAgent("session-declared-fallback", {
source: "relay-desktop", session_id: "declared-session-id", session_kind: "claude", injectable: "true",
});
const client = await relayClient(t, env);
const originalQuery = env.database.query.bind(env.database);
let mode: "reject" | "duplicate" = "reject";
Expand All @@ -929,15 +932,20 @@ test("list_relay_agents session enrichment fails open and refuses ambiguous Desk

const unavailable = structured(await client.callTool({ name: "list_relay_agents", arguments: { status: "all" } }));
const unavailableRow = unavailable.agents.find((agent: any) => agent.name === peer.name);
assert.deepEqual([unavailableRow.session_id, unavailableRow.session_attribution], [null, null]);
assert.deepEqual([unavailableRow.session_id, unavailableRow.session_kind, unavailableRow.session_attribution,
unavailableRow.session_unavailable_reason], [null, "claude", null, "enrichment_failed"]);
const declaredRow = unavailable.agents.find((agent: any) => agent.name === declared.name);
assert.deepEqual([declaredRow.session_id, declaredRow.session_kind, declaredRow.session_attribution,
declaredRow.session_unavailable_reason], ["declared-session-id", "claude", "declared", null]);
assert.deepEqual(warnings, [["[selfhost-mcp] session enrichment failed",
{ operation: "list_relay_agents", error: "TypeError" }]]);
assert.doesNotMatch(JSON.stringify(warnings), /private session query detail/);

mode = "duplicate";
const ambiguous = structured(await client.callTool({ name: "list_relay_agents", arguments: { status: "all" } }));
const ambiguousRow = ambiguous.agents.find((agent: any) => agent.name === peer.name);
assert.deepEqual([ambiguousRow.session_id, ambiguousRow.session_attribution], [null, null]);
assert.deepEqual([ambiguousRow.session_id, ambiguousRow.session_kind, ambiguousRow.session_attribution,
ambiguousRow.session_unavailable_reason], [null, "claude", null, "ambiguous_sync"]);
});

test("agent card owner enrichment fails open when its journal or membership read fails", async (t) => {
Expand Down
Loading