Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/cli/src/cli/agent-relay-mcp.startup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@ describe('createAgentRelayMcpServer', () => {
// `node up` mentioned it.
expect(result.structuredContent.message).toContain('node_abc');
expect(result.structuredContent.message).toContain('relay cloud enroll');
// A cleared enrollment means the write SUCCEEDED. Reporting it through the
// persistence-failure wording would tell the caller the key never landed.
expect(result.structuredContent.message).toContain('persisted for this project');
expect(result.structuredContent.message).not.toContain('could not be persisted');
});

it('registers submit_result when a spawned-agent result callback is configured', async () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/cli/agent-relay-mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
});
} catch (err) {
if ((err as { name?: string }).name === 'AbortError') {
throw new Error(`Agent Relay result submission timed out after ${timeoutMs}ms`);

Check warning on line 279 in packages/cli/src/cli/agent-relay-mcp.ts

View workflow job for this annotation

GitHub Actions / lint

There is no `cause` attached to the symptom error being thrown
}
throw err;
} finally {
Expand Down Expand Up @@ -329,7 +329,7 @@
return { agentName, agentToken };
}

export async function registerAgentWithRebind({

Check warning on line 332 in packages/cli/src/cli/agent-relay-mcp.ts

View workflow job for this annotation

GitHub Actions / lint

Async function 'registerAgentWithRebind' has a complexity of 23. Maximum allowed is 15
session,
setSession,
getRelay,
Expand Down Expand Up @@ -499,11 +499,15 @@
} else {
setSession({ workspaceKey: key });
}
// Two distinct outcomes, never conflated: the write failed, or the write
// succeeded and dropped this project's enrolled fleet node. Reporting the
// second as the first would tell the caller the key had not persisted.
let persistenceWarning: string | undefined;
let clearedEnrollmentWarning: string | undefined;
try {
// Joining a different workspace drops this project's enrolled fleet
// node; surface that here instead of at the next `node up`.
persistenceWarning = describeClearedEnrollment(persistWorkspaceSession({ workspaceKey: key }));
clearedEnrollmentWarning = describeClearedEnrollment(persistWorkspaceSession({ workspaceKey: key }));
} catch (error) {
const persistenceError = error instanceof Error ? error.message : String(error);
persistenceWarning =
Expand All @@ -517,7 +521,9 @@
const activeMessage = switchingWorkspace
? 'Workspace key set. Call "register_agent" to join this workspace.'
: 'Workspace key set.';
const message = persistenceWarning ? `${activeMessage} ${persistenceWarning}` : persistedMessage;
const message = persistenceWarning
? `${activeMessage} ${persistenceWarning}`
: [persistedMessage, clearedEnrollmentWarning].filter(Boolean).join(' ');
return textContent(message);
}
);
Expand Down
Loading