Skip to content

Modern Docker Management, Designed for Everyone

fix: show all environment activities (#2762)

Kyle Mendell0a6be65d72c4
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index c031475c5..a4c3d9dc6 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -2056,10 +2056,12 @@
"activity_started_by_label": "Started by",
"activity_clear_history": "Clear history",
"activity_clear_history_title": "Clear activity history?",
- "activity_clear_history_message": "Completed, failed, and cancelled entries for the selected environment will be deleted. Running activity will stay visible.",
+ "activity_clear_history_message": "Completed, failed, and cancelled entries for every configured environment will be deleted. Running activity will stay visible.",
"activity_clear_history_confirm": "Clear History",
"activity_clear_history_success": "Activity history cleared",
+ "activity_clear_history_partial": "Activity history partially cleared. Succeeded for {count}. Failed for {environments}.",
"activity_clear_history_failed": "Failed to clear activity history",
+ "activity_environment_load_failed": "Could not load activity from {environment}",
"activity_cancel": "Cancel activity",
"activity_cancel_title": "Cancel activity?",
"activity_cancel_message": "This requests cancellation of the running operation. Work already completed by Docker may not be rolled back.",
diff --git a/frontend/src/lib/components/activity/activity-center.svelte b/frontend/src/lib/components/activity/activity-center.svelte
index 6f93ac67f..b402f01d4 100644
--- a/frontend/src/lib/components/activity/activity-center.svelte
+++ b/frontend/src/lib/components/activity/activity-center.svelte
@@ -6,7 +6,7 @@
import ActivityDetailPanel from './activity-detail-panel.svelte';
import { activityStore } from '$lib/stores/activity.store.svelte';
import type { ActivityFilter } from '$lib/types/activity.type';
- import { ActivityIcon, CloseIcon, RefreshIcon, TrashIcon } from '$lib/icons';
+ import { ActivityIcon, AlertTriangleIcon, CloseIcon, RefreshIcon, TrashIcon } from '$lib/icons';
import { m } from '$lib/paraglide/messages';
import { cn } from '$lib/utils';
import { activityFilterLabel } from './activity-labels';
@@ -34,7 +34,16 @@
destructive: true,
action: async () => {
try {
- await activityStore.clearHistory();
+ const result = await activityStore.clearHistory();
+ if (result.failed.length > 0) {
+ toast.warning(
+ m.activity_clear_history_partial({
+ count: result.succeeded,
+ environments: result.failed.map((failure) => failure.environmentName).join(', ')
+ })
+ );
+ return;
+ }
toast.success(m.activity_clear_history_success());
} catch (error) {
console.error('Failed to clear activity history:', error);
@@ -104,6 +113,28 @@
</div>
<div class="min-h-[68vh] flex-1 overflow-y-auto">
+ {#if activityStore.environmentFailures.length > 0}
+ <div class="border-border/60 bg-muted/25 border-b px-4 py-3">
+ <div class="text-muted-foreground flex items-start gap-2 text-xs">
+ <AlertTriangleIcon class="mt-0.5 size-4 shrink-0 text-amber-500" aria-hidden="true" />
+ <div class="min-w-0 flex-1 space-y-1">
+ {#each activityStore.environmentFailures as failure (failure.environmentId)}
+ <p class="leading-relaxed">
+ {m.activity_environment_load_failed({ environment: failure.environmentName })}
+ </p>
+ {/each}
+ </div>
+ <button
+ type="button"
+ onclick={() => activityStore.retryStream()}
+ class="text-primary hover:text-primary/80 shrink-0 text-xs font-medium underline"
+ >
+ {m.common_retry()}
+ </button>
+ </div>
+ </div>
+ {/if}
+
{#if activityStore.loading && activityStore.activities.length === 0}
<div class="flex min-h-96 items-center justify-center p-6 text-center">
<div class="space-y-2">
diff --git a/frontend/src/lib/stores/activity.store.svelte.ts b/frontend/src/lib/stores/activity.store.svelte.ts
index 90ed0fe8a..0f7a7f179 100644
--- a/frontend/src/lib/stores/activity.store.svelte.ts
+++ b/frontend/src/lib/stores/activity.store.svelte.ts
@@ -3,18 +3,31 @@ import { activityService } from '$lib/services/activity-service';
import { environmentStore, LOCAL_DOCKER_ENVIRONMENT_ID } from '$lib/stores/environment.store.svelte';
import type {
Activity,
+ ActivityClearHistorySummary,
ActivityDetail,
+ ActivityEnvironmentFailure,
ActivityFilter,
ActivityMessage,
ActivityStatus,
ActivityStreamEvent
} from '$lib/types/activity.type';
+import type { Environment } from '$lib/types/environment';
const ACTIVITY_LIST_LIMIT = 50;
const ACTIVITY_DETAIL_LIMIT = 500;
const MAX_RECONNECT_DELAY = 15_000;
const MAX_RECONNECT_ATTEMPTS = 20;
+type ActivityEnvironmentState = {
+ id: string;
+ name: string;
+ activities: Activity[];
+ loading: boolean;
+ connected: boolean;
+ streamError: boolean;
+ errorMessage?: string;
+};
+
function sortActivitiesInternal(items: Activity[]): Activity[] {
return [...items].sort((a, b) => {
const aActive = isActiveStatusInternal(a.status);
@@ -44,8 +57,30 @@ function filterActivityInternal(activity: Activity, filter: ActivityFilter): boo
}
}
+function sourceEnvironmentIdInternal(activity: Activity | null | undefined): string {
+ return activity?.sourceEnvironmentId || activity?.environmentId || LOCAL_DOCKER_ENVIRONMENT_ID;
+}
+
+function environmentNameInternal(
+ environment: Pick<Environment, 'id' | 'name'> | ActivityEnvironmentState | null | undefined
+): string {
+ if (!environment) {
+ return 'Local';
+ }
+ return environment.name || environment.id;
+}
+
+function errorMessageInternal(error: unknown): string | undefined {
+ if (error instanceof Error && error.message.trim()) {
+ return error.message;
+ }
+ return undefined;
+}
+
function createActivityStore() {
let _activities = $state<Activity[]>([]);
+ let _environmentStates = $state<Record<string, ActivityEnvironmentState>>({});
+ let _environmentActivities = $state<Record<string, Activity[]>>({});
let _details = $state<Record<string, ActivityDetail>>({});
let _expandedActivityIds = $state<Record<string, boolean>>({});
let _detailLoadingIds = $state<Record<string, boolean>>({});
@@ -53,65 +88,137 @@ function createActivityStore() {
let _cancellingIds = $state<Record<string, boolean>>({});
let _filter = $state<ActivityFilter>('running');
let _open = $state(false);
- let _loading = $state(false);
- let _connected = $state(false);
- let _streamError = $state(false);
let _currentEnvironmentId = $state(LOCAL_DOCKER_ENVIRONMENT_ID);
let started = false;
- let streamGeneration = 0;
- let streamAbortController: AbortController | null = null;
- let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
let unsubscribeEnvironment: (() => void) | null = null;
- let reconnectAttempt = 0;
+ const streamAbortControllers = new Map<string, AbortController>();
+ const reconnectTimers = new Map<string, ReturnType<typeof setTimeout>>();
+ const reconnectAttempts = new Map<string, number>();
+ const streamGenerations = new Map<string, number>();
+
+ function createEnvironmentStateInternal(environment: Pick<Environment, 'id' | 'name'>): ActivityEnvironmentState {
+ return {
+ id: environment.id || LOCAL_DOCKER_ENVIRONMENT_ID,
+ name: environmentNameInternal(environment),
+ activities: [],
+ loading: true,
+ connected: false,
+ streamError: false
+ };
+ }
- function clearReconnectTimerInternal() {
- if (reconnectTimer) {
- clearTimeout(reconnectTimer);
- reconnectTimer = null;
- }
+ function environmentStateInternal(environmentId: string): ActivityEnvironmentState | undefined {
+ return _environmentStates[environmentId];
}
- function abortStreamInternal() {
- clearReconnectTimerInternal();
- streamAbortController?.abort();
- streamAbortController = null;
- _connected = false;
+ function updateEnvironmentStateInternal(
+ environmentId: string,
+ updater: (state: ActivityEnvironmentState) => ActivityEnvironmentState
+ ) {
+ const current =
+ _environmentStates[environmentId] ?? createEnvironmentStateInternal({ id: environmentId, name: environmentId });
+ _environmentStates = {
+ ..._environmentStates,
+ [environmentId]: updater(current)
+ };
}
- function resetEnvironmentStateInternal(environmentId: string) {
- _currentEnvironmentId = environmentId || LOCAL_DOCKER_ENVIRONMENT_ID;
- _activities = [];
- _details = {};
- _expandedActivityIds = {};
- _detailLoadingIds = {};
- _detailErrorIds = {};
- _connected = false;
- _streamError = false;
- _loading = true;
- reconnectAttempt = 0;
+ function setEnvironmentErrorInternal(environmentId: string, error: unknown) {
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ loading: false,
+ connected: false,
+ streamError: true,
+ errorMessage: errorMessageInternal(error)
+ }));
}
- async function refreshInternal(environmentId = _currentEnvironmentId, generation = streamGeneration) {
- _loading = true;
- try {
- const result = await activityService.getActivities({ pagination: { page: 1, limit: ACTIVITY_LIST_LIMIT } }, environmentId);
- if (generation !== streamGeneration || environmentId !== _currentEnvironmentId) {
- return;
- }
- replaceSnapshotInternal(result.data ?? []);
- } catch (error) {
- console.warn('Failed to refresh activities:', error);
- } finally {
- if (generation === streamGeneration && environmentId === _currentEnvironmentId) {
- _loading = false;
- }
+ function clearEnvironmentErrorInternal(environmentId: string) {
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ streamError: false,
+ errorMessage: undefined
+ }));
+ }
+
+ function generationInternal(environmentId: string): number {
+ return streamGenerations.get(environmentId) ?? 0;
+ }
+
+ function nextGenerationInternal(environmentId: string): number {
+ const generation = generationInternal(environmentId) + 1;
+ streamGenerations.set(environmentId, generation);
+ return generation;
+ }
+
+ function isCurrentGenerationInternal(environmentId: string, generation: number): boolean {
+ return generationInternal(environmentId) === generation;
+ }
+
+ function clearReconnectTimerInternal(environmentId: string) {
+ const timer = reconnectTimers.get(environmentId);
+ if (timer) {
+ clearTimeout(timer);
+ reconnectTimers.delete(environmentId);
}
}
- function replaceSnapshotInternal(activities: Activity[]) {
- _activities = sortActivitiesInternal(activities);
- // Drop expansion state for activities that no longer exist in the snapshot.
+ function abortEnvironmentStreamInternal(environmentId: string) {
+ clearReconnectTimerInternal(environmentId);
+ streamAbortControllers.get(environmentId)?.abort();
+ streamAbortControllers.delete(environmentId);
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ connected: false
+ }));
+ }
+
+ function stopEnvironmentInternal(environmentId: string) {
+ nextGenerationInternal(environmentId);
+ abortEnvironmentStreamInternal(environmentId);
+ reconnectAttempts.delete(environmentId);
+ streamGenerations.delete(environmentId);
+
+ const nextStates = { ..._environmentStates };
+ delete nextStates[environmentId];
+ _environmentStates = nextStates;
+ const nextActivities = { ..._environmentActivities };
+ delete nextActivities[environmentId];
+ _environmentActivities = nextActivities;
+ rebuildActivitiesInternal();
+ }
+
+ function normalizeActivityInternal(activity: Activity, environmentId: string): Activity {
+ const state = environmentStateInternal(environmentId);
+ return {
+ ...activity,
+ sourceEnvironmentId: activity.sourceEnvironmentId || environmentId,
+ sourceEnvironmentName: activity.sourceEnvironmentName || state?.name || environmentId
+ };
+ }
+
+ function replaceEnvironmentSnapshotInternal(environmentId: string, activities: Activity[]) {
+ const normalizedActivities = sortActivitiesInternal(
+ activities.map((activity) => normalizeActivityInternal(activity, environmentId))
+ );
+ _environmentActivities = {
+ ..._environmentActivities,
+ [environmentId]: normalizedActivities
+ };
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ activities: normalizedActivities,
+ loading: false,
+ streamError: false,
+ errorMessage: undefined
+ }));
+ rebuildActivitiesInternal();
+ }
+
+ function rebuildActivitiesInternal() {
+ _activities = sortActivitiesInternal(Object.values(_environmentActivities).flat());
+
const present = new Set(_activities.map((activity) => activity.id));
const nextExpanded: Record<string, boolean> = {};
for (const id of Object.keys(_expandedActivityIds)) {
@@ -123,20 +230,36 @@ function createActivityStore() {
}
function mergeActivityInternal(activity: Activity) {
- const index = _activities.findIndex((item) => item.id === activity.id);
- if (index >= 0) {
- _activities = sortActivitiesInternal([..._activities.slice(0, index), activity, ..._activities.slice(index + 1)]);
- } else {
- _activities = sortActivitiesInternal([activity, ..._activities]).slice(0, ACTIVITY_LIST_LIMIT);
- }
+ const environmentId = sourceEnvironmentIdInternal(activity);
+ const normalized = normalizeActivityInternal(activity, environmentId);
+ const currentActivities = _environmentActivities[environmentId] ?? environmentStateInternal(environmentId)?.activities ?? [];
+ const index = currentActivities.findIndex((item) => item.id === normalized.id);
+ const activities = sortActivitiesInternal(
+ index >= 0
+ ? [...currentActivities.slice(0, index), normalized, ...currentActivities.slice(index + 1)]
+ : [normalized, ...currentActivities]
+ ).slice(0, ACTIVITY_LIST_LIMIT);
+ _environmentActivities = {
+ ..._environmentActivities,
+ [environmentId]: activities
+ };
+ updateEnvironmentStateInternal(environmentId, (state) => {
+ return {
+ ...state,
+ activities,
+ streamError: false,
+ errorMessage: undefined
+ };
+ });
+ rebuildActivitiesInternal();
- const existingDetail = _details[activity.id];
+ const existingDetail = _details[normalized.id];
if (existingDetail) {
_details = {
..._details,
- [activity.id]: {
+ [normalized.id]: {
...existingDetail,
- activity
+ activity: normalized
}
};
}
@@ -159,15 +282,14 @@ function createActivityStore() {
};
}
- function applyStreamEventInternal(event: ActivityStreamEvent) {
+ function applyStreamEventInternal(environmentId: string, event: ActivityStreamEvent) {
switch (event.type) {
case 'snapshot':
- replaceSnapshotInternal(event.activities ?? []);
- _loading = false;
+ replaceEnvironmentSnapshotInternal(environmentId, event.activities ?? []);
break;
case 'activity':
if (event.activity) {
- mergeActivityInternal(event.activity);
+ mergeActivityInternal(normalizeActivityInternal(event.activity, environmentId));
}
break;
case 'message':
@@ -176,48 +298,89 @@ function createActivityStore() {
}
break;
case 'heartbeat':
- _connected = true;
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ connected: true
+ }));
break;
}
}
+ async function refreshEnvironmentInternal(environmentId: string, generation = generationInternal(environmentId)) {
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ loading: true
+ }));
+ try {
+ const result = await activityService.getActivities({ pagination: { page: 1, limit: ACTIVITY_LIST_LIMIT } }, environmentId);
+ if (!isCurrentGenerationInternal(environmentId, generation)) {
+ return;
+ }
+ replaceEnvironmentSnapshotInternal(environmentId, result.data ?? []);
+ } catch (error) {
+ if (isCurrentGenerationInternal(environmentId, generation)) {
+ console.warn('Failed to refresh activities:', error);
+ setEnvironmentErrorInternal(environmentId, error);
+ }
+ }
+ }
+
+ async function refreshInternal() {
+ reconcileEnvironmentsInternal();
+ await Promise.all(Object.keys(_environmentStates).map((environmentId) => refreshEnvironmentInternal(environmentId)));
+ }
+
async function connectStreamInternal(environmentId: string, generation: number) {
- if (!browser || generation !== streamGeneration) {
+ if (!browser || !isCurrentGenerationInternal(environmentId, generation)) {
return;
}
- streamAbortController = new AbortController();
+ const controller = new AbortController();
+ streamAbortControllers.set(environmentId, controller);
try {
- const response = await activityService.openActivityStream(environmentId, streamAbortController.signal, ACTIVITY_LIST_LIMIT);
- if (generation !== streamGeneration || !response.body) {
- streamAbortController = null;
+ const response = await activityService.openActivityStream(environmentId, controller.signal, ACTIVITY_LIST_LIMIT);
+ if (!isCurrentGenerationInternal(environmentId, generation) || !response.body) {
+ if (streamAbortControllers.get(environmentId) === controller) {
+ streamAbortControllers.delete(environmentId);
+ }
return;
}
- _connected = true;
- _streamError = false;
- reconnectAttempt = 0;
- await readJSONLinesInternal(response.body, generation);
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ connected: true,
+ streamError: false,
+ errorMessage: undefined
+ }));
+ reconnectAttempts.set(environmentId, 0);
+ await readJSONLinesInternal(environmentId, response.body, generation);
} catch (error) {
- if (!streamAbortController?.signal.aborted && generation === streamGeneration) {
+ if (!controller.signal.aborted && isCurrentGenerationInternal(environmentId, generation)) {
console.warn('Activity stream disconnected:', error);
}
} finally {
- streamAbortController = null;
- if (generation === streamGeneration) {
- _connected = false;
- scheduleReconnectInternal(environmentId, generation);
+ if (streamAbortControllers.get(environmentId) === controller) {
+ streamAbortControllers.delete(environmentId);
+ }
+ if (isCurrentGenerationInternal(environmentId, generation)) {
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ connected: false
+ }));
+ if (!controller.signal.aborted) {
+ scheduleReconnectInternal(environmentId, generation);
+ }
}
}
}
- async function readJSONLinesInternal(stream: ReadableStream<Uint8Array>, generation: number) {
+ async function readJSONLinesInternal(environmentId: string, stream: ReadableStream<Uint8Array>, generation: number) {
const reader = stream.getReader();
const decoder = new TextDecoder();
let buffer = '';
try {
- while (generation === streamGeneration) {
+ while (isCurrentGenerationInternal(environmentId, generation)) {
const { done, value } = await reader.read();
if (done) {
break;
@@ -227,59 +390,142 @@ function createActivityStore() {
const lines = buffer.split('\n');
buffer = lines.pop() ?? '';
for (const line of lines) {
- handleStreamLineInternal(line);
+ handleStreamLineInternal(environmentId, line);
}
}
buffer += decoder.decode();
if (buffer.trim()) {
- handleStreamLineInternal(buffer);
+ handleStreamLineInternal(environmentId, buffer);
}
} finally {
reader.releaseLock();
}
}
- function handleStreamLineInternal(line: string) {
+ function handleStreamLineInternal(environmentId: string, line: string) {
const trimmed = line.trim();
if (!trimmed) {
return;
}
try {
- applyStreamEventInternal(JSON.parse(trimmed) as ActivityStreamEvent);
+ applyStreamEventInternal(environmentId, JSON.parse(trimmed) as ActivityStreamEvent);
} catch (error) {
console.warn('Failed to parse activity stream line:', error);
}
}
function scheduleReconnectInternal(environmentId: string, generation: number) {
- if (!browser || !started || generation !== streamGeneration) {
+ if (!browser || !started || !isCurrentGenerationInternal(environmentId, generation)) {
return;
}
- if (reconnectAttempt >= MAX_RECONNECT_ATTEMPTS) {
- _streamError = true;
+ const attempt = reconnectAttempts.get(environmentId) ?? 0;
+ if (attempt >= MAX_RECONNECT_ATTEMPTS) {
+ setEnvironmentErrorInternal(environmentId, new Error('Activity stream reconnect attempts exhausted'));
return;
}
- clearReconnectTimerInternal();
- const delay = Math.min(1000 * 2 ** reconnectAttempt, MAX_RECONNECT_DELAY);
- reconnectAttempt += 1;
- reconnectTimer = setTimeout(() => {
- void connectStreamInternal(environmentId, generation);
- }, delay);
+ clearReconnectTimerInternal(environmentId);
+ const delay = Math.min(1000 * 2 ** attempt, MAX_RECONNECT_DELAY);
+ reconnectAttempts.set(environmentId, attempt + 1);
+ reconnectTimers.set(
+ environmentId,
+ setTimeout(() => {
+ void connectStreamInternal(environmentId, generation);
+ }, delay)
+ );
}
- function restartForEnvironmentInternal(environmentId: string) {
- streamGeneration += 1;
- abortStreamInternal();
- resetEnvironmentStateInternal(environmentId);
- const generation = streamGeneration;
- void refreshInternal(environmentId, generation);
+ function startEnvironmentInternal(environment: Pick<Environment, 'id' | 'name'>) {
+ const environmentId = environment.id || LOCAL_DOCKER_ENVIRONMENT_ID;
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ id: environmentId,
+ name: environmentNameInternal(environment)
+ }));
+
+ const generation = nextGenerationInternal(environmentId);
+ reconnectAttempts.set(environmentId, 0);
+ abortEnvironmentStreamInternal(environmentId);
+ void refreshEnvironmentInternal(environmentId, generation);
void connectStreamInternal(environmentId, generation);
}
+ function restartEnvironmentInternal(environmentId: string) {
+ const state = environmentStateInternal(environmentId);
+ if (!state) {
+ return;
+ }
+
+ clearEnvironmentErrorInternal(environmentId);
+ startEnvironmentInternal({ id: state.id, name: state.name });
+ }
+
+ function reconcileEnvironmentsInternal() {
+ if (!browser || !started) {
+ return;
+ }
+
+ const available = environmentStore.available;
+ const environments =
+ available.length > 0
+ ? available
+ : [
+ {
+ id: environmentStore.selected?.id ?? LOCAL_DOCKER_ENVIRONMENT_ID,
+ name: environmentStore.selected?.name ?? 'Local'
+ }
+ ];
+ const targetIds = new Set(environments.map((environment) => environment.id || LOCAL_DOCKER_ENVIRONMENT_ID));
+
+ for (const environmentId of Object.keys(_environmentStates)) {
+ if (!targetIds.has(environmentId)) {
+ stopEnvironmentInternal(environmentId);
+ }
+ }
+
+ for (const environment of environments) {
+ const environmentId = environment.id || LOCAL_DOCKER_ENVIRONMENT_ID;
+ const existing = environmentStateInternal(environmentId);
+ if (!existing) {
+ _environmentStates = {
+ ..._environmentStates,
+ [environmentId]: createEnvironmentStateInternal(environment)
+ };
+ startEnvironmentInternal(environment);
+ continue;
+ }
+
+ if (existing.name !== environmentNameInternal(environment)) {
+ const updatedActivities = (_environmentActivities[environmentId] ?? existing.activities).map((activity) =>
+ activity.sourceEnvironmentName
+ ? activity
+ : {
+ ...activity,
+ sourceEnvironmentName: environmentNameInternal(environment)
+ }
+ );
+ _environmentActivities = {
+ ..._environmentActivities,
+ [environmentId]: updatedActivities
+ };
+ updateEnvironmentStateInternal(environmentId, (state) => ({
+ ...state,
+ name: environmentNameInternal(environment),
+ activities: updatedActivities
+ }));
+ rebuildActivitiesInternal();
+ }
+ }
+ }
+
+ function activityEnvironmentIdInternal(activityId: string): string {
+ const activity = _details[activityId]?.activity ?? _activities.find((item) => item.id === activityId) ?? null;
+ return sourceEnvironmentIdInternal(activity) || _currentEnvironmentId || LOCAL_DOCKER_ENVIRONMENT_ID;
+ }
+
async function loadDetailInternal(activityId: string) {
if (_details[activityId] || _detailLoadingIds[activityId]) {
return;
@@ -287,8 +533,17 @@ function createActivityStore() {
_detailLoadingIds = { ..._detailLoadingIds, [activityId]: true };
try {
- const detail = await activityService.getActivity(activityId, _currentEnvironmentId, ACTIVITY_DETAIL_LIMIT);
- _details = { ..._details, [activityId]: detail };
+ const detail = await activityService.getActivity(
+ activityId,
+ activityEnvironmentIdInternal(activityId),
+ ACTIVITY_DETAIL_LIMIT
+ );
+ const environmentId = sourceEnvironmentIdInternal(detail.activity);
+ const normalized = {
+ ...detail,
+ activity: normalizeActivityInternal(detail.activity, environmentId)
+ };
+ _details = { ..._details, [activityId]: normalized };
const nextErrors = { ..._detailErrorIds };
delete nextErrors[activityId];
_detailErrorIds = nextErrors;
@@ -327,6 +582,16 @@ function createActivityStore() {
setActivityExpanded(activityId, !_expandedActivityIds[activityId]);
}
+ function environmentFailuresInternal(): ActivityEnvironmentFailure[] {
+ return Object.values(_environmentStates)
+ .filter((state) => state.streamError)
+ .map((state) => ({
+ environmentId: state.id,
+ environmentName: state.name,
+ message: state.errorMessage
+ }));
+ }
+
return {
get activities(): Activity[] {
return _activities;
@@ -344,13 +609,16 @@ function createActivityStore() {
return _open;
},
get loading(): boolean {
- return _loading;
+ return Object.values(_environmentStates).some((state) => state.loading);
},
get connected(): boolean {
- return _connected;
+ return Object.values(_environmentStates).some((state) => state.connected);
},
get streamError(): boolean {
- return _streamError;
+ return Object.values(_environmentStates).some((state) => state.streamError);
+ },
+ get environmentFailures(): ActivityEnvironmentFailure[] {
+ return environmentFailuresInternal();
},
get currentEnvironmentId(): string {
return _currentEnvironmentId;
@@ -384,17 +652,22 @@ function createActivityStore() {
started = true;
await environmentStore.ready;
- restartForEnvironmentInternal(environmentStore.selected?.id ?? LOCAL_DOCKER_ENVIRONMENT_ID);
+ _currentEnvironmentId = environmentStore.selected?.id ?? LOCAL_DOCKER_ENVIRONMENT_ID;
+ reconcileEnvironmentsInternal();
unsubscribeEnvironment = environmentStore.subscribeSelected((environment) => {
- restartForEnvironmentInternal(environment?.id ?? LOCAL_DOCKER_ENVIRONMENT_ID);
+ _currentEnvironmentId = environment?.id ?? LOCAL_DOCKER_ENVIRONMENT_ID;
+ reconcileEnvironmentsInternal();
});
},
stop: () => {
started = false;
unsubscribeEnvironment?.();
unsubscribeEnvironment = null;
- streamGeneration += 1;
- abortStreamInternal();
+
+ for (const environmentId of Object.keys(_environmentStates)) {
+ nextGenerationInternal(environmentId);
+ abortEnvironmentStreamInternal(environmentId);
+ }
},
refresh: () => refreshInternal(),
cancelActivity: async (activityId: string) => {
@@ -405,20 +678,47 @@ function createActivityStore() {
try {
// The cancelled status arrives via the stream (mergeActivityInternal);
// callers handle success/error toasts.
- await activityService.cancelActivity(activityId, _currentEnvironmentId);
+ await activityService.cancelActivity(activityId, activityEnvironmentIdInternal(activityId));
} finally {
const next = { ..._cancellingIds };
delete next[activityId];
_cancellingIds = next;
}
},
- clearHistory: async () => {
- await activityService.clearHistory(_currentEnvironmentId);
+ clearHistory: async (): Promise<ActivityClearHistorySummary> => {
+ reconcileEnvironmentsInternal();
+
+ let deleted = 0;
+ let succeeded = 0;
+ const failed: ActivityEnvironmentFailure[] = [];
+ const states = Object.values(_environmentStates);
+ await Promise.all(
+ states.map(async (state) => {
+ try {
+ const result = await activityService.clearHistory(state.id);
+ deleted += result.deleted ?? 0;
+ succeeded += 1;
+ } catch (error) {
+ failed.push({
+ environmentId: state.id,
+ environmentName: state.name,
+ message: errorMessageInternal(error)
+ });
+ }
+ })
+ );
+
_details = {};
_expandedActivityIds = {};
_detailLoadingIds = {};
_detailErrorIds = {};
await refreshInternal();
+
+ return {
+ deleted,
+ succeeded,
+ failed
+ };
},
setFilter: (filter: ActivityFilter) => {
_filter = filter;
@@ -442,9 +742,12 @@ function createActivityStore() {
void loadDetailInternal(activityId);
},
retryStream: () => {
- _streamError = false;
- reconnectAttempt = 0;
- restartForEnvironmentInternal(_currentEnvironmentId);
+ for (const environmentId of Object.keys(_environmentStates)) {
+ const state = environmentStateInternal(environmentId);
+ if (state?.streamError) {
+ restartEnvironmentInternal(environmentId);
+ }
+ }
},
setActivityExpanded,
toggleActivity
diff --git a/frontend/src/lib/types/activity.type.ts b/frontend/src/lib/types/activity.type.ts
index 8c2a8a571..3fd0b69ef 100644
--- a/frontend/src/lib/types/activity.type.ts
+++ b/frontend/src/lib/types/activity.type.ts
@@ -72,6 +72,18 @@ export interface ActivityClearHistoryResult {
deleted: number;
}
+export interface ActivityEnvironmentFailure {
+ environmentId: string;
+ environmentName: string;
+ message?: string;
+}
+
+export interface ActivityClearHistorySummary {
+ deleted: number;
+ succeeded: number;
+ failed: ActivityEnvironmentFailure[];
+}
+
export interface ActivityStreamEvent {
type: 'snapshot' | 'activity' | 'message' | 'heartbeat';
activityId?: string;
diff --git a/tests/spec/activity-center.spec.ts b/tests/spec/activity-center.spec.ts
index ccf1d7a38..4fd42aeee 100644
--- a/tests/spec/activity-center.spec.ts
+++ b/tests/spec/activity-center.spec.ts
@@ -1,4 +1,157 @@
-import { test, expect, type Page } from '@playwright/test';
+import { test, expect, type Locator, type Page, type Route } from '@playwright/test';
+
+type MockEnvironment = {
+ id: string;
+ name: string;
+ apiUrl: string;
+ status: 'online' | 'standby' | 'offline' | 'error' | 'pending';
+ enabled: boolean;
+ isEdge: boolean;
+};
+
+type MockActivity = {
+ id: string;
+ environmentId: string;
+ sourceEnvironmentId?: string;
+ sourceEnvironmentName?: string;
+ type: string;
+ status: string;
+ resourceType?: string;
+ resourceId?: string;
+ resourceName?: string;
+ latestMessage?: string;
+ startedAt: string;
+ createdAt: string;
+ updatedAt?: string;
+};
+
+const localEnvironment: MockEnvironment = {
+ id: '0',
+ name: 'Local',
+ apiUrl: 'unix:///var/run/docker.sock',
+ status: 'online',
+ enabled: true,
+ isEdge: false
+};
+
+const remoteEnvironment: MockEnvironment = {
+ id: 'remote-activity-test',
+ name: 'Remote Lab',
+ apiUrl: 'https://remote.example.invalid',
+ status: 'offline',
+ enabled: false,
+ isEdge: false
+};
+
+function paginated<T>(data: T[]) {
+ return {
+ success: true,
+ data,
+ pagination: {
+ totalPages: 1,
+ totalItems: data.length,
+ currentPage: 1,
+ itemsPerPage: data.length,
+ grandTotalItems: data.length
+ }
+ };
+}
+
+function activity(
+ id: string,
+ environmentId: string,
+ sourceEnvironmentName: string,
+ resourceName: string,
+ minutesAgo: number
+): MockActivity {
+ const timestamp = new Date(Date.now() - minutesAgo * 60_000).toISOString();
+ return {
+ id,
+ environmentId,
+ sourceEnvironmentId: environmentId,
+ sourceEnvironmentName,
+ type: 'resource_action',
+ status: 'success',
+ resourceType: 'network',
+ resourceId: resourceName,
+ resourceName,
+ latestMessage: `${resourceName} completed`,
+ startedAt: timestamp,
+ createdAt: timestamp,
+ updatedAt: timestamp
+ };
+}
+
+function activityEnvironmentIdFromPath(pathname: string): string | null {
+ const match = pathname.match(/^\/api\/environments\/([^/]+)\/activities(?:\/stream)?$/);
+ return match ? decodeURIComponent(match[1]) : null;
+}
+
+async function preserveLocalEnvironmentSelection(page: Page) {
+ await page.addInitScript(() => {
+ localStorage.removeItem('selectedEnvironmentId');
+ });
+}
+
+async function mockEnvironmentList(page: Page, environments: MockEnvironment[]) {
+ await page.context().route(/\/api\/environments(?:\?.*)?$/, async (route) => {
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify(paginated(environments))
+ });
+ });
+}
+
+async function mockActivityReads(
+ page: Page,
+ activitiesByEnvironment: Record<string, MockActivity[]>,
+ failedEnvironmentIds = new Set<string>()
+) {
+ await page
+ .context()
+ .route(
+ /\/api\/environments\/[^/]+\/activities(?:\/stream)?(?:\?.*)?$/,
+ async (route: Route) => {
+ const url = new URL(route.request().url());
+ const environmentId = activityEnvironmentIdFromPath(url.pathname);
+ if (!environmentId) {
+ await route.continue();
+ return;
+ }
+
+ if (failedEnvironmentIds.has(environmentId)) {
+ await route.fulfill({
+ status: 503,
+ contentType: 'application/json',
+ body: JSON.stringify({ success: false, message: 'environment unavailable' })
+ });
+ return;
+ }
+
+ const activities = activitiesByEnvironment[environmentId] ?? [];
+ if (url.pathname.endsWith('/stream')) {
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/x-json-stream',
+ body:
+ JSON.stringify({
+ type: 'snapshot',
+ activities,
+ timestamp: new Date().toISOString()
+ }) + '\n'
+ });
+ return;
+ }
+
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify(paginated(activities))
+ });
+ }
+ );
+}
function extractActivityId(value: unknown): string | undefined {
if (!value || typeof value !== 'object') return undefined;
@@ -76,7 +229,127 @@ async function openActivityCenter(page: Page) {
return activityCenter;
}
+function activityRow(activityCenter: Locator, text: string) {
+ return activityCenter
+ .locator('button[aria-label="Activity Center"]')
+ .filter({ hasText: text })
+ .first();
+}
+
+function waitForActivityList(page: Page, environmentId: string) {
+ return page.waitForResponse((response) => {
+ const url = new URL(response.url());
+ return (
+ response.request().method() === 'GET' &&
+ url.pathname === `/api/environments/${encodeURIComponent(environmentId)}/activities`
+ );
+ });
+}
+
test.describe('Activity Center', () => {
+ test('shows activity from every configured environment', async ({ page }) => {
+ await preserveLocalEnvironmentSelection(page);
+ await mockEnvironmentList(page, [localEnvironment, remoteEnvironment]);
+ await mockActivityReads(page, {
+ '0': [activity('local-activity', '0', 'Local', 'local-network', 5)],
+ 'remote-activity-test': [
+ activity('remote-activity', 'remote-activity-test', 'Remote Lab', 'remote-network', 1)
+ ]
+ });
+
+ const localActivityList = waitForActivityList(page, '0');
+ const remoteActivityList = waitForActivityList(page, 'remote-activity-test');
+ await page.goto('/dashboard');
+ await Promise.all([localActivityList, remoteActivityList]);
+ await page.waitForLoadState('load');
+ await page.waitForLoadState('networkidle');
+
+ const activityCenter = await openActivityCenter(page);
+ await activityCenter.getByRole('button', { name: 'Completed' }).click();
+
+ await expect(activityRow(activityCenter, 'local-network')).toBeVisible();
+ await expect(activityRow(activityCenter, 'remote-network')).toBeVisible();
+ await expect(activityCenter.getByText('Local').first()).toBeVisible();
+ await expect(activityCenter.getByText('Remote Lab').first()).toBeVisible();
+ await expect(page.getByRole('button', { name: /Local/ }).first()).toBeVisible();
+ });
+
+ test('keeps reachable activity visible when a configured environment fails', async ({ page }) => {
+ await preserveLocalEnvironmentSelection(page);
+ await mockEnvironmentList(page, [localEnvironment, remoteEnvironment]);
+ await mockActivityReads(
+ page,
+ {
+ '0': [activity('local-activity', '0', 'Local', 'local-network', 5)]
+ },
+ new Set(['remote-activity-test'])
+ );
+
+ const localActivityList = waitForActivityList(page, '0');
+ const remoteActivityList = waitForActivityList(page, 'remote-activity-test');
+ await page.goto('/dashboard');
+ await Promise.all([localActivityList, remoteActivityList]);
+ await page.waitForLoadState('load');
+ await page.waitForLoadState('networkidle');
+
+ const activityCenter = await openActivityCenter(page);
+ await activityCenter.getByRole('button', { name: 'Completed' }).click();
+
+ await expect(activityRow(activityCenter, 'local-network')).toBeVisible();
+ await expect(activityCenter.getByText('Could not load activity from Remote Lab')).toBeVisible();
+ });
+
+ test('clears history for every configured environment and reports partial failures', async ({
+ page
+ }) => {
+ await preserveLocalEnvironmentSelection(page);
+ await mockEnvironmentList(page, [localEnvironment, remoteEnvironment]);
+ await mockActivityReads(page, {
+ '0': [activity('local-activity', '0', 'Local', 'local-network', 5)],
+ 'remote-activity-test': [
+ activity('remote-activity', 'remote-activity-test', 'Remote Lab', 'remote-network', 1)
+ ]
+ });
+
+ const deletedEnvironments: string[] = [];
+ await page.route(/\/api\/environments\/[^/]+\/activities\/history$/, async (route) => {
+ const url = new URL(route.request().url());
+ const match = url.pathname.match(/^\/api\/environments\/([^/]+)\/activities\/history$/);
+ const environmentId = match ? decodeURIComponent(match[1]) : '';
+ deletedEnvironments.push(environmentId);
+
+ if (environmentId === 'remote-activity-test') {
+ await route.fulfill({
+ status: 503,
+ contentType: 'application/json',
+ body: JSON.stringify({ success: false, message: 'environment unavailable' })
+ });
+ return;
+ }
+
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify({ success: true, data: { deleted: 2 } })
+ });
+ });
+
+ const localActivityList = waitForActivityList(page, '0');
+ const remoteActivityList = waitForActivityList(page, 'remote-activity-test');
+ await page.goto('/dashboard');
+ await Promise.all([localActivityList, remoteActivityList]);
+ await page.waitForLoadState('load');
+
+ const activityCenter = await openActivityCenter(page);
+ await activityCenter.getByRole('button', { name: 'Clear history' }).click();
+ await page.getByRole('button', { name: 'Clear History', exact: true }).last().click();
+
+ await expect.poll(() => deletedEnvironments.sort()).toEqual(['0', 'remote-activity-test']);
+ await expect(
+ page.getByText('Activity history partially cleared. Succeeded for 1. Failed for Remote Lab.')
+ ).toBeVisible();
+ });
+
test('shows completed activity details for UI-triggered work', async ({ page }) => {
const networkName = `e2e-activity-network-${Date.now()}`;
let networkId: string | undefined;