diff --git a/src/prerna/reactor/agent/AgentRunner.java b/src/prerna/reactor/agent/AgentRunner.java index a9dc0d5d6f..d9f43a43df 100644 --- a/src/prerna/reactor/agent/AgentRunner.java +++ b/src/prerna/reactor/agent/AgentRunner.java @@ -280,6 +280,11 @@ private static AgentHarnessResult run(String roomId, String input, String engine AgentConfig agentConfig = AgentConfigLoader.load(room, filePath, modelId, params, agentParams, maxTurns, maxReflections, explicitWorkspaceId); + // List a room this run starts under its workspace, as CreateRoom does. + if (!resumeMode) { + persistWorkspaceOnEmptyRoom(room, insight, explicitWorkspaceId); + } + try { if (target.isInsight() && CollaborationUtils.isCollaborationRoom(room) && agentConfig.getSkills().stream().noneMatch(ref -> ref != null @@ -418,6 +423,33 @@ private static final class WorkspaceOverlay { } } + /** + * Sets {@code ROOM.WORKSPACE_ID} on a room with no messages yet so it shows in + * GetWorkspaceRooms, matching {@code CreateRoom(workspaceId)}. Options are not + * touched, so later runs can pick another agent or none. Skipped when the + * workspace is missing, disabled, or not viewable by the user. + */ + private static void persistWorkspaceOnEmptyRoom(Room room, Insight insight, String workspaceId) { + if (workspaceId == null || workspaceId.trim().isEmpty()) { + return; + } + List messages = room.getMessages(); + if (messages != null && !messages.isEmpty()) { + return; + } + try { + Map ws = ModelInferenceLogsUtils.getWorkspaceEntry(workspaceId); + if (ws == null || !Boolean.TRUE.equals(ws.get("is_active")) || insight.getUser() == null + || !SecurityProjectUtils.userCanViewProject(insight.getUser(), workspaceId)) { + return; + } + ModelInferenceLogsUtils.setRoomWorkspaceId(room.getId(), room.getUserId(), workspaceId); + } catch (Exception e) { + logger.warn("AgentRunner: could not set workspace '{}' on room '{}': {}", workspaceId, room.getId(), + e.getMessage(), e); + } + } + /** * Applies an in-memory workspace override for one run when needed. */