diff --git a/components/ws-manager-bridge/src/bridge.ts b/components/ws-manager-bridge/src/bridge.ts index 5546b2a1678f58..623f769e1618f9 100644 --- a/components/ws-manager-bridge/src/bridge.ts +++ b/components/ws-manager-bridge/src/bridge.ts @@ -618,12 +618,18 @@ export class WorkspaceManagerBridge implements Disposable { protected async markWorkspaceInstanceAsStopped(ctx: TraceContext, info: RunningWorkspaceInfo, now: Date) { const nowISO = now.toISOString(); - info.latestInstance.stoppingTime = nowISO; + if (!info.latestInstance.stoppingTime) { + info.latestInstance.stoppingTime = nowISO; + } info.latestInstance.stoppedTime = nowISO; info.latestInstance.status.message = `Stopped by ws-manager-bridge. Previously in phase ${info.latestInstance.status.phase}`; info.latestInstance.status.phase = "stopped"; await this.workspaceDB.trace(ctx).storeInstance(info.latestInstance); + // cleanup + // important: call this after the DB update + await this.onInstanceStopped(ctx, info.workspace.ownerId, info.latestInstance); + await this.messagebus.notifyOnInstanceUpdate(ctx, info.workspace.ownerId, info.latestInstance); await this.prebuildUpdater.stopPrebuildInstance(ctx, info.latestInstance); }