Skip to content

Modern Docker Management, Designed for Everyone

feat: rework activity center ui/ux and backend lifecycle (#3313)

Kyle Mendelldd3336a32849
diff --git a/backend/api/api.go b/backend/api/api.go
index e89e93791..aba6ef39b 100644
--- a/backend/api/api.go
+++ b/backend/api/api.go
@@ -202,6 +202,7 @@ func SetupAPI(e *echo.Echo, apiGroup *echo.Group, appCtx handlers.ActivityAppCon
// Add authentication middleware
api.UseMiddleware(middleware.NewAuthBridge(api, svc.Auth, svc.ApiKey, svc.Role, svc.Environment, cfg))
+ api.UseMiddleware(middleware.NewActivityBatchID())
// Register all Huma handlers
registerHandlersInternal(api, svc, appCtx, cfg)
diff --git a/backend/api/handlers/activities.go b/backend/api/handlers/activities.go
index fef0d68d4..8da4790c1 100644
--- a/backend/api/handlers/activities.go
+++ b/backend/api/handlers/activities.go
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
+ "hash/fnv"
"io"
"net/http"
"net/url"
@@ -438,9 +439,38 @@ func activityStreamEnvironmentVersionInternal(environment models.Environment) st
return environment.ID + ":" + environment.UpdatedAt.UTC().Format(time.RFC3339Nano)
}
+// activitySnapshotFingerprintInternal hashes the fields that affect what the
+// client renders, so a poller can skip re-sending a snapshot identical to the
+// previous one.
+func activitySnapshotFingerprintInternal(items []activity.Activity) string {
+ hash := fnv.New64a()
+ writeField := func(value string) {
+ _, _ = hash.Write([]byte(value))
+ _, _ = hash.Write([]byte{0})
+ }
+ for _, item := range items {
+ writeField(item.ID)
+ writeField(string(item.Status))
+ if item.Progress != nil {
+ writeField(strconv.Itoa(*item.Progress))
+ }
+ writeField(item.Step)
+ writeField(item.LatestMessage)
+ if item.UpdatedAt != nil {
+ writeField(item.UpdatedAt.UTC().Format(time.RFC3339Nano))
+ }
+ if item.EndedAt != nil {
+ writeField(item.EndedAt.UTC().Format(time.RFC3339Nano))
+ }
+ writeField("|")
+ }
+ return strconv.FormatUint(hash.Sum64(), 16)
+}
+
func (h *ActivityHandler) runRemoteActivityStreamPollerInternal(ctx context.Context, environment models.Environment, limit int, events chan<- activity.StreamEvent) {
environmentID := environment.ID
lastError := ""
+ lastFingerprint := ""
poll := func() {
pollCtx, cancelPoll := context.WithTimeout(ctx, activityStreamRemotePollTimeout)
@@ -475,15 +505,23 @@ func (h *ActivityHandler) runRemoteActivityStreamPollerInternal(ctx context.Cont
Timestamp: time.Now(),
})
}
+ // Force a resync once the environment recovers.
+ lastFingerprint = ""
return
}
lastError = ""
- agg.Send(ctx, events, activity.StreamEvent{
+ fingerprint := activitySnapshotFingerprintInternal(output.Body.Data)
+ if fingerprint == lastFingerprint {
+ return
+ }
+ if agg.Send(ctx, events, activity.StreamEvent{
Type: "snapshot",
EnvironmentID: environmentID,
Activities: output.Body.Data,
Timestamp: time.Now(),
- })
+ }) {
+ lastFingerprint = fingerprint
+ }
}
poll()
diff --git a/backend/api/handlers/activities_test.go b/backend/api/handlers/activities_test.go
index 1ec2cf3b0..8a879d3c3 100644
--- a/backend/api/handlers/activities_test.go
+++ b/backend/api/handlers/activities_test.go
@@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
+ "fmt"
"io"
"net/http"
"net/http/httptest"
@@ -36,10 +37,24 @@ func setupActivityHandlerTestDBInternal(t *testing.T) *database.DB {
return &database.DB{DB: db}
}
+func TestActivitySnapshotFingerprintDetectsChangesInternal(t *testing.T) {
+ progress := 10
+ items := []activity.Activity{
+ {ID: "a-1", Status: activity.StatusRunning, Progress: &progress, Step: "pull"},
+ {ID: "a-2", Status: activity.StatusSuccess},
+ }
+ base := activitySnapshotFingerprintInternal(items)
+ require.Equal(t, base, activitySnapshotFingerprintInternal(items))
+
+ bumped := 20
+ items[0].Progress = &bumped
+ require.NotEqual(t, base, activitySnapshotFingerprintInternal(items))
+}
+
func TestActivityHandlerClearHistoryDeletesSelectedEnvironmentOnlyInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityHandlerTestDBInternal(t)
- activityService := services.NewActivityService(db)
+ activityService := services.NewActivityService(db, nil)
handler := &ActivityHandler{activityService: activityService}
completed, err := activityService.StartActivity(ctx, services.StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
@@ -173,7 +188,7 @@ func TestActivityHandlerStreamAllEmitsEnvironmentScopedEventsInternal(t *testing
limitStreamTestDBToSingleConnInternal(t, db)
settingsService, err := services.NewSettingsService(ctx, db)
require.NoError(t, err)
- activityService := services.NewActivityService(db)
+ activityService := services.NewActivityService(db, settingsService)
local, err := activityService.StartActivity(ctx, services.StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
require.NoError(t, err)
@@ -219,7 +234,7 @@ func TestActivityHandlerStreamAllReusesRemoteEnvironmentAfterInitialPollInternal
limitStreamTestDBToSingleConnInternal(t, db)
settingsService, err := services.NewSettingsService(ctx, db)
require.NoError(t, err)
- activityService := services.NewActivityService(db)
+ activityService := services.NewActivityService(db, settingsService)
var countEnvironmentQueries atomic.Bool
var environmentQueryCount atomic.Int64
@@ -230,9 +245,13 @@ func TestActivityHandlerStreamAllReusesRemoteEnvironmentAfterInitialPollInternal
}))
token := "remote-token"
+ // Vary the payload per poll so snapshot fingerprint suppression does not
+ // swallow the follow-up snapshots this test waits for.
+ var pollCount atomic.Int64
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"success":true,"data":[{"id":"remote-activity-1"}],"pagination":{"totalPages":1,"totalItems":1,"currentPage":1,"itemsPerPage":50}}`))
+ payload := fmt.Sprintf(`{"success":true,"data":[{"id":"remote-activity-1","latestMessage":"poll-%d"}],"pagination":{"totalPages":1,"totalItems":1,"currentPage":1,"itemsPerPage":50}}`, pollCount.Add(1))
+ _, _ = w.Write([]byte(payload))
}))
defer server.Close()
createStreamTestRemoteEnvironmentInternal(t, db, "remote-1", "Remote", server.URL, token)
@@ -281,7 +300,7 @@ func TestActivityHandlerStreamAllRemoteFailureEmitsErrorAndKeepsStreamingInterna
limitStreamTestDBToSingleConnInternal(t, db)
settingsService, err := services.NewSettingsService(ctx, db)
require.NoError(t, err)
- activityService := services.NewActivityService(db)
+ activityService := services.NewActivityService(db, settingsService)
token := "remote-token"
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -318,7 +337,7 @@ func TestActivityHandlerStreamAllFiltersUnauthorizedEnvironmentsInternal(t *test
limitStreamTestDBToSingleConnInternal(t, db)
settingsService, err := services.NewSettingsService(ctx, db)
require.NoError(t, err)
- activityService := services.NewActivityService(db)
+ activityService := services.NewActivityService(db, settingsService)
_, err = activityService.StartActivity(ctx, services.StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
require.NoError(t, err)
diff --git a/backend/api/handlers/containers.go b/backend/api/handlers/containers.go
index 01a7b9f73..e66fb4fb9 100644
--- a/backend/api/handlers/containers.go
+++ b/backend/api/handlers/containers.go
@@ -811,7 +811,8 @@ func (h *ContainerHandler) RedeployContainer(ctx context.Context, input *Contain
}
runtimeCtx := utils.ActivityRuntimeContext(ctx, h.appCtx)
- activityID, runtimeCtx := activitylib.StartHandlerActivityForUser(runtimeCtx, h.activityService, input.EnvironmentID, models.ActivityTypeContainerRedeploy, "container", input.ContainerID, input.ContainerID, user, "Starting redeploy", "Container redeploy requested", models.JSON{"containerID": input.ContainerID})
+ activityID, runtimeCtx := activitylib.StartQueuedHandlerActivityForUser(runtimeCtx, h.activityService, input.EnvironmentID, models.ActivityTypeContainerRedeploy, "container", input.ContainerID, input.ContainerID, user, "Starting redeploy", "Container redeploy requested", models.JSON{"containerID": input.ContainerID})
+ activitylib.AwaitHandlerActivitySlot(runtimeCtx, h.activityService, activityID, input.EnvironmentID)
activityWriter := activitylib.NewWriter(runtimeCtx, h.activityService, activityID, io.Discard, "Redeploying container")
redeployCtx := context.WithValue(runtimeCtx, projects.ProgressWriterKey{}, activityWriter)
newContainerID, err := h.containerService.RedeployContainer(redeployCtx, input.ContainerID, *user)
diff --git a/backend/api/handlers/images.go b/backend/api/handlers/images.go
index d86a9e08f..5e63960d9 100644
--- a/backend/api/handlers/images.go
+++ b/backend/api/handlers/images.go
@@ -703,7 +703,7 @@ func (h *ImageHandler) PullImage(ctx context.Context, input *PullImageInput) (*h
runtimeCtx := utils.ActivityRuntimeContext(humaCtx.Context(), h.appCtx)
rawWriter := humaCtx.BodyWriter()
- activityID, runtimeCtx := activitylib.StartHandlerActivityForUser(
+ activityID, runtimeCtx := activitylib.StartQueuedHandlerActivityForUser(
runtimeCtx,
h.activityService,
input.EnvironmentID,
@@ -720,6 +720,7 @@ func (h *ImageHandler) PullImage(ctx context.Context, input *PullImageInput) (*h
if f, ok := rawWriter.(http.Flusher); ok {
f.Flush()
}
+ activitylib.AwaitHandlerActivitySlot(runtimeCtx, h.activityService, activityID, input.EnvironmentID)
writer := activitylib.NewWriter(runtimeCtx, h.activityService, activityID, rawWriter, "Pulling image")
if err := h.imageService.PullImage(runtimeCtx, fullImageName, writer, *user, credentials); err != nil {
@@ -759,7 +760,7 @@ func (h *ImageHandler) BuildImage(ctx context.Context, input *BuildImageInput) (
if strings.TrimSpace(resourceName) == "" {
resourceName = input.Body.ContextDir
}
- activityID, runtimeCtx := activitylib.StartHandlerActivityForUser(
+ activityID, runtimeCtx := activitylib.StartQueuedHandlerActivityForUser(
runtimeCtx,
h.activityService,
input.EnvironmentID,
@@ -776,6 +777,7 @@ func (h *ImageHandler) BuildImage(ctx context.Context, input *BuildImageInput) (
if f, ok := rawWriter.(http.Flusher); ok {
f.Flush()
}
+ activitylib.AwaitHandlerActivitySlot(runtimeCtx, h.activityService, activityID, input.EnvironmentID)
writer := activitylib.NewWriter(runtimeCtx, h.activityService, activityID, rawWriter, "Building image")
if _, err := h.buildService.BuildImage(runtimeCtx, input.EnvironmentID, input.Body, writer, "", user); err != nil {
diff --git a/backend/api/handlers/projects.go b/backend/api/handlers/projects.go
index e4e9691af..b9e3a863a 100644
--- a/backend/api/handlers/projects.go
+++ b/backend/api/handlers/projects.go
@@ -588,7 +588,7 @@ func (h *ProjectHandler) DeployProject(ctx context.Context, input *DeployProject
runtimeCtx := utils.ActivityRuntimeContext(humaCtx.Context(), h.appCtx)
rawWriter := humaCtx.BodyWriter()
- activityID, runtimeCtx := activitylib.StartHandlerActivityForUser(
+ activityID, runtimeCtx := activitylib.StartQueuedHandlerActivityForUser(
runtimeCtx,
h.activityService,
input.EnvironmentID,
@@ -605,6 +605,7 @@ func (h *ProjectHandler) DeployProject(ctx context.Context, input *DeployProject
if f, ok := rawWriter.(http.Flusher); ok {
f.Flush()
}
+ activitylib.AwaitHandlerActivitySlot(runtimeCtx, h.activityService, activityID, input.EnvironmentID)
writer := activitylib.NewWriter(runtimeCtx, h.activityService, activityID, rawWriter, "Deploying project")
_, _ = writer.Write([]byte(`{"type":"deploy","phase":"begin"}` + "\n"))
@@ -1088,8 +1089,11 @@ type projectActivityActionConfigInternal struct {
FailureMessage string
SuccessComplete string
SuccessMessage string
- Action func(context.Context, string, models.User) error
- Error func(error) error
+ // Queue routes the activity through the per-environment concurrency
+ // limiter; set for long-running deploy-like actions, not quick restarts.
+ Queue bool
+ Action func(context.Context, string, models.User) error
+ Error func(error) error
}
func (h *ProjectHandler) redeployProjectActivityConfigInternal(options *project.DeployOptions) projectActivityActionConfigInternal {
@@ -1101,6 +1105,7 @@ func (h *ProjectHandler) redeployProjectActivityConfigInternal(options *project.
FailureMessage: "Project redeploy failed",
SuccessComplete: "Project redeploy completed",
SuccessMessage: "Project redeployed successfully",
+ Queue: true,
Action: func(runtimeCtx context.Context, projectID string, user models.User) error {
return h.projectService.RedeployProject(runtimeCtx, projectID, user, options)
},
@@ -1119,6 +1124,7 @@ func (h *ProjectHandler) updateProjectServicesActivityConfigInternal(services []
FailureMessage: "Project services update failed",
SuccessComplete: "Project services updated",
SuccessMessage: "Project services updated successfully",
+ Queue: true,
Action: func(runtimeCtx context.Context, projectID string, user models.User) error {
return h.projectService.UpdateProjectServices(runtimeCtx, projectID, services, user)
},
@@ -1187,7 +1193,13 @@ func (h *ProjectHandler) runProjectActivityActionInternal(ctx context.Context, e
}
runtimeCtx := utils.ActivityRuntimeContext(ctx, h.appCtx)
- activityID, runtimeCtx := activitylib.StartHandlerActivityForUser(runtimeCtx, h.activityService, environmentID, cfg.ActivityType, "project", projectID, projectID, user, cfg.Step, cfg.StartMessage, models.JSON{"projectID": projectID})
+ var activityID string
+ if cfg.Queue {
+ activityID, runtimeCtx = activitylib.StartQueuedHandlerActivityForUser(runtimeCtx, h.activityService, environmentID, cfg.ActivityType, "project", projectID, projectID, user, cfg.Step, cfg.StartMessage, models.JSON{"projectID": projectID})
+ activitylib.AwaitHandlerActivitySlot(runtimeCtx, h.activityService, activityID, environmentID)
+ } else {
+ activityID, runtimeCtx = activitylib.StartHandlerActivityForUser(runtimeCtx, h.activityService, environmentID, cfg.ActivityType, "project", projectID, projectID, user, cfg.Step, cfg.StartMessage, models.JSON{"projectID": projectID})
+ }
activityWriter := activitylib.NewWriter(runtimeCtx, h.activityService, activityID, io.Discard, cfg.WriterStep)
actionCtx := context.WithValue(runtimeCtx, projects.ProgressWriterKey{}, activityWriter)
if err := cfg.Action(actionCtx, projectID, *user); err != nil {
@@ -1280,7 +1292,7 @@ func (h *ProjectHandler) PullProjectImages(ctx context.Context, input *PullProje
runtimeCtx := utils.ActivityRuntimeContext(humaCtx.Context(), h.appCtx)
rawWriter := humaCtx.BodyWriter()
- activityID, runtimeCtx := activitylib.StartHandlerActivityForUser(
+ activityID, runtimeCtx := activitylib.StartQueuedHandlerActivityForUser(
runtimeCtx,
h.activityService,
input.EnvironmentID,
@@ -1294,6 +1306,7 @@ func (h *ProjectHandler) PullProjectImages(ctx context.Context, input *PullProje
models.JSON{"projectID": input.ProjectID},
)
activitylib.WriteStartedLine(rawWriter, activityID)
+ activitylib.AwaitHandlerActivitySlot(runtimeCtx, h.activityService, activityID, input.EnvironmentID)
writer := activitylib.NewWriter(runtimeCtx, h.activityService, activityID, rawWriter, "Pulling project images")
_, _ = writer.Write([]byte(`{"status":"starting project image pull"}` + "\n"))
@@ -1349,7 +1362,7 @@ func (h *ProjectHandler) BuildProjectImages(ctx context.Context, input *BuildPro
runtimeCtx := utils.ActivityRuntimeContext(humaCtx.Context(), h.appCtx)
rawWriter := humaCtx.BodyWriter()
- activityID, runtimeCtx := activitylib.StartHandlerActivityForUser(
+ activityID, runtimeCtx := activitylib.StartQueuedHandlerActivityForUser(
runtimeCtx,
h.activityService,
input.EnvironmentID,
@@ -1363,6 +1376,7 @@ func (h *ProjectHandler) BuildProjectImages(ctx context.Context, input *BuildPro
models.JSON{"projectID": input.ProjectID, "services": options.Services},
)
activitylib.WriteStartedLine(rawWriter, activityID)
+ activitylib.AwaitHandlerActivitySlot(runtimeCtx, h.activityService, activityID, input.EnvironmentID)
writer := activitylib.NewWriter(runtimeCtx, h.activityService, activityID, rawWriter, "Building project images")
_, _ = writer.Write([]byte(`{"type":"build","phase":"begin"}` + "\n"))
diff --git a/backend/api/middleware/activity_batch.go b/backend/api/middleware/activity_batch.go
new file mode 100644
index 000000000..03243c179
--- /dev/null
+++ b/backend/api/middleware/activity_batch.go
@@ -0,0 +1,22 @@
+package middleware
+
+import (
+ "strings"
+
+ "github.com/danielgtaylor/huma/v2"
+
+ pkgutils "github.com/getarcaneapp/arcane/backend/v2/pkg/utils"
+)
+
+// NewActivityBatchID lifts the client-supplied activity batch ID header into
+// the request context so activities spawned by one logical bulk action can be
+// grouped without threading the ID through every handler. Invalid values are
+// ignored by utils.WithActivityBatchID.
+func NewActivityBatchID() func(ctx huma.Context, next func(huma.Context)) {
+ return func(ctx huma.Context, next func(huma.Context)) {
+ if batchID := strings.TrimSpace(ctx.Header(pkgutils.HeaderActivityBatchID)); batchID != "" {
+ ctx = huma.WithContext(ctx, pkgutils.WithActivityBatchID(ctx.Context(), batchID))
+ }
+ next(ctx)
+ }
+}
diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.go
index fc0ebec83..d6c35985d 100644
--- a/backend/internal/bootstrap/jobs_bootstrap.go
+++ b/backend/internal/bootstrap/jobs_bootstrap.go
@@ -31,6 +31,13 @@ func registerJobs(appCtx context.Context, newScheduler *scheduler.JobScheduler,
} else if resolved > 0 {
slog.InfoContext(appCtx, "Resolved stale auto-update activities", "count", resolved)
}
+
+ orphaned, err := appServices.Activity.ResolveOrphanedQueuedActivities(appCtx)
+ if err != nil {
+ slog.WarnContext(appCtx, "Failed to resolve orphaned queued activities", "count", orphaned, "error", err)
+ } else if orphaned > 0 {
+ slog.InfoContext(appCtx, "Resolved orphaned queued activities", "count", orphaned)
+ }
}
// Finalize a fleet-wide update-all job whose manager self-upgrade restarted the
diff --git a/backend/internal/configschema/schema_test.go b/backend/internal/configschema/schema_test.go
index 08460dc79..42d0b5255 100644
--- a/backend/internal/configschema/schema_test.go
+++ b/backend/internal/configschema/schema_test.go
@@ -310,6 +310,7 @@ var expectedSettingOverrideKeys = []string{
"lifecycleDefaultRunnerImage",
"lifecycleEnabled",
"lifecycleMaxTimeoutSec",
+ "maxConcurrentActivities",
"maxImageUploadSize",
"mobileNavigationMode",
"mobileNavigationShowLabels",
diff --git a/backend/internal/database/database_test.go b/backend/internal/database/database_test.go
index 3a2d10f7f..cf8ad4916 100644
--- a/backend/internal/database/database_test.go
+++ b/backend/internal/database/database_test.go
@@ -113,6 +113,32 @@ func TestMigration066_GlobalVariables_UpAndDown(t *testing.T) {
assert.Zero(t, rowCount)
}
+func TestMigration067_ActivityBatchID_UpAndDown(t *testing.T) {
+ ctx := context.Background()
+ rawDB, _ := newSQLiteSQLDBInternal(t, t.TempDir(), "arcane-activity-batch-id.db")
+
+ require.NoError(t, migrateDatabaseToVersionInternal(ctx, rawDB, dbProviderSQLite, MigrationOptions{}, 66))
+ var columnCount int
+ require.NoError(t, rawDB.QueryRow(`SELECT COUNT(*) FROM pragma_table_info('activities') WHERE name = 'batch_id'`).Scan(&columnCount))
+ assert.Zero(t, columnCount)
+
+ require.NoError(t, migrateDatabaseToVersionInternal(ctx, rawDB, dbProviderSQLite, MigrationOptions{}, 67))
+ var notNull int
+ require.NoError(t, rawDB.QueryRow(`SELECT COUNT(*), COALESCE(MAX("notnull"), 0) FROM pragma_table_info('activities') WHERE name = 'batch_id'`).Scan(&columnCount, &notNull))
+ assert.Equal(t, 1, columnCount)
+ assert.Zero(t, notNull)
+
+ var indexCount int
+ require.NoError(t, rawDB.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type = 'index' AND name = 'idx_activities_environment_batch'`).Scan(&indexCount))
+ assert.Equal(t, 1, indexCount)
+
+ require.NoError(t, migrateDatabaseToVersionInternal(ctx, rawDB, dbProviderSQLite, MigrationOptions{AllowDowngrade: true}, 66))
+ require.NoError(t, rawDB.QueryRow(`SELECT COUNT(*) FROM pragma_table_info('activities') WHERE name = 'batch_id'`).Scan(&columnCount))
+ assert.Zero(t, columnCount)
+ require.NoError(t, rawDB.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type = 'index' AND name = 'idx_activities_environment_batch'`).Scan(&indexCount))
+ assert.Zero(t, indexCount)
+}
+
func TestMigrateDatabase_BlocksFutureGooseVersionWithoutFlag(t *testing.T) {
ctx := context.Background()
rawDB, dsn := newSQLiteSQLDBInternal(t, t.TempDir(), "arcane-future.db")
diff --git a/backend/internal/di/wire_gen.go b/backend/internal/di/wire_gen.go
index b550840e6..650b92cc9 100644
--- a/backend/internal/di/wire_gen.go
+++ b/backend/internal/di/wire_gen.go
@@ -37,7 +37,7 @@ func InitializeServices(ctx context.Context, db *database.DB, cfg *config.Config
apiKeyService := provideApiKeyServiceInternal(db, userService, roleService)
environmentService := services.NewEnvironmentService(db, httpClient, dockerClientService, eventService, settingsService, apiKeyService)
notificationService := services.NewNotificationService(db, cfg, environmentService, eventService)
- activityService := services.NewActivityService(db)
+ activityService := services.NewActivityService(db, settingsService)
imageUpdateService := services.NewImageUpdateService(db, settingsService, containerRegistryService, dockerClientService, eventService, notificationService, activityService)
vulnerabilityService := services.NewVulnerabilityService(db, dockerClientService, eventService, settingsService, notificationService, activityService, containerRegistryService)
imageService := services.NewImageService(db, dockerClientService, containerRegistryService, imageUpdateService, vulnerabilityService, eventService)
diff --git a/backend/internal/models/activity.go b/backend/internal/models/activity.go
index 0400d1b88..1a3a0eb5f 100644
--- a/backend/internal/models/activity.go
+++ b/backend/internal/models/activity.go
@@ -52,6 +52,7 @@ type Activity struct {
BaseModel
EnvironmentID string `json:"environmentId" gorm:"column:environment_id;not null;index" sortable:"true"`
+ BatchID *string `json:"batchId,omitempty" gorm:"column:batch_id;index"`
Type ActivityType `json:"type" gorm:"column:type;not null;index" sortable:"true"`
Status ActivityStatus `json:"status" gorm:"column:status;not null;index" sortable:"true"`
ResourceType *string `json:"resourceType,omitempty" gorm:"column:resource_type;index" sortable:"true"`
diff --git a/backend/internal/models/settings.go b/backend/internal/models/settings.go
index c263ee981..fb97df6e9 100644
--- a/backend/internal/models/settings.go
+++ b/backend/internal/models/settings.go
@@ -93,6 +93,7 @@ type Settings struct {
ExpiredSessionsCleanupInterval SettingVariable `key:"expiredSessionsCleanupInterval" meta:"label=Expired Sessions Cleanup Interval;type=cron;keywords=sessions,cleanup,retention,expired,revoked,interval,frequency,schedule,auth,jobs;description=How often to delete expired and old revoked sessions (cron expression)"`
ActivityHistoryRetentionDays SettingVariable `key:"activityHistoryRetentionDays" meta:"label=Activity History Retention;type=number;keywords=activity,history,retention,days,cleanup,background,tasks;category=activity;description=Delete completed Activity Center entries older than this many days. Set 0 to disable age-based cleanup." catmeta:"id=activity;title=Activity;icon=activity;url=/settings/activity;description=Configure Activity Center history and cleanup"`
ActivityHistoryMaxEntries SettingVariable `key:"activityHistoryMaxEntries" meta:"label=Activity History Limit;type=number;keywords=activity,history,limit,entries,count,cleanup,background,tasks;category=activity;description=Maximum completed Activity Center entries to keep per environment. Set 0 to disable count-based cleanup."`
+ MaxConcurrentActivities SettingVariable `key:"maxConcurrentActivities" meta:"label=Concurrent Activity Limit;type=number;keywords=activity,concurrency,limit,queue,parallel,bulk,background,tasks;category=activity;description=Maximum long-running activities per environment before new ones queue. Set 0 for unlimited."`
AutoInjectEnv SettingVariable `key:"autoInjectEnv" meta:"label=Auto Inject Env Variables;type=boolean;keywords=auto,inject,env,environment,variables,interpolation;category=internal;description=Automatically inject project .env variables into all containers (default: false)"`
DefaultDeployPullPolicy SettingVariable `key:"defaultDeployPullPolicy" meta:"label=Default Deploy Pull Policy;type=select;keywords=deploy,pull,policy,compose,up,missing,always;category=internal;description=Default image pull policy when deploying projects"`
ScheduledPruneEnabled SettingVariable `key:"scheduledPruneEnabled" meta:"label=Scheduled Prune Enabled;type=boolean;keywords=prune,cleanup,maintenance,schedule,automatic;category=internal;description=Enable scheduled pruning of unused Docker resources"`
diff --git a/backend/internal/services/activity_limiter.go b/backend/internal/services/activity_limiter.go
new file mode 100644
index 000000000..66bb57bac
--- /dev/null
+++ b/backend/internal/services/activity_limiter.go
@@ -0,0 +1,123 @@
+package services
+
+import (
+ "context"
+ "sync"
+ "time"
+)
+
+const (
+ maxConcurrentActivitiesSettingKey = "maxConcurrentActivities"
+ defaultMaxConcurrentActivities = 5
+ // slotWaitRecheckInterval bounds how long a queued waiter can miss a limit
+ // increase made while no slots were being released.
+ slotWaitRecheckInterval = 2 * time.Second
+)
+
+// activitySlotLimiter bounds how many queue-opted activities run concurrently
+// per environment. The limit is read from settings on every acquisition
+// attempt, while held slots are counted independently of it — so changing the
+// limit mid-flight never miscounts running work: existing holders keep
+// occupying capacity until they release, and waiters are re-evaluated against
+// the new limit.
+type activitySlotLimiter struct {
+ settings *SettingsService
+
+ mu sync.Mutex
+ state map[string]*activityEnvironmentSlots
+}
+
+type activityEnvironmentSlots struct {
+ held int
+ // wake is closed (and replaced) on every release to broadcast to waiters;
+ // each re-checks against the current limit, so a raised limit can admit
+ // more than one of them.
+ wake chan struct{}
+}
+
+func newActivitySlotLimiterInternal(settings *SettingsService) *activitySlotLimiter {
+ return &activitySlotLimiter{
+ settings: settings,
+ state: map[string]*activityEnvironmentSlots{},
+ }
+}
+
+func (l *activitySlotLimiter) limitInternal(ctx context.Context) int {
+ return l.settings.GetIntSetting(ctx, maxConcurrentActivitiesSettingKey, defaultMaxConcurrentActivities)
+}
+
+func (l *activitySlotLimiter) stateForLockedInternal(environmentID string) *activityEnvironmentSlots {
+ slots := l.state[environmentID]
+ if slots == nil {
+ slots = &activityEnvironmentSlots{wake: make(chan struct{})}
+ l.state[environmentID] = slots
+ }
+ return slots
+}
+
+// tryAcquireInternal grabs a slot without blocking; ok=false means the caller
+// should queue and block via acquireInternal. Held slots are counted even
+// while the limit is unlimited, so enabling a limit later still sees the work
+// already running.
+func (l *activitySlotLimiter) tryAcquireInternal(ctx context.Context, environmentID string) (func(), bool) {
+ if l == nil || l.settings == nil {
+ return func() {}, true
+ }
+ limit := l.limitInternal(ctx)
+
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ slots := l.stateForLockedInternal(environmentID)
+ if limit > 0 && slots.held >= limit {
+ return nil, false
+ }
+ slots.held++
+ return l.releaseOnceInternal(environmentID), true
+}
+
+// acquireInternal blocks until a slot frees or ctx is cancelled. The limit is
+// re-read on every attempt so setting changes apply to queued waiters.
+func (l *activitySlotLimiter) acquireInternal(ctx context.Context, environmentID string) (func(), error) {
+ if l == nil || l.settings == nil {
+ return func() {}, nil
+ }
+
+ for {
+ limit := l.limitInternal(ctx)
+ l.mu.Lock()
+ slots := l.stateForLockedInternal(environmentID)
+ if limit <= 0 || slots.held < limit {
+ slots.held++
+ l.mu.Unlock()
+ return l.releaseOnceInternal(environmentID), nil
+ }
+ wake := slots.wake
+ l.mu.Unlock()
+
+ timer := time.NewTimer(slotWaitRecheckInterval)
+ select {
+ case <-wake:
+ case <-timer.C:
+ case <-ctx.Done():
+ timer.Stop()
+ return nil, context.Cause(ctx)
+ }
+ timer.Stop()
+ }
+}
+
+func (l *activitySlotLimiter) releaseOnceInternal(environmentID string) func() {
+ var once sync.Once
+ return func() {
+ once.Do(func() {
+ l.mu.Lock()
+ slots := l.stateForLockedInternal(environmentID)
+ if slots.held > 0 {
+ slots.held--
+ }
+ close(slots.wake)
+ slots.wake = make(chan struct{})
+ l.mu.Unlock()
+ })
+ }
+}
diff --git a/backend/internal/services/activity_service.go b/backend/internal/services/activity_service.go
index 51e3881b5..a8a325e8e 100644
--- a/backend/internal/services/activity_service.go
+++ b/backend/internal/services/activity_service.go
@@ -39,27 +39,150 @@ type ActivityService struct {
// are added by Track and removed when the activity is completed.
runningMu sync.Mutex
running map[string]context.CancelCauseFunc
+
+ // limiter bounds concurrent queue-opted activities per environment.
+ // slotReleases maps an activity ID to the release func of the slot it
+ // holds; the slot is freed when the activity completes.
+ limiter *activitySlotLimiter
+ slotMu sync.Mutex
+ slotReleases map[string]func()
}
// ErrActivityNotCancelable indicates the activity has already reached a terminal
// state and can no longer be cancelled.
var ErrActivityNotCancelable = errors.New("activity is not cancelable")
+// subscriberMessageQueueLimit bounds the per-subscriber backlog of "message"
+// events; the oldest message is dropped (and flagged as missed) on overflow.
+const subscriberMessageQueueLimit = 256
+
+// activitySubscriber buffers stream events between publishers and one stream
+// consumer. "activity" events are coalesced in place per activity ID (only the
+// latest pending state matters to the UI), so bulk operations emitting rapid
+// progress updates cannot overflow the subscriber and force full-snapshot
+// resends. Other events keep arrival order in a FIFO bounded by
+// subscriberMessageQueueLimit with drop-oldest on overflow.
type activitySubscriber struct {
environmentID string
ch chan activitytypes.StreamEvent
- missedEvents bool
+ done chan struct{}
+ wake chan struct{}
+
+ mu sync.Mutex
+ missed bool
+ queue []*pendingStreamEvent
+ pendingActivity map[string]*pendingStreamEvent
+ messageCount int
+}
+
+type pendingStreamEvent struct {
+ event activitytypes.StreamEvent
+}
+
+func newActivitySubscriberInternal(environmentID string, ch chan activitytypes.StreamEvent) *activitySubscriber {
+ return &activitySubscriber{
+ environmentID: environmentID,
+ ch: ch,
+ done: make(chan struct{}),
+ wake: make(chan struct{}, 1),
+ pendingActivity: map[string]*pendingStreamEvent{},
+ }
+}
+
+func isCoalescableEventInternal(event activitytypes.StreamEvent) bool {
+ return event.Type == "activity" && event.ActivityID != ""
+}
+
+func (sub *activitySubscriber) enqueue(event activitytypes.StreamEvent) {
+ sub.mu.Lock()
+ if isCoalescableEventInternal(event) {
+ if pending, ok := sub.pendingActivity[event.ActivityID]; ok {
+ pending.event = event
+ sub.mu.Unlock()
+ return
+ }
+ } else {
+ if sub.messageCount >= subscriberMessageQueueLimit {
+ sub.dropOldestMessageLockedInternal()
+ }
+ sub.messageCount++
+ }
+ entry := &pendingStreamEvent{event: event}
+ sub.queue = append(sub.queue, entry)
+ if isCoalescableEventInternal(event) {
+ sub.pendingActivity[event.ActivityID] = entry
+ }
+ sub.mu.Unlock()
+
+ select {
+ case sub.wake <- struct{}{}:
+ default:
+ }
+}
+
+func (sub *activitySubscriber) dropOldestMessageLockedInternal() {
+ for i, entry := range sub.queue {
+ if !isCoalescableEventInternal(entry.event) {
+ sub.queue = append(sub.queue[:i], sub.queue[i+1:]...)
+ sub.messageCount--
+ sub.missed = true
+ slog.Warn("activity subscriber message buffer full; snapshot will be sent on next heartbeat", "environmentId", sub.environmentID)
+ return
+ }
+ }
+}
+
+func (sub *activitySubscriber) nextInternal() (activitytypes.StreamEvent, bool) {
+ sub.mu.Lock()
+ defer sub.mu.Unlock()
+
+ if len(sub.queue) == 0 {
+ return activitytypes.StreamEvent{}, false
+ }
+ entry := sub.queue[0]
+ sub.queue = sub.queue[1:]
+ event := entry.event
+ if isCoalescableEventInternal(event) {
+ if sub.pendingActivity[event.ActivityID] == entry {
+ delete(sub.pendingActivity, event.ActivityID)
+ }
+ } else {
+ sub.messageCount--
+ }
+ return event, true
+}
+
+func (sub *activitySubscriber) pump() {
+ defer close(sub.ch)
+ for {
+ event, ok := sub.nextInternal()
+ if !ok {
+ select {
+ case <-sub.wake:
+ continue
+ case <-sub.done:
+ return
+ }
+ }
+ select {
+ case sub.ch <- event:
+ case <-sub.done:
+ return
+ }
+ }
}
type StartActivityRequest = activitylib.StartRequest
type UpdateActivityRequest = activitylib.UpdateRequest
type AppendActivityMessageRequest = activitylib.AppendMessageRequest
-func NewActivityService(db *database.DB) *ActivityService {
+func NewActivityService(db *database.DB, settingsService *SettingsService) *ActivityService {
return &ActivityService{
- db: db,
- subscribers: map[int]*activitySubscriber{},
- running: map[string]context.CancelCauseFunc{},
+ db: db,
+ subscribers: map[int]*activitySubscriber{},
+ running: map[string]context.CancelCauseFunc{},
+ limiter: newActivitySlotLimiterInternal(settingsService),
+ slotReleases: map[string]func(){},
}
}
@@ -153,10 +276,31 @@ func (s *ActivityService) StartActivity(ctx context.Context, req StartActivityRe
}
}
+ batchID := req.BatchID
+ if batchID == nil {
+ if contextBatchID := utils.ActivityBatchIDFromContext(ctx); contextBatchID != "" {
+ batchID = &contextBatchID
+ }
+ }
+
+ // Queue-opted activities take a concurrency slot up front when one is
+ // free; otherwise they are created as queued and AwaitActivitySlot blocks
+ // until a slot opens.
+ status := models.ActivityStatusRunning
+ var slotRelease func()
+ if req.Queue {
+ if release, ok := s.limiter.tryAcquireInternal(ctx, environmentID); ok {
+ slotRelease = release
+ } else {
+ status = models.ActivityStatusQueued
+ }
+ }
+
model := &models.Activity{
EnvironmentID: environmentID,
+ BatchID: copyPtrInternal(batchID),
Type: req.Type,
- Status: models.ActivityStatusRunning,
+ Status: status,
ResourceType: copyPtrInternal(req.ResourceType),
ResourceID: copyPtrInternal(req.ResourceID),
ResourceName: copyPtrInternal(req.ResourceName),
@@ -177,14 +321,81 @@ func (s *ActivityService) StartActivity(ctx context.Context, req StartActivityRe
}
if err := s.db.WithContext(ctx).Create(model).Error; err != nil {
+ if slotRelease != nil {
+ slotRelease()
+ }
return nil, fmt.Errorf("failed to create activity: %w", err)
}
+ if slotRelease != nil {
+ s.registerSlotReleaseInternal(model.ID, slotRelease)
+ }
dto := activityToDTOInternal(model)
s.publishActivityInternal(dto)
return &dto, nil
}
+func (s *ActivityService) registerSlotReleaseInternal(activityID string, release func()) {
+ s.slotMu.Lock()
+ if existing, ok := s.slotReleases[activityID]; ok {
+ existing()
+ }
+ s.slotReleases[activityID] = release
+ s.slotMu.Unlock()
+}
+
+func (s *ActivityService) releaseSlotInternal(activityID string) {
+ if s == nil {
+ return
+ }
+ s.slotMu.Lock()
+ release, ok := s.slotReleases[activityID]
+ if ok {
+ delete(s.slotReleases, activityID)
+ }
+ s.slotMu.Unlock()
+ if ok {
+ release()
+ }
+}
+
+// AwaitActivitySlot blocks until the queued activity holds a concurrency slot,
+// then flips its status to running. It returns immediately when the activity
+// already took a slot at creation. On cancellation the context cause is
+// returned and the activity stays queued for its caller to finalize.
+// Implements activitylib.SlotWaiter.
+func (s *ActivityService) AwaitActivitySlot(ctx context.Context, activityID, environmentID string) error {
+ if err := s.checkInitInternal(); err != nil {
+ return err
+ }
+ activityID = strings.TrimSpace(activityID)
+ if activityID == "" {
+ return errors.New("activity id is required")
+ }
+ environmentID = strings.TrimSpace(environmentID)
+ if environmentID == "" {
+ environmentID = "0"
+ }
+
+ s.slotMu.Lock()
+ _, held := s.slotReleases[activityID]
+ s.slotMu.Unlock()
+ if held {
+ return nil
+ }
+
+ release, err := s.limiter.acquireInternal(ctx, environmentID)
+ if err != nil {
+ return err
+ }
+ s.registerSlotReleaseInternal(activityID, release)
+
+ if _, updateErr := s.UpdateActivity(ctx, activityID, UpdateActivityRequest{Status: models.ActivityStatusRunning}); updateErr != nil {
+ slog.Warn("failed to mark queued activity running", "activityId", activityID, "error", updateErr)
+ }
+ return nil
+}
+
func (s *ActivityService) UpdateActivity(ctx context.Context, activityID string, req UpdateActivityRequest) (*activitytypes.Activity, error) {
if err := s.checkInitInternal(); err != nil {
return nil, err
@@ -325,8 +536,10 @@ func (s *ActivityService) CompleteActivity(ctx context.Context, activityID strin
return nil, errors.New("activity id is required")
}
- // The activity is reaching a terminal state; release any cancel registration.
+ // The activity is reaching a terminal state; release any cancel
+ // registration and free its concurrency slot.
s.releaseCancelInternal(activityID)
+ s.releaseSlotInternal(activityID)
// Detach from cancellation so the terminal write always lands — completion is
// often triggered precisely because the work context was cancelled.
@@ -491,6 +704,36 @@ func (s *ActivityService) FailStaleImageUpdateChecks(ctx context.Context) (int64
return failed, errors.Join(failErrs...)
}
+// ResolveOrphanedQueuedActivities fails any activity still queued at startup.
+// Queued state is owned by a live goroutine blocked on AwaitActivitySlot, so a
+// queued row after a restart can never start running.
+func (s *ActivityService) ResolveOrphanedQueuedActivities(ctx context.Context) (int64, error) {
+ if s == nil || s.db == nil {
+ return 0, nil
+ }
+
+ var queued []models.Activity
+ if err := s.db.WithContext(ctx).
+ Where("status = ?", models.ActivityStatusQueued).
+ Find(&queued).Error; err != nil {
+ return 0, fmt.Errorf("find orphaned queued activities: %w", err)
+ }
+
+ const message = "Queued activity was interrupted by an Arcane restart"
+ errMessage := message
+ var failed int64
+ var failErrs []error
+ for i := range queued {
+ if _, err := s.CompleteActivity(ctx, queued[i].ID, models.ActivityStatusFailed, message, &errMessage); err != nil {
+ failErrs = append(failErrs, fmt.Errorf("fail orphaned queued activity %s: %w", queued[i].ID, err))
+ continue
+ }
+ failed++
+ }
+
+ return failed, errors.Join(failErrs...)
+}
+
// PatchActivityMetadata merges patch into the activity's existing metadata,
// unlike UpdateActivity which replaces the metadata wholesale.
func (s *ActivityService) PatchActivityMetadata(ctx context.Context, activityID string, patch models.JSON) error {
@@ -612,9 +855,12 @@ func (s *ActivityService) ListActivitiesPaginated(ctx context.Context, environme
q = pagination.ApplyFilter(q, "resource_type", params.Filters["resourceType"])
if params.Sort == "" {
+ // Active rows sort by created_at (immutable) and terminal rows by ended_at
+ // (set once), so a row's position only changes on the active->terminal
+ // transition instead of on every progress update.
q = q.Order("CASE WHEN status IN ('queued', 'running') THEN 0 ELSE 1 END ASC").
- Order("COALESCE(updated_at, created_at) DESC").
- Order("started_at DESC")
+ Order("COALESCE(ended_at, created_at) DESC").
+ Order("id DESC")
}
paginationResp, err := pagination.PaginateAndSortDB(params, q, &activities)
@@ -752,31 +998,42 @@ func (s *ActivityService) Subscribe(environmentID string) (<-chan activitytypes.
environmentID = "0"
}
+ sub := newActivitySubscriberInternal(environmentID, ch)
s.subscribersMu.Lock()
s.nextSubID++
id := s.nextSubID
- s.subscribers[id] = &activitySubscriber{environmentID: environmentID, ch: ch}
+ s.subscribers[id] = sub
s.subscribersMu.Unlock()
+ go sub.pump()
missedEvents := func() bool {
- s.subscribersMu.Lock()
- defer s.subscribersMu.Unlock()
-
+ s.subscribersMu.RLock()
sub, ok := s.subscribers[id]
- if !ok || !sub.missedEvents {
+ s.subscribersMu.RUnlock()
+ if !ok {
+ return false
+ }
+
+ sub.mu.Lock()
+ defer sub.mu.Unlock()
+ if !sub.missed {
return false
}
- sub.missedEvents = false
+ sub.missed = false
return true
}
unsubscribe := func() {
s.subscribersMu.Lock()
- if sub, ok := s.subscribers[id]; ok {
+ sub, ok := s.subscribers[id]
+ if ok {
delete(s.subscribers, id)
- close(sub.ch)
}
s.subscribersMu.Unlock()
+ if ok {
+ // The pump goroutine owns ch and closes it on shutdown.
+ close(sub.done)
+ }
}
return ch, missedEvents, unsubscribe
@@ -804,20 +1061,18 @@ func (s *ActivityService) publishInternal(environmentID string, event activityty
if s == nil {
return
}
- s.subscribersMu.Lock()
- defer s.subscribersMu.Unlock()
-
+ s.subscribersMu.RLock()
+ subs := make([]*activitySubscriber, 0, len(s.subscribers))
for _, sub := range s.subscribers {
- if sub.environmentID != environmentID {
- continue
- }
- select {
- case sub.ch <- event:
- default:
- sub.missedEvents = true
- slog.Warn("activity subscriber event buffer full; snapshot will be sent on next heartbeat", "environmentId", environmentID, "eventType", event.Type)
+ if sub.environmentID == environmentID {
+ subs = append(subs, sub)
}
}
+ s.subscribersMu.RUnlock()
+
+ for _, sub := range subs {
+ sub.enqueue(event)
+ }
}
func activityToDTOInternal(model *models.Activity) activitytypes.Activity {
@@ -828,6 +1083,7 @@ func activityToDTOInternal(model *models.Activity) activitytypes.Activity {
ID: model.ID,
EnvironmentID: model.EnvironmentID,
SourceEnvironmentID: model.EnvironmentID,
+ BatchID: copyPtrInternal(model.BatchID),
Type: activitytypes.Type(model.Type),
Status: activitytypes.Status(model.Status),
ResourceType: copyPtrInternal(model.ResourceType),
diff --git a/backend/internal/services/activity_service_test.go b/backend/internal/services/activity_service_test.go
index 8a23a7299..83a6d8222 100644
--- a/backend/internal/services/activity_service_test.go
+++ b/backend/internal/services/activity_service_test.go
@@ -29,7 +29,7 @@ func setupActivityServiceTestDBInternal(t *testing.T) *database.DB {
func TestActivityServiceLifecycleInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
progress := 5
startedBy := &models.User{
@@ -95,7 +95,7 @@ func TestActivityServiceLifecycleInternal(t *testing.T) {
func TestActivityServiceStreamFanoutInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
events, _, unsubscribe := service.Subscribe("0")
defer unsubscribe()
@@ -129,7 +129,7 @@ func TestActivityServiceStreamFanoutInternal(t *testing.T) {
func TestActivityServiceRetentionCleanupInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
created, err := service.StartActivity(ctx, StartActivityRequest{
EnvironmentID: "0",
@@ -163,7 +163,7 @@ func TestActivityServiceRetentionCleanupInternal(t *testing.T) {
func TestActivityServicePruneHistoryZeroRetentionDisablesAgeCleanupInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
created, err := service.StartActivity(ctx, StartActivityRequest{
EnvironmentID: "0",
@@ -187,17 +187,18 @@ func TestActivityServicePruneHistoryZeroRetentionDisablesAgeCleanupInternal(t *t
}
func TestActivityServiceSubscribeMarksMissedEventsWhenBufferFullInternal(t *testing.T) {
- service := NewActivityService(nil)
+ service := NewActivityService(nil, nil)
events, missedEvents, unsubscribe := service.Subscribe("0")
defer unsubscribe()
- for i := 0; i < cap(events); i++ {
- service.publishInternal("0", activitytypes.StreamEvent{Type: "activity"})
+ // Message-type events are not coalesced; overflowing the delivery channel
+ // plus the bounded pending FIFO must flag missed events so the stream
+ // handler resends a snapshot.
+ total := cap(events) + subscriberMessageQueueLimit + 50
+ for range total {
+ service.publishInternal("0", activitytypes.StreamEvent{Type: "message"})
}
- require.False(t, missedEvents())
-
- service.publishInternal("0", activitytypes.StreamEvent{Type: "activity"})
require.True(t, missedEvents())
require.False(t, missedEvents())
}
@@ -205,7 +206,7 @@ func TestActivityServiceSubscribeMarksMissedEventsWhenBufferFullInternal(t *test
func TestActivityServiceDeleteHistoryPreservesActiveActivitiesInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
completed, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
require.NoError(t, err)
@@ -235,7 +236,7 @@ func TestActivityServiceDeleteHistoryPreservesActiveActivitiesInternal(t *testin
func TestActivityServicePruneHistoryByAgeAndCountInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
oldActivity, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeResourceAction})
require.NoError(t, err)
@@ -281,15 +282,199 @@ func TestActivityServicePruneHistoryByAgeAndCountInternal(t *testing.T) {
require.Zero(t, oldCount)
}
+func TestActivitySubscriberCoalescesProgressEventsInternal(t *testing.T) {
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db, nil)
+
+ events, missedEvents, unsubscribe := service.Subscribe("0")
+ defer unsubscribe()
+
+ const updates = 500
+ for i := 1; i <= updates; i++ {
+ progress := i * 100 / updates
+ service.publishActivityInternal(activitytypes.Activity{
+ ID: "act-1",
+ EnvironmentID: "0",
+ Status: activitytypes.StatusRunning,
+ Progress: &progress,
+ })
+ }
+
+ received := 0
+ deadline := time.After(5 * time.Second)
+ for {
+ select {
+ case event := <-events:
+ received++
+ require.Equal(t, "activity", event.Type)
+ if event.Activity != nil && event.Activity.Progress != nil && *event.Activity.Progress == 100 {
+ // The consumer was idle during publishing, so the backlog must
+ // have been coalesced instead of delivered event-for-event.
+ require.Less(t, received, updates)
+ require.False(t, missedEvents())
+ return
+ }
+ case <-deadline:
+ t.Fatal("did not receive final coalesced progress event")
+ }
+ }
+}
+
+func TestActivityServiceListOrderStableUnderProgressUpdatesInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupActivityServiceTestDBInternal(t)
+ service := NewActivityService(db, nil)
+
+ older, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull})
+ require.NoError(t, err)
+ newer, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull})
+ require.NoError(t, err)
+ require.NoError(t, db.Model(&models.Activity{}).Where("id = ?", older.ID).
+ Update("created_at", time.Now().Add(-time.Minute)).Error)
+
+ terminal, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull})
+ require.NoError(t, err)
+ _, err = service.CompleteActivity(ctx, terminal.ID, models.ActivityStatusSuccess, "done", nil)
+ require.NoError(t, err)
+
+ listIDs := func() []string {
+ list, _, listErr := service.ListActivitiesPaginated(ctx, "0", pagination.QueryParams{
+ Params: pagination.Params{Limit: 10},
+ })
+ require.NoError(t, listErr)
+ ids := make([]string, 0, len(list))
+ for _, item := range list {
+ ids = append(ids, item.ID)
+ }
+ return ids
+ }
+
+ expected := []string{newer.ID, older.ID, terminal.ID}
+ require.Equal(t, expected, listIDs())
+
+ progress := 50
+ _, err = service.UpdateActivity(ctx, older.ID, UpdateActivityRequest{Progress: &progress, LatestMessage: new("halfway")})
+ require.NoError(t, err)
+ require.Equal(t, expected, listIDs())
+}
+
+func setupQueuedActivityServiceInternal(t *testing.T) (*ActivityService, context.Context) {
+ t.Helper()
+ ctx := context.Background()
+
+ db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
+ require.NoError(t, err)
+ require.NoError(t, db.AutoMigrate(&models.Activity{}, &models.ActivityMessage{}, &models.SettingVariable{}))
+ wrapped := &database.DB{DB: db}
+
+ // Every extra pooled connection to a :memory: SQLite database is a fresh
+ // empty database; the await goroutine must see the same data.
+ sqlDB, err := db.DB()
+ require.NoError(t, err)
+ sqlDB.SetMaxOpenConns(1)
+
+ settings, err := NewSettingsService(ctx, wrapped)
+ require.NoError(t, err)
+ require.NoError(t, settings.SetIntSetting(ctx, maxConcurrentActivitiesSettingKey, 1))
+ return NewActivityService(wrapped, settings), ctx
+}
+
+func TestActivityServiceQueuedActivityFlipsToRunningWhenSlotFreesInternal(t *testing.T) {
+ service, ctx := setupQueuedActivityServiceInternal(t)
+
+ first, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull, Queue: true})
+ require.NoError(t, err)
+ require.Equal(t, "running", string(first.Status))
+
+ second, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull, Queue: true})
+ require.NoError(t, err)
+ require.Equal(t, "queued", string(second.Status))
+
+ awaitDone := make(chan error, 1)
+ go func() { awaitDone <- service.AwaitActivitySlot(ctx, second.ID, "0") }()
+
+ select {
+ case awaitErr := <-awaitDone:
+ t.Fatalf("await returned before the slot freed: %v", awaitErr)
+ case <-time.After(100 * time.Millisecond):
+ }
+
+ _, err = service.CompleteActivity(ctx, first.ID, models.ActivityStatusSuccess, "done", nil)
+ require.NoError(t, err)
+
+ select {
+ case awaitErr := <-awaitDone:
+ require.NoError(t, awaitErr)
+ case <-time.After(5 * time.Second):
+ t.Fatal("await did not acquire the freed slot")
+ }
+
+ var model models.Activity
+ require.NoError(t, service.db.First(&model, "id = ?", second.ID).Error)
+ require.Equal(t, models.ActivityStatusRunning, model.Status)
+}
+
+func TestActivityServiceLimitIncreaseKeepsCountingActiveSlotsInternal(t *testing.T) {
+ service, ctx := setupQueuedActivityServiceInternal(t)
+
+ running, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull, Queue: true})
+ require.NoError(t, err)
+ require.Equal(t, "running", string(running.Status))
+ waiting, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull, Queue: true})
+ require.NoError(t, err)
+ require.Equal(t, "queued", string(waiting.Status))
+
+ awaitDone := make(chan error, 1)
+ go func() { awaitDone <- service.AwaitActivitySlot(ctx, waiting.ID, "0") }()
+
+ // Raising the limit to 2 must admit the waiter while still counting the
+ // original holder, leaving no capacity for a third activity.
+ require.NoError(t, service.limiter.settings.SetIntSetting(ctx, maxConcurrentActivitiesSettingKey, 2))
+
+ select {
+ case awaitErr := <-awaitDone:
+ require.NoError(t, awaitErr)
+ case <-time.After(2 * slotWaitRecheckInterval):
+ t.Fatal("waiter was not admitted after the limit increase")
+ }
+
+ third, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull, Queue: true})
+ require.NoError(t, err)
+ require.Equal(t, "queued", string(third.Status))
+}
+
+func TestActivityServiceCancelWhileQueuedUnblocksAwaitInternal(t *testing.T) {
+ service, ctx := setupQueuedActivityServiceInternal(t)
+
+ _, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull, Queue: true})
+ require.NoError(t, err)
+ queued, err := service.StartActivity(ctx, StartActivityRequest{EnvironmentID: "0", Type: models.ActivityTypeImagePull, Queue: true})
+ require.NoError(t, err)
+ require.Equal(t, "queued", string(queued.Status))
+
+ workCtx := service.Track(ctx, queued.ID)
+ awaitDone := make(chan error, 1)
+ go func() { awaitDone <- service.AwaitActivitySlot(workCtx, queued.ID, "0") }()
+
+ require.True(t, service.RequestCancel(queued.ID))
+
+ select {
+ case awaitErr := <-awaitDone:
+ require.ErrorIs(t, awaitErr, activitylib.ErrCanceled)
+ case <-time.After(5 * time.Second):
+ t.Fatal("cancel did not unblock the queued slot wait")
+ }
+}
+
func TestActivityServiceCompleteActivityRejectsUninitializedServiceInternal(t *testing.T) {
- service := NewActivityService(nil)
+ service := NewActivityService(nil, nil)
_, err := service.CompleteActivity(context.Background(), "any-id", models.ActivityStatusSuccess, "done", nil)
require.Error(t, err)
}
func TestActivityServiceTrackAndRequestCancelInternal(t *testing.T) {
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
// Mirror the handler flow: work runs under an app-lifecycle runtime context.
appCtx := utils.WithAppLifecycleContext(context.Background())
@@ -325,7 +510,7 @@ func TestActivityServiceTrackAndRequestCancelInternal(t *testing.T) {
func TestActivityServiceCancelActivityInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
// An untracked running activity (e.g. after a restart) is finalized directly.
created, err := service.StartActivity(ctx, StartActivityRequest{
@@ -352,7 +537,7 @@ func TestActivityServiceCancelActivityInternal(t *testing.T) {
func TestActivityServiceFailStaleImageUpdateChecksInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
staleCheck, err := service.StartActivity(ctx, StartActivityRequest{
EnvironmentID: "0",
@@ -420,7 +605,7 @@ func TestActivityServiceFailStaleImageUpdateChecksInternal(t *testing.T) {
func TestActivityServiceResolveStaleAutoUpdateActivitiesInternal(t *testing.T) {
ctx := context.Background()
db := setupActivityServiceTestDBInternal(t)
- service := NewActivityService(db)
+ service := NewActivityService(db, nil)
selfUpdateRun, err := service.StartActivity(ctx, StartActivityRequest{
EnvironmentID: "0",
diff --git a/backend/internal/services/environment_service.go b/backend/internal/services/environment_service.go
index aabf6f9b4..70a6dc7c2 100644
--- a/backend/internal/services/environment_service.go
+++ b/backend/internal/services/environment_service.go
@@ -18,6 +18,7 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/timeouts"
"github.com/getarcaneapp/arcane/backend/v2/pkg/pagination"
"github.com/getarcaneapp/arcane/backend/v2/pkg/remenv"
+ pkgutils "github.com/getarcaneapp/arcane/backend/v2/pkg/utils"
httputils "github.com/getarcaneapp/arcane/backend/v2/pkg/utils/httpx"
"github.com/getarcaneapp/arcane/backend/v2/pkg/utils/mapper"
"github.com/getarcaneapp/arcane/types/v2/containerregistry"
@@ -1844,7 +1845,13 @@ func (s *EnvironmentService) executeRemoteRequestForTargetInternal(
path string,
body []byte,
) (*remenv.Response, error) {
- request, err := s.buildRemoteRequestInternal(target, method, path, body, nil)
+ // Forward the activity batch ID so bulk actions proxied to a remote
+ // environment group the same way they do locally.
+ var headers map[string]string
+ if batchID := pkgutils.ActivityBatchIDFromContext(ctx); batchID != "" {
+ headers = map[string]string{pkgutils.HeaderActivityBatchID: batchID}
+ }
+ request, err := s.buildRemoteRequestInternal(target, method, path, body, headers)
if err != nil {
return nil, err
}
diff --git a/backend/internal/services/image_update_service.go b/backend/internal/services/image_update_service.go
index 1de33a681..c3c071c8e 100644
--- a/backend/internal/services/image_update_service.go
+++ b/backend/internal/services/image_update_service.go
@@ -137,6 +137,7 @@ func (s *ImageUpdateService) startImageUpdateActivityInternal(ctx context.Contex
activity, err := s.activityService.StartActivity(ctx, StartActivityRequest{
EnvironmentID: "0",
Type: models.ActivityTypeImageUpdateCheck,
+ Queue: true,
ResourceType: &resourceType,
ResourceName: utils.StringPtrFromTrimmed(resourceName),
Step: "Checking image updates",
@@ -197,6 +198,7 @@ func (s *ImageUpdateService) CheckImageUpdate(ctx context.Context, imageRef stri
startTime := time.Now()
activityID := s.startImageUpdateActivityInternal(ctx, imageRef, 1)
ctx = s.activityService.Track(ctx, activityID)
+ activitylib.AwaitHandlerActivitySlot(ctx, s.activityService, activityID, "0")
if result, ok := digestPinnedImageUpdateResultInternal(imageRef); ok {
result.ResponseTimeMs = int(time.Since(startTime).Milliseconds())
@@ -1323,6 +1325,7 @@ func (s *ImageUpdateService) CheckMultipleImages(ctx context.Context, imageRefs
activityID := s.startImageUpdateActivityInternal(ctx, fmt.Sprintf("%d images", len(imageRefs)), len(imageRefs))
ctx = s.activityService.Track(ctx, activityID)
+ activitylib.AwaitHandlerActivitySlot(ctx, s.activityService, activityID, "0")
s.appendImageUpdateActivityMessageInternal(ctx, activityID, models.ActivityMessageLevelInfo, fmt.Sprintf("Checking %d image references", len(imageRefs)), 5, "Preparing image update check")
slog.DebugContext(ctx, "Starting batch image update check", "imageCount", len(imageRefs), "externalCredCount", len(externalCreds))
diff --git a/backend/internal/services/image_update_service_test.go b/backend/internal/services/image_update_service_test.go
index f0a26312e..2870db7c7 100644
--- a/backend/internal/services/image_update_service_test.go
+++ b/backend/internal/services/image_update_service_test.go
@@ -796,7 +796,7 @@ func TestImageUpdateService_CheckMultipleImagesCompletesActivityWhenRequestConte
db := setupImageUpdateTestDB(t)
require.NoError(t, db.AutoMigrate(&models.Activity{}, &models.ActivityMessage{}))
- activityService := NewActivityService(db)
+ activityService := NewActivityService(db, nil)
svc := NewImageUpdateService(db, nil, nil, nil, nil, nil, activityService)
for range 5 {
@@ -844,7 +844,7 @@ func TestImageUpdateService_CheckMultipleImagesTimesOutStalledRegistryCheckInter
require.NoError(t, db.AutoMigrate(&models.Activity{}, &models.ActivityMessage{}))
settingsService := newImageUpdateTestSettingsServiceInternal("1", "30")
- activityService := NewActivityService(db)
+ activityService := NewActivityService(db, nil)
dockerServer := newImageUpdateRegistryOnlyServer(t, "team/app:1.2.3", digest.FromString("unused").String())
defer dockerServer.Close()
registryService := NewContainerRegistryService(db, func(context.Context) (RegistryDaemonClient, error) {
diff --git a/backend/internal/services/job_service.go b/backend/internal/services/job_service.go
index b909a64d7..170dde666 100644
--- a/backend/internal/services/job_service.go
+++ b/backend/internal/services/job_service.go
@@ -192,64 +192,67 @@ func (s *JobService) RescheduleJobsForSettingKeys(ctx context.Context, changedKe
slog.DebugContext(ctx, "Skipping manager-only job reschedule in agent mode", "job", jobID)
continue
}
-
- // environment-health fans out to per-environment dynamic jobs; delegate the
- // reschedule to EnvironmentService instead of looking up a single job.
- if jobID == "environment-health" {
- if s.OnEnvironmentHealthReschedule != nil {
- reschedCtx := ctx //nolint:contextcheck // lifecycle context preferred so jobs outlive the request
- if s.lifecycleCtx != nil {
- reschedCtx = s.lifecycleCtx
- }
- s.OnEnvironmentHealthReschedule(reschedCtx)
- } else {
- rescheduleErrors = append(rescheduleErrors, errors.New("environment-health rescheduler not initialized"))
- }
- continue
+ if err := s.rescheduleAffectedJobInternal(ctx, jobID, jobMeta); err != nil {
+ rescheduleErrors = append(rescheduleErrors, err)
}
+ }
- // Continuous bus watchers have no cron entry to reschedule; notify the
- // watcher so it re-reads its poll schedule instead.
- if jobMeta.IsContinuous {
- if jobID == "image-polling" && s.settings != nil && s.settings.OnImagePollingSettingsChanged != nil {
- notifyCtx := ctx //nolint:contextcheck // lifecycle context preferred so the watcher outlives the request
- if s.lifecycleCtx != nil {
- notifyCtx = s.lifecycleCtx
- }
- s.settings.OnImagePollingSettingsChanged(notifyCtx)
- }
- continue
- }
+ return errors.Join(rescheduleErrors...)
+}
- job, ok := s.scheduler.GetJob(jobID)
- if !ok {
- rescheduleErrors = append(rescheduleErrors, fmt.Errorf("job %s not found in scheduler", jobID))
- continue
- }
+// jobRescheduleContextInternal prefers the app lifecycle context so cron jobs
+// and watchers outlive the HTTP request that triggered the reschedule.
+func (s *JobService) jobRescheduleContextInternal(ctx context.Context) context.Context {
+ if s.lifecycleCtx != nil {
+ return s.lifecycleCtx
+ }
+ return ctx
+}
- slog.DebugContext(ctx, "Processing job setting change", "job", jobID, "settingsKey", jobMeta.SettingsKey, "enabledKey", jobMeta.EnabledKey)
- rescheduleCtx := ctx //nolint:contextcheck // fallback only; lifecycle context is preferred so cron jobs outlive HTTP requests
- if s.lifecycleCtx != nil {
- rescheduleCtx = s.lifecycleCtx
- }
- if err := s.scheduler.RescheduleJob(rescheduleCtx, job); err != nil {
- rescheduleErrors = append(rescheduleErrors, fmt.Errorf("reschedule job %s: %w", jobID, err))
- continue
+// rescheduleAffectedJobInternal applies a settings change to one job:
+// delegated fan-out jobs and continuous bus watchers are notified, cron jobs
+// are rescheduled and their runtime schedule verified.
+func (s *JobService) rescheduleAffectedJobInternal(ctx context.Context, jobID string, jobMeta meta.JobMetadata) error {
+ // environment-health fans out to per-environment dynamic jobs; delegate the
+ // reschedule to EnvironmentService instead of looking up a single job.
+ if jobID == "environment-health" {
+ if s.OnEnvironmentHealthReschedule == nil {
+ return errors.New("environment-health rescheduler not initialized")
}
+ s.OnEnvironmentHealthReschedule(s.jobRescheduleContextInternal(ctx))
+ return nil
+ }
- runtimeState, ok := s.scheduler.GetJobRuntimeState(jobID)
- if !ok {
- rescheduleErrors = append(rescheduleErrors, fmt.Errorf("job %s has no runtime scheduler state", jobID))
- continue
+ // Continuous bus watchers have no cron entry to reschedule; notify the
+ // watcher so it re-reads its poll schedule instead.
+ if jobMeta.IsContinuous {
+ if jobID == "image-polling" && s.settings != nil && s.settings.OnImagePollingSettingsChanged != nil {
+ s.settings.OnImagePollingSettingsChanged(s.jobRescheduleContextInternal(ctx))
}
+ return nil
+ }
- expectedSchedule := job.Schedule(rescheduleCtx)
- if runtimeState.Schedule != expectedSchedule {
- rescheduleErrors = append(rescheduleErrors, fmt.Errorf("job %s runtime schedule %q does not match requested schedule %q", jobID, runtimeState.Schedule, expectedSchedule))
- }
+ job, ok := s.scheduler.GetJob(jobID)
+ if !ok {
+ return fmt.Errorf("job %s not found in scheduler", jobID)
}
- return errors.Join(rescheduleErrors...)
+ slog.DebugContext(ctx, "Processing job setting change", "job", jobID, "settingsKey", jobMeta.SettingsKey, "enabledKey", jobMeta.EnabledKey)
+ rescheduleCtx := s.jobRescheduleContextInternal(ctx)
+ if err := s.scheduler.RescheduleJob(rescheduleCtx, job); err != nil {
+ return fmt.Errorf("reschedule job %s: %w", jobID, err)
+ }
+
+ runtimeState, ok := s.scheduler.GetJobRuntimeState(jobID)
+ if !ok {
+ return fmt.Errorf("job %s has no runtime scheduler state", jobID)
+ }
+
+ expectedSchedule := job.Schedule(rescheduleCtx)
+ if runtimeState.Schedule != expectedSchedule {
+ return fmt.Errorf("job %s runtime schedule %q does not match requested schedule %q", jobID, runtimeState.Schedule, expectedSchedule)
+ }
+ return nil
}
func (s *JobService) restoreJobSchedulesInternal(ctx context.Context, previousValues map[string]string, changedKeys []string) error {
diff --git a/backend/internal/services/settings_service.go b/backend/internal/services/settings_service.go
index 8dabfd6a1..b8c9df693 100644
--- a/backend/internal/services/settings_service.go
+++ b/backend/internal/services/settings_service.go
@@ -122,6 +122,7 @@ func DefaultSettingsConfig() *models.Settings {
ExpiredSessionsCleanupInterval: models.SettingVariable{Value: "0 0 0 * * *"},
ActivityHistoryRetentionDays: models.SettingVariable{Value: "30"},
ActivityHistoryMaxEntries: models.SettingVariable{Value: "1000"},
+ MaxConcurrentActivities: models.SettingVariable{Value: "5"},
AutoInjectEnv: models.SettingVariable{Value: "false"},
DefaultDeployPullPolicy: models.SettingVariable{Value: "missing"},
ScheduledPruneEnabled: models.SettingVariable{Value: "false"},
diff --git a/backend/internal/services/updater_service.go b/backend/internal/services/updater_service.go
index a2c27303c..282805536 100644
--- a/backend/internal/services/updater_service.go
+++ b/backend/internal/services/updater_service.go
@@ -151,6 +151,7 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, options updater.Optio
out = &updater.Result{Items: []updater.ResourceResult{}, ActivityID: utils.StringPtrFromTrimmed(activityID)}
ctx = s.trackActivityInternal(ctx, activityID)
ctx = contextWithActivityIDInternal(ctx, activityID)
+ activitylib.AwaitHandlerActivitySlot(ctx, s.deps.Activity, activityID, "0")
defer func() {
if out == nil {
@@ -365,6 +366,7 @@ func (s *UpdaterService) UpdateSingleContainer(ctx context.Context, containerID
out = &updater.Result{Items: []updater.ResourceResult{}, ActivityID: utils.StringPtrFromTrimmed(activityID)}
ctx = s.trackActivityInternal(ctx, activityID)
ctx = contextWithActivityIDInternal(ctx, activityID)
+ activitylib.AwaitHandlerActivitySlot(ctx, s.deps.Activity, activityID, "0")
defer func() {
if out == nil {
@@ -759,6 +761,7 @@ func (s *UpdaterService) startAutoUpdateActivityInternal(ctx context.Context, dr
activity, err := s.deps.Activity.StartActivity(ctx, activitylib.StartRequest{
EnvironmentID: "0",
Type: models.ActivityTypeAutoUpdate,
+ Queue: true,
ResourceType: utils.StringPtrFromTrimmed("system"),
ResourceName: utils.StringPtrFromTrimmed("Auto update"),
Step: "Planning updates",
@@ -779,6 +782,7 @@ func (s *UpdaterService) startSingleContainerUpdateActivityInternal(ctx context.
activity, err := s.deps.Activity.StartActivity(ctx, activitylib.StartRequest{
EnvironmentID: "0",
Type: models.ActivityTypeAutoUpdate,
+ Queue: true,
ResourceType: utils.StringPtrFromTrimmed("container"),
ResourceID: &containerID,
ResourceName: utils.StringPtrFromTrimmed(containerID),
diff --git a/backend/pkg/libarcane/activity/handler.go b/backend/pkg/libarcane/activity/handler.go
index 88aa9dafe..3ef221888 100644
--- a/backend/pkg/libarcane/activity/handler.go
+++ b/backend/pkg/libarcane/activity/handler.go
@@ -40,6 +40,10 @@ type HandlerOptions struct {
Message string
SuccessMessage string
Metadata models.JSON
+ // Queue routes the activity through the per-environment concurrency
+ // limiter so bulk long-running operations wait visibly instead of all
+ // running at once. Quick actions (start/stop/delete) must not set this.
+ Queue bool
}
// StartHandlerActivityForUser creates a background activity and returns its ID
@@ -60,6 +64,63 @@ func StartHandlerActivityForUser(
step string,
message string,
metadata models.JSON,
+) (string, context.Context) {
+ return startHandlerActivityInternal(ctx, activityService, environmentID, activityType, resourceType, resourceID, resourceName, user, step, message, metadata, false)
+}
+
+// StartQueuedHandlerActivityForUser behaves like StartHandlerActivityForUser
+// but routes the activity through the per-environment concurrency limiter:
+// when no slot is free the activity is created with status queued. The caller
+// MUST call AwaitHandlerActivitySlot on the returned work context before doing
+// the actual work (streaming endpoints write their started line in between,
+// so the client learns the activity ID before the queue wait begins).
+func StartQueuedHandlerActivityForUser(
+ ctx context.Context,
+ activityService Service,
+ environmentID string,
+ activityType models.ActivityType,
+ resourceType string,
+ resourceID string,
+ resourceName string,
+ user *models.User,
+ step string,
+ message string,
+ metadata models.JSON,
+) (string, context.Context) {
+ return startHandlerActivityInternal(ctx, activityService, environmentID, activityType, resourceType, resourceID, resourceName, user, step, message, metadata, true)
+}
+
+// AwaitHandlerActivitySlot blocks until the queued activity holds a
+// concurrency slot (flipping it to running). A cancellation while waiting is
+// not an error to the caller: the work context is already cancelled, so the
+// subsequent action fails fast and CompleteHandlerActivity records the
+// cancelled status.
+func AwaitHandlerActivitySlot(ctx context.Context, activityService Service, activityID, environmentID string) {
+ if activityService == nil || strings.TrimSpace(activityID) == "" {
+ return
+ }
+ waiter, ok := activityService.(SlotWaiter)
+ if !ok {
+ return
+ }
+ if err := waiter.AwaitActivitySlot(ctx, activityID, environmentID); err != nil {
+ slog.DebugContext(ctx, "queued activity wait ended before acquiring a slot", "activityId", activityID, "error", err)
+ }
+}
+
+func startHandlerActivityInternal(
+ ctx context.Context,
+ activityService Service,
+ environmentID string,
+ activityType models.ActivityType,
+ resourceType string,
+ resourceID string,
+ resourceName string,
+ user *models.User,
+ step string,
+ message string,
+ metadata models.JSON,
+ queue bool,
) (string, context.Context) {
if activityService == nil {
return "", ctx
@@ -68,6 +129,7 @@ func StartHandlerActivityForUser(
activity, err := activityService.StartActivity(ctx, StartRequest{
EnvironmentID: environmentID,
Type: activityType,
+ Queue: queue,
ResourceType: utils.StringPtrFromTrimmed(resourceType),
ResourceID: utils.StringPtrFromTrimmed(resourceID),
ResourceName: utils.StringPtrFromTrimmed(resourceName),
@@ -121,7 +183,7 @@ func CompleteHandlerActivity(ctx context.Context, activityService Service, activ
// The action MUST use the provided context for its operation so cancellation
// propagates.
func RunHandlerActivity(ctx context.Context, activityService Service, opts HandlerOptions, action func(ctx context.Context) error) (string, error) {
- activityID, workCtx := StartHandlerActivityForUser(
+ activityID, workCtx := startHandlerActivityInternal(
ctx,
activityService,
opts.EnvironmentID,
@@ -133,7 +195,11 @@ func RunHandlerActivity(ctx context.Context, activityService Service, opts Handl
opts.Step,
opts.Message,
opts.Metadata,
+ opts.Queue,
)
+ if opts.Queue {
+ AwaitHandlerActivitySlot(workCtx, activityService, activityID, opts.EnvironmentID)
+ }
err := action(workCtx)
CompleteHandlerActivity(workCtx, activityService, activityID, opts.SuccessMessage, err)
diff --git a/backend/pkg/libarcane/activity/requests.go b/backend/pkg/libarcane/activity/requests.go
index 9bcd2f6c5..69a8b05cb 100644
--- a/backend/pkg/libarcane/activity/requests.go
+++ b/backend/pkg/libarcane/activity/requests.go
@@ -24,8 +24,25 @@ type Tracker interface {
Track(ctx context.Context, activityID string) context.Context
}
+// SlotWaiter is an optional interface a Service may implement to support
+// per-environment activity concurrency limiting. AwaitActivitySlot blocks
+// until the queued activity holds a slot (flipping its status to running), or
+// returns the context cause when the wait is cancelled. The slot is released
+// when the activity completes.
+type SlotWaiter interface {
+ AwaitActivitySlot(ctx context.Context, activityID, environmentID string) error
+}
+
type StartRequest struct {
EnvironmentID string
+ // BatchID groups activities spawned by one logical user action. When nil,
+ // the batch ID attached to the request context (if any) is used instead.
+ BatchID *string
+ // Queue routes the activity through the per-environment concurrency
+ // limiter: with a free slot it starts running as usual; otherwise it is
+ // created with status queued and the caller must block on
+ // SlotWaiter.AwaitActivitySlot before doing the work.
+ Queue bool
Type models.ActivityType
ResourceType *string
ResourceID *string
diff --git a/backend/pkg/utils/activity_context.go b/backend/pkg/utils/activity_context.go
index c13f3a666..b8ddc3fc9 100644
--- a/backend/pkg/utils/activity_context.go
+++ b/backend/pkg/utils/activity_context.go
@@ -2,11 +2,44 @@ package utils
import (
"context"
+ "regexp"
"time"
)
type appLifecycleContextKey struct{}
+type activityBatchIDContextKey struct{}
+
+var activityBatchIDPattern = regexp.MustCompile(`^[A-Za-z0-9_-]{1,64}$`)
+
+// ValidActivityBatchID reports whether id is safe to persist as a batch ID.
+func ValidActivityBatchID(id string) bool {
+ return activityBatchIDPattern.MatchString(id)
+}
+
+// WithActivityBatchID attaches a client-supplied batch ID that groups the
+// activities spawned by one logical user action (e.g. a bulk container
+// update). Invalid IDs are ignored.
+func WithActivityBatchID(ctx context.Context, batchID string) context.Context {
+ if ctx == nil {
+ ctx = context.Background()
+ }
+ if !ValidActivityBatchID(batchID) {
+ return ctx
+ }
+ return context.WithValue(ctx, activityBatchIDContextKey{}, batchID)
+}
+
+// ActivityBatchIDFromContext returns the batch ID attached by
+// WithActivityBatchID, or "" when none is set.
+func ActivityBatchIDFromContext(ctx context.Context) string {
+ if ctx == nil {
+ return ""
+ }
+ batchID, _ := ctx.Value(activityBatchIDContextKey{}).(string)
+ return batchID
+}
+
type activityRuntimeContext struct {
valueCtx context.Context
lifecycleCtx context.Context
diff --git a/backend/pkg/utils/auth.go b/backend/pkg/utils/auth.go
index ea01e29df..3e39fa289 100644
--- a/backend/pkg/utils/auth.go
+++ b/backend/pkg/utils/auth.go
@@ -4,8 +4,9 @@ package utils
// (WebSocket/diagnostics) and the Huma auth bridge (REST). Keep these in one
// place so a change to a header name applies to every route type at once.
const (
- HeaderAgentBootstrap = "X-Arcane-Agent-Bootstrap"
- HeaderAgentToken = "X-Arcane-Agent-Token" // #nosec G101: header name, not a credential
- HeaderApiKey = "X-Api-Key" // #nosec G101: header name, not a credential
- AgentPairingPrefix = "/api/environments/0/agent/pair"
+ HeaderAgentBootstrap = "X-Arcane-Agent-Bootstrap"
+ HeaderAgentToken = "X-Arcane-Agent-Token" // #nosec G101: header name, not a credential
+ HeaderApiKey = "X-Api-Key" // #nosec G101: header name, not a credential
+ HeaderActivityBatchID = "X-Arcane-Batch-Id"
+ AgentPairingPrefix = "/api/environments/0/agent/pair"
)
diff --git a/backend/resources/migrations/postgres/067_add_activity_batch_id.sql b/backend/resources/migrations/postgres/067_add_activity_batch_id.sql
new file mode 100644
index 000000000..530e3ded1
--- /dev/null
+++ b/backend/resources/migrations/postgres/067_add_activity_batch_id.sql
@@ -0,0 +1,8 @@
+-- +goose Up
+ALTER TABLE activities ADD COLUMN batch_id TEXT;
+
+CREATE INDEX idx_activities_environment_batch ON activities(environment_id, batch_id);
+
+-- +goose Down
+DROP INDEX IF EXISTS idx_activities_environment_batch;
+ALTER TABLE activities DROP COLUMN batch_id;
diff --git a/backend/resources/migrations/sqlite/067_add_activity_batch_id.sql b/backend/resources/migrations/sqlite/067_add_activity_batch_id.sql
new file mode 100644
index 000000000..530e3ded1
--- /dev/null
+++ b/backend/resources/migrations/sqlite/067_add_activity_batch_id.sql
@@ -0,0 +1,8 @@
+-- +goose Up
+ALTER TABLE activities ADD COLUMN batch_id TEXT;
+
+CREATE INDEX idx_activities_environment_batch ON activities(environment_id, batch_id);
+
+-- +goose Down
+DROP INDEX IF EXISTS idx_activities_environment_batch;
+ALTER TABLE activities DROP COLUMN batch_id;
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 3303020c6..01885a036 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -1937,9 +1937,31 @@
"activity_history_max_entries_description": "Keep this many completed Activity Center entries per environment.",
"activity_history_max_entries_placeholder": "1000",
"activity_history_max_entries_help": "Set to 0 to disable count-based cleanup.",
+ "activity_max_concurrent": "Concurrent Activity Limit",
+ "activity_max_concurrent_description": "Maximum long-running activities per environment before new ones wait in a queue.",
+ "activity_max_concurrent_placeholder": "5",
+ "activity_max_concurrent_help": "Set to 0 for unlimited concurrency.",
"activity_scan_phase_creating_container": "Creating container",
"activity_scan_phase_scanning_image": "Scanning image",
"activity_scan_phase_storing_results": "Storing results",
+ "activity_section_running": "Running",
+ "activity_section_history": "History",
+ "activity_search_placeholder": "Search activity…",
+ "activity_filters_label": "Filter",
+ "activity_filter_status": "Status",
+ "activity_filter_type": "Type",
+ "activity_no_results_title": "No matching activity",
+ "activity_no_results_description": "Nothing matches your search or filters.",
+ "activity_batch_items": "{count} items",
+ "activity_batch_done_of_total": "{done}/{total} done",
+ "activity_batch_failed_count": "{count} failed",
+ "activity_more_options": "More options",
+ "activity_toast_success": "{name} completed",
+ "activity_toast_failed": "{name} failed",
+ "activity_toast_batch_success": "{type}: {count} completed",
+ "activity_toast_batch_partial": "{type}: {failed} of {total} failed",
+ "activity_toast_view": "View",
+ "activity_completion_toasts_label": "Completion notifications",
"version_info_title": "About Arcane",
"version_info_tag": "Image Tag",
"version_info_full_commit": "Full Commit Hash",
diff --git a/frontend/src/lib/components/activity/activity-batch-item.svelte b/frontend/src/lib/components/activity/activity-batch-item.svelte
new file mode 100644
index 000000000..a7c355421
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-batch-item.svelte
@@ -0,0 +1,93 @@
+<script lang="ts">
+ import { Progress } from '$lib/components/ui/progress/index.js';
+ import { Badge } from '$lib/components/ui/badge';
+ import { ArrowDownIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+ import type { ActivityBatchGroup, ActivityStatus } from '$lib/types/activity.type';
+ import { activityStatusLabel, activityStatusVariant, activityTypeIcon, activityTypeLabel } from './activity-labels';
+
+ let {
+ group,
+ expanded = false
+ }: {
+ group: ActivityBatchGroup;
+ expanded?: boolean;
+ } = $props();
+
+ // Batch groups are constructed with at least one member.
+ const leadActivity = $derived(group.items[0]!);
+ const IconComponent = $derived(activityTypeIcon(leadActivity.type));
+ const isActive = $derived(group.status === 'running' || group.status === 'queued');
+
+ function statusAccentClass(status: ActivityStatus): string {
+ switch (status) {
+ case 'failed':
+ return 'bg-red-500';
+ case 'running':
+ return 'bg-blue-500';
+ case 'queued':
+ return 'bg-amber-500';
+ case 'success':
+ return 'bg-emerald-500';
+ case 'cancelled':
+ return 'bg-muted-foreground/40';
+ }
+ }
+</script>
+
+<div
+ class={cn(
+ 'group relative grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 border-b border-border/40 px-4 py-3 text-left transition-colors last:border-b-0 hover:bg-muted/30',
+ expanded && 'bg-muted/40'
+ )}
+>
+ <span
+ aria-hidden="true"
+ class={cn(
+ 'absolute top-2 bottom-2 left-0 rounded-r-full transition-all',
+ statusAccentClass(group.status),
+ expanded ? 'w-1' : 'w-0.5'
+ )}
+ ></span>
+
+ <div
+ class={cn(
+ 'mt-0.5 flex size-8 items-center justify-center rounded-md bg-muted/80 text-muted-foreground',
+ (isActive || expanded) && 'bg-primary/10 text-primary'
+ )}
+ >
+ <IconComponent class="size-4" aria-hidden="true" />
+ </div>
+ <div class="min-w-0 space-y-1.5">
+ <div class="flex min-w-0 items-start justify-between gap-3">
+ <div class="min-w-0 flex-1">
+ <div class="flex min-w-0 items-center gap-2">
+ <span class="truncate text-sm font-semibold text-foreground">{activityTypeLabel(leadActivity.type)}</span>
+ <span class="shrink-0 text-[11px] text-muted-foreground/70">· {m.activity_batch_items({ count: group.total })}</span>
+ </div>
+ <div class="flex min-w-0 flex-wrap items-center gap-x-1.5 text-xs text-muted-foreground">
+ <span>{m.activity_batch_done_of_total({ done: group.done, total: group.total })}</span>
+ {#if group.failed > 0}
+ <span class="text-muted-foreground/50">·</span>
+ <span class="text-red-500">{m.activity_batch_failed_count({ count: group.failed })}</span>
+ {/if}
+ </div>
+ </div>
+ <Badge variant={activityStatusVariant(group.status)} size="sm">{activityStatusLabel(group.status)}</Badge>
+ </div>
+
+ {#if isActive}
+ <div class="flex items-center gap-2">
+ <Progress value={group.progress ?? 0} class="h-1.5 rounded-full" />
+ <span class="w-9 shrink-0 text-right text-[11px] text-muted-foreground tabular-nums">
+ {m.activity_progress_percent({ progress: group.progress ?? 0 })}
+ </span>
+ </div>
+ {/if}
+ </div>
+
+ <div class="mt-1 flex size-6 shrink-0 items-center justify-center text-muted-foreground">
+ <ArrowDownIcon class={cn('size-4 transition-transform duration-200', expanded && 'rotate-180')} aria-hidden="true" />
+ </div>
+</div>
diff --git a/frontend/src/lib/components/activity/activity-center.svelte b/frontend/src/lib/components/activity/activity-center.svelte
index 0d380763a..121d0ff90 100644
--- a/frontend/src/lib/components/activity/activity-center.svelte
+++ b/frontend/src/lib/components/activity/activity-center.svelte
@@ -2,21 +2,23 @@
import { onMount } from 'svelte';
import ResponsiveDialog from '$lib/components/ui/responsive-dialog/responsive-dialog.svelte';
import * as Collapsible from '$lib/components/ui/collapsible/index.js';
+ import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';
+ import { Input } from '$lib/components/ui/input/index.js';
import ActivityListItem from './activity-list-item.svelte';
+ import ActivityBatchItem from './activity-batch-item.svelte';
import ActivityDetailPanel from './activity-detail-panel.svelte';
+ import ActivityFilterPopover from './activity-filter-popover.svelte';
import { activityStore } from '$lib/stores/activity.store.svelte';
- import type { ActivityFilter } from '$lib/types/activity.type';
- import { ActivityIcon, AlertTriangleIcon, CloseIcon, RefreshIcon, TrashIcon } from '$lib/icons';
+ import type { Activity, ActivityGroup } from '$lib/types/activity.type';
+ import { ActivityIcon, AlertTriangleIcon, CloseIcon, EllipsisIcon, RefreshIcon, SearchIcon, TrashIcon } from '$lib/icons';
import { m } from '$lib/paraglide/messages';
import { cn } from '$lib/utils';
- import { activityFilterLabel } from './activity-labels';
import { confirmCancelActivity } from './activity-cancel';
+ import { activityCompletionToastsEnabled } from './activity-completion-toasts';
import { openConfirmDialog } from '$lib/components/confirm-dialog';
import { toast } from 'svelte-sonner';
import IfPermitted from '$lib/components/if-permitted.svelte';
- const filters: ActivityFilter[] = ['running', 'failed', 'completed'];
-
onMount(() => {
void activityStore.start();
return () => activityStore.stop();
@@ -54,8 +56,85 @@
}
});
}
+
+ function groupKeyInternal(group: ActivityGroup): string {
+ return group.kind === 'batch' ? `batch:${group.batchId}` : group.activity.id;
+ }
+
+ const hasNoResults = $derived(
+ activityStore.activities.length > 0 &&
+ activityStore.hasActiveFilters &&
+ activityStore.runningGroups.length === 0 &&
+ activityStore.historyGroups.length === 0
+ );
</script>
+{#snippet activityRow(activity: Activity, child: boolean)}
+ {@const expanded = activityStore.isExpanded(activity.id)}
+ {@const cancelable = activity.status === 'running' || activity.status === 'queued'}
+ <div class="group/activity relative">
+ <Collapsible.Root open={expanded} onOpenChange={(open) => activityStore.setActivityExpanded(activity.id, open)}>
+ <Collapsible.Trigger
+ class="block w-full cursor-pointer appearance-none border-0 bg-transparent p-0 text-left focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden focus-visible:ring-inset"
+ aria-label={m.activity_center_title()}
+ >
+ <ActivityListItem {activity} {expanded} {child} />
+ </Collapsible.Trigger>
+ <Collapsible.Content
+ class="overflow-hidden data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-1 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-top-1"
+ >
+ <ActivityDetailPanel {activity} />
+ </Collapsible.Content>
+ </Collapsible.Root>
+ {#if cancelable}
+ <IfPermitted perm="activities:cancel">
+ <button
+ type="button"
+ onclick={() => confirmCancelActivity(activity.id)}
+ disabled={activityStore.isCancelling(activity.id)}
+ title={m.activity_cancel()}
+ aria-label={m.activity_cancel()}
+ class="absolute top-1/2 right-11 z-[var(--arcane-z-raised)] flex size-7 -translate-y-1/2 items-center justify-center rounded-md bg-background/70 text-muted-foreground opacity-0 backdrop-blur-sm transition group-hover/activity:opacity-100 hover:bg-destructive/10 hover:text-destructive focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-40"
+ >
+ <CloseIcon class="size-4" aria-hidden="true" />
+ </button>
+ </IfPermitted>
+ {/if}
+ </div>
+{/snippet}
+
+{#snippet groupRow(group: ActivityGroup)}
+ {#if group.kind === 'single'}
+ {@render activityRow(group.activity, false)}
+ {:else}
+ {@const expanded = activityStore.isBatchExpanded(group.batchId)}
+ <Collapsible.Root open={expanded} onOpenChange={(open) => activityStore.setBatchExpanded(group.batchId, open)}>
+ <Collapsible.Trigger
+ class="block w-full cursor-pointer appearance-none border-0 bg-transparent p-0 text-left focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden focus-visible:ring-inset"
+ aria-label={m.activity_center_title()}
+ >
+ <ActivityBatchItem {group} {expanded} />
+ </Collapsible.Trigger>
+ <Collapsible.Content
+ class="overflow-hidden data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-1 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-top-1"
+ >
+ <div class="ml-6 border-l border-border/40">
+ {#each group.items as activity (activity.id)}
+ {@render activityRow(activity, true)}
+ {/each}
+ </div>
+ </Collapsible.Content>
+ </Collapsible.Root>
+ {/if}
+{/snippet}
+
+{#snippet sectionHeader(title: string, count: number)}
+ <div class="flex items-center gap-2 border-b border-border/50 bg-muted/20 px-4 py-1.5">
+ <span class="text-[11px] font-medium tracking-wide text-muted-foreground uppercase">{title}</span>
+ <span class="text-[11px] text-muted-foreground/70 tabular-nums">{count}</span>
+ </div>
+{/snippet}
+
<ResponsiveDialog
open={activityStore.open}
onOpenChange={handleOpenChangeInternal}
@@ -64,32 +143,28 @@
contentClass="w-[min(94vw,760px)] sm:max-w-[760px]"
class="flex min-h-0 flex-1 flex-col pt-3 pb-0"
>
- <div class="flex flex-wrap items-center justify-between gap-3 border-b border-border/60 px-4 py-3">
- <div class="flex min-w-0 items-center gap-2">
+ <div class="flex flex-wrap items-center gap-2 border-b border-border/60 px-4 py-3">
+ <div class="relative min-w-40 flex-1">
+ <SearchIcon
+ class="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground"
+ aria-hidden="true"
+ />
+ <Input
+ type="search"
+ value={activityStore.searchTerm}
+ oninput={(event) => activityStore.setSearchTerm(event.currentTarget.value)}
+ placeholder={m.activity_search_placeholder()}
+ class="h-8 pl-8 text-xs"
+ />
+ </div>
+
+ <div class="flex items-center gap-2">
{#if activityStore.activeCount > 0}
<span class="rounded-md bg-primary/10 px-2 py-1 text-xs font-semibold text-primary tabular-nums">
{m.activity_active_count({ count: activityStore.activeCount })}
</span>
{/if}
- </div>
-
- <div class="flex items-center gap-2">
- <div class="inline-flex rounded-md bg-muted/40 p-0.5">
- {#each filters as filter (filter)}
- <button
- type="button"
- onclick={() => activityStore.setFilter(filter)}
- class={cn(
- 'rounded-sm px-2.5 py-1 text-xs font-medium transition-colors',
- activityStore.filter === filter
- ? 'bg-background text-foreground shadow-xs'
- : 'text-muted-foreground hover:text-foreground'
- )}
- >
- {activityFilterLabel(filter)}
- </button>
- {/each}
- </div>
+ <ActivityFilterPopover />
<button
type="button"
onclick={() => activityStore.refresh()}
@@ -99,17 +174,31 @@
>
<RefreshIcon class={cn('size-4', activityStore.loading && 'animate-spin')} aria-hidden="true" />
</button>
- <IfPermitted perm="activities:delete">
- <button
- type="button"
- onclick={clearHistoryInternal}
- title={m.activity_clear_history()}
- aria-label={m.activity_clear_history()}
- class="flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
+ <DropdownMenu.Root>
+ <DropdownMenu.Trigger
+ title={m.activity_more_options()}
+ aria-label={m.activity_more_options()}
+ class="flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden"
>
- <TrashIcon class="size-4" aria-hidden="true" />
- </button>
- </IfPermitted>
+ <EllipsisIcon class="size-4" aria-hidden="true" />
+ </DropdownMenu.Trigger>
+ <DropdownMenu.Content align="end" class="w-56">
+ <DropdownMenu.CheckboxItem
+ checked={activityCompletionToastsEnabled.current}
+ onCheckedChange={(checked) => (activityCompletionToastsEnabled.current = checked)}
+ closeOnSelect={false}
+ >
+ {m.activity_completion_toasts_label()}
+ </DropdownMenu.CheckboxItem>
+ <IfPermitted perm="activities:delete">
+ <DropdownMenu.Separator />
+ <DropdownMenu.Item onclick={clearHistoryInternal} class="text-destructive data-highlighted:text-destructive">
+ <TrashIcon class="size-4" aria-hidden="true" />
+ {m.activity_clear_history()}
+ </DropdownMenu.Item>
+ </IfPermitted>
+ </DropdownMenu.Content>
+ </DropdownMenu.Root>
</div>
</div>
@@ -143,7 +232,7 @@
<p class="text-sm text-muted-foreground">{m.common_loading()}</p>
</div>
</div>
- {:else if activityStore.filteredActivities.length === 0}
+ {:else if activityStore.activities.length === 0}
<div class="flex min-h-96 items-center justify-center p-6 text-center">
<div class="max-w-56 space-y-2">
<ActivityIcon class="mx-auto size-9 text-muted-foreground/50" aria-hidden="true" />
@@ -151,41 +240,35 @@
<p class="text-xs leading-relaxed text-muted-foreground">{m.activity_empty_description()}</p>
</div>
</div>
+ {:else if hasNoResults}
+ <div class="flex min-h-96 items-center justify-center p-6 text-center">
+ <div class="max-w-56 space-y-2">
+ <SearchIcon class="mx-auto size-9 text-muted-foreground/50" aria-hidden="true" />
+ <h3 class="text-sm font-semibold">{m.activity_no_results_title()}</h3>
+ <p class="text-xs leading-relaxed text-muted-foreground">{m.activity_no_results_description()}</p>
+ <button
+ type="button"
+ onclick={() => activityStore.clearFilters()}
+ class="text-xs font-medium text-primary underline hover:text-primary/80"
+ >
+ {m.common_clear_filters()}
+ </button>
+ </div>
+ </div>
{:else}
<div>
- {#each activityStore.filteredActivities as activity (activity.id)}
- {@const expanded = activityStore.isExpanded(activity.id)}
- {@const cancelable = activity.status === 'running' || activity.status === 'queued'}
- <div class="group/activity relative">
- <Collapsible.Root open={expanded} onOpenChange={(open) => activityStore.setActivityExpanded(activity.id, open)}>
- <Collapsible.Trigger
- class="block w-full cursor-pointer appearance-none border-0 bg-transparent p-0 text-left focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden focus-visible:ring-inset"
- aria-label={m.activity_center_title()}
- >
- <ActivityListItem {activity} {expanded} />
- </Collapsible.Trigger>
- <Collapsible.Content
- class="overflow-hidden data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-1 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-top-1"
- >
- <ActivityDetailPanel {activity} />
- </Collapsible.Content>
- </Collapsible.Root>
- {#if cancelable}
- <IfPermitted perm="activities:cancel">
- <button
- type="button"
- onclick={() => confirmCancelActivity(activity.id)}
- disabled={activityStore.isCancelling(activity.id)}
- title={m.activity_cancel()}
- aria-label={m.activity_cancel()}
- class="absolute top-1/2 right-11 z-[var(--arcane-z-raised)] flex size-7 -translate-y-1/2 items-center justify-center rounded-md bg-background/70 text-muted-foreground opacity-0 backdrop-blur-sm transition group-hover/activity:opacity-100 hover:bg-destructive/10 hover:text-destructive focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-40"
- >
- <CloseIcon class="size-4" aria-hidden="true" />
- </button>
- </IfPermitted>
- {/if}
- </div>
- {/each}
+ {#if activityStore.runningGroups.length > 0}
+ {@render sectionHeader(m.activity_section_running(), activityStore.runningGroups.length)}
+ {#each activityStore.runningGroups as group (groupKeyInternal(group))}
+ {@render groupRow(group)}
+ {/each}
+ {/if}
+ {#if activityStore.historyGroups.length > 0}
+ {@render sectionHeader(m.activity_section_history(), activityStore.historyGroups.length)}
+ {#each activityStore.historyGroups as group (groupKeyInternal(group))}
+ {@render groupRow(group)}
+ {/each}
+ {/if}
</div>
{/if}
</div>
diff --git a/frontend/src/lib/components/activity/activity-completion-toasts.ts b/frontend/src/lib/components/activity/activity-completion-toasts.ts
new file mode 100644
index 000000000..f3aeaf6d5
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-completion-toasts.ts
@@ -0,0 +1,166 @@
+import { toast } from 'svelte-sonner';
+import { PersistedState } from 'runed';
+import { m } from '$lib/paraglide/messages';
+import type { Activity, ActivityType } from '$lib/types/activity.type';
+import { activityStore } from '$lib/stores/activity.store.svelte';
+import { activityTypeLabel } from './activity-labels';
+
+/**
+ * In-the-moment success/failure toasts for activities the current user
+ * started, shown when the Activity Center sheet is closed. Completions are
+ * buffered briefly and grouped (by batch, falling back to type+status) so a
+ * bulk operation produces one aggregated toast instead of one per item.
+ *
+ * Quick actions (container start/stop, project down, ...) are excluded: they
+ * complete within their HTTP request and the action call sites already show a
+ * response toast. Activities whose call site showed such a toast are also
+ * suppressed here (see markActivityToastShown) so nothing fires twice.
+ */
+
+export const activityCompletionToastsEnabled = new PersistedState<boolean>('arcane-activity-toasts', true);
+
+const DEBOUNCE_MS = 1500;
+const MAX_WAIT_MS = 4000;
+
+// How long a direct response toast suppresses the completion toast for the
+// same activity. Covers the debounce window plus response/stream skew.
+const SHOWN_SUPPRESSION_MS = 15_000;
+
+const LONG_RUNNING_TYPES = new Set<ActivityType>([
+ 'image_pull',
+ 'image_build',
+ 'image_update_check',
+ 'project_pull',
+ 'project_build',
+ 'project_deploy',
+ 'project_redeploy',
+ 'container_redeploy',
+ 'vulnerability_scan',
+ 'auto_update',
+ 'system_prune'
+]);
+
+let pending: Activity[] = [];
+let debounceTimer: ReturnType<typeof setTimeout> | null = null;
+let hardFlushTimer: ReturnType<typeof setTimeout> | null = null;
+const shownActivityIds = new Map<string, number>();
+
+// Records that the UI already showed a response toast for this activity, so
+// the stream-driven completion toast stays silent for it.
+export function markActivityToastShown(activityId: string | undefined) {
+ if (!activityId) {
+ return;
+ }
+ const now = Date.now();
+ for (const [id, shownAt] of shownActivityIds) {
+ if (now - shownAt > SHOWN_SUPPRESSION_MS) {
+ shownActivityIds.delete(id);
+ }
+ }
+ shownActivityIds.set(activityId, now);
+}
+
+function wasToastShownInternal(activityId: string): boolean {
+ const shownAt = shownActivityIds.get(activityId);
+ return shownAt !== undefined && Date.now() - shownAt <= SHOWN_SUPPRESSION_MS;
+}
+
+export function queueActivityCompletionToast(activity: Activity) {
+ if (!activityCompletionToastsEnabled.current) {
+ return;
+ }
+ if (!LONG_RUNNING_TYPES.has(activity.type)) {
+ return;
+ }
+ pending.push(activity);
+ if (debounceTimer) {
+ clearTimeout(debounceTimer);
+ }
+ debounceTimer = setTimeout(flushInternal, DEBOUNCE_MS);
+ // Cap how long a steady stream of completions can defer the first toast.
+ hardFlushTimer ??= setTimeout(flushInternal, MAX_WAIT_MS);
+}
+
+export function discardPendingActivityToasts() {
+ clearTimersInternal();
+ pending = [];
+}
+
+function clearTimersInternal() {
+ if (debounceTimer) {
+ clearTimeout(debounceTimer);
+ debounceTimer = null;
+ }
+ if (hardFlushTimer) {
+ clearTimeout(hardFlushTimer);
+ hardFlushTimer = null;
+ }
+}
+
+function flushInternal() {
+ clearTimersInternal();
+ const items = pending;
+ pending = [];
+ if (items.length === 0) {
+ return;
+ }
+
+ const groups = new Map<string, Activity[]>();
+ for (const activity of items) {
+ const key = activity.batchId ?? `${activity.type}:${activity.status}`;
+ const group = groups.get(key);
+ if (group) {
+ group.push(activity);
+ } else {
+ groups.set(key, [activity]);
+ }
+ }
+ for (const members of groups.values()) {
+ // A response toast (single or bulk summary) already covered this work.
+ if (members.some((activity) => wasToastShownInternal(activity.id))) {
+ continue;
+ }
+ emitGroupToastInternal(members);
+ }
+}
+
+// Container activities often carry a 64-char hex ID as their resource name;
+// show the familiar 12-char short ID instead.
+function shortenDockerIdInternal(value: string): string {
+ return /^[0-9a-f]{25,64}$/i.test(value) ? value.slice(0, 12) : value;
+}
+
+function emitGroupToastInternal(members: Activity[]) {
+ const first = members[0];
+ if (!first) {
+ return;
+ }
+
+ if (members.length === 1) {
+ const rawName = first.resourceName || first.resourceId || '';
+ const name = rawName ? shortenDockerIdInternal(rawName) : activityTypeLabel(first.type);
+ const action = viewActionInternal(first.id, first.batchId);
+ if (first.status === 'failed') {
+ toast.error(m.activity_toast_failed({ name }), { action });
+ } else {
+ toast.success(m.activity_toast_success({ name }), { action });
+ }
+ return;
+ }
+
+ const type = activityTypeLabel(first.type);
+ const failed = members.filter((activity) => activity.status === 'failed').length;
+ const action = viewActionInternal(undefined, first.batchId);
+ if (failed > 0) {
+ toast.error(m.activity_toast_batch_partial({ type, failed, total: members.length }), { action });
+ } else {
+ toast.success(m.activity_toast_batch_success({ type, count: members.length }), { action });
+ }
+}
+
+function viewActionInternal(activityId: string | undefined, batchId: string | undefined) {
+ return {
+ label: m.activity_toast_view(),
+ onClick: () => activityStore.openCenter(activityId, batchId)
+ };
+}
diff --git a/frontend/src/lib/components/activity/activity-filter-popover.svelte b/frontend/src/lib/components/activity/activity-filter-popover.svelte
new file mode 100644
index 000000000..796f57b2f
--- /dev/null
+++ b/frontend/src/lib/components/activity/activity-filter-popover.svelte
@@ -0,0 +1,99 @@
+<script lang="ts">
+ import * as Popover from '$lib/components/ui/popover/index.js';
+ import { activityStore } from '$lib/stores/activity.store.svelte';
+ import type { ActivityStatus, ActivityType } from '$lib/types/activity.type';
+ import { CheckIcon, FilterIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+ import { activityStatusLabel, activityTypeLabel } from './activity-labels';
+
+ const statuses: ActivityStatus[] = ['queued', 'running', 'success', 'failed', 'cancelled'];
+ const types: ActivityType[] = [
+ 'image_pull',
+ 'image_build',
+ 'image_update_check',
+ 'project_pull',
+ 'project_build',
+ 'project_deploy',
+ 'project_redeploy',
+ 'project_down',
+ 'project_restart',
+ 'project_destroy',
+ 'container_start',
+ 'container_stop',
+ 'container_restart',
+ 'container_redeploy',
+ 'container_delete',
+ 'vulnerability_scan',
+ 'auto_update',
+ 'system_prune',
+ 'resource_action'
+ ];
+</script>
+
+{#snippet filterOption(label: string, selected: boolean, toggle: () => void)}
+ <button
+ type="button"
+ onclick={toggle}
+ class="flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs transition-colors hover:bg-muted/60"
+ >
+ <span
+ class={cn(
+ 'flex size-3.5 shrink-0 items-center justify-center rounded-sm border border-primary',
+ selected ? 'bg-primary text-primary-foreground' : 'opacity-50 [&_svg]:invisible'
+ )}
+ >
+ <CheckIcon class="size-3" aria-hidden="true" />
+ </span>
+ <span class="truncate">{label}</span>
+ </button>
+{/snippet}
+
+<Popover.Root>
+ <Popover.Trigger
+ title={m.activity_filters_label()}
+ aria-label={m.activity_filters_label()}
+ class={cn(
+ 'relative flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-hidden',
+ activityStore.activeFilterCount > 0 && 'bg-primary/10 text-primary'
+ )}
+ >
+ <FilterIcon class="size-4" aria-hidden="true" />
+ {#if activityStore.activeFilterCount > 0}
+ <span
+ class="absolute -top-1 -right-1 flex size-4 items-center justify-center rounded-full bg-primary text-[10px] font-semibold text-primary-foreground tabular-nums"
+ >
+ {activityStore.activeFilterCount}
+ </span>
+ {/if}
+ </Popover.Trigger>
+ <Popover.Content class="max-h-[min(60vh,480px)] w-56 overflow-y-auto p-2" align="end">
+ <p class="px-2 pt-1 pb-1.5 text-[11px] font-medium tracking-wide text-muted-foreground uppercase">
+ {m.activity_filter_status()}
+ </p>
+ {#each statuses as status (status)}
+ {@render filterOption(activityStatusLabel(status), activityStore.statusFilters.includes(status), () =>
+ activityStore.toggleStatusFilter(status)
+ )}
+ {/each}
+ <p class="px-2 pt-3 pb-1.5 text-[11px] font-medium tracking-wide text-muted-foreground uppercase">
+ {m.activity_filter_type()}
+ </p>
+ {#each types as type (type)}
+ {@render filterOption(activityTypeLabel(type), activityStore.typeFilters.includes(type), () =>
+ activityStore.toggleTypeFilter(type)
+ )}
+ {/each}
+ {#if activityStore.activeFilterCount > 0}
+ <div class="mt-2 border-t border-border/50 pt-2">
+ <button
+ type="button"
+ onclick={() => activityStore.clearFilters()}
+ class="w-full cursor-pointer rounded-sm px-2 py-1.5 text-center text-xs font-medium text-primary transition-colors hover:bg-muted/60"
+ >
+ {m.common_clear_filters()}
+ </button>
+ </div>
+ {/if}
+ </Popover.Content>
+</Popover.Root>
diff --git a/frontend/src/lib/components/activity/activity-labels.ts b/frontend/src/lib/components/activity/activity-labels.ts
index 4cfea627b..a39f8f6f5 100644
--- a/frontend/src/lib/components/activity/activity-labels.ts
+++ b/frontend/src/lib/components/activity/activity-labels.ts
@@ -1,5 +1,5 @@
import { m } from '$lib/paraglide/messages';
-import type { ActivityFilter, ActivityStatus, ActivityType } from '$lib/types/activity.type';
+import type { ActivityStatus, ActivityType } from '$lib/types/activity.type';
import type { IconType } from '$lib/icons';
import {
ActivityIcon,
@@ -127,14 +127,3 @@ export function activityTypeIcon(type: ActivityType): IconType {
return ActivityIcon;
}
}
-
-export function activityFilterLabel(filter: ActivityFilter): string {
- switch (filter) {
- case 'running':
- return m.common_running();
- case 'failed':
- return m.common_failed();
- case 'completed':
- return m.completed();
- }
-}
diff --git a/frontend/src/lib/components/activity/activity-list-item.svelte b/frontend/src/lib/components/activity/activity-list-item.svelte
index 74eede5f1..f610f6e72 100644
--- a/frontend/src/lib/components/activity/activity-list-item.svelte
+++ b/frontend/src/lib/components/activity/activity-list-item.svelte
@@ -10,17 +10,22 @@
let {
activity,
- expanded = false
+ expanded = false,
+ child = false
}: {
activity: Activity;
expanded?: boolean;
+ /** Compact variant for rows nested inside a batch group. */
+ child?: boolean;
} = $props();
const IconComponent = $derived(activityTypeIcon(activity.type));
const hasProgress = $derived(typeof activity.progress === 'number');
const progressValue = $derived(Math.round(activity.progress ?? 0));
const isActive = $derived(activity.status === 'running' || activity.status === 'queued');
- const targetName = $derived(activity.resourceName || activity.resourceId || m.activity_unknown_target());
+ // Resource-less activities (e.g. prunes) promote the type label instead.
+ const resourceLabel = $derived(activity.resourceName || activity.resourceId || '');
+ const targetName = $derived(resourceLabel || activityTypeLabel(activity.type));
const subtitle = $derived(activity.latestMessage || activity.step || m.activity_no_message());
const sourceEnvironmentName = $derived(
activity.sourceEnvironmentName || activity.sourceEnvironmentId || activity.environmentId
@@ -48,7 +53,8 @@
<div
class={cn(
- 'group relative grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 border-b border-border/40 px-4 py-3 text-left transition-colors last:border-b-0 hover:bg-muted/30',
+ 'group relative grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 border-b border-border/40 text-left transition-colors last:border-b-0 hover:bg-muted/30',
+ child ? 'px-3 py-2' : 'px-4 py-3',
expanded && 'bg-muted/40'
)}
>
@@ -63,32 +69,37 @@
<div
class={cn(
- 'mt-0.5 flex size-8 items-center justify-center rounded-md bg-muted/80 text-muted-foreground',
+ 'mt-0.5 flex items-center justify-center rounded-md bg-muted/80 text-muted-foreground',
+ child ? 'size-6' : 'size-8',
isActive && 'bg-primary/10 text-primary',
expanded && 'bg-primary/10 text-primary'
)}
>
- <IconComponent class="size-4" aria-hidden="true" />
+ <IconComponent class={cn(child ? 'size-3.5' : 'size-4')} aria-hidden="true" />
</div>
<div class="min-w-0 space-y-1.5">
<div class="flex min-w-0 items-start justify-between gap-3">
<div class="min-w-0 flex-1">
<div class="flex min-w-0 items-center gap-2">
- <span class="truncate text-sm font-semibold text-foreground">{activityTypeLabel(activity.type)}</span>
+ <span class="truncate text-sm font-semibold text-foreground">{targetName}</span>
{#if relativeTime}
<span class="shrink-0 text-[11px] text-muted-foreground/70">· {relativeTime}</span>
{/if}
</div>
- <div class="truncate text-xs text-muted-foreground">{targetName}</div>
- <div class="flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] text-muted-foreground/80">
- {#if sourceEnvironmentName}
- <span class="truncate">{sourceEnvironmentName}</span>
- {/if}
- {#if startedByName}
- <span class="text-muted-foreground/50">·</span>
- <span class="truncate">{m.activity_started_by({ user: startedByName })}</span>
- {/if}
- </div>
+ {#if resourceLabel}
+ <div class="truncate text-xs text-muted-foreground">{activityTypeLabel(activity.type)}</div>
+ {/if}
+ {#if !child}
+ <div class="flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] text-muted-foreground/80">
+ {#if sourceEnvironmentName}
+ <span class="truncate">{sourceEnvironmentName}</span>
+ {/if}
+ {#if startedByName}
+ <span class="text-muted-foreground/50">·</span>
+ <span class="truncate">{m.activity_started_by({ user: startedByName })}</span>
+ {/if}
+ </div>
+ {/if}
</div>
<Badge variant={activityStatusVariant(activity.status)} size="sm">{activityStatusLabel(activity.status)}</Badge>
</div>
diff --git a/frontend/src/lib/services/api-service.ts b/frontend/src/lib/services/api-service.ts
index 21fcc389e..974c90f01 100644
--- a/frontend/src/lib/services/api-service.ts
+++ b/frontend/src/lib/services/api-service.ts
@@ -79,6 +79,22 @@ function extractServerMessage(data: any, includeErrors = false): string | undefi
return undefined;
}
+// Batch id applied to mutating requests STARTED synchronously inside
+// runWithActivityBatchId, so the backend groups the resulting activities under
+// one Activity Center row. The scope never spans an await: fn must kick off
+// its requests synchronously and return their promises, so an unrelated action
+// started from any other task can never inherit the batch id.
+let activeActivityBatchIdInternal: string | null = null;
+
+export function runWithActivityBatchId<T>(batchId: string, fn: () => T): T {
+ activeActivityBatchIdInternal = batchId;
+ try {
+ return fn();
+ } finally {
+ activeActivityBatchIdInternal = null;
+ }
+}
+
function isBodyInit(value: unknown): value is BodyInit {
return (
value instanceof FormData ||
@@ -274,9 +290,14 @@ class APIClient {
};
try {
+ const headers = new Headers(config.headers);
+ const isMutation = !['GET', 'HEAD'].includes(method.toUpperCase());
+ if (activeActivityBatchIdInternal && isMutation && !headers.has('X-Arcane-Batch-Id')) {
+ headers.set('X-Arcane-Batch-Id', activeActivityBatchIdInternal);
+ }
const options: KyOptions = {
method,
- headers: config.headers,
+ headers,
retry: config.retry ?? 0,
searchParams: config.params,
timeout: config.timeout ?? false
diff --git a/frontend/src/lib/stores/activity.store.svelte.ts b/frontend/src/lib/stores/activity.store.svelte.ts
index f4eeb261a..0db8bcf90 100644
--- a/frontend/src/lib/stores/activity.store.svelte.ts
+++ b/frontend/src/lib/stores/activity.store.svelte.ts
@@ -8,16 +8,20 @@ import {
} from '$lib/stores/environment-stream.svelte';
import type {
Activity,
+ ActivityBatchGroup,
ActivityClearHistorySummary,
ActivityDetail,
ActivityEnvironmentFailure,
- ActivityFilter,
+ ActivityGroup,
ActivityMessage,
ActivityStatus,
- ActivityStreamEvent
+ ActivityStreamEvent,
+ ActivityType
} from '$lib/types/activity.type';
import type { Environment } from '$lib/types/environment';
import userStore from '$lib/stores/user-store';
+import { get } from 'svelte/store';
+import { discardPendingActivityToasts, queueActivityCompletionToast } from '$lib/components/activity/activity-completion-toasts';
const ACTIVITY_LIST_LIMIT = 50;
const ACTIVITY_DETAIL_LIMIT = 500;
@@ -31,12 +35,16 @@ function sortActivitiesInternal(items: Activity[]): Activity[] {
const aActive = isActiveStatusInternal(a.status);
const bActive = isActiveStatusInternal(b.status);
if (aActive !== bActive) return aActive ? -1 : 1;
- return getActivitySortTimeInternal(b) - getActivitySortTimeInternal(a);
+ const diff = getActivitySortTimeInternal(b) - getActivitySortTimeInternal(a);
+ if (diff !== 0) return diff;
+ return b.id.localeCompare(a.id);
});
}
+// Mirrors the backend default order: active rows keep their immutable createdAt
+// so progress updates never reshuffle them; terminal rows sort by endedAt.
function getActivitySortTimeInternal(activity: Activity): number {
- const value = activity.updatedAt || activity.endedAt || activity.startedAt || activity.createdAt;
+ const value = activity.endedAt || activity.createdAt || activity.startedAt;
return value ? new Date(value).getTime() : 0;
}
@@ -44,15 +52,97 @@ function isActiveStatusInternal(status: ActivityStatus): boolean {
return status === 'queued' || status === 'running';
}
-function filterActivityInternal(activity: Activity, filter: ActivityFilter): boolean {
- switch (filter) {
- case 'running':
- return isActiveStatusInternal(activity.status);
- case 'failed':
- return activity.status === 'failed';
- case 'completed':
- return activity.status === 'success' || activity.status === 'cancelled';
+function activitySearchHaystackInternal(activity: Activity): string {
+ // Mirrors the backend LIKE search fields, plus the environment name.
+ return [
+ activity.type,
+ activity.resourceName,
+ activity.resourceId,
+ activity.latestMessage,
+ activity.step,
+ activity.error,
+ activity.sourceEnvironmentName
+ ]
+ .filter(Boolean)
+ .join('\n')
+ .toLowerCase();
+}
+
+// Groups consecutive-by-batch activities of an already-sorted list into
+// ActivityGroups. A batch group sits at the position of its first (newest)
+// member, so group positions inherit the stable activity ordering.
+function groupActivitiesInternal(items: Activity[]): ActivityGroup[] {
+ const groups: ActivityGroup[] = [];
+ const batches = new Map<string, ActivityBatchGroup>();
+ for (const activity of items) {
+ const batchId = activity.batchId;
+ if (!batchId) {
+ groups.push({ kind: 'single', activity });
+ continue;
+ }
+ const existing = batches.get(batchId);
+ if (existing) {
+ existing.items.push(activity);
+ continue;
+ }
+ const group: ActivityBatchGroup = {
+ kind: 'batch',
+ batchId,
+ items: [activity],
+ total: 0,
+ done: 0,
+ failed: 0,
+ status: 'running',
+ progress: null
+ };
+ batches.set(batchId, group);
+ groups.push(group);
+ }
+
+ for (const group of batches.values()) {
+ // A "batch" of one renders as a plain activity row.
+ const only = group.items.length === 1 ? group.items[0] : undefined;
+ if (only) {
+ const index = groups.indexOf(group);
+ groups[index] = { kind: 'single', activity: only };
+ continue;
+ }
+ finalizeBatchGroupInternal(group);
}
+ return groups;
+}
+
+function finalizeBatchGroupInternal(group: ActivityBatchGroup) {
+ group.total = group.items.length;
+ group.done = group.items.filter((item) => !isActiveStatusInternal(item.status)).length;
+ group.failed = group.items.filter((item) => item.status === 'failed').length;
+ if (group.items.some((item) => isActiveStatusInternal(item.status))) {
+ group.status = group.items.some((item) => item.status === 'running') ? 'running' : 'queued';
+ const memberProgress = group.items.map((item) =>
+ isActiveStatusInternal(item.status) ? clampBatchProgressInternal(item.progress) : 100
+ );
+ group.progress = Math.round(memberProgress.reduce((sum, value) => sum + value, 0) / group.total);
+ } else {
+ if (group.failed > 0) {
+ group.status = 'failed';
+ } else if (group.items.every((item) => item.status === 'cancelled')) {
+ group.status = 'cancelled';
+ } else {
+ group.status = 'success';
+ }
+ group.progress = 100;
+ }
+}
+
+function clampBatchProgressInternal(progress: number | null | undefined): number {
+ if (typeof progress !== 'number' || Number.isNaN(progress)) {
+ return 0;
+ }
+ return Math.min(100, Math.max(0, progress));
+}
+
+function groupStatusIsActiveInternal(group: ActivityGroup): boolean {
+ return group.kind === 'batch' ? isActiveStatusInternal(group.status) : isActiveStatusInternal(group.activity.status);
}
function sourceEnvironmentIdInternal(activity: Activity | null | undefined): string {
@@ -67,10 +157,41 @@ function createActivityStore() {
let _detailLoadingIds = $state<Record<string, boolean>>({});
let _detailErrorIds = $state<Record<string, boolean>>({});
let _cancellingIds = $state<Record<string, boolean>>({});
- let _filter = $state<ActivityFilter>('running');
+ let _expandedBatchIds = $state<Record<string, boolean>>({});
+ let _searchTerm = $state('');
+ let _statusFilters = $state<ActivityStatus[]>([]);
+ let _typeFilters = $state<ActivityType[]>([]);
let _open = $state(false);
let _currentEnvironmentId = $state(LOCAL_DOCKER_ENVIRONMENT_ID);
let sessionGeneration = 0;
+ // Last observed status per activity, for completion-toast transition
+ // detection. Intentionally non-reactive: only stream handling reads it.
+ const observedStatusById = new Map<string, ActivityStatus>();
+
+ // Toast when an activity this session observed as active reaches
+ // success/failed while the sheet is closed. Activities that first appear
+ // already terminal (history snapshots on load) and other users' work
+ // (schedulers, other admins) stay silent.
+ function noteActivityStatusInternal(activity: Activity) {
+ const prev = observedStatusById.get(activity.id);
+ observedStatusById.set(activity.id, activity.status);
+ if (!prev || !isActiveStatusInternal(prev) || prev === activity.status) {
+ return;
+ }
+ if (activity.status !== 'success' && activity.status !== 'failed') {
+ return;
+ }
+ if (_open) {
+ return;
+ }
+ // Only the initiating user's own actions toast — scheduled jobs and
+ // other users' work carry no/another userId and stay silent.
+ const currentUserId = get(userStore)?.id;
+ if (!activity.startedBy?.userId || !currentUserId || activity.startedBy.userId !== currentUserId) {
+ return;
+ }
+ queueActivityCompletionToast(activity);
+ }
const core = createEnvironmentStreamStore<ActivityEnvironmentState, ActivityStreamEvent>({
label: 'Activity',
@@ -181,6 +302,11 @@ function createActivityStore() {
const normalizedActivities = sortActivitiesInternal(
activities.map((activity) => normalizeActivityInternal(activity, environmentId))
);
+ // Remote environments only deliver snapshots, so transition detection
+ // for completion toasts has to happen here as well as in merges.
+ for (const activity of normalizedActivities) {
+ noteActivityStatusInternal(activity);
+ }
_environmentActivities = {
..._environmentActivities,
[environmentId]: normalizedActivities
@@ -206,11 +332,18 @@ function createActivityStore() {
}
}
_expandedActivityIds = nextExpanded;
+
+ for (const id of observedStatusById.keys()) {
+ if (!present.has(id)) {
+ observedStatusById.delete(id);
+ }
+ }
}
function mergeActivityInternal(activity: Activity) {
const environmentId = sourceEnvironmentIdInternal(activity);
const normalized = normalizeActivityInternal(activity, environmentId);
+ noteActivityStatusInternal(normalized);
const currentActivities = _environmentActivities[environmentId] ?? core.environmentState(environmentId)?.activities ?? [];
const index = currentActivities.findIndex((item) => item.id === normalized.id);
const activities = sortActivitiesInternal(
@@ -331,6 +464,19 @@ function createActivityStore() {
setActivityExpanded(activityId, !_expandedActivityIds[activityId]);
}
+ function setBatchExpandedInternal(batchId: string, expanded: boolean) {
+ if (!batchId) {
+ return;
+ }
+ if (expanded) {
+ _expandedBatchIds = { ..._expandedBatchIds, [batchId]: true };
+ } else {
+ const next = { ..._expandedBatchIds };
+ delete next[batchId];
+ _expandedBatchIds = next;
+ }
+ }
+
function environmentFailuresInternal(): ActivityEnvironmentFailure[] {
return Object.values(core.environmentStates)
.filter((state) => state.streamError)
@@ -341,18 +487,53 @@ function createActivityStore() {
}));
}
+ function matchesFiltersInternal(activity: Activity): boolean {
+ if (_statusFilters.length > 0 && !_statusFilters.includes(activity.status)) {
+ return false;
+ }
+ if (_typeFilters.length > 0 && !_typeFilters.includes(activity.type)) {
+ return false;
+ }
+ const term = _searchTerm.trim().toLowerCase();
+ if (term && !activitySearchHaystackInternal(activity).includes(term)) {
+ return false;
+ }
+ return true;
+ }
+
+ function filteredGroupsInternal(): ActivityGroup[] {
+ return groupActivitiesInternal(_activities.filter(matchesFiltersInternal));
+ }
+
return {
get activities(): Activity[] {
return _activities;
},
- get filteredActivities(): Activity[] {
- return _activities.filter((activity) => filterActivityInternal(activity, _filter));
+ // A batch containing any active member renders once, in the running
+ // section, so completing members never duplicate into history early.
+ get runningGroups(): ActivityGroup[] {
+ return filteredGroupsInternal().filter(groupStatusIsActiveInternal);
+ },
+ get historyGroups(): ActivityGroup[] {
+ return filteredGroupsInternal().filter((group) => !groupStatusIsActiveInternal(group));
},
get activeCount(): number {
return _activities.filter((activity) => isActiveStatusInternal(activity.status)).length;
},
- get filter(): ActivityFilter {
- return _filter;
+ get searchTerm(): string {
+ return _searchTerm;
+ },
+ get statusFilters(): ActivityStatus[] {
+ return _statusFilters;
+ },
+ get typeFilters(): ActivityType[] {
+ return _typeFilters;
+ },
+ get hasActiveFilters(): boolean {
+ return _searchTerm.trim() !== '' || _statusFilters.length > 0 || _typeFilters.length > 0;
+ },
+ get activeFilterCount(): number {
+ return _statusFilters.length + _typeFilters.length;
},
get open(): boolean {
return _open;
@@ -375,6 +556,10 @@ function createActivityStore() {
isExpanded(activityId: string): boolean {
return !!_expandedActivityIds[activityId];
},
+ isBatchExpanded(batchId: string): boolean {
+ return !!_expandedBatchIds[batchId];
+ },
+ setBatchExpanded: setBatchExpandedInternal,
isDetailLoading(activityId: string): boolean {
return !!_detailLoadingIds[activityId];
},
@@ -399,14 +584,19 @@ function createActivityStore() {
const wasStarted = core.stop(options);
if (options?.resetState) {
sessionGeneration += 1;
+ observedStatusById.clear();
+ discardPendingActivityToasts();
_activities = [];
_environmentActivities = {};
_details = {};
_expandedActivityIds = {};
+ _expandedBatchIds = {};
_detailLoadingIds = {};
_detailErrorIds = {};
_cancellingIds = {};
- _filter = 'running';
+ _searchTerm = '';
+ _statusFilters = [];
+ _typeFilters = [];
_open = false;
_currentEnvironmentId = LOCAL_DOCKER_ENVIRONMENT_ID;
}
@@ -468,17 +658,37 @@ function createActivityStore() {
failed
};
},
- setFilter: (filter: ActivityFilter) => {
- _filter = filter;
+ setSearchTerm: (term: string) => {
+ _searchTerm = term;
+ },
+ toggleStatusFilter: (status: ActivityStatus) => {
+ _statusFilters = _statusFilters.includes(status)
+ ? _statusFilters.filter((item) => item !== status)
+ : [..._statusFilters, status];
+ },
+ toggleTypeFilter: (type: ActivityType) => {
+ _typeFilters = _typeFilters.includes(type) ? _typeFilters.filter((item) => item !== type) : [..._typeFilters, type];
+ },
+ clearFilters: () => {
+ _searchTerm = '';
+ _statusFilters = [];
+ _typeFilters = [];
},
setOpen: (open: boolean) => {
_open = open;
+ if (open) {
+ discardPendingActivityToasts();
+ }
},
- openCenter: (activityId?: string) => {
+ openCenter: (activityId?: string, batchId?: string) => {
_open = true;
+ discardPendingActivityToasts();
if (activityId) {
setActivityExpanded(activityId, true);
}
+ if (batchId) {
+ setBatchExpandedInternal(batchId, true);
+ }
},
retryLoadDetail: (activityId: string) => {
const nextErrors = { ..._detailErrorIds };
diff --git a/frontend/src/lib/types/activity.type.ts b/frontend/src/lib/types/activity.type.ts
index 8c158bfbc..786e5b150 100644
--- a/frontend/src/lib/types/activity.type.ts
+++ b/frontend/src/lib/types/activity.type.ts
@@ -23,11 +23,10 @@ export type ActivityType =
export type ActivityMessageLevel = 'info' | 'warning' | 'error' | 'success';
-export type ActivityFilter = 'running' | 'failed' | 'completed';
-
export interface Activity {
id: string;
environmentId: string;
+ batchId?: string;
sourceEnvironmentId?: string;
sourceEnvironmentName?: string;
type: ActivityType;
@@ -68,6 +67,19 @@ export interface ActivityDetail {
messages: ActivityMessage[];
}
+export interface ActivityBatchGroup {
+ kind: 'batch';
+ batchId: string;
+ items: Activity[];
+ total: number;
+ done: number;
+ failed: number;
+ status: ActivityStatus;
+ progress: number | null;
+}
+
+export type ActivityGroup = { kind: 'single'; activity: Activity } | ActivityBatchGroup;
+
export interface ActivityClearHistoryResult {
deleted: number;
}
diff --git a/frontend/src/lib/types/settings.ts b/frontend/src/lib/types/settings.ts
index 47c5dbd64..2d506fa79 100644
--- a/frontend/src/lib/types/settings.ts
+++ b/frontend/src/lib/types/settings.ts
@@ -20,6 +20,7 @@ export type Settings = {
environmentHealthInterval: number;
activityHistoryRetentionDays: number;
activityHistoryMaxEntries: number;
+ maxConcurrentActivities: number;
defaultDeployPullPolicy: 'missing' | 'always' | 'never';
scheduledPruneEnabled?: boolean;
scheduledPruneInterval?: number;
diff --git a/frontend/src/lib/utils/activity-toast.ts b/frontend/src/lib/utils/activity-toast.ts
index fdf978fe9..0aee0dfa1 100644
--- a/frontend/src/lib/utils/activity-toast.ts
+++ b/frontend/src/lib/utils/activity-toast.ts
@@ -1,4 +1,5 @@
import { activityStore } from '$lib/stores/activity.store.svelte';
+import { markActivityToastShown } from '$lib/components/activity/activity-completion-toasts';
import { m } from '$lib/paraglide/messages';
export function activityToastOptions(activityId?: string) {
@@ -6,6 +7,10 @@ export function activityToastOptions(activityId?: string) {
return undefined;
}
+ // The caller is about to show a response toast for this activity; keep the
+ // stream-driven completion toast from duplicating it.
+ markActivityToastShown(activityId);
+
return {
action: {
label: m.activity_view_activity(),
diff --git a/frontend/src/lib/utils/bulk-actions.ts b/frontend/src/lib/utils/bulk-actions.ts
index f348c5c00..e6ccee342 100644
--- a/frontend/src/lib/utils/bulk-actions.ts
+++ b/frontend/src/lib/utils/bulk-actions.ts
@@ -1,5 +1,7 @@
import { toast } from 'svelte-sonner';
import { openConfirmDialog } from '$lib/components/confirm-dialog';
+import { markActivityToastShown } from '$lib/components/activity/activity-completion-toasts';
+import { runWithActivityBatchId } from '$lib/services/api-service';
import { handleApiResultWithCallbacks, tryCatch, type Result } from '$lib/utils/api';
import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
@@ -62,30 +64,46 @@ async function runBulkOperation<T>({
if (total === 0) return result;
let firstActivityId: string | undefined;
+ const activityIds: string[] = [];
const tally = (id: string, outcome: Result<T>) => {
if (outcome.error) {
result.failed += 1;
onItemFailure?.(id);
} else {
result.success += 1;
- if (!firstActivityId) firstActivityId = extractActivityId(outcome.data);
+ const activityId = extractActivityId(outcome.data);
+ if (activityId) {
+ activityIds.push(activityId);
+ firstActivityId ??= activityId;
+ }
}
};
setLoading?.(true);
try {
+ // Multi-item runs share a batch id so the Activity Center renders one
+ // batch row. Each request is STARTED inside the synchronous batch scope
+ // (awaited outside it), so concurrent unrelated actions never inherit it.
+ const batchId = total > 1 ? crypto.randomUUID() : null;
+ const startRun = (id: string) => (batchId ? runWithActivityBatchId(batchId, () => tryCatch(run(id))) : tryCatch(run(id)));
if (sequential) {
for (const id of ids) {
- tally(id, await tryCatch(run(id)));
+ tally(id, await startRun(id));
}
} else {
- const outcomes = await Promise.all(ids.map(async (id) => [id, await tryCatch(run(id))] as const));
+ const outcomes = await Promise.all(ids.map(async (id) => [id, await startRun(id)] as const));
for (const [id, outcome] of outcomes) tally(id, outcome);
}
} finally {
setLoading?.(false);
}
+ // The summary toast below covers every spawned activity; suppress the
+ // per-activity completion toasts for all of them, not just the linked one.
+ for (const activityId of activityIds) {
+ markActivityToastShown(activityId);
+ }
+
if (result.failed === 0) {
toast.success(messages.success(result.success), activityToastOptions(firstActivityId));
} else if (result.success > 0) {
diff --git a/frontend/src/routes/(app)/settings/activity/+page.svelte b/frontend/src/routes/(app)/settings/activity/+page.svelte
index 20d94ed19..861a0e9f9 100644
--- a/frontend/src/routes/(app)/settings/activity/+page.svelte
+++ b/frontend/src/routes/(app)/settings/activity/+page.svelte
@@ -15,14 +15,16 @@
const formSchema = z.object({
activityHistoryRetentionDays: z.coerce.number().int().min(0).max(3650),
- activityHistoryMaxEntries: z.coerce.number().int().min(0).max(100000)
+ activityHistoryMaxEntries: z.coerce.number().int().min(0).max(100000),
+ maxConcurrentActivities: z.coerce.number().int().min(0).max(1000)
});
const getFormDefaults = () => {
const settings = $settingsStore || data.settings!;
return {
activityHistoryRetentionDays: settings.activityHistoryRetentionDays,
- activityHistoryMaxEntries: settings.activityHistoryMaxEntries
+ activityHistoryMaxEntries: settings.activityHistoryMaxEntries,
+ maxConcurrentActivities: settings.maxConcurrentActivities
};
};
@@ -84,6 +86,25 @@
</div>
</div>
</div>
+
+ <div class="border-t pt-6">
+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">
+ <div>
+ <Label class="text-base">{m.activity_max_concurrent()}</Label>
+ <p class="mt-1 text-sm text-muted-foreground">{m.activity_max_concurrent_description()}</p>
+ </div>
+ <div class="max-w-xs">
+ <TextInputWithLabel
+ bind:value={$formInputs.maxConcurrentActivities.value}
+ error={$formInputs.maxConcurrentActivities.error}
+ label={m.activity_max_concurrent()}
+ placeholder={m.activity_max_concurrent_placeholder()}
+ helpText={m.activity_max_concurrent_help()}
+ type="number"
+ />
+ </div>
+ </div>
+ </div>
</div>
</div>
</div>
diff --git a/tests/spec/activity-center.spec.ts b/tests/spec/activity-center.spec.ts
index bf1a1b7ac..e5b8cc99b 100644
--- a/tests/spec/activity-center.spec.ts
+++ b/tests/spec/activity-center.spec.ts
@@ -340,7 +340,6 @@ test.describe('Activity Center', () => {
await expect(page.getByRole('heading', { name: 'Environment Board' })).toBeVisible();
const activityCenter = await openActivityCenter(page);
- await activityCenter.getByRole('button', { name: 'Completed' }).click();
await expect(activityRow(activityCenter, 'remote-network')).toBeVisible();
await expect(activityRow(activityCenter, 'local-network')).toHaveCount(0);
await expect.poll(() => activityReads).toContain('remote-activity-test');
@@ -417,14 +416,12 @@ test.describe('Activity Center', () => {
await page.goto('/dashboard');
let activityCenter = await openActivityCenter(page);
- await activityCenter.getByRole('button', { name: 'Completed' }).click();
await expect(activityRow(activityCenter, 'user-a-private-activity')).toBeVisible();
await page.goto('/logout');
await page.waitForURL('/dashboard');
await expect.poll(() => streamedUsers).toContain('user-b');
activityCenter = await openActivityCenter(page);
- await activityCenter.getByRole('button', { name: 'Completed' }).click();
await expect(activityRow(activityCenter, 'user-b-activity')).toBeVisible();
await expect(activityRow(activityCenter, 'user-a-private-activity')).toHaveCount(0);
});
@@ -445,7 +442,6 @@ test.describe('Activity Center', () => {
await page.waitForLoadState('load');
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();
@@ -481,7 +477,6 @@ test.describe('Activity Center', () => {
});
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();
@@ -528,7 +523,8 @@ test.describe('Activity Center', () => {
await page.waitForLoadState('load');
const activityCenter = await openActivityCenter(page);
- await activityCenter.getByRole('button', { name: 'Clear history' }).click();
+ await activityCenter.getByRole('button', { name: 'More options' }).click();
+ await page.getByRole('menuitem', { 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']);
@@ -547,9 +543,9 @@ test.describe('Activity Center', () => {
expect(created.activityId).toBeTruthy();
const activityCenter = await openActivityCenter(page);
- await expect(activityCenter.getByRole('button', { name: 'Running' })).toBeVisible();
- await expect(activityCenter.getByRole('button', { name: 'Failed' })).toBeVisible();
- await activityCenter.getByRole('button', { name: 'Completed' }).click();
+ await expect(activityCenter.getByPlaceholder('Search activity…')).toBeVisible();
+ await expect(activityCenter.getByRole('button', { name: 'Filter' })).toBeVisible();
+ await expect(activityCenter.getByText('History', { exact: true })).toBeVisible();
const activityItem = activityCenter
.locator('button[aria-label="Activity Center"]')
@@ -562,11 +558,14 @@ test.describe('Activity Center', () => {
await expect(activityItem).toContainText('Started by');
await activityItem.click();
- await expect(activityCenter.getByText('Output', { exact: true })).toBeVisible();
- await expect(activityCenter.getByText('Creating network').first()).toBeVisible();
- await expect(activityCenter.getByText('Network created successfully').first()).toBeVisible();
- await expect(activityCenter.getByText('Source environment')).toBeVisible();
- await expect(activityCenter.getByText('Started by', { exact: true })).toBeVisible();
+ // Collapsed rows keep their (hidden) detail panels mounted, so scope
+ // the assertions to the expanded panel.
+ const detailPanel = activityCenter.locator('[data-collapsible-content][data-state="open"]');
+ await expect(detailPanel.getByText('Output', { exact: true })).toBeVisible();
+ await expect(detailPanel.getByText('Creating network').first()).toBeVisible();
+ await expect(detailPanel.getByText('Network created successfully').first()).toBeVisible();
+ await expect(detailPanel.getByText('Source environment')).toBeVisible();
+ await expect(detailPanel.getByText('Started by', { exact: true })).toBeVisible();
} finally {
await removeNetworkViaApi(page, networkId);
}
diff --git a/types/activity/activity.go b/types/activity/activity.go
index 48f1a3016..8e27a42bd 100644
--- a/types/activity/activity.go
+++ b/types/activity/activity.go
@@ -48,6 +48,7 @@ const (
type Activity struct {
ID string `json:"id"`
EnvironmentID string `json:"environmentId"`
+ BatchID *string `json:"batchId,omitempty"`
SourceEnvironmentID string `json:"sourceEnvironmentId,omitempty"`
SourceEnvironmentName string `json:"sourceEnvironmentName,omitempty"`
Type Type `json:"type"`
diff --git a/types/settings/settings.go b/types/settings/settings.go
index d07d576b8..29d8e03a5 100644
--- a/types/settings/settings.go
+++ b/types/settings/settings.go
@@ -104,6 +104,11 @@ type Update struct {
// Required: false
ActivityHistoryMaxEntries *string `json:"activityHistoryMaxEntries,omitempty"`
+ // MaxConcurrentActivities is the maximum long-running activities per environment before new ones queue (0 = unlimited).
+ //
+ // Required: false
+ MaxConcurrentActivities *string `json:"maxConcurrentActivities,omitempty"`
+
// DefaultDeployPullPolicy is the default image pull policy used for project deploys.
//
// Required: false